FileDocCategorySizeDatePackage
ImmersiveModeConfirmation.javaAPI DocAndroid 5.1 API12960Thu Mar 12 22:22:42 GMT 2015com.android.internal.policy.impl

ImmersiveModeConfirmation

public class ImmersiveModeConfirmation extends Object
Helper to manage showing/hiding a confirmation prompt when the navigation bar is hidden entering immersive mode.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
DEBUG_SHOW_EVERY_TIME
private static final String
CONFIRMED
private final android.content.Context
mContext
private final H
mHandler
private final long
mShowDelayMs
private final long
mPanicThresholdMs
private final android.util.SparseBooleanArray
mUserPanicResets
private boolean
mConfirmed
private ClingWindowView
mClingWindow
private long
mPanicTime
private android.view.WindowManager
mWindowManager
private int
mCurrentUserId
private final Runnable
mConfirm
Constructors Summary
public ImmersiveModeConfirmation(android.content.Context context)


       
        mContext = context;
        mHandler = new H();
        mShowDelayMs = getNavBarExitDuration() * 3;
        mPanicThresholdMs = context.getResources()
                .getInteger(R.integer.config_immersive_mode_confirmation_panic);
        mWindowManager = (WindowManager)
                mContext.getSystemService(Context.WINDOW_SERVICE);
    
Methods Summary
public voidconfirmCurrentPrompt()

        if (mClingWindow != null) {
            if (DEBUG) Slog.d(TAG, "confirmCurrentPrompt()");
            mHandler.post(mConfirm);
        }
    
public FrameLayout.LayoutParamsgetBubbleLayoutParams()

        return new FrameLayout.LayoutParams(
                mContext.getResources().getDimensionPixelSize(
                        R.dimen.immersive_mode_cling_width),
                ViewGroup.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    
public WindowManager.LayoutParamsgetClingWindowLayoutParams()

        final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_TOAST,
                0
                        | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
                ,
                PixelFormat.TRANSLUCENT);
        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        lp.setTitle("ImmersiveModeConfirmation");
        lp.windowAnimations = com.android.internal.R.style.Animation_RecentApplications;
        lp.gravity = Gravity.FILL;
        return lp;
    
private longgetNavBarExitDuration()

        Animation exit = AnimationUtils.loadAnimation(mContext, R.anim.dock_bottom_exit);
        return exit != null ? exit.getDuration() : 0;
    
private voidhandleHide()

        if (mClingWindow != null) {
            if (DEBUG) Slog.d(TAG, "Hiding immersive mode confirmation");
            mWindowManager.removeView(mClingWindow);
            mClingWindow = null;
        }
    
private voidhandlePanic()

        if (DEBUG) Slog.d(TAG, "handlePanic()");
        if (mUserPanicResets.get(mCurrentUserId, false)) return;  // already reset for panic
        mUserPanicResets.put(mCurrentUserId, true);
        mConfirmed = false;
        saveSetting();
    
private voidhandleShow()

        if (DEBUG) Slog.d(TAG, "Showing immersive mode confirmation");

        mClingWindow = new ClingWindowView(mContext, mConfirm);

        // we will be hiding the nav bar, so layout as if it's already hidden
        mClingWindow.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

        // show the confirmation
        WindowManager.LayoutParams lp = getClingWindowLayoutParams();
        mWindowManager.addView(mClingWindow, lp);
    
public voidimmersiveModeChanged(java.lang.String pkg, boolean isImmersiveMode, boolean userSetupComplete)

        mHandler.removeMessages(H.SHOW);
        if (isImmersiveMode) {
            final boolean disabled = PolicyControl.disableImmersiveConfirmation(pkg);
            if (DEBUG) Slog.d(TAG, String.format("immersiveModeChanged() disabled=%s mConfirmed=%s",
                    disabled, mConfirmed));
            if (!disabled && (DEBUG_SHOW_EVERY_TIME || !mConfirmed) && userSetupComplete) {
                mHandler.sendEmptyMessageDelayed(H.SHOW, mShowDelayMs);
            }
        } else {
            mHandler.sendEmptyMessage(H.HIDE);
        }
    
public voidloadSetting(int currentUserId)

        mConfirmed = false;
        mCurrentUserId = currentUserId;
        if (DEBUG) Slog.d(TAG, String.format("loadSetting() mCurrentUserId=%d resetForPanic=%s",
                mCurrentUserId, mUserPanicResets.get(mCurrentUserId, false)));
        String value = null;
        try {
            value = Settings.Secure.getStringForUser(mContext.getContentResolver(),
                    Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
                    UserHandle.USER_CURRENT);
            mConfirmed = CONFIRMED.equals(value);
            if (DEBUG) Slog.d(TAG, "Loaded mConfirmed=" + mConfirmed);
        } catch (Throwable t) {
            Slog.w(TAG, "Error loading confirmations, value=" + value, t);
        }
    
public booleanonPowerKeyDown(boolean isScreenOn, long time, boolean inImmersiveMode)

        if (!isScreenOn && (time - mPanicTime < mPanicThresholdMs)) {
            // turning the screen back on within the panic threshold
            mHandler.sendEmptyMessage(H.PANIC);
            return mClingWindow == null;
        }
        if (isScreenOn && inImmersiveMode) {
            // turning the screen off, remember if we were in immersive mode
            mPanicTime = time;
        } else {
            mPanicTime = 0;
        }
        return false;
    
private voidsaveSetting()

        if (DEBUG) Slog.d(TAG, "saveSetting()");
        try {
            final String value = mConfirmed ? CONFIRMED : null;
            Settings.Secure.putStringForUser(mContext.getContentResolver(),
                    Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS,
                    value,
                    UserHandle.USER_CURRENT);
            if (DEBUG) Slog.d(TAG, "Saved value=" + value);
        } catch (Throwable t) {
            Slog.w(TAG, "Error saving confirmations, mConfirmed=" + mConfirmed, t);
        }