11package com .zcshou .gogogo ;
22
33import android .Manifest ;
4+ import android .annotation .SuppressLint ;
45import android .app .AlertDialog ;
56import android .content .Intent ;
67import android .content .SharedPreferences ;
1011import android .text .SpannableStringBuilder ;
1112import android .text .TextPaint ;
1213import android .text .method .LinkMovementMethod ;
14+ import android .text .method .MovementMethod ;
1315import android .text .style .ClickableSpan ;
1416import android .view .Gravity ;
17+ import android .view .MotionEvent ;
1518import android .view .View ;
1619import android .view .Window ;
1720import 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
0 commit comments