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