mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-22 22:11:27 +01:00
implemented #56: configurable edge width for edge gestures
This commit is contained in:
parent
3423534085
commit
6b31f8dc3b
7 changed files with 125 additions and 10 deletions
|
@ -60,6 +60,7 @@ import eu.jonahbauer.android.preference.annotations.serializer.PreferenceSeriali
|
|||
@PreferenceGroup(name = "enabled_gestures", prefix = "settings_enabled_gestures_", suffix = "_key", value = {
|
||||
@Preference(name = "double_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 {
|
||||
|
|
|
@ -57,6 +57,8 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
}
|
||||
}
|
||||
|
||||
private var edgeWidth = 0.15f
|
||||
|
||||
private var bufferedPointerCount = 1 // how many fingers on screen
|
||||
private var pointerBufferTimer = Timer()
|
||||
|
||||
|
@ -99,6 +101,7 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
|
||||
LauncherPreferences.getSharedPreferences()
|
||||
.registerOnSharedPreferenceChangeListener(sharedPreferencesListener)
|
||||
|
||||
}
|
||||
|
||||
private fun updateClock() {
|
||||
|
@ -161,6 +164,9 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
edgeWidth = LauncherPreferences.enabled_gestures().edgeSwipeEdgeWidth() / 100f
|
||||
|
||||
updateClock()
|
||||
}
|
||||
|
||||
|
@ -200,7 +206,6 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
|
||||
val doubleActions = LauncherPreferences.enabled_gestures().doubleSwipe()
|
||||
val edgeActions = LauncherPreferences.enabled_gestures().edgeSwipe()
|
||||
val edgeStrictness = 0.15
|
||||
|
||||
val threshold = ViewConfiguration.get(this).scaledTouchSlop
|
||||
|
||||
|
@ -227,15 +232,15 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
|||
}
|
||||
|
||||
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) }
|
||||
} 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) }
|
||||
}
|
||||
|
||||
if (max(e1.y, e2.y) < edgeStrictness * height) {
|
||||
if (max(e1.y, e2.y) < edgeWidth * height) {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -12,9 +11,9 @@
|
|||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/settings_appbar"
|
||||
android:background="@null"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
app:elevation="0dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
@ -55,6 +54,7 @@
|
|||
android:id="@+id/settings_system"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:gravity="center"
|
||||
android:includeFontPadding="true"
|
||||
|
@ -64,8 +64,7 @@
|
|||
custom:layout_constraintBottom_toBottomOf="parent"
|
||||
custom:layout_constraintStart_toStartOf="parent"
|
||||
custom:layout_constraintTop_toTopOf="parent"
|
||||
custom:type="solid"
|
||||
android:layout_marginStart="8dp" />
|
||||
custom:type="solid" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
|
@ -81,4 +80,15 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
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>
|
||||
|
|
|
@ -97,6 +97,7 @@
|
|||
|
||||
<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_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_open_keyboard_key" translatable="false">functionality.search_auto_keyboard</string>
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
|
||||
<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_width">Edge width</string>
|
||||
<string name="settings_functionality_auto_launch">Launch search results</string>
|
||||
<string name="settings_functionality_auto_keyboard">Start keyboard for search</string>
|
||||
|
||||
|
|
|
@ -95,6 +95,16 @@
|
|||
android:key="@string/settings_enabled_gestures_edge_swipe_key"
|
||||
android:defaultValue="true"
|
||||
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>
|
||||
|
|
Loading…
Add table
Reference in a new issue