Skip to content

Commit c6556eb

Browse files
committed
fix(welcome):adjust the logic of selecting privacy and agreement
1 parent b5fb815 commit c6556eb

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zcshou.gogogo;
22

33
import android.Manifest;
4+
import android.annotation.SuppressLint;
45
import android.app.AlertDialog;
56
import android.content.Intent;
67
import android.content.SharedPreferences;
@@ -10,8 +11,10 @@
1011
import android.text.SpannableStringBuilder;
1112
import android.text.TextPaint;
1213
import android.text.method.LinkMovementMethod;
14+
import android.text.method.MovementMethod;
1315
import android.text.style.ClickableSpan;
1416
import android.view.Gravity;
17+
import android.view.MotionEvent;
1518
import android.view.View;
1619
import android.view.Window;
1720
import android.widget.Button;
@@ -106,16 +109,12 @@ private void checkDefaultPermissions() {
106109
ReqPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
107110
}
108111

109-
// if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
110-
// ReqPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
111-
// }
112-
113112
// 读取电话状态权限
114113
if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
115114
ReqPermissions.add(Manifest.permission.READ_PHONE_STATE);
116115
}
117116

118-
if (ReqPermissions.size() <= 0) {
117+
if (ReqPermissions.size() == 0) {
119118
isPermission = true;
120119
} else {
121120
requestPermissions(ReqPermissions.toArray(new String[0]), SDK_PERMISSION_REQUEST);
@@ -235,18 +234,44 @@ private void showPrivacyDialog() {
235234
}
236235
}
237236

237+
@SuppressLint("ClickableViewAccessibility")
238238
private void checkAgreementAndPrivacy() {
239239
preferences = getSharedPreferences(KEY_ACCEPT_AGREEMENT, MODE_PRIVATE);
240240
mPrivacy = preferences.getBoolean(KEY_ACCEPT_PRIVACY, false);
241241
mAgreement = preferences.getBoolean(KEY_ACCEPT_AGREEMENT, false);
242242

243243
checkBox = findViewById(R.id.check_agreement);
244+
// 拦截 CheckBox 的点击事件
245+
checkBox.setOnTouchListener((v, event) -> {
246+
if (v instanceof TextView) {
247+
TextView text = (TextView) v;
248+
MovementMethod method = text.getMovementMethod();
249+
if (method != null && text.getText() instanceof Spannable
250+
&& event.getAction() == MotionEvent.ACTION_UP) {
251+
if (method.onTouchEvent(text, (Spannable) text.getText(), event)) {
252+
event.setAction(MotionEvent.ACTION_CANCEL);
253+
}
254+
}
255+
}
256+
return false;
257+
});
258+
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
259+
if (isChecked) {
260+
if (!mPrivacy || !mAgreement) {
261+
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_read));
262+
checkBox.setChecked(false);
263+
}
264+
} else {
265+
mPrivacy = false;
266+
mAgreement = false;
267+
}
268+
});
244269

245270
String str = getString(R.string.app_agreement_privacy);
246271
SpannableStringBuilder builder = new SpannableStringBuilder(str);
247272
ClickableSpan clickSpanAgreement = new ClickableSpan() {
248273
@Override
249-
public void onClick( View widget) {
274+
public void onClick(@NonNull View widget) {
250275
showAgreementDialog();
251276
}
252277

@@ -261,7 +286,7 @@ public void updateDrawState(TextPaint ds) {
261286
builder.setSpan(clickSpanAgreement, agreement_start,agreement_end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
262287
ClickableSpan clickSpanPrivacy = new ClickableSpan() {
263288
@Override
264-
public void onClick( View widget) {
289+
public void onClick(@NonNull View widget) {
265290
showPrivacyDialog();
266291
}
267292

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"6. 如果用户自行安装本软件,即表明用户信任软件作者,自愿选择安装本软件,并接受本协议所有条款。 如果用户不接受本协议,请立即删除。\n"
2626
</string>
2727
<string name="app_agreement_privacy">已阅读《用户协议》和《隐私政策》</string>
28-
<string name="app_error_agreement">必须先接受《用户协议》和《隐私政策》</string>
28+
<string name="app_error_agreement">必须接受《用户协议》和《隐私政策》</string>
29+
<string name="app_error_read">请先阅读《用户协议》和《隐私政策》</string>
2930
<string name="app_error_gps">定位不可用,请检查 GPS 是否开启</string>
3031
<string name="app_error_network">网络不可用,请检查网络连接</string>
3132
<string name="app_error_permission">权限不足,请授予相关权限</string>

0 commit comments

Comments
 (0)