Skip to content

Commit

Permalink
fix(Handle opacity): Use SliderPreference
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Feb 8, 2024
1 parent 3df1f8d commit a8d994f
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 174 deletions.
129 changes: 86 additions & 43 deletions app/src/main/java/cu/axel/smartdock/fragments/AdvancedPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
showAccessibilityDialog(requireContext())
true
}
findPreference<Preference>("soft_reboot")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
DeviceUtils.softReboot()
false
}
findPreference<Preference>("soft_reboot")!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
DeviceUtils.softReboot()
false
}
val moveToSystem = findPreference<Preference>("move_to_system")
moveToSystem!!.isVisible = !AppUtils.isSystemApp(requireContext(), requireContext().packageName)
moveToSystem!!.isVisible =
!AppUtils.isSystemApp(requireContext(), requireContext().packageName)
moveToSystem.onPreferenceClickListener = Preference.OnPreferenceClickListener {
try {
val appInfo = requireActivity().packageManager
.getApplicationInfo(requireActivity().packageName, 0)
.getApplicationInfo(requireActivity().packageName, 0)
val appDir = appInfo.sourceDir.substring(0, appInfo.sourceDir.lastIndexOf("/"))
DeviceUtils.runAsRoot("mv $appDir /system/priv-app/")
DeviceUtils.reboot()
Expand All @@ -65,21 +67,31 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
hideStatus!!.isVisible = Build.VERSION.SDK_INT < 31
if (hasWriteSettingsPermission) {
findPreference<Preference>("secure_category")!!.isEnabled = true
findPreference<Preference>("custom_display_size")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
showDisplaySizeDialog(requireContext())
true
}
hideStatus.isChecked = (DeviceUtils.getGlobalSetting(requireActivity(), DeviceUtils.POLICY_CONTROL, "")
== DeviceUtils.IMMERSIVE_APPS)
findPreference<Preference>("custom_display_size")!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
showDisplaySizeDialog(requireContext())
true
}
hideStatus.isChecked =
(DeviceUtils.getGlobalSetting(requireActivity(), DeviceUtils.POLICY_CONTROL, "")
== DeviceUtils.IMMERSIVE_APPS)
hideStatus.setOnPreferenceChangeListener { _, newValue ->
if (newValue as Boolean) {
if (DeviceUtils.putGlobalSetting(requireActivity(), DeviceUtils.POLICY_CONTROL,
DeviceUtils.IMMERSIVE_APPS)) {
if (DeviceUtils.putGlobalSetting(
requireActivity(), DeviceUtils.POLICY_CONTROL,
DeviceUtils.IMMERSIVE_APPS
)
) {
if (rootAvailable)
showRebootDialog(requireContext(), true)
}
} else {
if (DeviceUtils.putGlobalSetting(requireActivity(), DeviceUtils.POLICY_CONTROL, null)) {
if (DeviceUtils.putGlobalSetting(
requireActivity(),
DeviceUtils.POLICY_CONTROL,
null
)
) {
if (rootAvailable)
showRebootDialog(requireActivity(), true)
}
Expand All @@ -91,14 +103,27 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
false
}
val disableHeadsUp = findPreference<SwitchPreferenceCompat>("disable_heads_up")!!
disableHeadsUp.isChecked = DeviceUtils.getGlobalSetting(requireActivity(), DeviceUtils.HEADS_UP_ENABLED, 1) == 0
disableHeadsUp.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, p2: Any ->
if (p2 as Boolean) {
DeviceUtils.putGlobalSetting(requireActivity(), DeviceUtils.HEADS_UP_ENABLED, 0)
} else {
DeviceUtils.putGlobalSetting(requireActivity(), DeviceUtils.HEADS_UP_ENABLED, 1)
disableHeadsUp.isChecked = DeviceUtils.getGlobalSetting(
requireActivity(),
DeviceUtils.HEADS_UP_ENABLED,
1
) == 0
disableHeadsUp.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, p2: Any ->
if (p2 as Boolean) {
DeviceUtils.putGlobalSetting(
requireActivity(),
DeviceUtils.HEADS_UP_ENABLED,
0
)
} else {
DeviceUtils.putGlobalSetting(
requireActivity(),
DeviceUtils.HEADS_UP_ENABLED,
1
)
}
}
}
}
hideNav.setOnPreferenceChangeListener { _, newValue ->
if (newValue as Boolean) {
Expand All @@ -108,7 +133,8 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
showRebootDialog(requireContext(), false)
}
} else {
val status = DeviceUtils.runAsRoot("sed -i /qemu.hw.mainkeys=1/d /system/build.prop")
val status =
DeviceUtils.runAsRoot("sed -i /qemu.hw.mainkeys=1/d /system/build.prop")
if (status != "error") {
hideNav.sharedPreferences!!.edit().putBoolean("navbar_fix", true).apply()
showRebootDialog(requireContext(), false)
Expand All @@ -117,35 +143,44 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
false
}
findPreference<Preference>("navbar_fix")!!.isVisible = Build.VERSION.SDK_INT > 31
findPreference<Preference>("backup_preferences")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivityForResult(Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
.setType("*/*").putExtra(Intent.EXTRA_TITLE,
requireActivity().packageName + "_backup_" + Utils.currentDateString + ".sdp"),
SAVE_REQUEST_CODE)
false
}
findPreference<Preference>("restore_preferences")!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startActivityForResult(
Intent(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE).setType("*/*"),
OPEN_REQUEST_CODE)
false
}
findPreference<Preference>("backup_preferences")!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
startActivityForResult(
Intent(Intent.ACTION_CREATE_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
.setType("*/*").putExtra(
Intent.EXTRA_TITLE,
requireActivity().packageName + "_backup_" + Utils.currentDateString + ".sdp"
),
SAVE_REQUEST_CODE
)
false
}
findPreference<Preference>("restore_preferences")!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener {
startActivityForResult(
Intent(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE)
.setType("*/*"),
OPEN_REQUEST_CODE
)
false
}
val dockHeight = findPreference<SliderPreference>("dock_height")!!
dockHeight.setOnDialogShownListener(object : SliderPreference.OnDialogShownListener {
override fun onDialogShown() {
val slider = dockHeight.slider
slider.isTickVisible = false
slider.labelBehavior = LabelFormatter.LABEL_GONE
slider.stepSize = 1f
slider.value = dockHeight.sharedPreferences!!.getString("dock_height", "58")!!.toFloat()
slider.value =
dockHeight.sharedPreferences!!.getString(dockHeight.key, "58")!!.toFloat()
slider.valueFrom = 50f
slider.valueTo = 70f
slider.addOnChangeListener { _, value, _
->
dockHeight.sharedPreferences!!.edit().putString("dock_height", value.toInt().toString()).apply()
dockHeight.sharedPreferences!!.edit()
.putString(dockHeight.key, value.toInt().toString()).apply()
}
}

})
}

