PrivacyAgreementDialog.java
5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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.TimerUtils;
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;
private boolean doubleClickFlag = false;
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) {
if (!isDobuleClick()) {
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);
}
boolean isDobuleClick() {
if (!this.doubleClickFlag) {
this.doubleClickFlag = true;
TimerUtils.setTimeout(()->{
this.doubleClickFlag = false;
}, 500);
return false;
}
return true;
}
@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);
}
}
}