• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.settings.notification.app;
17 
18 import android.app.Dialog;
19 import android.app.settings.SettingsEnums;
20 import android.os.Bundle;
21 
22 import androidx.appcompat.app.AlertDialog;
23 
24 import com.android.settings.R;
25 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
26 
27 public class BubbleWarningDialogFragment extends InstrumentedDialogFragment {
28     static final String KEY_PKG = "p";
29     static final String KEY_UID = "u";
30     static final String KEY_SELECTED_PREFERENCE = "pref";
31 
32 
33     @Override
getMetricsCategory()34     public int getMetricsCategory() {
35         return SettingsEnums.DIALOG_APP_BUBBLE_SETTINGS;
36     }
37 
setPkgPrefInfo(String pkg, int uid, int preference)38     public BubbleWarningDialogFragment setPkgPrefInfo(String pkg, int uid, int preference) {
39         Bundle args = new Bundle();
40         args.putString(KEY_PKG, pkg);
41         args.putInt(KEY_UID, uid);
42         args.putInt(KEY_SELECTED_PREFERENCE, preference);
43         setArguments(args);
44         return this;
45     }
46 
47     @Override
onCreateDialog(Bundle savedInstanceState)48     public Dialog onCreateDialog(Bundle savedInstanceState) {
49         super.onCreate(savedInstanceState);
50         final Bundle args = getArguments();
51         final String pkg = args.getString(KEY_PKG);
52         final int uid = args.getInt(KEY_UID);
53         final int pref = args.getInt(KEY_SELECTED_PREFERENCE);
54 
55         final String title =
56                 getResources().getString(R.string.bubbles_feature_disabled_dialog_title);
57         final String summary = getResources()
58                 .getString(R.string.bubbles_feature_disabled_dialog_text);
59         return new AlertDialog.Builder(getContext())
60                 .setMessage(summary)
61                 .setTitle(title)
62                 .setCancelable(true)
63                 .setPositiveButton(R.string.bubbles_feature_disabled_button_approve,
64                         (dialog, id) ->
65                                 BubblePreferenceController.applyBubblesApproval(
66                                         getContext(), pkg, uid, pref))
67                 .setNegativeButton(R.string.bubbles_feature_disabled_button_cancel,
68                         (dialog, id) ->
69                                 BubblePreferenceController.revertBubblesApproval(
70                                         getContext(), pkg, uid))
71                 .create();
72     }
73 }
74