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