Expand All @@ -158,7 +193,12 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
dialog.setPositiveButton(R.string.ok) { _, _ ->
val value = contentEt.text.toString()
val size = if (value == "0") "" else value
if (DeviceUtils.putSecureSetting(context, DeviceUtils.DISPLAY_SIZE, size) && rootAvailable) showRebootDialog(requireContext(), true)
if (DeviceUtils.putSecureSetting(
context,
DeviceUtils.DISPLAY_SIZE,
size
) && rootAvailable
) showRebootDialog(requireContext(), true)
}
dialog.setNegativeButton(getString(R.string.cancel), null)
dialog.setView(view)
Expand All @@ -172,8 +212,10 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
val contentEt = view.findViewById<EditText>(R.id.icon_blacklist_et)
contentEt.setText(DeviceUtils.getSecureSetting(context, DeviceUtils.ICON_BLACKLIST, ""))
dialog.setPositiveButton(R.string.ok) { _, _ ->
DeviceUtils.putSecureSetting(context,
DeviceUtils.ICON_BLACKLIST, contentEt.text.toString())
DeviceUtils.putSecureSetting(
context,
DeviceUtils.ICON_BLACKLIST, contentEt.text.toString()
)
}
dialog.setNegativeButton(getString(R.string.cancel), null)
dialog.setView(view)
Expand All @@ -196,7 +238,8 @@ class AdvancedPreferences : PreferenceFragmentCompat() {
dialog.setTitle(R.string.restart)
dialog.setMessage(R.string.restart_accessibility)
dialog.setNegativeButton(getString(R.string.cancel), null)
dialog.setPositiveButton(getString(R.string.open_accessibility)
dialog.setPositiveButton(
getString(R.string.open_accessibility)
) { _, _ -> startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)) }
dialog.show()
}
Expand Down
46 changes: 40 additions & 6 deletions app/src/main/java/cu/axel/smartdock/fragments/DockPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.slider.LabelFormatter
import cu.axel.smartdock.R
import cu.axel.smartdock.preferences.SliderPreference

