• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.deviceinfo.simstatus;
18 
19 import android.app.Dialog;
20 import android.app.settings.SettingsEnums;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.widget.TextView;
26 
27 import androidx.appcompat.app.AlertDialog;
28 import androidx.fragment.app.Fragment;
29 import androidx.fragment.app.FragmentManager;
30 
31 import com.android.settings.R;
32 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
33 
34 public class SimStatusDialogFragment extends InstrumentedDialogFragment {
35 
36     private static final String SIM_SLOT_BUNDLE_KEY = "arg_key_sim_slot";
37     private static final String DIALOG_TITLE_BUNDLE_KEY = "arg_key_dialog_title";
38 
39     private static final String TAG = "SimStatusDialog";
40 
41     private View mRootView;
42     private SimStatusDialogController mController;
43 
44     @Override
getMetricsCategory()45     public int getMetricsCategory() {
46         return SettingsEnums.DIALOG_SIM_STATUS;
47     }
48 
show(Fragment host, int slotId, String dialogTitle)49     public static void show(Fragment host, int slotId, String dialogTitle) {
50         final FragmentManager manager = host.getChildFragmentManager();
51         if (manager.findFragmentByTag(TAG) == null) {
52             final Bundle bundle = new Bundle();
53             bundle.putInt(SIM_SLOT_BUNDLE_KEY, slotId);
54             bundle.putString(DIALOG_TITLE_BUNDLE_KEY, dialogTitle);
55             final SimStatusDialogFragment dialog =
56                     new SimStatusDialogFragment();
57             dialog.setArguments(bundle);
58             dialog.show(manager, TAG);
59         }
60     }
61 
62     @Override
onCreateDialog(Bundle savedInstanceState)63     public Dialog onCreateDialog(Bundle savedInstanceState) {
64         final Bundle bundle = getArguments();
65         final int slotId = bundle.getInt(SIM_SLOT_BUNDLE_KEY);
66         final String dialogTitle = bundle.getString(DIALOG_TITLE_BUNDLE_KEY);
67         mController = new SimStatusDialogController(this, mLifecycle, slotId);
68         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
69                 .setTitle(dialogTitle)
70                 .setPositiveButton(android.R.string.ok, null /* onClickListener */);
71         mRootView = LayoutInflater.from(builder.getContext())
72                 .inflate(R.layout.dialog_sim_status, null /* parent */);
73         mController.initialize();
74         return builder.setView(mRootView).create();
75     }
76 
removeSettingFromScreen(int viewId)77     public void removeSettingFromScreen(int viewId) {
78         final View view = mRootView.findViewById(viewId);
79         if (view != null) {
80             view.setVisibility(View.GONE);
81         }
82     }
83 
setText(int viewId, CharSequence text)84     public void setText(int viewId, CharSequence text) {
85         final TextView textView = mRootView.findViewById(viewId);
86         if (TextUtils.isEmpty(text)) {
87             text = getResources().getString(R.string.device_info_default);
88         }
89         if (textView != null) {
90             textView.setText(text);
91         }
92     }
93 }
94