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.Nullable; 25 import androidx.appcompat.app.AlertDialog; 26 import androidx.fragment.app.Fragment; 27 import androidx.fragment.app.FragmentManager; 28 29 import com.android.settings.R; 30 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 31 32 public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragment { 33 private static final String TAG = "AudioSharingConfirmDialog"; 34 35 @Override getMetricsCategory()36 public int getMetricsCategory() { 37 return SettingsEnums.DIALOG_AUDIO_SHARING_CONFIRMATION; 38 } 39 40 /** 41 * Display the {@link AudioSharingConfirmDialogFragment} dialog. 42 * 43 * @param host The Fragment this dialog will be hosted. 44 */ show(Fragment host)45 public static void show(Fragment host) { 46 if (!AudioSharingUtils.isFeatureEnabled()) return; 47 FragmentManager manager = host.getChildFragmentManager(); 48 AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG); 49 if (dialog != null) { 50 Log.d(TAG, "Dialog is showing, return."); 51 return; 52 } 53 Log.d(TAG, "Show up the confirm dialog."); 54 AudioSharingConfirmDialogFragment dialogFrag = new AudioSharingConfirmDialogFragment(); 55 dialogFrag.show(manager, TAG); 56 } 57 58 @Override onCreateDialog(@ullable Bundle savedInstanceState)59 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { 60 AlertDialog dialog = 61 AudioSharingDialogFactory.newBuilder(getActivity()) 62 .setTitle(R.string.audio_sharing_confirm_dialog_title) 63 .setTitleIcon(com.android.settingslib.R.drawable.ic_bt_le_audio_sharing) 64 .setIsCustomBodyEnabled(true) 65 .setCustomMessage(R.string.audio_sharing_comfirm_dialog_content) 66 .setPositiveButton(com.android.settings.R.string.okay, (d, w) -> {}) 67 .build(); 68 dialog.setCanceledOnTouchOutside(true); 69 return dialog; 70 } 71 } 72