• 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.network;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.app.settings.SettingsEnums;
22 import android.content.DialogInterface;
23 import android.os.Bundle;
24 import android.text.TextUtils;
25 import android.util.Log;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.widget.TextView;
29 
30 import androidx.annotation.NonNull;
31 import androidx.annotation.Nullable;
32 import androidx.fragment.app.Fragment;
33 import androidx.fragment.app.FragmentManager;
34 
35 import com.android.settings.R;
36 import com.android.settings.overlay.FeatureFactory;
37 import com.android.settings.system.ResetDashboardFragment;
38 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
39 import com.android.settingslib.core.lifecycle.ObservableDialogFragment;
40 
41 public class EuiccRacConnectivityDialogFragment extends ObservableDialogFragment
42         implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
43     public static final String TAG = "EuiccRacConnectivityDlg";
44     private static final int METRICS_TAG =
45             SettingsEnums.ACTION_RESET_ESIMS_RAC_CONNECTIVITY_WARNING;
46     private static final int METRICS_CANCEL_VALUE = 0;
47     private static final int METRICS_CONTINUE_VALUE = 1;
48 
49     private MetricsFeatureProvider mMetricsFeatureProvider;
50 
show(ResetDashboardFragment host)51     static void show(ResetDashboardFragment host) {
52         if (host.getActivity() == null) {
53             return;
54         }
55         final EuiccRacConnectivityDialogFragment dialog = new EuiccRacConnectivityDialogFragment();
56         dialog.setTargetFragment(host, /* requestCode= */ 0);
57         final FragmentManager manager = host.getActivity().getSupportFragmentManager();
58         dialog.show(manager, TAG);
59     }
60 
61     @Override
onCreate(@ullable Bundle savedInstanceState)62     public void onCreate(@Nullable Bundle savedInstanceState) {
63         super.onCreate(savedInstanceState);
64         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
65     }
66 
67     @NonNull
68     @Override
onCreateDialog(@ullable Bundle savedInstanceState)69     public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
70         String title = getString(R.string.wifi_warning_dialog_title);
71         String message = getString(R.string.wifi_warning_dialog_text);
72 
73         AlertDialog.Builder builder =
74                 new AlertDialog.Builder(getContext())
75                         .setOnDismissListener(this)
76                         // Return is on the right side
77                         .setPositiveButton(R.string.wifi_warning_return_button, this)
78                         // Continue is on the left side
79                         .setNegativeButton(R.string.wifi_warning_continue_button, this);
80 
81         View content =
82                 LayoutInflater.from(getContext())
83                         .inflate(R.layout.sim_warning_dialog_wifi_connectivity, null);
84 
85         // Found the layout resource
86         if (content != null) {
87             TextView dialogTitle = content.findViewById(R.id.title);
88             if (!TextUtils.isEmpty(title) && dialogTitle != null) {
89                 dialogTitle.setText(title);
90                 dialogTitle.setVisibility(View.VISIBLE);
91             }
92             TextView dialogMessage = content.findViewById(R.id.msg);
93             if (!TextUtils.isEmpty(message) && dialogMessage != null) {
94                 dialogMessage.setText(message);
95                 dialogMessage.setVisibility(View.VISIBLE);
96             }
97 
98             builder.setView(content);
99         } else { // Not found the layout resource, use standard layout
100             if (!TextUtils.isEmpty(title)) {
101                 builder.setTitle(title);
102             }
103             if (!TextUtils.isEmpty(message)) {
104                 builder.setMessage(message);
105             }
106         }
107 
108         AlertDialog dialog = builder.create();
109         dialog.setCanceledOnTouchOutside(false);
110         return dialog;
111     }
112 
113     @Override
onClick(@onNull DialogInterface dialog, int which)114     public void onClick(@NonNull DialogInterface dialog, int which) {
115         final Fragment fragment = getTargetFragment();
116         if (!(fragment instanceof ResetDashboardFragment)) {
117             Log.e(TAG, "getTargetFragment return unexpected type");
118             return;
119         }
120 
121         // Positions of the buttons have been switch:
122         // negative button = left button = the button to continue
123         if (which == DialogInterface.BUTTON_NEGATIVE) {
124             logMetrics(METRICS_CONTINUE_VALUE);
125             EraseEuiccDataDialogFragment.show(((ResetDashboardFragment) fragment));
126         } else {
127             logMetrics(METRICS_CANCEL_VALUE);
128         }
129     }
130 
131     @Override
onCancel(@onNull DialogInterface dialog)132     public void onCancel(@NonNull DialogInterface dialog) {
133         final Fragment fragment = getTargetFragment();
134         if (!(fragment instanceof ResetDashboardFragment)) {
135             Log.e(TAG, "getTargetFragment return unexpected type");
136             return;
137         }
138         logMetrics(METRICS_CANCEL_VALUE);
139     }
140 
logMetrics(int value)141     private void logMetrics(int value) {
142         mMetricsFeatureProvider.action(getActivity(), METRICS_TAG, value);
143     }
144 }
145