diff --git a/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java b/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java index 9b7d68e..b0aae81 100644 --- a/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java +++ b/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java @@ -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.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 @@ private void checkDefaultPermissions() { 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 @@ private void showPrivacyDialog() { } } + @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 void updateDrawState(TextPaint ds) { 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(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08f9d2d..0f4a48a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,8 @@ "6. 如果用户自行安装本软件,即表明用户信任软件作者,自愿选择安装本软件,并接受本协议所有条款。 如果用户不接受本协议,请立即删除。\n" 已阅读《用户协议》和《隐私政策》 - 必须先接受《用户协议》和《隐私政策》 + 必须接受《用户协议》和《隐私政策》 + 请先阅读《用户协议》和《隐私政策》 定位不可用,请检查 GPS 是否开启 网络不可用,请检查网络连接 权限不足,请授予相关权限