mirror of
https://github.com/ZCShou/GoGoGo.git
synced 2026-06-13 21:00:55 +08:00
refactor(welcome):redesign the welcome page
This commit is contained in:
parent
add0e83182
commit
db727d3682
@ -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));
|
||||
|
||||
|
||||
@ -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<String> 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();
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -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" />
|
||||
|
||||
<TextView
|
||||
<CheckBox
|
||||
android:id="@+id/check_agreement"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:textSize="13sp"
|
||||
android:text="@string/app_email"
|
||||
android:layout_margin="3dp"
|
||||
tools:ignore="SmallSp" />
|
||||
android:gravity="center"
|
||||
android:text="@string/app_agreement_tips" />
|
||||
|
||||
</merge>
|
||||
|
||||
@ -31,14 +31,6 @@
|
||||
android:textSize="15sp" />
|
||||
</ScrollView>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/tv_check"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_protocol_check" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@ -15,10 +15,13 @@
|
||||
"5. 由于用户计算机软硬件环境的差异性和复杂性,本软件所提供的各项功能并不能保证在任何情况下都能正常执行或达到用户所期望的结果。 用户使用本软件所产生的一切后果,软件作者不承担任何责任。\n"
|
||||
"6. 如果用户自行安装本软件,即表明用户信任软件作者,自愿选择安装本软件,并接受本协议所有条款。 如果用户不接受本协议,请立即删除。\n"
|
||||
</string>
|
||||
<string name="app_agreement">用户协议</string>
|
||||
<string name="app_agreement_tips">已阅读《用户协议》及《隐私政策》</string>
|
||||
<string name="app_protocol_title">用户协议</string>
|
||||
<string name="app_protocol_agree">同意并继续</string>
|
||||
<string name="app_protocol_disagree">不同意</string>
|
||||
<string name="app_protocol_check">不再显示</string>
|
||||
<string name="app_error_agreement">您必须先阅读并同意用户协议</string>
|
||||
<string name="app_error_gps">定位不可用,请检查 GPS 是否开启</string>
|
||||
<string name="app_error_network">网络不可用,请检查网络连接</string>
|
||||
<string name="app_error_permission">权限不足,请授予相关权限</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user