Skip to content

Commit

Permalink
Open Recents as a gesture option (LawnchairLauncher#4773)
Browse files Browse the repository at this point in the history
* Initial test of adding recents on gestures.

* Rename

* FIxes

* Fix options?

* surely this time!

* A11y and some cleanup (this is still very ugly and needs fixing)

* Update accessibility desc.

* Fix strings rename

* Update RecentsGestureHandler

* Fix merge

* Update GestureHandlerConfig.kt (fix compilation errors)

* Update strings.xml

* Fix build

* fixed style

---------

Co-authored-by: MrSluffy <[email protected]>
  • Loading branch information
2 people authored and nulldrf committed Sep 19, 2024
1 parent 425cdb7 commit 0eb09fc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<string name="what_to_show">What to show</string>

<!-- A11y description -->
<string name="accessibility_service_description">To lock your phone when performing a gesture, Lawnchair requires accessibility access.\n\nLawnchair doesn\'t watch any user action, though the privilege to do so is required for all accessibility services. Lawnchair discards any event sent by the system.\n\nIn order to lock your phone, Lawnchair uses the performGlobalAction Accessibility service.</string>
<string name="accessibility_service_description">To lock your phone when performing a gesture, and to open Recents via gesture, Lawnchair requires accessibility access.\n\nLawnchair doesn\'t watch any user action, though the privilege to do so is required for all accessibility services. Lawnchair discards any event sent by the system.\n\nIn order to lock your phone, or to open Recents, Lawnchair uses the performGlobalAction Accessibility service.</string>

<string name="iconPackPackageDefault" translatable="false">""</string>

Expand Down Expand Up @@ -434,6 +434,7 @@

<string name="gesture_handler_no_op">Do nothing</string>
<string name="gesture_handler_sleep">Sleep</string>
<string name="gesture_handler_recents">Open Recents</string>
<string name="gesture_handler_open_notifications">Open notification panel</string>
<string name="gesture_handler_open_app_option">Open app</string>
<string name="gesture_handler_open_app_config">Open %1$s</string>
Expand All @@ -447,9 +448,12 @@
<string name="dt2s_admin_hint">To use Double-Tap to Sleep, set Lawnchair as a device admin app. Tap \"Open settings\", then tap \"Activate this device admin app.\"</string>
<string name="dt2s_admin_warning">Double-Tap to Sleep will be turned off.</string>

<string name="dt2s_a11y_hint_title">Turn on accessibility service</string>

<string name="d2ts_recents_a11y_hint_title">Turn on accessibility service</string>
<string name="dt2s_a11y_hint">To use Double-Tap to Sleep, turn on the Lawnchair accessibility service. Tap \"Open settings\", select \"Lawnchair\" and turn on \"Use Lawnchair.\"\n\nLawnchair uses Accessibility\'s `performGlobalAction` method to perform this action. This is a sensitive permission that allows monitoring other apps. However, Lawnchair is not configured for that functionality and receives no events.</string>
<string name="dt2s_warning_open_settings">Open settings</string>
<string name="dt2s_recents_warning_open_settings">Open settings</string>

<string name="recents_a11y_hint">To use Open Recents, turn on the Lawnchair accessibility service. Tap \"Open settings\", select \"Lawnchair\" and turn on \"Use Lawnchair.\"\n\nLawnchair uses Accessibility\'s `performGlobalAction` method to perform this action. This is a sensitive permission that allows monitoring other apps. However, Lawnchair is not configured for that functionality and receives no events.</string>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import app.lawnchair.gestures.handlers.OpenAppSearchGestureHandler
import app.lawnchair.gestures.handlers.OpenAppTarget
import app.lawnchair.gestures.handlers.OpenNotificationsHandler
import app.lawnchair.gestures.handlers.OpenSearchGestureHandler
import app.lawnchair.gestures.handlers.RecentsGestureHandler
import app.lawnchair.gestures.handlers.SleepGestureHandler
import com.android.launcher3.R
import kotlinx.serialization.SerialName
Expand Down Expand Up @@ -41,7 +42,11 @@ sealed class GestureHandlerConfig {
data object Sleep : Simple(R.string.gesture_handler_sleep, ::SleepGestureHandler)

@Serializable
@SerialName("openNotifications")
@SerialName("recents")
data object Recents : Simple(R.string.gesture_handler_recents, ::RecentsGestureHandler)

@Serializable
@SerialName("openNotificationdata")
data object OpenNotifications : Simple(R.string.gesture_handler_open_notifications, ::OpenNotificationsHandler)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sealed class GestureHandlerOption(

data object NoOp : Simple(GestureHandlerConfig.NoOp)
data object Sleep : Simple(GestureHandlerConfig.Sleep)
data object Recents : Simple(GestureHandlerConfig.Recents)
data object OpenNotifications : Simple(GestureHandlerConfig.OpenNotifications)
data object OpenAppDrawer : Simple(GestureHandlerConfig.OpenAppDrawer)
data object OpenAppSearch : Simple(GestureHandlerConfig.OpenAppSearch)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021, Lawnchair
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package app.lawnchair.gestures.handlers

import android.accessibilityservice.AccessibilityService
import android.content.Context
import android.content.Intent
import android.provider.Settings
import app.lawnchair.LawnchairLauncher
import app.lawnchair.lawnchairApp
import app.lawnchair.views.ComposeBottomSheet
import com.android.launcher3.R

class RecentsGestureHandler(context: Context) : GestureHandler(context) {

override suspend fun onTrigger(launcher: LawnchairLauncher) {
val app = launcher.lawnchairApp
if (!app.isAccessibilityServiceBound()) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
ComposeBottomSheet.show(launcher) {
ServiceWarningDialog(
title = R.string.d2ts_recents_a11y_hint_title,
description = R.string.recents_a11y_hint,
settingsIntent = intent,
) { close(true) }
}
return
}
app.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SleepMethodPieAccessibility(context: Context) : SleepGestureHandler.SleepM
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
ComposeBottomSheet.show(launcher) {
ServiceWarningDialog(
title = R.string.dt2s_a11y_hint_title,
title = R.string.d2ts_recents_a11y_hint_title,
description = R.string.dt2s_a11y_hint,
settingsIntent = intent,
) { close(true) }
Expand Down Expand Up @@ -155,7 +155,7 @@ fun ServiceWarningDialog(
handleClose()
},
) {
Text(text = stringResource(id = R.string.dt2s_warning_open_settings))
Text(text = stringResource(id = R.string.dt2s_recents_warning_open_settings))
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.launch
val options = listOf(
GestureHandlerOption.NoOp,
GestureHandlerOption.Sleep,
GestureHandlerOption.Recents,
GestureHandlerOption.OpenNotifications,
GestureHandlerOption.OpenAppDrawer,
GestureHandlerOption.OpenAppSearch,
Expand Down

0 comments on commit 0eb09fc

Please sign in to comment.