Skip to content

Commit 7ddcdf3

Browse files
committed
add overall in settings for lock screen to see what's clickable
1 parent fc1dcd5 commit 7ddcdf3

4 files changed

Lines changed: 177 additions & 2 deletions

File tree

app/src/androidTest/java/com/ah/taplock/SettingsUiTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,42 @@ class SettingsUiTest {
264264
)
265265
}
266266

267+
@Test
268+
fun updateLockZone_updatesPref() {
269+
getPrefs().edit()
270+
.putBoolean(context.getString(R.string.lock_screen_double_tap), true)
271+
.commit()
272+
273+
setScreenContent()
274+
275+
composeTestRule.onNodeWithTag("slider_lock_zone")
276+
.performScrollTo()
277+
.performSemanticsAction(SemanticsActions.SetProgress) { setProgress ->
278+
assertTrue(setProgress(80f))
279+
}
280+
281+
assertEquals(
282+
80,
283+
getPrefs().getInt(context.getString(R.string.lock_zone_percent), 0)
284+
)
285+
}
286+
287+
@Test
288+
fun highlightActiveArea_showsOverlayPreview() {
289+
getPrefs().edit()
290+
.putBoolean(context.getString(R.string.lock_screen_double_tap), true)
291+
.commit()
292+
293+
setScreenContent()
294+
295+
composeTestRule.onNodeWithTag("button_lock_zone_preview")
296+
.performScrollTo()
297+
.performClick()
298+
299+
composeTestRule.onNodeWithTag("lock_zone_live_overlay")
300+
.assertExists()
301+
}
302+
267303
@Test
268304
fun updateTimeout_updatesPref() {
269305
composeTestRule.onNode(hasSetTextAction())
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.ah.taplock
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.BoxWithConstraints
7+
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.foundation.layout.fillMaxWidth
9+
import androidx.compose.foundation.layout.height
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.width
12+
import androidx.compose.foundation.shape.RoundedCornerShape
13+
import androidx.compose.material3.MaterialTheme
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.ui.Alignment
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.graphics.Color
18+
import androidx.compose.ui.platform.testTag
19+
import androidx.compose.ui.unit.dp
20+
21+
private fun lockZoneFraction(lockZonePercent: Int): Float = (lockZonePercent / 100f).coerceIn(0.2f, 1f)
22+
23+
@Composable
24+
fun LockScreenZonePreview(
25+
lockZonePercent: Int
26+
) {
27+
val previewWidth = 120.dp
28+
val previewHeight = 220.dp
29+
val previewVerticalPadding = 16.dp
30+
val previewInnerHeight = 188.dp
31+
val highlightedHeight = previewInnerHeight * lockZoneFraction(lockZonePercent)
32+
val frameColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.6f)
33+
val zoneColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.28f)
34+
val shape = RoundedCornerShape(24.dp)
35+
36+
Box(
37+
modifier = Modifier.fillMaxWidth(),
38+
contentAlignment = Alignment.Center
39+
) {
40+
Box(
41+
modifier = Modifier
42+
.testTag("lock_zone_preview")
43+
.width(previewWidth)
44+
.height(previewHeight)
45+
.border(1.dp, frameColor, shape)
46+
.background(
47+
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.18f),
48+
shape
49+
)
50+
.padding(vertical = previewVerticalPadding)
51+
) {
52+
Box(
53+
modifier = Modifier
54+
.fillMaxSize()
55+
.align(Alignment.TopCenter)
56+
) {
57+
Box(
58+
modifier = Modifier
59+
.align(Alignment.TopCenter)
60+
.fillMaxWidth()
61+
.height(highlightedHeight)
62+
.background(
63+
zoneColor,
64+
RoundedCornerShape(bottomStart = 18.dp, bottomEnd = 18.dp)
65+
)
66+
)
67+
}
68+
}
69+
}
70+
}
71+
72+
@Composable
73+
fun LockScreenZoneLiveOverlay(
74+
lockZonePercent: Int
75+
) {
76+
BoxWithConstraints(
77+
modifier = Modifier
78+
.fillMaxSize()
79+
.testTag("lock_zone_live_overlay")
80+
) {
81+
val highlightedHeight = maxHeight * lockZoneFraction(lockZonePercent)
82+
val zoneColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.18f)
83+
val zoneBorderColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f)
84+
85+
Box(
86+
modifier = Modifier
87+
.fillMaxSize()
88+
.background(Color.Black.copy(alpha = 0.16f))
89+
)
90+
91+
Box(
92+
modifier = Modifier
93+
.align(Alignment.TopCenter)
94+
.fillMaxWidth()
95+
.height(highlightedHeight)
96+
.background(
97+
zoneColor,
98+
RoundedCornerShape(bottomStart = 24.dp, bottomEnd = 24.dp)
99+
)
100+
.border(
101+
width = 1.dp,
102+
color = zoneBorderColor,
103+
shape = RoundedCornerShape(bottomStart = 24.dp, bottomEnd = 24.dp)
104+
)
105+
)
106+
}
107+
}

