Reduce clutter through convenience function

This commit is contained in:
SerpentSpirale 2021-08-11 15:38:52 +02:00
parent 142e658299
commit ea9c821676
2 changed files with 26 additions and 18 deletions

View File

@ -44,9 +44,7 @@ public class CustomSeekBarPreference extends SeekBarPreference {
public void setMin(int min) { public void setMin(int min) {
//Note: since the max (setMax is a final function) is not taken into account properly, setting the min over the max may produce funky results //Note: since the max (setMax is a final function) is not taken into account properly, setting the min over the max may produce funky results
super.setMin(min); super.setMin(min);
if (min != mMin) { if (min != mMin) mMin = min;
mMin = min;
}
} }
@ -92,7 +90,21 @@ public class CustomSeekBarPreference extends SeekBarPreference {
} }
/**
* Set a suffix to be appended on the TextView associated to the value
* @param suffix The suffix to append as a String
*/
public void setSuffix(String suffix) { public void setSuffix(String suffix) {
this.suffix = suffix; this.suffix = suffix;
} }
/**
* Convenience function to set both min and max at the same time.
* @param min The minimum value
* @param max The maximum value
*/
public void setRange(int min, int max){
setMin(min);
setMax(max);
}
} }

View File

@ -22,37 +22,33 @@ public class LauncherPreferenceFragment extends PreferenceFragmentCompat impleme
//Disable notch checking behavior on android 8.1 and below. //Disable notch checking behavior on android 8.1 and below.
findPreference("ignoreNotch").setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && PREF_NOTCH_SIZE != 0); findPreference("ignoreNotch").setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && PREF_NOTCH_SIZE != 0);
CustomSeekBarPreference seek2 = (CustomSeekBarPreference) findPreference("timeLongPressTrigger"); CustomSeekBarPreference seek2 = findPreference("timeLongPressTrigger");
seek2.setMin(100); seek2.setRange(100, 1000);
seek2.setMax(1000);
seek2.setValue(LauncherPreferences.PREF_LONGPRESS_TRIGGER); seek2.setValue(LauncherPreferences.PREF_LONGPRESS_TRIGGER);
seek2.setSuffix(" ms"); seek2.setSuffix(" ms");
CustomSeekBarPreference seek3 = (CustomSeekBarPreference) findPreference("buttonscale"); CustomSeekBarPreference seek3 = findPreference("buttonscale");
seek3.setMin(80); seek3.setRange(80, 250);
seek3.setMax(250);
seek3.setValue((int) LauncherPreferences.PREF_BUTTONSIZE); seek3.setValue((int) LauncherPreferences.PREF_BUTTONSIZE);
seek3.setSuffix(" %"); seek3.setSuffix(" %");
CustomSeekBarPreference seek4 = (CustomSeekBarPreference) findPreference("mousescale"); CustomSeekBarPreference seek4 = findPreference("mousescale");
seek4.setMin(25); seek4.setRange(25, 300);
seek4.setMax(300);
seek4.setValue((int) LauncherPreferences.PREF_MOUSESCALE); seek4.setValue((int) LauncherPreferences.PREF_MOUSESCALE);
seek4.setSuffix(" %"); seek4.setSuffix(" %");
CustomSeekBarPreference seek5 = (CustomSeekBarPreference) findPreference("resolutionRatio"); CustomSeekBarPreference seek5 = findPreference("resolutionRatio");
seek5.setMin(25); seek5.setMin(25);
seek5.setSuffix(" %"); seek5.setSuffix(" %");
CustomSeekBarPreference seek6 = (CustomSeekBarPreference) findPreference("mousespeed"); CustomSeekBarPreference seek6 = findPreference("mousespeed");
seek6.setMin(25); seek6.setRange(25, 300);
seek6.setMax(300); seek6.setValue((int)(LauncherPreferences.PREF_MOUSESPEED*100f));
seek6.setValue((int)(LauncherPreferences.PREF_MOUSESPEED*100f));
seek6.setSuffix(" %"); seek6.setSuffix(" %");
int freeMem = (int) (Runtime.getRuntime().freeMemory() / 1048576l); int freeMem = (int) (Runtime.getRuntime().freeMemory() / 1048576l);
CustomSeekBarPreference seek7 = (CustomSeekBarPreference) findPreference("allocation"); CustomSeekBarPreference seek7 = findPreference("allocation");
seek7.setMin(256); seek7.setMin(256);
if(Tools.CURRENT_ARCHITECTURE.contains("32")) seek7.setMax(1100); if(Tools.CURRENT_ARCHITECTURE.contains("32")) seek7.setMax(1100);
else seek7.setMax(freeMem > 4096 ? freeMem : 4096); else seek7.setMax(freeMem > 4096 ? freeMem : 4096);