diff --git a/res/layout/dialog_sim_status.xml b/res/layout/dialog_sim_status.xml index c169e586d1d..4fc7f4620d0 100644 --- a/res/layout/dialog_sim_status.xml +++ b/res/layout/dialog_sim_status.xml @@ -17,6 +17,7 @@ + mEid = null; private final BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() { @Override @@ -263,6 +268,19 @@ public class SimStatusDialogController implements LifecycleObserver { updateImsRegistrationState(); } + /** + * Callback when dialog end of show(). + */ + public void onShow(DialogInterface dialog) { + if (mEid != null) { + String eidText = mEid.get(); + if (eidText != null) { + // Present QR code after the completion of layout + mDialog.setQrCode(EID_INFO_QRCODE_ID, eidText); + } + } + } + /** * Deinitialization works */ @@ -618,8 +636,8 @@ public class SimStatusDialogController implements LifecycleObserver { @VisibleForTesting protected void requestForUpdateEid() { ThreadUtils.postOnBackgroundThread(() -> { - final AtomicReference eid = getEid(mSlotIndex); - ThreadUtils.postOnMainThread(() -> updateEid(eid)); + mEid = getEid(mSlotIndex); + ThreadUtils.postOnMainThread(() -> updateEid(mEid)); }); } @@ -663,11 +681,20 @@ public class SimStatusDialogController implements LifecycleObserver { @VisibleForTesting protected void updateEid(AtomicReference eid) { + boolean removeQrCode = true; if (eid == null) { mDialog.removeSettingFromScreen(EID_INFO_LABEL_ID); mDialog.removeSettingFromScreen(EID_INFO_VALUE_ID); - } else if (eid.get() != null) { - mDialog.setText(EID_INFO_VALUE_ID, eid.get()); + mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID); + } else { + String eidText = eid.get(); + if (eidText != null) { + mDialog.setText(EID_INFO_VALUE_ID, eidText); + removeQrCode = (eidText == ""); + } + } + if (removeQrCode) { + mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID); } } diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java index 96acd43fc97..3bd9b343b2d 100644 --- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java +++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java @@ -19,11 +19,14 @@ package com.android.settings.deviceinfo.simstatus; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.os.Bundle; +import android.graphics.Bitmap; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; +import android.widget.ImageView; import android.widget.TextView; +import android.util.Log; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; @@ -32,6 +35,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.deviceinfo.PhoneNumberUtil; +import com.android.settingslib.qrcode.QrCodeGenerator; import java.util.Arrays; import java.util.stream.IntStream; @@ -80,6 +84,7 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { Dialog dlg = builder.setView(mRootView).create(); dlg.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + dlg.setOnShowListener(mController); return dlg; } @@ -107,6 +112,10 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { .sorted().toArray(); public void setText(int viewId, CharSequence text) { + setText(viewId, text, true); + } + + public void setText(int viewId, CharSequence text, boolean enableCopy) { final TextView textView = mRootView.findViewById(viewId); if (textView == null) { return; @@ -117,5 +126,21 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { text = PhoneNumberUtil.expandByTts(text); } textView.setText(text); + textView.setTextIsSelectable(enableCopy); + } + + public void setQrCode(int viewId, String qrcodeText) { + ImageView qrCodeView = (ImageView) mRootView.findViewById(viewId); + + Bitmap qrCodeBitmap = null; + try { + qrCodeBitmap = QrCodeGenerator.encodeQrCode(qrcodeText, qrCodeView.getWidth()); + } catch (Exception exception) { + Log.w(TAG, "Error when presenting QR code in + " + qrCodeView, exception); + } + if (qrCodeBitmap == null) { + return; + } + qrCodeView.setImageBitmap(qrCodeBitmap); } }