app/src/main/java/com/ah/taplock/MainActivity.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import androidx.lifecycle.Lifecycle
9191
import androidx.lifecycle.LifecycleEventObserver
9292
import com.ah.taplock.ui.theme.TapLockTheme
9393
import kotlinx.coroutines.Dispatchers
94+
import kotlinx.coroutines.delay
9495
import kotlinx.coroutines.launch
9596
import kotlinx.coroutines.withContext
9697
import java.io.File
@@ -214,10 +215,13 @@ fun TapLockScreen() {
214215
val edgeTopOffsetSliderInteraction = remember { MutableInteractionSource() }
215216
val edgeBottomOffsetSliderInteraction = remember { MutableInteractionSource() }
216217
val cornerSizeSliderInteraction = remember { MutableInteractionSource() }
218+
val lockZoneSliderInteraction = remember { MutableInteractionSource() }
217219
val isEdgeWidthSliderDragged by edgeWidthSliderInteraction.collectIsDraggedAsState()
218220
val isEdgeTopOffsetSliderDragged by edgeTopOffsetSliderInteraction.collectIsDraggedAsState()
219221
val isEdgeBottomOffsetSliderDragged by edgeBottomOffsetSliderInteraction.collectIsDraggedAsState()
220222
val isCornerSizeSliderDragged by cornerSizeSliderInteraction.collectIsDraggedAsState()
223+
val isLockZoneSliderDragged by lockZoneSliderInteraction.collectIsDraggedAsState()
224+
var showLockZonePreviewOverlay by remember { mutableStateOf(false) }
221225
val editableLeftEdgeZoneEnabled = leftEdgeZoneEnabled
222226
val editableRightEdgeZoneEnabled = rightEdgeZoneEnabled
223227
val editableTopLeftCornerZoneEnabled = topLeftCornerZoneEnabled
@@ -233,14 +237,23 @@ fun TapLockScreen() {
233237
editableTopRightCornerZoneEnabled ||
234238
editableBottomLeftCornerZoneEnabled ||
235239
editableBottomRightCornerZoneEnabled
236-
val showLiveZoneOverlay = (
240+
val showEdgeZoneLiveOverlay = (
237241
anyEdgeZoneEnabled || anyCornerZoneEnabled
238242
) && (
239243
isEdgeWidthSliderDragged ||
240244
isEdgeTopOffsetSliderDragged ||
241245
isEdgeBottomOffsetSliderDragged ||
242246
isCornerSizeSliderDragged
243247
)
248+
val showLockZoneLiveOverlay = lockScreenDoubleTap &&
249+
(isLockZoneSliderDragged || showLockZonePreviewOverlay)
250+
251+
LaunchedEffect(showLockZonePreviewOverlay) {
252+
if (showLockZonePreviewOverlay) {
253+
delay(1500)
254+
showLockZonePreviewOverlay = false
255+
}
256+
}
244257

245258
fun saveSelectedZoneBoolean(baseKey: String, value: Boolean) {
246259
context.getSharedPreferences(sharedPrefName, Context.MODE_PRIVATE)
@@ -1101,8 +1114,21 @@ fun TapLockScreen() {
11011114
},
11021115
valueRange = 20f..100f,
11031116
steps = 15,
1117+
interactionSource = lockZoneSliderInteraction,
11041118
modifier = Modifier.testTag("slider_lock_zone")
11051119
)
1120+
Text(
1121+
stringResource(R.string.lock_zone_preview_label),
1122+
style = MaterialTheme.typography.bodySmall,
1123+
color = MaterialTheme.colorScheme.onSurfaceVariant
1124+
)
1125+
LockScreenZonePreview(lockZonePercent = lockZonePercent.toInt())
1126+
Button(
1127+
onClick = { showLockZonePreviewOverlay = true },
1128+
modifier = Modifier.testTag("button_lock_zone_preview")
1129+
) {
1130+
Text(stringResource(R.string.lock_zone_preview_button))
1131+
}
11061132
}
11071133

11081134
HorizontalDivider(modifier = Modifier.padding(vertical = 4.dp))
@@ -1544,7 +1570,11 @@ fun TapLockScreen() {
15441570

15451571
}
15461572

1547-
if (showLiveZoneOverlay) {
1573+
if (showLockZoneLiveOverlay) {
1574+
LockScreenZoneLiveOverlay(lockZonePercent = lockZonePercent.toInt())
1575+
}
1576+
1577+
if (showEdgeZoneLiveOverlay) {
15481578
EdgeZoneLiveOverlay(
15491579
leftEnabled = editableLeftEdgeZoneEnabled,
15501580
rightEnabled = editableRightEdgeZoneEnabled,

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<string name="quick_settings_tile_manual_toast">Add TapLock from the Quick Settings edit screen on this Android version.</string>
132132
<string name="lock_zone_percent">lock_zone_percent</string>
133133
<string name="lock_zone_label">Lock screen tap zone: %d%%</string>
134+
<string name="lock_zone_preview_label">Active area preview</string>
135+
<string name="lock_zone_preview_button">Highlight active area</string>
134136
<string name="edge_zones_label">Screen Edge And Corner Lock Zones</string>
135137
<string name="edge_zones_description">Double-tap enabled screen edges or corners to lock. Swiping inward from an enabled screen edge still goes Back.</string>
136138
<string name="edge_zones_portrait_only">These settings apply in both portrait and landscape.</string>

0 commit comments

Comments
 (0)