diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8520763..3afcf6c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -35,7 +35,8 @@
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/Theme.YamLauncher"
- android:windowSoftInputMode="adjustResize">
+ android:windowSoftInputMode="adjustResize"
+ tools:ignore="DiscouragedApi,LockedOrientationActivity">
@@ -44,6 +45,18 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt
index 0e8ab85..34c1807 100644
--- a/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt
+++ b/app/src/main/java/eu/ottop/yamlauncher/MainActivity.kt
@@ -1,11 +1,15 @@
package eu.ottop.yamlauncher
+import android.accessibilityservice.AccessibilityService
+import android.accessibilityservice.AccessibilityServiceInfo
import android.annotation.SuppressLint
+import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
+import android.content.pm.ServiceInfo
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color
@@ -15,6 +19,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.UserHandle
+import android.provider.Settings
import android.text.Editable
import android.text.TextWatcher
import android.view.GestureDetector
@@ -27,7 +32,7 @@ import android.view.View.TEXT_ALIGNMENT_TEXT_START
import android.view.ViewTreeObserver
import android.view.WindowInsets
import android.view.WindowInsetsController
-import android.view.WindowManager
+import android.view.accessibility.AccessibilityManager
import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
import android.widget.TextClock
@@ -49,8 +54,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-import kotlin.math.abs
import java.lang.reflect.Method
+import kotlin.math.abs
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener, AppMenuAdapter.OnItemClickListener, AppMenuAdapter.OnShortcutListener, AppMenuAdapter.OnItemLongClickListener {
@@ -427,6 +432,26 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
startActivity(Intent(this@MainActivity, SettingsActivity::class.java))
}
+ override fun onDoubleTap(e: MotionEvent): Boolean {
+ if (preferences.getBoolean("doubleTap", false)) {
+ if (isAccessibilityServiceEnabled(
+ this@MainActivity,
+ ScreenLockService::class.java
+ )
+ ) {
+ println("enabled")
+ val intent = Intent(this@MainActivity, ScreenLockService::class.java)
+ intent.action = "LOCK_SCREEN"
+ startService(intent)
+ } else {
+ promptEnableAccessibility()
+ }
+ }
+
+ return super.onDoubleTap(e)
+
+ }
+
}
inner class TextGestureListener : GestureListener() {
@@ -435,6 +460,40 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
}
}
+
+ fun isAccessibilityServiceEnabled(context: Context, service: Class): Boolean {
+ val am = context.getSystemService(ACCESSIBILITY_SERVICE) as AccessibilityManager
+ val enabledServices =
+ am.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK)
+
+ for (enabledService in enabledServices) {
+ val enabledServiceInfo: ServiceInfo = enabledService.resolveInfo.serviceInfo
+ if (enabledServiceInfo.packageName.equals(context.packageName) && enabledServiceInfo.name.equals(
+ service.name
+ )
+ ) return true
+ }
+
+ return false
+ }
+
+ private fun promptEnableAccessibility() {
+ AlertDialog.Builder(this@MainActivity).apply {
+ setTitle("Confirmation")
+ setMessage("To lock with double tap, enable YAM Launcher in accessibility settings.")
+ setPositiveButton("Yes") { _, _ ->
+ // Perform action on confirmation
+ val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ startActivity(intent)
+ }
+ setNegativeButton("Cancel") { _, _ ->
+
+ }
+
+ }.create().show()
+ }
+
private fun getSwipeInfo(direction: String): Pair {
val app = preferences.getString("${direction}SwipeApp", "")?.split("§splitter§")
diff --git a/app/src/main/java/eu/ottop/yamlauncher/ScreenLockService.kt b/app/src/main/java/eu/ottop/yamlauncher/ScreenLockService.kt
new file mode 100644
index 0000000..a6776c2
--- /dev/null
+++ b/app/src/main/java/eu/ottop/yamlauncher/ScreenLockService.kt
@@ -0,0 +1,28 @@
+package eu.ottop.yamlauncher
+
+import android.accessibilityservice.AccessibilityService
+import android.content.Intent
+import android.view.accessibility.AccessibilityEvent
+
+class ScreenLockService : AccessibilityService() {
+
+ override fun onAccessibilityEvent(event: AccessibilityEvent?) {
+ // Handle accessibility events if needed
+ }
+
+ override fun onInterrupt() {
+ // Handle interrupt
+ }
+
+ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
+ if (intent != null && intent.action == "LOCK_SCREEN") {
+ performLockScreen()
+ }
+ stopSelf()
+ return super.onStartCommand(intent, flags, startId)
+ }
+
+ private fun performLockScreen() {
+ performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2239916..8378828 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -75,5 +75,6 @@
Open-Meteo.com
(CC BY 4.0)]]>
Open-Meteo.com (CC BY 4.0)]]>
+ Idk this is my service
\ No newline at end of file
diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml
index be30ced..039733f 100644
--- a/app/src/main/res/xml/root_preferences.xml
+++ b/app/src/main/res/xml/root_preferences.xml
@@ -173,6 +173,12 @@
app:key="rightSwipeApp"
app:selectable="true"
app:title="Right Swipe App" />
+
+
\ No newline at end of file