1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.systemui.development.ui.compose
18
19 import androidx.compose.foundation.basicMarquee
20 import androidx.compose.foundation.focusable
21 import androidx.compose.foundation.layout.Spacer
22 import androidx.compose.foundation.layout.wrapContentWidth
23 import androidx.compose.material3.Text
24 import androidx.compose.material3.minimumInteractiveComponentSize
25 import androidx.compose.runtime.Composable
26 import androidx.compose.ui.Modifier
27 import androidx.compose.ui.graphics.Color
28 import androidx.compose.ui.hapticfeedback.HapticFeedbackType
29 import androidx.compose.ui.input.pointer.pointerInput
30 import androidx.compose.ui.platform.LocalHapticFeedback
31 import androidx.compose.ui.res.stringResource
32 import androidx.compose.ui.semantics.onLongClick
33 import androidx.compose.ui.semantics.semantics
34 import com.android.systemui.communal.ui.compose.extensions.detectLongPressGesture
35 import com.android.systemui.development.ui.viewmodel.BuildNumberViewModel
36 import com.android.systemui.lifecycle.rememberViewModel
37 import com.android.systemui.res.R
38
39 @Composable
BuildNumbernull40 fun BuildNumber(
41 viewModelFactory: BuildNumberViewModel.Factory,
42 textColor: Color,
43 modifier: Modifier = Modifier,
44 ) {
45 val viewModel = rememberViewModel(traceName = "BuildNumber") { viewModelFactory.create() }
46
47 val buildNumber = viewModel.buildNumber
48
49 if (buildNumber != null) {
50 val haptics = LocalHapticFeedback.current
51 val copyToClipboardActionLabel = stringResource(id = R.string.copy_to_clipboard_a11y_action)
52
53 Text(
54 text = buildNumber.value,
55 modifier =
56 modifier
57 .focusable()
58 .wrapContentWidth()
59 // Using this instead of combinedClickable because this node should not support
60 // single click
61 .pointerInput(Unit) {
62 detectLongPressGesture {
63 haptics.performHapticFeedback(HapticFeedbackType.LongPress)
64 viewModel.onBuildNumberLongPress()
65 }
66 }
67 .semantics {
68 onLongClick(copyToClipboardActionLabel) {
69 viewModel.onBuildNumberLongPress()
70 true
71 }
72 }
73 .basicMarquee(iterations = 1, initialDelayMillis = 2000)
74 .minimumInteractiveComponentSize(),
75 color = textColor,
76 maxLines = 1,
77 )
78 } else {
79 Spacer(modifier)
80 }
81 }
82