Merge "Fix toast is covered by PIN code screen after wrong pin"
am: d5abc0eb44
Change-Id: Ie2cfeeb5573ae6b79855edbd87210bfe0e0a8287
diff --git a/src/com/android/settings/IccLockSettings.java b/src/com/android/settings/IccLockSettings.java
index 2ff6931..cb196d0 100644
--- a/src/com/android/settings/IccLockSettings.java
+++ b/src/com/android/settings/IccLockSettings.java
@@ -20,7 +20,9 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.res.Configuration;
import android.content.res.Resources;
+import android.graphics.PixelFormat;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
@@ -32,9 +34,11 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TabHost;
@@ -42,6 +46,7 @@
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
+import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.CommandException;
@@ -116,6 +121,9 @@
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
private static final int MSG_SIM_STATE_CHANGED = 102;
+ // @see android.widget.Toast$TN
+ private static final long LONG_DURATION_TIMEOUT = 7000;
+
// For replies from IccCard interface
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
@@ -459,8 +467,7 @@
if (exception instanceof CommandException) {
CommandException.Error err = ((CommandException)(exception)).getCommandError();
if (err == CommandException.Error.PASSWORD_INCORRECT) {
- Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
- Toast.LENGTH_LONG).show();
+ createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
} else {
if (mToState) {
Toast.makeText(getContext(), mRes.getString
@@ -476,11 +483,56 @@
resetDialogState();
}
+ private void createCustomTextToast(CharSequence errorMessage) {
+ // Cannot overlay Toast on PUK unlock screen.
+ // The window type of Toast is set by NotificationManagerService.
+ // It can't be overwritten by LayoutParams.type.
+ // Ovarlay a custom window with LayoutParams (TYPE_STATUS_BAR_PANEL) on PUK unlock screen.
+ View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
+ .inflate(com.android.internal.R.layout.transient_notification, null);
+ TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
+ tv.setText(errorMessage);
+
+ final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
+ final Configuration config = v.getContext().getResources().getConfiguration();
+ final int gravity = Gravity.getAbsoluteGravity(
+ getContext().getResources().getInteger(
+ com.android.internal.R.integer.config_toastDefaultGravity),
+ config.getLayoutDirection());
+ params.gravity = gravity;
+ if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
+ params.horizontalWeight = 1.0f;
+ }
+ if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
+ params.verticalWeight = 1.0f;
+ }
+ params.y = getContext().getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.toast_y_offset);
+
+ params.height = WindowManager.LayoutParams.WRAP_CONTENT;
+ params.width = WindowManager.LayoutParams.WRAP_CONTENT;
+ params.format = PixelFormat.TRANSLUCENT;
+ params.windowAnimations = com.android.internal.R.style.Animation_Toast;
+ params.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
+ params.setTitle(errorMessage);
+ params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
+
+ WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ wm.addView(v, params);
+
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ wm.removeViewImmediate(v);
+ }
+ }, LONG_DURATION_TIMEOUT);
+ }
+
private void iccPinChanged(boolean success, int attemptsRemaining) {
if (!success) {
- Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
- Toast.LENGTH_LONG)
- .show();
+ createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
} else {
Toast.makeText(getContext(), mRes.getString(R.string.sim_change_succeeded),
Toast.LENGTH_SHORT)