Merge "Fix toast is covered by PIN code screen after wrong pin" am: d5abc0eb44
am: c150f5eb29
Change-Id: Ia4e59e195720919f2baa52e7d5667aed27c5ce7c
This commit is contained in:
@@ -20,7 +20,9 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.PixelFormat;
|
||||||
import android.os.AsyncResult;
|
import android.os.AsyncResult;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -32,9 +34,11 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
@@ -42,6 +46,7 @@ import android.widget.TabHost.OnTabChangeListener;
|
|||||||
import android.widget.TabHost.TabContentFactory;
|
import android.widget.TabHost.TabContentFactory;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.telephony.CommandException;
|
import com.android.internal.telephony.CommandException;
|
||||||
@@ -116,6 +121,9 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101;
|
||||||
private static final int MSG_SIM_STATE_CHANGED = 102;
|
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
|
// For replies from IccCard interface
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
@@ -459,8 +467,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
if (exception instanceof CommandException) {
|
if (exception instanceof CommandException) {
|
||||||
CommandException.Error err = ((CommandException)(exception)).getCommandError();
|
CommandException.Error err = ((CommandException)(exception)).getCommandError();
|
||||||
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
||||||
Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
|
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
} else {
|
||||||
if (mToState) {
|
if (mToState) {
|
||||||
Toast.makeText(getContext(), mRes.getString
|
Toast.makeText(getContext(), mRes.getString
|
||||||
@@ -476,11 +483,56 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
resetDialogState();
|
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) {
|
private void iccPinChanged(boolean success, int attemptsRemaining) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
|
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
||||||
Toast.LENGTH_LONG)
|
|
||||||
.show();
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getContext(), mRes.getString(R.string.sim_change_succeeded),
|
Toast.makeText(getContext(), mRes.getString(R.string.sim_change_succeeded),
|
||||||
Toast.LENGTH_SHORT)
|
Toast.LENGTH_SHORT)
|
||||||
|
Reference in New Issue
Block a user