From 09926d34ed8cc610c1318595d670ff0e784083c5 Mon Sep 17 00:00:00 2001 From: Finn M Glas Date: Thu, 20 Aug 2020 22:41:50 +0200 Subject: [PATCH] Implement double swipe actions Closes #52 --- .../java/com/finnmglas/launcher/Functions.kt | 35 +++++++++++++++++-- .../com/finnmglas/launcher/HomeActivity.kt | 34 +++++++++++------- .../SettingsFragmentActionsRecycler.kt | 14 ++++++++ app/src/main/res/values-de/strings.xml | 4 +++ app/src/main/res/values-fr/strings.xml | 4 +++ app/src/main/res/values/defaults.xml | 21 ++++++++++- app/src/main/res/values/strings.xml | 4 +++ 7 files changed, 99 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/finnmglas/launcher/Functions.kt b/app/src/main/java/com/finnmglas/launcher/Functions.kt index 7bb4717..d0ecc4f 100644 --- a/app/src/main/java/com/finnmglas/launcher/Functions.kt +++ b/app/src/main/java/com/finnmglas/launcher/Functions.kt @@ -36,19 +36,30 @@ lateinit var launcherPreferences: SharedPreferences /* Preference Key Constants */ const val ACTION_UP = "action_upApp" +const val ACTION_DOUBLE_UP = "action_doubleUpApp" const val ACTION_DOWN = "action_downApp" +const val ACTION_DOUBLE_DOWN = "action_doubleDownApp" const val ACTION_RIGHT = "action_rightApp" +const val ACTION_DOUBLE_RIGHT = "action_doubleRightApp" const val ACTION_LEFT = "action_leftApp" +const val ACTION_DOUBLE_LEFT = "action_doubleLeftApp" + const val ACTION_VOL_UP = "action_volumeUpApp" const val ACTION_VOL_DOWN = "action_volumeDownApp" const val ACTION_DOUBLE_CLICK = "action_doubleClickApp" const val ACTION_LONG_CLICK = "action_longClickApp" + const val ACTION_CALENDAR = "action_calendarApp" const val ACTION_CLOCK = "action_clockApp" -val ACTIONS = listOf(ACTION_UP, ACTION_DOWN, ACTION_RIGHT, ACTION_LEFT, - ACTION_VOL_UP, ACTION_VOL_DOWN, ACTION_DOUBLE_CLICK, ACTION_LONG_CLICK, - ACTION_CALENDAR, ACTION_CLOCK) +val ACTIONS = listOf( + ACTION_UP, ACTION_DOUBLE_UP, + ACTION_DOWN, ACTION_DOUBLE_DOWN, + ACTION_RIGHT, ACTION_LEFT, + ACTION_VOL_UP, ACTION_VOL_DOWN, + ACTION_DOUBLE_CLICK, ACTION_LONG_CLICK, + ACTION_CALENDAR, ACTION_CLOCK +) const val PREF_DOMINANT = "custom_dominant" const val PREF_VIBRANT = "custom_vibrant" @@ -58,6 +69,8 @@ const val PREF_THEME = "theme" const val PREF_SCREEN_TIMEOUT_DISABLED = "disableTimeout" const val PREF_SCREEN_FULLSCREEN = "useFullScreen" const val PREF_DATE_FORMAT = "dateFormat" + +const val PREF_DOUBLE_ACTIONS_ENABLED = "enableDoubleActions" const val PREF_SEARCH_AUTO_LAUNCH = "searchAutoLaunch" const val PREF_STARTED = "startedBefore" @@ -72,9 +85,13 @@ val appsList: MutableList = ArrayList() val displayMetrics = DisplayMetrics() var upApp = "" +var doubleUpApp = "" var downApp = "" +var doubleDownApp = "" var rightApp = "" +var doubleRightApp = "" var leftApp = "" +var doubleLeftApp = "" var volumeUpApp = "" var volumeDownApp = "" var doubleClickApp = "" @@ -331,9 +348,13 @@ fun loadApps(packageManager: PackageManager) { fun loadSettings() { upApp = launcherPreferences.getString(ACTION_UP, "")!! + doubleUpApp = launcherPreferences.getString(ACTION_DOUBLE_UP, "")!! downApp = launcherPreferences.getString(ACTION_DOWN, "")!! + doubleDownApp = launcherPreferences.getString(ACTION_DOUBLE_DOWN, "")!! rightApp = launcherPreferences.getString(ACTION_RIGHT, "")!! + doubleRightApp = launcherPreferences.getString(ACTION_DOUBLE_RIGHT, "")!! leftApp = launcherPreferences.getString(ACTION_LEFT, "")!! + doubleLeftApp = launcherPreferences.getString(ACTION_DOUBLE_LEFT, "")!! volumeUpApp = launcherPreferences.getString(ACTION_VOL_UP, "")!! volumeDownApp = launcherPreferences.getString(ACTION_VOL_DOWN, "")!! @@ -362,6 +383,9 @@ fun resetSettings(context: Context) { .putString(PREF_THEME, "finn") .putBoolean(PREF_SCREEN_TIMEOUT_DISABLED, false) .putBoolean(PREF_SEARCH_AUTO_LAUNCH, false) + .putInt(PREF_DATE_FORMAT, 0) + .putBoolean(PREF_SCREEN_FULLSCREEN, true) + .putBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) // load action defaults for (actionKey in ACTIONS) @@ -390,15 +414,20 @@ fun setWindowFlags(window: Window) { fun pickDefaultApp(action: String, context: Context) : String { val arrayResource = when (action) { ACTION_UP -> R.array.default_up + ACTION_DOUBLE_UP -> R.array.default_double_up ACTION_DOWN -> R.array.default_down + ACTION_DOUBLE_DOWN -> R.array.default_double_down ACTION_RIGHT -> R.array.default_right + ACTION_DOUBLE_RIGHT -> R.array.default_double_right ACTION_LEFT -> R.array.default_left + ACTION_DOUBLE_LEFT -> R.array.default_double_left ACTION_VOL_UP -> R.array.default_volume_up ACTION_VOL_DOWN -> R.array.default_volume_down ACTION_DOUBLE_CLICK -> R.array.default_double_click ACTION_LONG_CLICK -> R.array.default_long_click ACTION_CLOCK -> R.array.default_clock ACTION_CALENDAR -> R.array.default_left + else -> return "" // just prevent crashing on unknown input } diff --git a/app/src/main/java/com/finnmglas/launcher/HomeActivity.kt b/app/src/main/java/com/finnmglas/launcher/HomeActivity.kt index 2e2a54a..054be5c 100644 --- a/app/src/main/java/com/finnmglas/launcher/HomeActivity.kt +++ b/app/src/main/java/com/finnmglas/launcher/HomeActivity.kt @@ -145,26 +145,34 @@ class HomeActivity: UIObject, AppCompatActivity(), override fun onFling(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { - Toast.makeText(this, bufferedPointerCount.toString(), Toast.LENGTH_SHORT) - .show() - val width = displayMetrics.widthPixels val height = displayMetrics.heightPixels val diffX = e1.x - e2.x val diffY = e1.y - e2.y - val strictness = 4 // how distinguished the swipe has to be to be accepted + val doubleActions = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) + + // how distinguished the swipe has to be to launch something + val strictness = (4 / bufferedPointerCount) // Only open if the swipe was not from the phones top edge - if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) - launch(downApp,this, R.anim.top_down) - else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) - launch(upApp, this, R.anim.bottom_up) - else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) - launch(leftApp,this, R.anim.right_left) - else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) - launch(rightApp, this, R.anim.left_right) + if (diffY < -height / 8 && abs(diffY) > strictness * abs(diffX) && e1.y > 100) { + if (bufferedPointerCount == 1) launch(downApp, this, R.anim.top_down) + else if (bufferedPointerCount == 2 && doubleActions) launch(doubleDownApp, this, R.anim.top_down) + } + else if (diffY > height / 8 && abs(diffY) > strictness * abs(diffX)) { + if (bufferedPointerCount == 1) launch(upApp, this, R.anim.bottom_up) + else if (bufferedPointerCount == 2 && doubleActions) launch(doubleUpApp, this, R.anim.bottom_up) + } + else if (diffX > width / 4 && abs(diffX) > strictness * abs(diffY)) { + if (bufferedPointerCount == 1) launch(leftApp,this, R.anim.right_left) + else if (bufferedPointerCount == 2 && doubleActions) launch(doubleLeftApp,this, R.anim.right_left) + } + else if (diffX < -width / 4 && abs(diffX) > strictness * abs(diffY)) { + if (bufferedPointerCount == 1) launch(rightApp, this, R.anim.left_right) + else if (bufferedPointerCount == 2 && doubleActions) launch(doubleRightApp, this, R.anim.left_right) + } return true } @@ -213,7 +221,7 @@ class HomeActivity: UIObject, AppCompatActivity(), // Buffer / Debounce the pointer count if (event.pointerCount > bufferedPointerCount) { bufferedPointerCount = event.pointerCount - pointerBufferTimer = fixedRateTimer("pointerBufferTimer", true, 200, 1000) { + pointerBufferTimer = fixedRateTimer("pointerBufferTimer", true, 300, 1000) { bufferedPointerCount = 1 this.cancel() // a non-recurring timer } diff --git a/app/src/main/java/com/finnmglas/launcher/settings/actions/SettingsFragmentActionsRecycler.kt b/app/src/main/java/com/finnmglas/launcher/settings/actions/SettingsFragmentActionsRecycler.kt index a0b55cb..d03f39e 100644 --- a/app/src/main/java/com/finnmglas/launcher/settings/actions/SettingsFragmentActionsRecycler.kt +++ b/app/src/main/java/com/finnmglas/launcher/settings/actions/SettingsFragmentActionsRecycler.kt @@ -134,19 +134,33 @@ class ActionsRecyclerAdapter(val activity: Activity): } init { + val doubleActions = launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false) + actionsList = ArrayList() actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_up),"upApp", upApp )) + if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_up), "doubleUpApp", + doubleUpApp + )) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_down),"downApp", downApp )) + if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_down), "doubleDownApp", + doubleDownApp + )) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_left), "leftApp", leftApp )) + if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_left), "doubleLeftApp", + doubleLeftApp + )) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_right), "rightApp", rightApp )) + if ( doubleActions) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_double_right), "doubleRightApp", + doubleRightApp + )) actionsList.add(ActionInfo(activity.getString(R.string.settings_apps_vol_up), "volumeUpApp", volumeUpApp )) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 873b97d..13660da 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -26,9 +26,13 @@ - --> Hochwischen + Doppelt hoch Runterwischen + Doppelt runter Linkswischen + Doppelt links Rechtswischen + Doppelt rechts Lautstärke + Lautstärke - Doppelklick diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 18548d4..dca0a11 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -26,9 +26,13 @@ - --> Balayez haut + Double haut Balayez bas + Double bas Balayez gauche + Double gauche Balayez droit + Double droit Monter volume Baisser volume Double clic diff --git a/app/src/main/res/values/defaults.xml b/app/src/main/res/values/defaults.xml index 0cbe85e..9d3adf8 100644 --- a/app/src/main/res/values/defaults.xml +++ b/app/src/main/res/values/defaults.xml @@ -8,9 +8,15 @@ launcher:choose + + + com.google.android.apps.translate + com.microsoft.translator + translate.speech.text.translation.voicetranslator + + - org.torproject.torbrowser org.mozilla.firefox com.brave.browser com.duckduckgo.mobile.android @@ -18,6 +24,11 @@ com.android.chrome + + + org.torproject.torbrowser + + de.web.mobile.android.mail @@ -31,6 +42,14 @@ com.samsung.android.calendar + + + + + + + + com.whatsapp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42c66aa..b514e9f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,9 +34,13 @@ - --> Swipe Up + Double Up Swipe Down + Double Down Swipe Left + Double Left Swipe Right + Double Right Volume Up Volume Down Double Click