mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
fixed #76
This commit is contained in:
parent
6eb4fd6104
commit
9423dcce11
3 changed files with 43 additions and 18 deletions
|
@ -16,7 +16,10 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/launcherBaseTheme">
|
android:enableOnBackInvokedCallback="true"
|
||||||
|
android:theme="@style/launcherBaseTheme"
|
||||||
|
tools:ignore="UnusedAttribute" >
|
||||||
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.HomeActivity"
|
android:name=".ui.HomeActivity"
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package de.jrpie.android.launcher.ui
|
package de.jrpie.android.launcher.ui
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewConfiguration
|
import android.view.ViewConfiguration
|
||||||
|
import android.window.OnBackInvokedDispatcher
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.GestureDetectorCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -92,6 +95,15 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
||||||
binding = HomeBinding.inflate(layoutInflater)
|
binding = HomeBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
// Handle back key / gesture on Android 13+, cf. onKeyDown()
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||||
|
OnBackInvokedDispatcher.PRIORITY_OVERLAY
|
||||||
|
) {
|
||||||
|
handleBack()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
@ -193,9 +205,13 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("GestureBackNavigation")
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
when (keyCode) {
|
when (keyCode) {
|
||||||
KeyEvent.KEYCODE_BACK -> LauncherAction.CHOOSE.launch(this)
|
KeyEvent.KEYCODE_BACK -> {
|
||||||
|
// Only used pre Android 13, cf. onBackInvokedDispatcher
|
||||||
|
handleBack()
|
||||||
|
}
|
||||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||||
if (Action.forGesture(Gesture.VOLUME_UP) == LauncherAction.VOLUME_UP) {
|
if (Action.forGesture(Gesture.VOLUME_UP) == LauncherAction.VOLUME_UP) {
|
||||||
// Let the OS handle the key event. This works better with some custom ROMs
|
// Let the OS handle the key event. This works better with some custom ROMs
|
||||||
|
@ -326,27 +342,24 @@ class HomeActivity : UIObject, AppCompatActivity(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Remove those. For now they are necessary
|
|
||||||
* because this inherits from GestureDetector.OnGestureListener */
|
|
||||||
override fun onDoubleTapEvent(event: MotionEvent): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDown(event: MotionEvent): Boolean {
|
private fun handleBack() {
|
||||||
return false
|
LauncherAction.CHOOSE.launch(this)
|
||||||
}
|
|
||||||
|
|
||||||
override fun onScroll(e1: MotionEvent?, e2: MotionEvent, dX: Float, dY: Float): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onShowPress(event: MotionEvent) {}
|
|
||||||
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isHomeScreen(): Boolean {
|
override fun isHomeScreen(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: Remove those. For now they are necessary
|
||||||
|
* because this inherits from GestureDetector.OnGestureListener */
|
||||||
|
override fun onDoubleTapEvent(event: MotionEvent): Boolean { return false }
|
||||||
|
override fun onDown(event: MotionEvent): Boolean { return false }
|
||||||
|
override fun onScroll(e1: MotionEvent?, e2: MotionEvent, dX: Float, dY: Float): Boolean { return false }
|
||||||
|
override fun onShowPress(event: MotionEvent) {}
|
||||||
|
override fun onSingleTapUp(event: MotionEvent): Boolean { return false }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import android.window.OnBackInvokedDispatcher
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
|
@ -53,6 +54,14 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
super<AppCompatActivity>.onCreate(savedInstanceState)
|
super<AppCompatActivity>.onCreate(savedInstanceState)
|
||||||
super<UIObject>.onCreate()
|
super<UIObject>.onCreate()
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && intention == ListActivityIntention.VIEW) {
|
||||||
|
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||||
|
OnBackInvokedDispatcher.PRIORITY_OVERLAY
|
||||||
|
) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get info about which action this activity is open for
|
// get info about which action this activity is open for
|
||||||
intent.extras?.let { bundle ->
|
intent.extras?.let { bundle ->
|
||||||
intention = bundle.getString("intention")
|
intention = bundle.getString("intention")
|
||||||
|
|
Loading…
Add table
Reference in a new issue