Merge "Delay transient navigation confirmation prompt." into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8b847dba09
@@ -943,7 +943,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
}
|
||||
});
|
||||
mTransientNavigationConfirmation = new TransientNavigationConfirmation(mContext, mHandler);
|
||||
mTransientNavigationConfirmation = new TransientNavigationConfirmation(mContext);
|
||||
mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
|
||||
|
||||
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
@@ -18,9 +18,13 @@ package com.android.internal.policy.impl;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Slog;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.R;
|
||||
@@ -30,29 +34,26 @@ import com.android.internal.R;
|
||||
* is hidden.
|
||||
*/
|
||||
public class TransientNavigationConfirmation {
|
||||
private final String TAG = "TransientNavigationConfirmation";
|
||||
private final boolean DEBUG = false;
|
||||
private static final String TAG = "TransientNavigationConfirmation";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final Context mContext;
|
||||
private final Handler mHandler;
|
||||
private final H mHandler;
|
||||
private final ArraySet<String> mConfirmedUserPackages = new ArraySet<String>();
|
||||
|
||||
private final Runnable mHandleDismiss = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mToast != null) {
|
||||
mToast.cancel();
|
||||
mToast = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
private final long mShowDelayMs;
|
||||
|
||||
private Toast mToast;
|
||||
private String mLastUserPackage;
|
||||
|
||||
public TransientNavigationConfirmation(Context context, Handler handler) {
|
||||
public TransientNavigationConfirmation(Context context) {
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
mHandler = new H();
|
||||
mShowDelayMs = getNavBarExitDuration() * 3;
|
||||
}
|
||||
|
||||
private long getNavBarExitDuration() {
|
||||
Animation exit = AnimationUtils.loadAnimation(mContext, R.anim.dock_bottom_exit);
|
||||
return exit != null ? exit.getDuration() : 0;
|
||||
}
|
||||
|
||||
public void transientNavigationChanged(int userId, String pkg, boolean isNavTransient) {
|
||||
@@ -60,16 +61,17 @@ public class TransientNavigationConfirmation {
|
||||
return;
|
||||
}
|
||||
String userPkg = userId + ":" + pkg;
|
||||
mHandler.removeMessages(H.SHOW);
|
||||
if (isNavTransient) {
|
||||
mLastUserPackage = userPkg;
|
||||
if (!mConfirmedUserPackages.contains(userPkg)) {
|
||||
if (DEBUG) Slog.d(TAG, "Showing transient navigation confirmation for " + userPkg);
|
||||
mHandler.post(handleShowConfirmation(userPkg));
|
||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(H.SHOW, userPkg), mShowDelayMs);
|
||||
}
|
||||
} else {
|
||||
mLastUserPackage = null;
|
||||
if (DEBUG) Slog.d(TAG, "Hiding transient navigation confirmation for " + userPkg);
|
||||
mHandler.post(mHandleDismiss);
|
||||
mHandler.sendEmptyMessage(H.HIDE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,22 +82,24 @@ public class TransientNavigationConfirmation {
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable handleShowConfirmation(final String userPkg) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// create the confirmation toast bar
|
||||
final int msg = R.string.transient_navigation_confirmation;
|
||||
mToast = Toast.makeBar(mContext, msg, Toast.LENGTH_INFINITE);
|
||||
mToast.setAction(R.string.ok, confirmAction(userPkg));
|
||||
private void handleHide() {
|
||||
if (mToast != null) {
|
||||
mToast.cancel();
|
||||
mToast = null;
|
||||
}
|
||||
}
|
||||
|
||||
// we will be hiding the nav bar, so layout as if it's already hidden
|
||||
mToast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
private void handleShow(String userPkg) {
|
||||
// create the confirmation toast bar
|
||||
final int msg = R.string.transient_navigation_confirmation;
|
||||
mToast = Toast.makeBar(mContext, msg, Toast.LENGTH_INFINITE);
|
||||
mToast.setAction(R.string.ok, confirmAction(userPkg));
|
||||
|
||||
// show the confirmation
|
||||
mToast.show();
|
||||
}
|
||||
};
|
||||
// we will be hiding the nav bar, so layout as if it's already hidden
|
||||
mToast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
|
||||
// show the confirmation
|
||||
mToast.show();
|
||||
}
|
||||
|
||||
private Runnable confirmAction(final String userPkg) {
|
||||
@@ -103,8 +107,25 @@ public class TransientNavigationConfirmation {
|
||||
@Override
|
||||
public void run() {
|
||||
mConfirmedUserPackages.add(userPkg);
|
||||
mHandleDismiss.run();
|
||||
handleHide();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final class H extends Handler {
|
||||
private static final int SHOW = 0;
|
||||
private static final int HIDE = 1;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch(msg.what) {
|
||||
case SHOW:
|
||||
handleShow((String)msg.obj);
|
||||
break;
|
||||
case HIDE:
|
||||
handleHide();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user