class DockPreferences : PreferenceFragmentCompat() {
override fun onCreatePreferences(arg0: Bundle?, arg1: String?) {
Expand All @@ -17,9 +19,26 @@ class DockPreferences : PreferenceFragmentCompat() {
false
}
val activationArea = findPreference<Preference>("dock_activation_area")
activationArea!!.isVisible = activationArea.sharedPreferences!!.getString("activation_method", "swipe") == "swipe"
val handleOpacity = findPreference<Preference>("handle_opacity")
handleOpacity!!.isVisible = handleOpacity.sharedPreferences!!.getString("activation_method", "swipe") == "handle"
activationArea!!.isVisible =
activationArea.sharedPreferences!!.getString("activation_method", "swipe") == "swipe"
val handleOpacity = findPreference<SliderPreference>("handle_opacity")
handleOpacity!!.isVisible =
handleOpacity.sharedPreferences!!.getString("activation_method", "swipe") == "handle"
handleOpacity.setOnDialogShownListener(object : SliderPreference.OnDialogShownListener {
override fun onDialogShown() {
val slider = handleOpacity.slider
slider.isTickVisible = false
slider.labelBehavior = LabelFormatter.LABEL_GONE
slider.stepSize = 0.1f
slider.value = handleOpacity.sharedPreferences!!.getString(handleOpacity.key, "0.5f")!!.toFloat()
slider.valueFrom = 0.2f
slider.valueTo = 1f
slider.addOnChangeListener { _, value, _ ->
handleOpacity.sharedPreferences!!.edit()
.putString(handleOpacity.key, value.toString()).apply()
}
}
})
val handlePosition = findPreference<Preference>("handle_position")
handlePosition!!.isVisible = handleOpacity.isVisible
val activationMethod = findPreference<Preference>("activation_method")
Expand All @@ -43,9 +62,24 @@ class DockPreferences : PreferenceFragmentCompat() {
startupChkbx.isChecked = sharedPreferences.getBoolean("pin_dock", true)
windowedChkbx.isChecked = sharedPreferences.getBoolean("auto_pin", true)
fullscreenChkbx.isChecked = sharedPreferences.getBoolean("auto_unpin", true)
startupChkbx.setOnCheckedChangeListener { _, checked -> editor.putBoolean("pin_dock", checked).apply() }
windowedChkbx.setOnCheckedChangeListener { _, checked -> editor.putBoolean("auto_pin", checked).commit() }
fullscreenChkbx.setOnCheckedChangeListener { _, checked -> editor.putBoolean("auto_unpin", checked).commit() }
startupChkbx.setOnCheckedChangeListener { _, checked ->
editor.putBoolean(
"pin_dock",
checked
).apply()
}
windowedChkbx.setOnCheckedChangeListener { _, checked ->
editor.putBoolean(
"auto_pin",
checked
).commit()
}
fullscreenChkbx.setOnCheckedChangeListener { _, checked ->
editor.putBoolean(
"auto_unpin",
checked
).commit()
}
dialogBuilder.setView(view)
dialogBuilder.setPositiveButton(R.string.ok, null)
dialogBuilder.show()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/cu/axel/smartdock/services/DockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
})
dock.setOnTouchListener(this)
dockLayout.setOnTouchListener(this)
dockHandle.alpha = 0.01f * sharedPreferences.getString("handle_opacity", "50")!!.toInt()
dockHandle.alpha = sharedPreferences.getString("handle_opacity", "0.5")!!.toFloat()
dockHandle.setOnClickListener { pinDock() }
appsBtn.setOnClickListener { toggleAppMenu() }
appsBtn.setOnLongClickListener {
Expand Down Expand Up @@ -1361,7 +1361,7 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
} else if (preference == "activation_method") {
updateActivationMethod()
} else if (preference == "handle_opacity")
dockHandle.alpha = 0.01f * sharedPreferences.getString("handle_opacity", "50")!!.toInt()
dockHandle.alpha = sharedPreferences.getString("handle_opacity", "0.5")!!.toFloat()
else if (preference == "dock_height")
updateDockHeight()
else if (preference == "handle_position")
Expand Down
Loading

0 comments on commit a8d994f

Please sign in to comment.