mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
universal7885: parts: Fix UI of smartcharge and show seekbar values
This commit is contained in:
parent
f35e7ce2a6
commit
7f099b9e43
3 changed files with 32 additions and 12 deletions
|
|
@ -41,6 +41,7 @@ class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceCh
|
||||||
mFlashLightPref.setMin(1)
|
mFlashLightPref.setMin(1)
|
||||||
val mFlashLight = Flashlight()
|
val mFlashLight = Flashlight()
|
||||||
mFlashLightPref.value = mFlashLight.getFlash(Build.DEVICE.contains("a10"))
|
mFlashLightPref.value = mFlashLight.getFlash(Build.DEVICE.contains("a10"))
|
||||||
|
mFlashLightPref.showSeekBarValue = true
|
||||||
mFlashLightEnable = findPreference(PREF_FLASHLIGHT_ENABLE)!!
|
mFlashLightEnable = findPreference(PREF_FLASHLIGHT_ENABLE)!!
|
||||||
mFlashLightEnable.isChecked = mSharedPreferences.getBoolean(PREF_FLASHLIGHT_ENABLE, true)
|
mFlashLightEnable.isChecked = mSharedPreferences.getBoolean(PREF_FLASHLIGHT_ENABLE, true)
|
||||||
mFlashLightEnable.addOnSwitchChangeListener(this)
|
mFlashLightEnable.addOnSwitchChangeListener(this)
|
||||||
|
|
|
||||||
|
|
@ -66,23 +66,29 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
mApplyBtn.setOnClickListener(this)
|
mApplyBtn.setOnClickListener(this)
|
||||||
mApplyBtn.isEnabled = false
|
mApplyBtn.isEnabled = false
|
||||||
mSmartChargeBtn.addOnSwitchChangeListener(this)
|
mSmartChargeBtn.addOnSwitchChangeListener(this)
|
||||||
|
mSmartChargeBtn.isChecked = mSharedPreferences.getBoolean(PREF_SMARTCHARGE_MAIN, false)
|
||||||
mAdjust.min = 1
|
mAdjust.min = 1
|
||||||
mAdjust.max = 5
|
mAdjust.max = 5
|
||||||
mAdjust.value = 3
|
mAdjust.value = 3
|
||||||
mAdjust.onPreferenceChangeListener = this
|
mAdjust.onPreferenceChangeListener = this
|
||||||
mLimit.setOnClickListener(this)
|
mLimit.setOnClickListener(this)
|
||||||
mRestart.setOnClickListener(this)
|
mRestart.setOnClickListener(this)
|
||||||
|
mLimitShow.summary = "${mSharedPreferences.getInt(PREF_LIMIT, 20)} %"
|
||||||
|
mRestartShow.summary = "${mSharedPreferences.getInt(PREF_RESTART, 80)} %"
|
||||||
|
updateSwitch(mLimit, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRadioButtonClicked(btn: SelectorWithWidgetPreference) {
|
override fun onRadioButtonClicked(btn: SelectorWithWidgetPreference) {
|
||||||
when (btn) {
|
when (btn) {
|
||||||
mLimit -> {
|
mLimit -> {
|
||||||
mSelected = SelectedOption.SELECTED_LIMIT
|
mSelected = SelectedOption.SELECTED_LIMIT
|
||||||
mRestart.isChecked = false
|
updateSwitch(mLimit, true)
|
||||||
|
updateSwitch(mRestart, false)
|
||||||
}
|
}
|
||||||
mRestart -> {
|
mRestart -> {
|
||||||
mSelected = SelectedOption.SELECTED_RESTART
|
mSelected = SelectedOption.SELECTED_RESTART
|
||||||
mLimit.isChecked = false
|
updateSwitch(mLimit, false)
|
||||||
|
updateSwitch(mRestart, true)
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
@ -97,25 +103,35 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
SelectedOption.SELECTED_RESTART -> PREF_RESTART
|
SelectedOption.SELECTED_RESTART -> PREF_RESTART
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline fun<T> updateSwitch(obj : T, value : Boolean) {
|
||||||
|
(obj as View).post({ (obj as Preference).isChecked = value })
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
|
||||||
if (preference == mAdjust) {
|
if (preference == mAdjust) {
|
||||||
var tmp = mSharedPreferences.getInt(fromSelectedToId(), 50)
|
var tmp = mSharedPreferences.getInt(fromSelectedToId(), 50)
|
||||||
val toAdd = when (newValue as Int) {
|
val toAdd = when (newValue as Int) {
|
||||||
0 -> -10
|
1 -> -10
|
||||||
1 -> -1
|
2 -> -1
|
||||||
3 -> 1
|
4 -> 1
|
||||||
4 -> 10
|
5 -> 10
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
if (tmp + toAdd > 99) tmp = 99 else if (tmp + toAdd < 1) tmp = 1 else tmp += toAdd
|
if (tmp + toAdd > 99) tmp = 99 else if (tmp + toAdd < 1) tmp = 1 else tmp += toAdd
|
||||||
mSharedPreferences.edit().putInt(fromSelectedToId(), tmp).apply()
|
mSharedPreferences.edit().putInt(fromSelectedToId(), tmp).apply()
|
||||||
when (mSelected) {
|
when (mSelected) {
|
||||||
SelectedOption.SELECTED_LIMIT -> mLimitShow
|
SelectedOption.SELECTED_LIMIT -> {
|
||||||
SelectedOption.SELECTED_RESTART -> mRestartShow
|
mSharedPreferences.edit().putInt(PREF_LIMIT, tmp).apply()
|
||||||
|
mLimitShow
|
||||||
|
}
|
||||||
|
SelectedOption.SELECTED_RESTART -> {
|
||||||
|
mSharedPreferences.edit().putInt(PREF_RESTART, tmp).apply()
|
||||||
|
mRestartShow
|
||||||
|
}
|
||||||
}.summary = "$tmp %"
|
}.summary = "$tmp %"
|
||||||
mSmartChargeBtn.isEnabled = false
|
mSmartChargeBtn.isEnabled = false
|
||||||
mApplyBtn.isEnabled = true
|
updateSwitch(mApplyBtn, true)
|
||||||
mAdjust.value = 3
|
(mAdjust as View).post({ mAdjust.value = 3 })
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
@ -127,8 +143,8 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
val restart = mSharedPreferences.getInt(PREF_RESTART, 80)
|
val restart = mSharedPreferences.getInt(PREF_RESTART, 80)
|
||||||
if (limit < restart) {
|
if (limit < restart) {
|
||||||
mSmartCharge.setConfig(limit, restart)
|
mSmartCharge.setConfig(limit, restart)
|
||||||
mSmartChargeBtn.isEnabled = true
|
updateSwitch(mSmartChargeBtn, true)
|
||||||
mApplyBtn.isEnabled = false
|
updateSwitch(mApplyBtn, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +164,9 @@ class SmartChargeFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListen
|
||||||
mSmartCharge.stop()
|
mSmartCharge.stop()
|
||||||
mPoolExecutor.shutdown()
|
mPoolExecutor.shutdown()
|
||||||
}
|
}
|
||||||
|
mSharedPreferences.edit().putBoolean(PREF_SMARTCHARGE_MAIN, isChecked).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PREF_SMARTCHARGE_MAIN = "smartcharge"
|
const val PREF_SMARTCHARGE_MAIN = "smartcharge"
|
||||||
const val PREF_LIMIT_SELECT = "choose_limit"
|
const val PREF_LIMIT_SELECT = "choose_limit"
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeLi
|
||||||
mSwapEnable.isChecked = mSharedPreferences.getBoolean(PREF_SWAP_ENABLE, false)
|
mSwapEnable.isChecked = mSharedPreferences.getBoolean(PREF_SWAP_ENABLE, false)
|
||||||
mSwapEnable.addOnSwitchChangeListener(this)
|
mSwapEnable.addOnSwitchChangeListener(this)
|
||||||
mSwapSizePref.isEnabled = !mSwapEnable.isChecked
|
mSwapSizePref.isEnabled = !mSwapEnable.isChecked
|
||||||
|
mSwapSizePref.showSeekBarValue = true
|
||||||
mFreeSpace = findPreference(INFO_FREE_SPACE)!!
|
mFreeSpace = findPreference(INFO_FREE_SPACE)!!
|
||||||
mFreeSpace.summary = "${mSwap.getFreeSpace()} GB"
|
mFreeSpace.summary = "${mSwap.getFreeSpace()} GB"
|
||||||
mSwapFileSize = findPreference(INFO_SWAP_FILE_SIZE)!!
|
mSwapFileSize = findPreference(INFO_SWAP_FILE_SIZE)!!
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue