From f603a2c62d71b7a4cd4fd789ee756c74cdb683e3 Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Tue, 22 Jan 2019 19:48:49 -0800 Subject: [PATCH] Add support for LearnMore option UsbContaminant dialog no longer uses AlertActivity/AlertController as UI design has been updated to a custom design to support the Learn more option. The CL also incorporates string updates. Bug: 132737150 Test: dumpsys usb add-port "matrix" ufp; dumpsys usb set-contaminant-status "matrix" true Change-Id: I2b27e60e48986e669ef9bfe0239a56430d14a5a2 --- core/res/res/values/strings.xml | 2 +- .../res/layout/contaminant_dialog.xml | 87 +++++++++++++++++++ packages/SystemUI/res/values/strings.xml | 5 +- packages/SystemUI/res/values/styles.xml | 18 ++++ .../systemui/usb/UsbContaminantActivity.java | 50 +++++++---- 5 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 packages/SystemUI/res/layout/contaminant_dialog.xml diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index b07e7ef0bd05d..df658f7f59f11 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3609,7 +3609,7 @@ USB port is automatically disabled. Tap to learn more. - Safe to use USB port + OK to use USB port Phone no longer detects liquid or debris. diff --git a/packages/SystemUI/res/layout/contaminant_dialog.xml b/packages/SystemUI/res/layout/contaminant_dialog.xml new file mode 100644 index 0000000000000..ea6d900e8fa7f --- /dev/null +++ b/packages/SystemUI/res/layout/contaminant_dialog.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 87d03ee978c4f..308c95e02b606 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -166,7 +166,7 @@ USB port disabled - To protect your device from liquid or debris, the USB port is disabled and won\u2019t detect any accessories.\n\nYou\u2019ll be notified when it\u2019s safe to use the USB port again. + To protect your device from liquid or debris, the USB port is disabled and won\u2019t detect any accessories.\n\nYou\u2019ll be notified when it\u2019s okay to use the USB port again. USB port enabled to detect chargers and accessories @@ -174,6 +174,9 @@ Enable USB + + Learn more + Zoom to fill screen diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 16328f8f299f3..2862f989134b4 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -572,4 +572,22 @@ true true + + + diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbContaminantActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbContaminantActivity.java index ecf608beb91cd..aec14be9c39ea 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/UsbContaminantActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbContaminantActivity.java @@ -16,30 +16,33 @@ package com.android.systemui.usb; -import android.app.AlertDialog; -import android.content.DialogInterface; +import android.app.Activity; import android.content.Intent; import android.hardware.usb.ParcelableUsbPort; import android.hardware.usb.UsbManager; import android.hardware.usb.UsbPort; import android.os.Bundle; import android.util.Log; +import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.widget.TextView; import android.widget.Toast; -import com.android.internal.app.AlertActivity; -import com.android.internal.app.AlertController; import com.android.systemui.R; /** * Activity that alerts the user when contaminant is detected on USB port. */ -public class UsbContaminantActivity extends AlertActivity - implements DialogInterface.OnClickListener { +public class UsbContaminantActivity extends Activity implements View.OnClickListener { private static final String TAG = "UsbContaminantActivity"; private UsbPort mUsbPort; + private TextView mLearnMore; + private TextView mGotIt; + private TextView mEnableUsb; + private TextView mTitle; + private TextView mMessage; @Override public void onCreate(Bundle icicle) { @@ -47,22 +50,30 @@ public class UsbContaminantActivity extends AlertActivity window.addSystemFlags(WindowManager.LayoutParams .SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); + requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(icicle); + setContentView(R.layout.contaminant_dialog); Intent intent = getIntent(); ParcelableUsbPort port = intent.getParcelableExtra(UsbManager.EXTRA_PORT); mUsbPort = port.getUsbPort(getSystemService(UsbManager.class)); - final AlertController.AlertParams ap = mAlertParams; - ap.mTitle = getString(R.string.usb_contaminant_title); - ap.mMessage = getString(R.string.usb_contaminant_message); - ap.mNegativeButtonText = getString(android.R.string.ok); - ap.mNeutralButtonText = getString(R.string.usb_disable_contaminant_detection); - ap.mNegativeButtonListener = this; - ap.mNeutralButtonListener = this; + mLearnMore = findViewById(R.id.learnMore); + mEnableUsb = findViewById(R.id.enableUsb); + mGotIt = findViewById(R.id.gotIt); + mTitle = findViewById(R.id.title); + mMessage = findViewById(R.id.message); - setupAlert(); + mTitle.setText(getString(R.string.usb_contaminant_title)); + mMessage.setText(getString(R.string.usb_contaminant_message)); + mEnableUsb.setText(getString(R.string.usb_disable_contaminant_detection)); + mGotIt.setText(getString(R.string.got_it)); + mLearnMore.setText(getString(R.string.learn_more)); + + mEnableUsb.setOnClickListener(this); + mGotIt.setOnClickListener(this); + mLearnMore.setOnClickListener(this); } @Override @@ -71,8 +82,8 @@ public class UsbContaminantActivity extends AlertActivity } @Override - public void onClick(DialogInterface dialog, int which) { - if (which == AlertDialog.BUTTON_NEUTRAL) { + public void onClick(View v) { + if (v == mEnableUsb) { try { mUsbPort.enableContaminantDetection(false); Toast.makeText(this, R.string.usb_port_enabled, @@ -80,6 +91,13 @@ public class UsbContaminantActivity extends AlertActivity } catch (Exception e) { Log.e(TAG, "Unable to notify Usb service", e); } + } else if (v == mLearnMore) { + final Intent intent = new Intent(); + intent.setClassName("com.android.settings", + "com.android.settings.HelpTrampoline"); + intent.putExtra(Intent.EXTRA_TEXT, + "help_url_usb_contaminant_detected"); + startActivity(intent); } finish(); }