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.settingslib.bluetooth;
18 
19 import android.app.AlertDialog;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.util.Log;
23 import android.view.View;
24 import android.view.Window;
25 import android.widget.Button;
26 import android.widget.TextView;
27 
28 import com.android.settingslib.R;
29 
30 public class BroadcastDialog extends AlertDialog {
31 
32     private static final String TAG = "BroadcastDialog";
33 
34     private String mCurrentApp;
35     private String mSwitchApp;
36     private Context mContext;
37 
BroadcastDialog(Context context)38     public BroadcastDialog(Context context) {
39         super(context);
40         mContext = context;
41     }
42 
43     @Override
onCreate(Bundle savedInstanceState)44     public void onCreate(Bundle savedInstanceState) {
45 
46         View layout = View.inflate(mContext, R.layout.broadcast_dialog, null);
47         final Window window = getWindow();
48         window.setContentView(layout);
49         window.setWindowAnimations(R.style.Theme_AlertDialog_SettingsLib);
50 
51         TextView title = layout.findViewById(R.id.dialog_title);
52         TextView subTitle = layout.findViewById(R.id.dialog_subtitle);
53         title.setText(mContext.getString(R.string.bt_le_audio_broadcast_dialog_title, mCurrentApp));
54         subTitle.setText(
55                 mContext.getString(R.string.bt_le_audio_broadcast_dialog_sub_title, mSwitchApp));
56         Button positiveBtn = layout.findViewById(R.id.positive_btn);
57         Button negativeBtn = layout.findViewById(R.id.negative_btn);
58         Button neutralBtn = layout.findViewById(R.id.neutral_btn);
59         positiveBtn.setText(mContext.getString(
60                 R.string.bt_le_audio_broadcast_dialog_switch_app, mSwitchApp), null);
61         neutralBtn.setOnClickListener((view) -> {
62             Log.d(TAG, "BroadcastDialog dismiss.");
63             dismiss();
64         });
65     }
66 }
67