Skip to content

Commit

Permalink
fix(settings):fix some warning in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Aug 23, 2022
1 parent c1da7ac commit c31db10
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions app/src/main/java/com/zcshou/gogogo/FragmentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (pfJoystick != null) {
// 使用自定义 SummaryProvider
pfJoystick.setSummaryProvider((Preference.SummaryProvider<ListPreference>) preference -> "当前类型: " + Objects.requireNonNull(preference.getEntry()));
pfJoystick.setOnPreferenceChangeListener((preference, newValue) -> !newValue.toString().trim().equals(""));
pfJoystick.setOnPreferenceChangeListener((preference, newValue) -> newValue.toString().trim().length() != 0);
}

EditTextPreference pfWalk = findPreference("setting_walk");
Expand All @@ -45,7 +45,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
pfWalk.setOnPreferenceChangeListener((preference, newValue) -> !newValue.toString().trim().equals(""));
pfWalk.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.toString().trim().length() == 0)
{
GoUtils.DisplayToast(this.getContext(),"输入无效");
return false;
}
return true;
});
}

EditTextPreference pfRun = findPreference("setting_run");
Expand All @@ -55,7 +62,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
pfRun.setOnPreferenceChangeListener((preference, newValue) -> !newValue.toString().trim().equals(""));
pfRun.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.toString().trim().length() == 0)
{
GoUtils.DisplayToast(this.getContext(),"输入无效");
return false;
}
return true;
});
}
EditTextPreference pfBike = findPreference("setting_bike");
if (pfBike != null) {
Expand All @@ -64,7 +78,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
pfBike.setOnPreferenceChangeListener((preference, newValue) -> !newValue.toString().trim().equals(""));
pfBike.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.toString().trim().length() == 0)
{
GoUtils.DisplayToast(this.getContext(),"输入无效");
return false;
}
return true;
});
}

SwitchPreferenceCompat pLog = findPreference("setting_log_off");
Expand Down Expand Up @@ -93,7 +114,14 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
pfPosHisValid.setOnPreferenceChangeListener((preference, newValue) -> !newValue.toString().trim().equals(""));
pfPosHisValid.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue.toString().trim().length() == 0)
{
GoUtils.DisplayToast(this.getContext(),"输入无效");
return false;
}
return true;
});
}
}
}

0 comments on commit c31db10

Please sign in to comment.