Files
lawnchair/compose/tests/com/android/launcher3/helper/TestHelper.kt
Jordan Silva 98795242eb Add AppChip in Compose
- Add a new app chip in composable.
- Implement the app chip expansion animations and styles.

Bug: 400436593
Bug: 366172565
Fix: 366387927
Flag: EXEMPT build flag: release_enable_compose_in_launcher.
Test: AppChipTest
Test: AppChipScreenshotTest
Change-Id: I05ca14354ab7702026343c4e636538d507336f6a
2025-05-23 02:37:30 -07:00

41 lines
1.7 KiB
Kotlin

/*
* Copyright (C) 2025 The Android Open Source Project
*
* 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 com.android.launcher3.helper
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.NativeKeyEvent
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
val NATIVE_DPAD_DOWN = NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_DPAD_DOWN)
val NATIVE_TAB = NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_TAB)
val NavigateDownKeyEvent = KeyEvent(NATIVE_DPAD_DOWN)
val NavigateDownTabEvent = KeyEvent(NATIVE_TAB)
fun hasMinTouchArea(minWidth: Dp = 48.dp, minHeight: Dp = 48.dp): SemanticsMatcher =
SemanticsMatcher("touch area is smaller than $minWidth x $minHeight") { node ->
val density: Density = node.root?.density ?: error("root node not available!")
with(density) {
val rect = node.touchBoundsInRoot
val size = node.size
(rect.width.toDp() >= minWidth && rect.height.toDp() >= minHeight) ||
(size.width.toDp() >= minWidth && size.height.toDp() >= minHeight)
}
}