1 /*
2  * Copyright (C) 2023 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.wm.shell.compatui;
18 
19 import android.content.Context;
20 import android.content.res.TypedArray;
21 import android.util.AttributeSet;
22 import android.view.View;
23 import android.widget.FrameLayout;
24 import android.widget.ImageView;
25 import android.widget.TextView;
26 
27 import com.android.wm.shell.R;
28 
29 /**
30  * Custom layout for Letterbox Education dialog action.
31  */
32 class LetterboxEduDialogActionLayout extends FrameLayout {
33 
LetterboxEduDialogActionLayout(Context context)34     public LetterboxEduDialogActionLayout(Context context) {
35         this(context, null);
36     }
37 
LetterboxEduDialogActionLayout(Context context, AttributeSet attrs)38     public LetterboxEduDialogActionLayout(Context context, AttributeSet attrs) {
39         this(context, attrs, 0);
40     }
41 
LetterboxEduDialogActionLayout(Context context, AttributeSet attrs, int defStyleAttr)42     public LetterboxEduDialogActionLayout(Context context, AttributeSet attrs, int defStyleAttr) {
43         this(context, attrs, defStyleAttr, 0);
44     }
45 
LetterboxEduDialogActionLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)46     public LetterboxEduDialogActionLayout(Context context, AttributeSet attrs, int defStyleAttr,
47             int defStyleRes) {
48         super(context, attrs, defStyleAttr, defStyleRes);
49 
50         TypedArray styledAttributes =
51                 context.getTheme().obtainStyledAttributes(
52                         attrs, R.styleable.LetterboxEduDialogActionLayout, defStyleAttr,
53                         defStyleRes);
54         int iconId = styledAttributes.getResourceId(
55                 R.styleable.LetterboxEduDialogActionLayout_icon, 0);
56         String text = styledAttributes.getString(
57                 R.styleable.LetterboxEduDialogActionLayout_text);
58         styledAttributes.recycle();
59 
60         View rootView = inflate(getContext(), R.layout.letterbox_education_dialog_action_layout,
61                 this);
62         ((ImageView) rootView.findViewById(
63                 R.id.letterbox_education_dialog_action_icon)).setImageResource(iconId);
64         ((TextView) rootView.findViewById(R.id.letterbox_education_dialog_action_text)).setText(
65                 text);
66     }
67 }
68