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 
17 package com.android.permissioncontroller.permission.ui.v33.widget
18 
19 import android.content.Context
20 import android.text.Html
21 import android.util.AttributeSet
22 import android.view.Gravity
23 import android.view.LayoutInflater
24 import android.view.View
25 import android.widget.LinearLayout
26 import android.widget.TextView
27 import com.android.permissioncontroller.R
28 import com.android.permissioncontroller.permission.utils.KotlinUtils
29 
30 class SafetyProtectionSectionView : LinearLayout {
31 
32     constructor(context: Context) : super(context) {}
33 
34     constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
35 
36     constructor(
37         context: Context,
38         attrs: AttributeSet?,
39         defStyleAttr: Int
40     ) : super(context, attrs, defStyleAttr) {}
41 
42     constructor(
43         context: Context,
44         attrs: AttributeSet?,
45         defStyleAttr: Int,
46         defStyleRes: Int
47     ) : super(context, attrs, defStyleAttr, defStyleRes) {}
48 
49     init {
50         gravity = Gravity.CENTER
51         orientation = HORIZONTAL
52         visibility =
53             if (KotlinUtils.shouldShowSafetyProtectionResources(context)) {
54                 View.VISIBLE
55             } else {
56                 View.GONE
57             }
58     }
59 
onFinishInflatenull60     override fun onFinishInflate() {
61         super.onFinishInflate()
62         if (KotlinUtils.shouldShowSafetyProtectionResources(context)) {
63             LayoutInflater.from(context).inflate(R.layout.safety_protection_section, this)
64             val safetyProtectionDisplayTextView =
65                 requireViewById<TextView>(R.id.safety_protection_display_text)
66             safetyProtectionDisplayTextView.setText(
67                 Html.fromHtml(context.getString(android.R.string.safety_protection_display_text), 0)
68             )
69         }
70     }
71 }
72