• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.settings.connecteddevice.audiosharing;
18 
19 import android.app.Dialog;
20 import android.app.settings.SettingsEnums;
21 import android.os.Bundle;
22 import android.util.Log;
23 
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 import androidx.appcompat.app.AlertDialog;
27 import androidx.fragment.app.Fragment;
28 import androidx.fragment.app.FragmentManager;
29 
30 import com.android.settings.R;
31 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
32 import com.android.settingslib.bluetooth.BluetoothUtils;
33 
34 public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragment {
35     private static final String TAG = "AudioSharingConfirmDialog";
36 
37     @Override
getMetricsCategory()38     public int getMetricsCategory() {
39         return SettingsEnums.DIALOG_AUDIO_SHARING_CONFIRMATION;
40     }
41 
42     /**
43      * Display the {@link AudioSharingConfirmDialogFragment} dialog.
44      *
45      * @param host The Fragment this dialog will be hosted.
46      */
show(@ullable Fragment host)47     public static void show(@Nullable Fragment host) {
48         if (host == null) {
49             Log.d(TAG, "Fail to show dialog, host is null");
50             return;
51         }
52         if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
53             final FragmentManager manager;
54             try {
55                 manager = host.getChildFragmentManager();
56             } catch (IllegalStateException e) {
57                 Log.d(TAG, "Fail to show dialog: " + e.getMessage());
58                 return;
59             }
60             AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
61             if (dialog != null) {
62                 Log.d(TAG, "Dialog is showing, return.");
63                 return;
64             }
65             Log.d(TAG, "Show up the confirm dialog.");
66             AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment();
67             dialogFrag.show(manager, TAG);
68         }
69     }
70 
71     @Override
72     @NonNull
onCreateDialog(@ullable Bundle savedInstanceState)73     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
74         AlertDialog dialog =
75                 AudioSharingDialogFactory.newBuilder(getActivity())
76                         .setTitle(R.string.audio_sharing_confirm_dialog_title)
77                         .setTitleIcon(com.android.settingslib.R.drawable.ic_bt_le_audio_sharing)
78                         .setIsCustomBodyEnabled(true)
79                         .setCustomMessage(R.string.audio_sharing_comfirm_dialog_content)
80                         .setPositiveButton(R.string.audio_sharing_close_button_label, (d, w) -> {})
81                         .build();
82         dialog.setCanceledOnTouchOutside(true);
83         return dialog;
84     }
85 }
86