1 /*
2  * Copyright (C) 2022 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 package com.android.settings.biometrics2.ui.view
17 
18 import android.app.Activity
19 import android.text.TextUtils
20 import android.view.View
21 import androidx.annotation.StringRes
22 import com.google.android.setupdesign.GlifLayout
23 
24 /**
25  * Utils class for GlifLayout
26  */
27 class GlifLayoutHelper(val activity: Activity, val glifLayout: GlifLayout) {
28 
29     /**
30      * Sets header text to GlifLayout
31      */
setHeaderTextnull32     fun setHeaderText(@StringRes textResId: Int) {
33         val layoutTitle = glifLayout.headerTextView
34         val previousTitle = layoutTitle.text
35         val title = activity.getText(textResId)
36         if (previousTitle !== title) {
37             if (!TextUtils.isEmpty(previousTitle)) {
38                 layoutTitle.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE
39             }
40             glifLayout.headerText = title
41             glifLayout.headerTextView.contentDescription = title
42             activity.title = title
43         }
44     }
45 
46     /**
47      * Sets description text to GlifLayout
48      */
setDescriptionTextnull49     fun setDescriptionText(description: CharSequence?) {
50         val previousDescription = glifLayout.descriptionText
51         // Prevent a11y for re-reading the same string
52         if (!TextUtils.equals(previousDescription, description)) {
53             glifLayout.descriptionText = description
54         }
55     }
56 }
57