diff --git a/app/src/main/java/com/zcshou/gogogo/MainActivity.java b/app/src/main/java/com/zcshou/gogogo/MainActivity.java index 3aceae0..149f460 100644 --- a/app/src/main/java/com/zcshou/gogogo/MainActivity.java +++ b/app/src/main/java/com/zcshou/gogogo/MainActivity.java @@ -588,8 +588,6 @@ public class MainActivity extends BaseActivity implements SensorEventListener { TextView tvContent = window.findViewById(R.id.tv_content); Button tvCancel = window.findViewById(R.id.tv_cancel); Button tvAgree = window.findViewById(R.id.tv_agree); - CheckBox tvCheck = window.findViewById(R.id.tv_check); - tvCheck.setVisibility(GONE); SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(getResources().getString(R.string.app_protocol)); diff --git a/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java b/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java index 4cd0ee3..b25384b 100644 --- a/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java +++ b/app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java @@ -19,25 +19,18 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.preference.PreferenceManager; import com.zcshou.utils.GoUtils; -import com.zcshou.utils.GoUtils.TimeCount; import java.util.ArrayList; -import java.util.Locale; public class WelcomeActivity extends AppCompatActivity { - private Button startBtn; - private static SharedPreferences preferences; - private static final String KEY_IS_FIRST_USAGE = "KEY_IS_FIRST_USAGE"; + private static final String KEY_ACCEPT_AGREEMENT = "KEY_ACCEPT_AGREEMENT"; private static boolean isPermission = false; private static final int SDK_PERMISSION_REQUEST = 127; private static final ArrayList ReqPermissions = new ArrayList<>(); - private static TimeCount mTimer; - private static final int TIMER_INTERVAL = 1000; - private static final int TIMER_DURATION = 3000; - private static final String TIMER_FORMAT = "%d 秒"; + private CheckBox checkBox; @Override protected void onCreate(Bundle savedInstanceState) { @@ -48,12 +41,16 @@ public class WelcomeActivity extends AppCompatActivity { // 生成默认参数的值(一定要尽可能早的调用,因为后续有些界面可能需要使用参数) PreferenceManager.setDefaultValues(this, R.xml.preferences_main, false); - startBtn = findViewById(R.id.startButton); + Button startBtn = findViewById(R.id.startButton); startBtn.setOnClickListener(v -> startMainActivity()); - initTimer(); - - checkFirstStartup(); + checkBox = findViewById(R.id.check_agreement); + checkBox.setOnClickListener(v -> showProtocolDialog()); + preferences = getSharedPreferences(KEY_ACCEPT_AGREEMENT, MODE_PRIVATE); + checkBox.setChecked(preferences.getBoolean(KEY_ACCEPT_AGREEMENT, false)); + if (checkBox.isChecked()) { + checkDefaultPermissions(); + } } @Override @@ -73,8 +70,6 @@ public class WelcomeActivity extends AppCompatActivity { @Override protected void onDestroy() { - mTimer.cancel(); - super.onDestroy(); } @@ -87,23 +82,11 @@ public class WelcomeActivity extends AppCompatActivity { return; } } - isPermission = true; - mTimer.start(); } super.onRequestPermissionsResult(requestCode, permissions, grantResults); } - private void checkFirstStartup() { - preferences = getSharedPreferences(KEY_IS_FIRST_USAGE, MODE_PRIVATE); - - if (preferences.getBoolean(KEY_IS_FIRST_USAGE, true)) { - showProtocolDialog(); - } else { - checkDefaultPermissions(); - } - } - private void checkDefaultPermissions() { // 定位精确位置 if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { @@ -133,28 +116,17 @@ public class WelcomeActivity extends AppCompatActivity { if (ReqPermissions.size() <= 0) { isPermission = true; - mTimer.start(); } else { requestPermissions(ReqPermissions.toArray(new String[0]), SDK_PERMISSION_REQUEST); } } - private void initTimer() { - mTimer = new TimeCount(TIMER_DURATION, TIMER_INTERVAL); - mTimer.setListener(new TimeCount.TimeCountListener() { - @Override - public void onTick(long millisUntilFinished) { - startBtn.setText(String.format(Locale.getDefault(), TIMER_FORMAT, millisUntilFinished / TIMER_INTERVAL)); - } - - @Override - public void onFinish() { - startMainActivity(); - } - }); - } - private void startMainActivity() { + if (!checkBox.isChecked()) { + GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_agreement)); + return; + } + if (!GoUtils.isNetworkAvailable(this)) { GoUtils.DisplayToast(this, getResources().getString(R.string.app_error_network)); return; @@ -172,8 +144,6 @@ public class WelcomeActivity extends AppCompatActivity { } else { checkDefaultPermissions(); } - - mTimer.cancel(); } private void showProtocolDialog() { @@ -189,32 +159,36 @@ public class WelcomeActivity extends AppCompatActivity { TextView tvContent = window.findViewById(R.id.tv_content); Button tvCancel = window.findViewById(R.id.tv_cancel); Button tvAgree = window.findViewById(R.id.tv_agree); - final CheckBox tvCheck = window.findViewById(R.id.tv_check); SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(getResources().getString(R.string.app_protocol)); tvContent.setMovementMethod(LinkMovementMethod.getInstance()); tvContent.setText(ssb, TextView.BufferType.SPANNABLE); tvCancel.setOnClickListener(v -> { + + checkBox.setChecked(false); + + //实例化Editor对象 + SharedPreferences.Editor editor = preferences.edit(); + //存入数据 + editor.putBoolean(KEY_ACCEPT_AGREEMENT, false); + //提交修改 + editor.apply(); + alertDialog.cancel(); - finish(); }); tvAgree.setOnClickListener(v -> { - if (tvCheck.isChecked()) { - //实例化Editor对象 - SharedPreferences.Editor editor = preferences.edit(); - //存入数据 - editor.putBoolean(KEY_IS_FIRST_USAGE, false); - //提交修改 - editor.apply(); - } + checkBox.setChecked(true); - if (isPermission) { - mTimer.start(); - } else { - checkDefaultPermissions(); - } + //实例化Editor对象 + SharedPreferences.Editor editor = preferences.edit(); + //存入数据 + editor.putBoolean(KEY_ACCEPT_AGREEMENT, true); + //提交修改 + editor.apply(); + + checkDefaultPermissions(); alertDialog.cancel(); }); diff --git a/app/src/main/res/layout/activity_welcome.xml b/app/src/main/res/layout/activity_welcome.xml index 8cd2a80..96043d6 100644 --- a/app/src/main/res/layout/activity_welcome.xml +++ b/app/src/main/res/layout/activity_welcome.xml @@ -1,7 +1,6 @@ @@ -19,15 +18,14 @@ android:text="@string/welcome_btn_txt" android:textAlignment="center" android:layout_gravity="bottom|center" - android:layout_margin="106dp" /> + android:layout_margin="120dp" /> - + android:gravity="center" + android:text="@string/app_agreement_tips" /> diff --git a/app/src/main/res/layout/user_protocol.xml b/app/src/main/res/layout/user_protocol.xml index a1a2c31..436ebd3 100644 --- a/app/src/main/res/layout/user_protocol.xml +++ b/app/src/main/res/layout/user_protocol.xml @@ -31,14 +31,6 @@ android:textSize="15sp" /> - - + 用户协议 + 已阅读《用户协议》及《隐私政策》 用户协议 同意并继续 不同意 不再显示 + 您必须先阅读并同意用户协议 定位不可用,请检查 GPS 是否开启 网络不可用,请检查网络连接 权限不足,请授予相关权限