implemented #56: configurable edge width for edge gestures

This commit is contained in:
Josia Pietsch 2024-11-01 23:16:27 +01:00
parent 3423534085
commit 6b31f8dc3b
Signed by: jrpie
GPG key ID: E70B571D66986A2D
7 changed files with 125 additions and 10 deletions

View file

@ -60,6 +60,7 @@ import eu.jonahbauer.android.preference.annotations.serializer.PreferenceSeriali
@PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = { @PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = {
@Preference(name = "double_swipe", type = boolean.class, defaultValue = "true"), @Preference(name = "double_swipe", type = boolean.class, defaultValue = "true"),
@Preference(name = "edge_swipe", type = boolean.class, defaultValue = "true"), @Preference(name = "edge_swipe", type = boolean.class, defaultValue = "true"),
@Preference(name = "edge_swipe_edge_width", type = int.class, defaultValue = "15"),
}), }),
}) })
public final class LauncherPreferences$Config { public final class LauncherPreferences$Config {

View file

@ -57,6 +57,8 @@ class HomeActivity : UIObject, AppCompatActivity(),
} }
} }
private var edgeWidth = 0.15f
private var bufferedPointerCount = 1 // how many fingers on screen private var bufferedPointerCount = 1 // how many fingers on screen
private var pointerBufferTimer = Timer() private var pointerBufferTimer = Timer()
@ -99,6 +101,7 @@ class HomeActivity : UIObject, AppCompatActivity(),
LauncherPreferences.getSharedPreferences() LauncherPreferences.getSharedPreferences()
.registerOnSharedPreferenceChangeListener(sharedPreferencesListener) .registerOnSharedPreferenceChangeListener(sharedPreferencesListener)
} }
private fun updateClock() { private fun updateClock() {
@ -161,6 +164,9 @@ class HomeActivity : UIObject, AppCompatActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
edgeWidth = LauncherPreferences.enabled_gestures().edgeSwipeEdgeWidth() / 100f
updateClock() updateClock()
} }
@ -200,7 +206,6 @@ class HomeActivity : UIObject, AppCompatActivity(),
val doubleActions = LauncherPreferences.enabled_gestures().doubleSwipe() val doubleActions = LauncherPreferences.enabled_gestures().doubleSwipe()
val edgeActions = LauncherPreferences.enabled_gestures().edgeSwipe() val edgeActions = LauncherPreferences.enabled_gestures().edgeSwipe()
val edgeStrictness = 0.15
val threshold = ViewConfiguration.get(this).scaledTouchSlop val threshold = ViewConfiguration.get(this).scaledTouchSlop
@ -227,15 +232,15 @@ class HomeActivity : UIObject, AppCompatActivity(),
} }
if (edgeActions) { if (edgeActions) {
if (max(e1.x, e2.x) < edgeStrictness * width) { if (max(e1.x, e2.x) < edgeWidth * width) {
gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.LEFT) } gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.LEFT) }
} else if (min(e1.x, e2.x) > (1 - edgeStrictness) * width) { } else if (min(e1.x, e2.x) > (1 - edgeWidth) * width) {
gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.RIGHT) } gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.RIGHT) }
} }
if (max(e1.y, e2.y) < edgeStrictness * height) { if (max(e1.y, e2.y) < edgeWidth * height) {
gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.TOP) } gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.TOP) }
} else if (min(e1.y, e2.y) > (1 - edgeStrictness) * height) { } else if (min(e1.y, e2.y) > (1 - edgeWidth) * height) {
gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.BOTTOM) } gesture = gesture?.let { it.getEdgeVariant(Gesture.Edge.BOTTOM) }
} }
} }

View file

