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