mirror of
https://github.com/ZCShou/GoGoGo.git
synced 2026-06-05 21:00:50 +08:00
refactor(welcome):refactor setting code
This commit is contained in:
parent
e521d6e1fa
commit
2ac7286609
@ -33,22 +33,21 @@ public class FragmentSettings extends PreferenceFragmentCompat {
|
||||
ListPreference pfJoystick = findPreference("setting_joystick_type");
|
||||
if (pfJoystick != null) {
|
||||
// 使用自定义 SummaryProvider
|
||||
pfJoystick.setSummaryProvider((Preference.SummaryProvider<ListPreference>) preference -> "当前类型: " + Objects.requireNonNull(preference.getEntry()));
|
||||
pfJoystick.setSummaryProvider((Preference.SummaryProvider<ListPreference>) preference -> getResources().getString(R.string.setting_current_value) + Objects.requireNonNull(preference.getEntry()));
|
||||
pfJoystick.setOnPreferenceChangeListener((preference, newValue) -> newValue.toString().trim().length() != 0);
|
||||
}
|
||||
|
||||
EditTextPreference pfWalk = findPreference("setting_walk");
|
||||
if (pfWalk != null) {
|
||||
// 使用自定义 SummaryProvider
|
||||
pfWalk.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> "当前值: " + preference.getText());
|
||||
pfWalk.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> getResources().getString(R.string.setting_current_value) + preference.getText());
|
||||
pfWalk.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
|
||||
Selection.setSelection(editText.getText(), editText.length());
|
||||
});
|
||||
pfWalk.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().trim().length() == 0)
|
||||
{
|
||||
GoUtils.DisplayToast(this.getContext(),"输入无效");
|
||||
if (newValue.toString().trim().length() == 0) {
|
||||
GoUtils.DisplayToast(this.getContext(),getResources().getString(R.string.app_error_input));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -57,15 +56,14 @@ public class FragmentSettings extends PreferenceFragmentCompat {
|
||||
|
||||
EditTextPreference pfRun = findPreference("setting_run");
|
||||
if (pfRun != null) {
|
||||
pfRun.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> "当前值: " + preference.getText());
|
||||
pfRun.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> getResources().getString(R.string.setting_current_value) + preference.getText());
|
||||
pfRun.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
|
||||
Selection.setSelection(editText.getText(), editText.length());
|
||||
});
|
||||
pfRun.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().trim().length() == 0)
|
||||
{
|
||||
GoUtils.DisplayToast(this.getContext(),"输入无效");
|
||||
if (newValue.toString().trim().length() == 0) {
|
||||
GoUtils.DisplayToast(this.getContext(),getResources().getString(R.string.app_error_input));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -73,15 +71,14 @@ public class FragmentSettings extends PreferenceFragmentCompat {
|
||||
}
|
||||
EditTextPreference pfBike = findPreference("setting_bike");
|
||||
if (pfBike != null) {
|
||||
pfBike.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> "当前值: " + preference.getText());
|
||||
pfBike.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> getResources().getString(R.string.setting_current_value) + preference.getText());
|
||||
pfBike.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
|
||||
Selection.setSelection(editText.getText(), editText.length());
|
||||
});
|
||||
pfBike.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().trim().length() == 0)
|
||||
{
|
||||
GoUtils.DisplayToast(this.getContext(),"输入无效");
|
||||
if (newValue.toString().trim().length() == 0) {
|
||||
GoUtils.DisplayToast(this.getContext(),getResources().getString(R.string.app_error_input));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -109,15 +106,14 @@ public class FragmentSettings extends PreferenceFragmentCompat {
|
||||
EditTextPreference pfPosHisValid = findPreference("setting_pos_history");
|
||||
if (pfPosHisValid != null) {
|
||||
// 使用自定义 SummaryProvider
|
||||
pfPosHisValid.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> "当前值: " + preference.getText());
|
||||
pfPosHisValid.setSummaryProvider((Preference.SummaryProvider<EditTextPreference>) preference -> getResources().getString(R.string.setting_current_value) + preference.getText());
|
||||
pfPosHisValid.setOnBindEditTextListener(editText -> {
|
||||
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
|
||||
Selection.setSelection(editText.getText(), editText.length());
|
||||
});
|
||||
pfPosHisValid.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().trim().length() == 0)
|
||||
{
|
||||
GoUtils.DisplayToast(this.getContext(),"输入无效");
|
||||
if (newValue.toString().trim().length() == 0) {
|
||||
GoUtils.DisplayToast(this.getContext(),getResources().getString(R.string.app_error_input));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -22,14 +22,35 @@
|
||||
<string name="app_error_gps">定位不可用,请检查 GPS 是否开启</string>
|
||||
<string name="app_error_network">网络不可用,请检查网络连接</string>
|
||||
<string name="app_error_permission">权限不足,请授予相关权限</string>
|
||||
<string name="app_error_input">输入有误,请检查输入是否合法</string>
|
||||
|
||||
<!-- 欢迎页 -->
|
||||
<string name="welcome_btn_txt">进入应用</string>
|
||||
|
||||
<!-- 设置界面 -->
|
||||
<string name="setting_group_move">移动</string>
|
||||
<string name="setting_current_value">当前值: </string>
|
||||
<string name="setting_joystick">摇杆类型</string>
|
||||
<string name="setting_joystick_tips">重启摇杆后生效</string>
|
||||
<string name="setting_walk">步行速度(米/秒)</string>
|
||||
<string name="setting_walk_default">1.2</string>
|
||||
<string name="setting_run">跑步速度(米/秒)</string>
|
||||
<string name="setting_run_default">3.6</string>
|
||||
<string name="setting_bike">驾驶速度(米/秒)</string>
|
||||
<string name="setting_bike_default">10.0</string>
|
||||
<string name="setting_group_log">记录</string>
|
||||
<string name="setting_log_off">关闭日志</string>
|
||||
<string name="setting_pos_history">历史记录有效期(天)</string>
|
||||
<string name="setting_pos_history_default">7</string>
|
||||
<string name="setting_group_about">关于</string>
|
||||
<string name="setting_version">版本号</string>
|
||||
<string name="setting_author">开发者</string>
|
||||
<string name="setting_group_sys">系统</string>
|
||||
|
||||
<!-- 通知栏 -->
|
||||
<string name="note_show">显示摇杆</string>
|
||||
<string name="note_hide">隐藏摇杆</string>
|
||||
|
||||
<!-- 欢迎页 -->
|
||||
<string name="welcome_btn_txt">进入应用</string>
|
||||
|
||||
<!-- 主界面 -->
|
||||
<string name="label_longitude">经度</string>
|
||||
<string name="label_latitude">纬度</string>
|
||||
@ -63,25 +84,6 @@
|
||||
<string name="nav_menu_feedback">问题反馈</string>
|
||||
<string name="nav_menu_contact">联系作者</string>
|
||||
|
||||
<!-- 设置界面 -->
|
||||
<string name="setting_group_move">移动</string>
|
||||
<string name="setting_joystick">摇杆类型</string>
|
||||
<string name="setting_joystick_tips">重启摇杆后生效</string>
|
||||
<string name="setting_walk">步行速度(米/秒)</string>
|
||||
<string name="setting_walk_default">1.2</string>
|
||||
<string name="setting_run">跑步速度(米/秒)</string>
|
||||
<string name="setting_run_default">3.6</string>
|
||||
<string name="setting_bike">驾驶速度(米/秒)</string>
|
||||
<string name="setting_bike_default">10.0</string>
|
||||
<string name="setting_group_log">记录</string>
|
||||
<string name="setting_log_off">关闭日志</string>
|
||||
<string name="setting_pos_history">历史记录有效期(天)</string>
|
||||
<string name="setting_pos_history_default">7</string>
|
||||
<string name="setting_group_about">关于</string>
|
||||
<string name="setting_version">版本号</string>
|
||||
<string name="setting_author">开发者</string>
|
||||
<string name="setting_group_sys">系统</string>
|
||||
|
||||
<!-- 百度地图 -->
|
||||
<string name="map_pic_sate">卫星图</string>
|
||||
<string name="map_pic_normal">普通图</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user