Commit b0d80ead by amateur

1

1 parent 74ac7982
No preview for this file type
package com.polysoft.nafmii.fragment.dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import com.alibaba.fastjson.JSON;
import com.polysoft.nafmii.bean.OpenUrlBean;
import com.polysoft.nafmii.utils.ToastUtils;
import com.whaty.nafmii.BuildConfig;
import com.whaty.nafmii.R;
import com.whaty.nafmii.activity.IActivityEvent;
import com.whaty.nafmii.activity.OutsideWebviewActivity;
public class PrivacyAgreementDialog extends DialogFragment implements View.OnClickListener {
private CheckBox mAgree;
public static void show(FragmentManager manager) {
DialogFragment dialog = new PrivacyAgreementDialog();
dialog.show(manager, "privacy");
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.setCancelable(false);
View view = inflater.inflate(R.layout.privacy_dialog, container, false);
view.findViewById(R.id.privacy_btn_cancel).setOnClickListener(this);
view.findViewById(R.id.privacy_btn_ok).setOnClickListener(this);
this.mAgree = view.findViewById(R.id.privacy_checkbox);
this.setTextInfo(view.findViewById(R.id.privacy_text));
return view;
}
void setTextInfo(TextView textView) {
LinkText[] links = new LinkText[]{
new LinkText("《隐私政策》", "#/user/service?type=1"),
new LinkText("《服务协议》", "#/user/service?type=1"),
};
String textStr = textView.getText().toString();
SpannableStringBuilder builder = new SpannableStringBuilder(textStr);
for (LinkText link : links) {
int index = textStr.indexOf(link.text);
if (index < 0) {
continue;
}
int colorId = getResources().getColor(R.color.theme_color, null);
ForegroundColorSpan colorSapn = new ForegroundColorSpan(colorId);
builder.setSpan(colorSapn, index, index + link.text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
link.gotoLinkUrl();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(colorId);
ds.setUnderlineText(false);
}
};
builder.setSpan(clickSpan, index, index + link.text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(getResources().getColor(android.R.color.transparent, null));
textView.setText(builder);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.privacy_btn_cancel:
// getActivity().finish();
System.exit(0);
break;
case R.id.privacy_btn_ok:
if (!this.mAgree.isChecked()) {
ToastUtils.showLong("请勾选同意");
return;
}
dismiss();
IActivityEvent event = (IActivityEvent) getActivity();
event.dispatchEvent(IActivityEvent.EVENT_PRIVACY_ARGEE);
break;
}
}
class LinkText {
public final String text;
public final String webUrl;
LinkText(String text, String url) {
this.text = text;
this.webUrl = BuildConfig.ONLINE_URL + url;
}
void gotoLinkUrl() {
Intent intent = new Intent(getActivity(), OutsideWebviewActivity.class);
OpenUrlBean bean = new OpenUrlBean();
bean.setLinkUrl(this.webUrl);
bean.setTitle(this.text);
bean.setNav("1");
intent.putExtra("data", JSON.toJSONString(bean));
getActivity().startActivity(intent);
}
}
}
......@@ -4,6 +4,7 @@ public interface IActivityEvent {
String EVENT_GUIDE = "EVENT_GUIDE";
String EVENT_ADVERTISEMENT = "EVENT_ADVERTISEMENT";
String EVENT_PRIVACY_ARGEE = "EVENT_PRIVACY_ARGEE";
void dispatchEvent(String event);
}
......@@ -10,6 +10,7 @@ import androidx.fragment.app.FragmentTransaction;
import com.polysoft.nafmii.constants.Constants;
import com.polysoft.nafmii.fragment.AdvertisementFragment;
import com.polysoft.nafmii.fragment.GuideFragment;
import com.polysoft.nafmii.fragment.dialog.PrivacyAgreementDialog;
import com.polysoft.nafmii.utils.IntentUtils;
import com.polysoft.nafmii.utils.PermissionUtils;
import com.polysoft.nafmii.utils.SpUtils;
......@@ -29,8 +30,12 @@ public class MainActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!isFirstRun()) {
PrivacyAgreementDialog.show(getSupportFragmentManager());
} else {
this.checkAndRequestPermission();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
......@@ -46,6 +51,10 @@ public class MainActivity extends BaseActivity {
@Override
public void dispatchEvent(String event) {
if (IActivityEvent.EVENT_PRIVACY_ARGEE.equals(event)) {
this.checkAndRequestPermission();
return;
}
if (IActivityEvent.EVENT_GUIDE.equals(event)) {
SpUtils.putBoolean(Constants.FIRST_RUN_KEY, true);
} else if (IActivityEvent.EVENT_ADVERTISEMENT.equals(event)) {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" /> <!-- 设置圆角弧度 -->
<solid android:color="#ffffff" /> <!-- 设置背景颜色 -->
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" /> <!-- 设置圆角弧度 -->
<solid android:color="#fff" /> <!-- 设置背景颜色 -->
<size android:height="40dp" />
<stroke android:color="#ccc" android:width="1dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" /> <!-- 设置圆角弧度 -->
<solid android:color="@color/theme_color" /> <!-- 设置背景颜色 -->
<size android:height="40dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fitsSystemWindows="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dialog_bg_white_round"
android:orientation="vertical"
android:padding="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.497"
tools:ignore="MissingConstraints">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="20dp"
android:text="欢迎使用NAFMII之窗"
android:textColor="#333"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text1"
android:textColor="#666"
android:textSize="14sp" />
<TextView
android:id="@+id/privacy_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text2"
android:textColor="#666"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text3"
android:textColor="#666"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text4"
android:textColor="#666"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text5"
android:textColor="#666"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/privacy_dialog_text6"
android:textColor="#666"
android:textSize="14sp" />
<CheckBox
android:id="@+id/privacy_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:text="查看并同意《隐私政策》及《服务协议》"
android:textColor="#999"
android:textSize="13sp"
android:theme="@style/Theme.AppCompat.Light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/privacy_btn_cancel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/dialog_privacy_btn_round"
android:gravity="center"
android:text="不同意"
android:textColor="#999" />
<TextView
android:id="@+id/privacy_btn_ok"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/dialog_privacy_btn_round2"
android:gravity="center"
android:text="同意并继续"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -8,4 +8,10 @@
-->
<string name="hello_world">Hello Square World!</string>
<string name="retry"><u>重试</u></string>
<string name="privacy_dialog_text1">为了更好地保护您的权益,同时遵守相关监管要求,我们将通过《隐私政策》向您说明我们会如何收集、存储、保护和使用您的信息。</string>
<string name="privacy_dialog_text2">在您使用我们产品前,请务必仔细阅读《隐私政策》及《服务协议》。</string>
<string name="privacy_dialog_text3">重要权限说明:</string>
<string name="privacy_dialog_text4">1.为了保障您正常使用附件下载,您需要授权我们获取您文件读写权限;</string>
<string name="privacy_dialog_text5">2.为了保证您的账号安全,您需要授权我们读取本机识别码;</string>
<string name="privacy_dialog_text6">3.为了方便您使用头像上传及问题反馈,您需要授权我们获取您的相机/相册权限;</string>
</resources>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!