@ -0,0 +1,87 @@
package de.jrpie.android.launcher.ui.settings
import android.animation.AnimatorListenerAdapter
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import android.view.animation.AccelerateInterpolator
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import de.jrpie.android.launcher.preferences.LauncherPreferences
/*
* An overlay to indicate the areas where edge-gestures are detected
*/
class GestureAreaIndicatorOverlayView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
private var horizontalWidth = 0.1f
private var verticalWidth = 0.1f
private lateinit var edgeLeft: Rect
private lateinit var edgeRight: Rect
private lateinit var edgeTop: Rect
private lateinit var edgeBottom: Rect
private val hideTask = Runnable {
visibility = INVISIBLE
}
private var sharedPreferencesListener =
SharedPreferences.OnSharedPreferenceChangeListener { _, prefKey ->
if (prefKey == LauncherPreferences.enabled_gestures().keys().edgeSwipeEdgeWidth()) {
this.removeCallbacks(hideTask)
visibility = VISIBLE
update()
requestLayout()
invalidate()
this.postDelayed(hideTask, 3000)
}
}
constructor(context: Context) : this(context, null) { }
private val overlayPaint = Paint()
init {
overlayPaint.setARGB(50,255,0,0)
overlayPaint.strokeWidth = 10f
update()
}
private fun update() {
horizontalWidth = LauncherPreferences.enabled_gestures().edgeSwipeEdgeWidth() / 100f
verticalWidth = horizontalWidth
edgeTop = Rect(0,0,(width * horizontalWidth).toInt(), height)
edgeBottom = Rect((width * (1 - horizontalWidth)).toInt(),0,width, height)
edgeLeft = Rect(0,0, width, (height * verticalWidth).toInt())
edgeRight = Rect(0,(height * (1-verticalWidth)).toInt(), width, height)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
LauncherPreferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(sharedPreferencesListener)
}
override fun onDetachedFromWindow() {
LauncherPreferences.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(sharedPreferencesListener)
super.onDetachedFromWindow()
}
override fun onDraw(canvas: Canvas) {
arrayOf(edgeLeft,
edgeRight, edgeTop, edgeBottom).forEach { e ->
canvas.drawRect(e, overlayPaint)
}
}
}

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto" xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
@ -12,9 +11,9 @@
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/settings_appbar" android:id="@+id/settings_appbar"
android:background="@null"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@null"
app:elevation="0dp"> app:elevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -55,6 +54,7 @@
android:id="@+id/settings_system" android:id="@+id/settings_system"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:gravity="center" android:gravity="center"
android:includeFontPadding="true" android:includeFontPadding="true"
@ -64,8 +64,7 @@
custom:layout_constraintBottom_toBottomOf="parent" custom:layout_constraintBottom_toBottomOf="parent"
custom:layout_constraintStart_toStartOf="parent" custom:layout_constraintStart_toStartOf="parent"
custom:layout_constraintTop_toTopOf="parent" custom:layout_constraintTop_toTopOf="parent"
custom:type="solid" custom:type="solid" />
android:layout_marginStart="8dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
@ -81,4 +80,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" /> app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<de.jrpie.android.launcher.ui.settings.GestureAreaIndicatorOverlayView
android:id="@+id/gestureAreaIndicatorOverlayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:clickable="false"
android:visibility="invisible"
android:padding="0dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -97,6 +97,7 @@
<string name="settings_enabled_gestures_double_swipe_key" translatable="false">enabled_gestures.double_actions</string> <string name="settings_enabled_gestures_double_swipe_key" translatable="false">enabled_gestures.double_actions</string>
<string name="settings_enabled_gestures_edge_swipe_key" translatable="false">enabled_gestures.edge_actions</string> <string name="settings_enabled_gestures_edge_swipe_key" translatable="false">enabled_gestures.edge_actions</string>
<string name="settings_enabled_gestures_edge_swipe_edge_width_key" translatable="false">enabled_gestures.edge_actions.edge_width</string>
<string name="settings_functionality_search_auto_launch_key" translatable="false">functionality.search_auto_launch</string> <string name="settings_functionality_search_auto_launch_key" translatable="false">functionality.search_auto_launch</string>
<string name="settings_functionality_search_auto_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string> <string name="settings_functionality_search_auto_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string>

View file

@ -109,6 +109,7 @@
<string name="settings_enabled_gestures_double_swipe">Double swipe actions</string> <string name="settings_enabled_gestures_double_swipe">Double swipe actions</string>
<string name="settings_enabled_gestures_edge_swipe">Edge swipe actions</string> <string name="settings_enabled_gestures_edge_swipe">Edge swipe actions</string>
<string name="settings_enabled_gestures_edge_swipe_edge_width">Edge width</string>
<string name="settings_functionality_auto_launch">Launch search results</string> <string name="settings_functionality_auto_launch">Launch search results</string>
<string name="settings_functionality_auto_keyboard">Start keyboard for search</string> <string name="settings_functionality_auto_keyboard">Start keyboard for search</string>

View file

@ -95,6 +95,16 @@
android:key="@string/settings_enabled_gestures_edge_swipe_key" android:key="@string/settings_enabled_gestures_edge_swipe_key"
android:defaultValue="true" android:defaultValue="true"
android:title="@string/settings_enabled_gestures_edge_swipe"/> android:title="@string/settings_enabled_gestures_edge_swipe"/>
<PreferenceCategory
android:dependency="@string/settings_enabled_gestures_edge_swipe_key"
app:allowDividerAbove="false" >
<SeekBarPreference
android:key="@string/settings_enabled_gestures_edge_swipe_edge_width_key"
android:defaultValue="15"
android:max="33"
android:title="@string/settings_enabled_gestures_edge_swipe_edge_width"/>
</PreferenceCategory>
</PreferenceCategory> </PreferenceCategory>