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.systemui.tv.hdmi;
18 
19 import android.hardware.hdmi.HdmiControlManager;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.view.WindowManager;
23 import android.widget.Button;
24 import android.widget.ImageView;
25 import android.widget.TextView;
26 
27 import com.android.systemui.tv.TvBottomSheetActivity;
28 import com.android.systemui.tv.res.R;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * Confirmation dialog shown when Set Menu Language CEC message was received.
34  */
35 public class HdmiCecSetMenuLanguageActivity extends TvBottomSheetActivity
36         implements View.OnClickListener {
37     private static final String TAG = HdmiCecSetMenuLanguageActivity.class.getSimpleName();
38 
39     private final HdmiCecSetMenuLanguageHelper mHdmiCecSetMenuLanguageHelper;
40 
41     @Inject
HdmiCecSetMenuLanguageActivity( HdmiCecSetMenuLanguageHelper hdmiCecSetMenuLanguageHelper)42     public HdmiCecSetMenuLanguageActivity(
43             HdmiCecSetMenuLanguageHelper hdmiCecSetMenuLanguageHelper) {
44         mHdmiCecSetMenuLanguageHelper = hdmiCecSetMenuLanguageHelper;
45     }
46 
47     @Override
onCreate(Bundle b)48     public final void onCreate(Bundle b) {
49         super.onCreate(b);
50         getWindow().addPrivateFlags(
51                 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
52         String languageTag = getIntent().getStringExtra(HdmiControlManager.EXTRA_LOCALE);
53         mHdmiCecSetMenuLanguageHelper.setLocale(languageTag);
54         if (mHdmiCecSetMenuLanguageHelper.isLocaleDenylisted()) {
55             finish();
56         }
57     }
58 
59     @Override
onResume()60     public void onResume() {
61         super.onResume();
62         CharSequence title =
63                 getString(
64                         com.android.systemui.R.string.hdmi_cec_set_menu_language_title,
65                         mHdmiCecSetMenuLanguageHelper.getLocale().getDisplayLanguage());
66         CharSequence text =
67                 getString(com.android.systemui.R.string.hdmi_cec_set_menu_language_description);
68         initUI(title, text);
69     }
70 
71     @Override
onClick(View v)72     public void onClick(View v) {
73         if (v.getId() == R.id.bottom_sheet_positive_button) {
74             mHdmiCecSetMenuLanguageHelper.acceptLocale();
75         } else {
76             mHdmiCecSetMenuLanguageHelper.declineLocale();
77         }
78         finish();
79     }
80 
initUI(CharSequence title, CharSequence text)81     void initUI(CharSequence title, CharSequence text) {
82         TextView titleTextView = findViewById(R.id.bottom_sheet_title);
83         TextView contentTextView = findViewById(R.id.bottom_sheet_body);
84         ImageView icon = findViewById(R.id.bottom_sheet_icon);
85         ImageView secondIcon = findViewById(R.id.bottom_sheet_second_icon);
86         Button okButton = findViewById(R.id.bottom_sheet_positive_button);
87         Button cancelButton = findViewById(R.id.bottom_sheet_negative_button);
88 
89         titleTextView.setText(title);
90         contentTextView.setText(text);
91         icon.setImageResource(com.android.internal.R.drawable.ic_settings_language);
92         secondIcon.setVisibility(View.GONE);
93 
94         okButton.setText(com.android.systemui.R.string.hdmi_cec_set_menu_language_accept);
95         okButton.setOnClickListener(this);
96 
97         cancelButton.setText(com.android.systemui.R.string.hdmi_cec_set_menu_language_decline);
98         cancelButton.setOnClickListener(this);
99         cancelButton.requestFocus();
100     }
101 }
102