diff --git a/KeyHandler/Android.bp b/KeyHandler/Android.bp
index be66272..0f63dee 100644
--- a/KeyHandler/Android.bp
+++ b/KeyHandler/Android.bp
@@ -2,11 +2,17 @@ android_app {
name: "KeyHandler",
srcs: ["src/**/*.kt"],
+ resource_dirs: ["res"],
certificate: "platform",
platform_apis: true,
system_ext_specific: true,
+ static_libs: [
+ "org.lineageos.platform.internal",
+ "org.lineageos.settings.resources",
+ ],
+
optimize: {
proguard_flags_files: ["proguard.flags"],
},
diff --git a/KeyHandler/AndroidManifest.xml b/KeyHandler/AndroidManifest.xml
index ea8e344..24190a7 100644
--- a/KeyHandler/AndroidManifest.xml
+++ b/KeyHandler/AndroidManifest.xml
@@ -1,6 +1,6 @@
+
+
+
+
+
+
+
+
+
diff --git a/KeyHandler/res/values/arrays.xml b/KeyHandler/res/values/arrays.xml
new file mode 100644
index 0000000..263c31d
--- /dev/null
+++ b/KeyHandler/res/values/arrays.xml
@@ -0,0 +1,18 @@
+
+
+
+
+ - @string/alert_slider_mode_normal
+ - @string/alert_slider_mode_vibration
+ - @string/alert_slider_mode_silent
+
+
+
+ - 2
+ - 1
+ - 0
+
+
diff --git a/KeyHandler/res/values/strings.xml b/KeyHandler/res/values/strings.xml
new file mode 100644
index 0000000..0031284
--- /dev/null
+++ b/KeyHandler/res/values/strings.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ Alert slider
+ Action
+ Top position
+ Middle position
+ Bottom position
+ Silent
+ Normal
+ Vibration
+
diff --git a/KeyHandler/res/xml/button_panel.xml b/KeyHandler/res/xml/button_panel.xml
new file mode 100644
index 0000000..3755e99
--- /dev/null
+++ b/KeyHandler/res/xml/button_panel.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsActivity.kt b/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsActivity.kt
new file mode 100644
index 0000000..b13cfa1
--- /dev/null
+++ b/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsActivity.kt
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2021 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.settings.device
+
+import android.R
+import android.preference.PreferenceActivity
+import android.os.Bundle
+
+class ButtonSettingsActivity : PreferenceActivity() {
+ public override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ fragmentManager.beginTransaction().replace(
+ R.id.content,
+ ButtonSettingsFragment()
+ ).commit()
+ }
+}
diff --git a/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsFragment.kt b/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsFragment.kt
new file mode 100644
index 0000000..7edbf2a
--- /dev/null
+++ b/KeyHandler/src/org/lineageos/settings/device/ButtonSettingsFragment.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2021 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.settings.device
+
+import android.os.Bundle
+import android.view.MenuItem
+import androidx.preference.PreferenceFragment
+
+class ButtonSettingsFragment : PreferenceFragment() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ addPreferencesFromResource(R.xml.button_panel)
+ activity.actionBar!!.setDisplayHomeAsUpEnabled(true)
+ }
+
+ override fun addPreferencesFromResource(preferencesResId: Int) {
+ super.addPreferencesFromResource(preferencesResId)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ when (item.itemId) {
+ R.id.home -> {
+ activity.finish()
+ return true
+ }
+ }
+ return super.onOptionsItemSelected(item)
+ }
+}
diff --git a/KeyHandler/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.kt b/KeyHandler/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.kt
new file mode 100644
index 0000000..9d9c556
--- /dev/null
+++ b/KeyHandler/src/org/lineageos/settings/device/ConfigPanelSearchIndexablesProvider.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.settings.device
+
+import android.database.Cursor
+import android.database.MatrixCursor
+import android.provider.SearchIndexableResource
+import android.provider.SearchIndexablesProvider
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RANK
+import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID
+import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS
+import android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS
+import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS
+
+class ConfigPanelSearchIndexablesProvider : SearchIndexablesProvider() {
+ override fun onCreate(): Boolean = true
+
+ override fun queryXmlResources(projection: Array?): Cursor {
+ val cursor = MatrixCursor(INDEXABLES_XML_RES_COLUMNS)
+ INDEXABLE_RES.forEach {
+ cursor.addRow(generateResourceRef(it))
+ }
+ return cursor
+ }
+
+ override fun queryRawData(projection: Array?): Cursor {
+ return MatrixCursor(INDEXABLES_RAW_COLUMNS)
+ }
+
+ override fun queryNonIndexableKeys(projection: Array?): Cursor {
+ return MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS)
+ }
+
+ private fun generateResourceRef(sir: SearchIndexableResource): Array {
+ val ref = arrayOfNulls(7)
+ ref[COLUMN_INDEX_XML_RES_RANK] = sir.rank
+ ref[COLUMN_INDEX_XML_RES_RESID] = sir.xmlResId
+ ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = null
+ ref[COLUMN_INDEX_XML_RES_ICON_RESID] = sir.iconResId
+ ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = "com.android.settings.action.EXTRA_SETTINGS"
+ ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = "org.lineageos.settings.device"
+ ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = sir.className
+ return ref
+ }
+
+ companion object {
+ private const val TAG = "ConfigPanelSearchIndexablesProvider"
+
+ private val INDEXABLE_RES = arrayOf(
+ SearchIndexableResource(
+ 1, R.xml.button_panel, ButtonSettingsActivity::class.java.name, 0
+ )
+ )
+ }
+}
diff --git a/KeyHandler/src/org/lineageos/settings/device/KeyHandler.kt b/KeyHandler/src/org/lineageos/settings/device/KeyHandler.kt
index 6fbd6d3..5fbf73b 100644
--- a/KeyHandler/src/org/lineageos/settings/device/KeyHandler.kt
+++ b/KeyHandler/src/org/lineageos/settings/device/KeyHandler.kt
@@ -15,33 +15,57 @@ import com.android.internal.os.DeviceKeyHandler
class KeyHandler(context: Context) : DeviceKeyHandler {
private val audioManager = context.getSystemService(AudioManager::class.java)
private val vibrator = context.getSystemService(Vibrator::class.java)
+ private val packageContext = context.createPackageContext(
+ KeyHandler::class.java.getPackage()!!.name, 0
+ )
+ private val sharedPreferences
+ get() = packageContext.getSharedPreferences(
+ packageContext.packageName + "_preferences",
+ Context.MODE_PRIVATE or Context.MODE_MULTI_PROCESS
+ )
override fun handleKeyEvent(event: KeyEvent): KeyEvent {
if (event.action == KeyEvent.ACTION_DOWN) {
when (event.scanCode) {
- MODE_NORMAL -> {
- audioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL)
- vibrator.vibrate(MODE_NORMAL_EFFECT)
+ POSITION_TOP -> {
+ val mode = sharedPreferences.getString(ALERT_SLIDER_TOP_KEY, "0")!!.toInt()
+ audioManager.setRingerModeInternal(mode)
+ vibrateIfNeeded(mode)
}
- MODE_VIBRATION -> {
- audioManager.setRingerModeInternal(AudioManager.RINGER_MODE_VIBRATE)
- vibrator.vibrate(MODE_VIBRATION_EFFECT)
+ POSITION_MIDDLE -> {
+ val mode = sharedPreferences.getString(ALERT_SLIDER_MIDDLE_KEY, "1")!!.toInt()
+ audioManager.setRingerModeInternal(mode)
+ vibrateIfNeeded(mode)
}
- MODE_SILENCE -> {
- audioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT)
+ POSITION_BOTTOM -> {
+ val mode = sharedPreferences.getString(ALERT_SLIDER_BOTTOM_KEY, "2")!!.toInt()
+ audioManager.setRingerModeInternal(mode)
+ vibrateIfNeeded(mode)
}
}
}
return event
}
+ private fun vibrateIfNeeded(mode: Int) {
+ when (mode) {
+ AudioManager.RINGER_MODE_VIBRATE -> vibrator.vibrate(MODE_VIBRATION_EFFECT)
+ AudioManager.RINGER_MODE_NORMAL -> vibrator.vibrate(MODE_NORMAL_EFFECT)
+ }
+ }
+
companion object {
private const val TAG = "KeyHandler"
// Slider key codes
- private const val MODE_NORMAL = 601
- private const val MODE_VIBRATION = 602
- private const val MODE_SILENCE = 603
+ private const val POSITION_TOP = 601
+ private const val POSITION_MIDDLE = 602
+ private const val POSITION_BOTTOM = 603
+
+ // Preference keys
+ private const val ALERT_SLIDER_TOP_KEY = "config_top_position"
+ private const val ALERT_SLIDER_MIDDLE_KEY = "config_middle_position"
+ private const val ALERT_SLIDER_BOTTOM_KEY = "config_bottom_position"
// Vibration effects
private val MODE_NORMAL_EFFECT = VibrationEffect.get(VibrationEffect.EFFECT_HEAVY_CLICK)