fix(welcome):adjust the logic of selecting privacy and agreement

This commit is contained in:
ZCShou 2023-12-17 15:00:48 +08:00
parent b5fb8150df
commit c6556eb0d5
No known key found for this signature in database
GPG Key ID: 40F856243C184EAB
2 changed files with 34 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package com.zcshou.gogogo;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
@ -10,8 +11,10 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.text.style.ClickableSpan;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
@ -106,16 +109,12 @@ public class WelcomeActivity extends AppCompatActivity {
ReqPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
// if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// ReqPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
// }
// 读取电话状态权限
if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
ReqPermissions.add(Manifest.permission.READ_PHONE_STATE);
}
if (ReqPermissions.size() <= 0) {
if (ReqPermissions.size() == 0) {
isPermission = true;
} else {
requestPermissions(ReqPermissions.toArray(new String[0]), SDK_PERMISSION_REQUEST);
@ -235,18 +234,44 @@ public class WelcomeActivity extends AppCompatActivity {
}
}
@SuppressLint("ClickableViewAccessibility")
private void checkAgreementAndPrivacy() {
preferences = getSharedPreferences(KEY_ACCEPT_AGREEMENT, MODE_PRIVATE);
mPrivacy = preferences.getBoolean(KEY_ACCEPT_PRIVACY, false);
mAgreement = preferences.getBoolean(KEY_ACCEPT_AGREEMENT, false);
checkBox = findViewById(R.id.check_agreement);
// 拦截 CheckBox 的点击事件
checkBox.setOnTouchListener((v, event) -> {
if (v instanceof TextView) {
TextView text = (TextView) v;
MovementMethod method = text.getMovementMethod();
if (method != null && text.getText() instanceof Spannable
&& event.getAction() == MotionEvent.ACTION_UP) {
if (method.onTouchEvent(text, (Spannable) text.getText(), event)) {
event.setAction(MotionEvent.ACTION_CANCEL);
}
}
}
return false;
});
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (!mPrivacy || !mAgreement) {
GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_read));
checkBox.setChecked(false);
}
} else {
mPrivacy = false;
mAgreement = false;
}
});
String str = getString(R.string.app_agreement_privacy);
SpannableStringBuilder builder = new SpannableStringBuilder(str);
ClickableSpan clickSpanAgreement = new ClickableSpan() {
@Override
public void onClick( View widget) {
public void onClick(@NonNull View widget) {
showAgreementDialog();
}
@ -261,7 +286,7 @@ public class WelcomeActivity extends AppCompatActivity {
builder.setSpan(clickSpanAgreement, agreement_start,agreement_end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ClickableSpan clickSpanPrivacy = new ClickableSpan() {
@Override
public void onClick( View widget) {
public void onClick(@NonNull View widget) {
showPrivacyDialog();
}

View File

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