Skip to content

Commit

Permalink
fix(welcome):adjust the logic of selecting privacy and agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Dec 17, 2023
1 parent b5fb815 commit c6556eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
39 changes: 32 additions & 7 deletions app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit c6556eb

Please sign in to comment.