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);
|
mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
|
||||||
|
|
||||||
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|||||||
@@ -18,9 +18,13 @@ package com.android.internal.policy.impl;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.AnimationSet;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -30,29 +34,26 @@ import com.android.internal.R;
|
|||||||
* is hidden.
|
* is hidden.
|
||||||
*/
|
*/
|
||||||
public class TransientNavigationConfirmation {
|
public class TransientNavigationConfirmation {
|
||||||
private final String TAG = "TransientNavigationConfirmation";
|
private static final String TAG = "TransientNavigationConfirmation";
|
||||||
private final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Handler mHandler;
|
private final H mHandler;
|
||||||
private final ArraySet<String> mConfirmedUserPackages = new ArraySet<String>();
|
private final ArraySet<String> mConfirmedUserPackages = new ArraySet<String>();
|
||||||
|
private final long mShowDelayMs;
|
||||||
private final Runnable mHandleDismiss = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (mToast != null) {
|
|
||||||
mToast.cancel();
|
|
||||||
mToast = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private Toast mToast;
|
private Toast mToast;
|
||||||
private String mLastUserPackage;
|
private String mLastUserPackage;
|
||||||
|
|
||||||
public TransientNavigationConfirmation(Context context, Handler handler) {
|
public TransientNavigationConfirmation(Context context) {
|
||||||
mContext = 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) {
|
public void transientNavigationChanged(int userId, String pkg, boolean isNavTransient) {
|
||||||
@@ -60,16 +61,17 @@ public class TransientNavigationConfirmation {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String userPkg = userId + ":" + pkg;
|
String userPkg = userId + ":" + pkg;
|
||||||
|
mHandler.removeMessages(H.SHOW);
|
||||||
if (isNavTransient) {
|
if (isNavTransient) {
|
||||||
mLastUserPackage = userPkg;
|
mLastUserPackage = userPkg;
|
||||||
if (!mConfirmedUserPackages.contains(userPkg)) {
|
if (!mConfirmedUserPackages.contains(userPkg)) {
|
||||||
if (DEBUG) Slog.d(TAG, "Showing transient navigation confirmation for " + 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 {
|
} else {
|
||||||
mLastUserPackage = null;
|
mLastUserPackage = null;
|
||||||
if (DEBUG) Slog.d(TAG, "Hiding transient navigation confirmation for " + userPkg);
|
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) {
|
private void handleHide() {
|
||||||
return new Runnable() {
|
if (mToast != null) {
|
||||||
@Override
|
mToast.cancel();
|
||||||
public void run() {
|
mToast = null;
|
||||||
// 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));
|
|
||||||
|
|
||||||
// we will be hiding the nav bar, so layout as if it's already hidden
|
private void handleShow(String userPkg) {
|
||||||
mToast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
// 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
|
// we will be hiding the nav bar, so layout as if it's already hidden
|
||||||
mToast.show();
|
mToast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||||
}
|
|
||||||
};
|
// show the confirmation
|
||||||
|
mToast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable confirmAction(final String userPkg) {
|
private Runnable confirmAction(final String userPkg) {
|
||||||
@@ -103,8 +107,25 @@ public class TransientNavigationConfirmation {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mConfirmedUserPackages.add(userPkg);
|
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