John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 17 | package com.android.server.policy; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 18 | |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 19 | import android.animation.ArgbEvaluator; |
| 20 | import android.animation.ValueAnimator; |
| 21 | import android.app.ActivityManager; |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 23 | import android.content.Context; |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 26 | import android.graphics.PixelFormat; |
| 27 | import android.graphics.drawable.ColorDrawable; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 28 | import android.os.Handler; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 29 | import android.os.Message; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 30 | import android.os.UserHandle; |
| 31 | import android.provider.Settings; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 32 | import android.util.DisplayMetrics; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 33 | import android.util.Slog; |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 34 | import android.util.SparseBooleanArray; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 35 | import android.view.Gravity; |
| 36 | import android.view.MotionEvent; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 37 | import android.view.View; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 38 | import android.view.ViewGroup; |
| 39 | import android.view.WindowManager; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 40 | import android.view.animation.Animation; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 41 | import android.view.animation.AnimationUtils; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 42 | import android.view.animation.DecelerateInterpolator; |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 43 | import android.view.animation.Interpolator; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 44 | import android.widget.Button; |
| 45 | import android.widget.FrameLayout; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 46 | |
| 47 | import com.android.internal.R; |
| 48 | |
| 49 | /** |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 50 | * Helper to manage showing/hiding a confirmation prompt when the navigation bar is hidden |
| 51 | * entering immersive mode. |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 52 | */ |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 53 | public class ImmersiveModeConfirmation { |
| 54 | private static final String TAG = "ImmersiveModeConfirmation"; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 55 | private static final boolean DEBUG = false; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 56 | private static final boolean DEBUG_SHOW_EVERY_TIME = false; // super annoying, use with caution |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 57 | private static final String CONFIRMED = "confirmed"; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 58 | |
| 59 | private final Context mContext; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 60 | private final H mHandler; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 61 | private final long mShowDelayMs; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 62 | private final long mPanicThresholdMs; |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 63 | private final SparseBooleanArray mUserPanicResets = new SparseBooleanArray(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 64 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 65 | private boolean mConfirmed; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 66 | private ClingWindowView mClingWindow; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 67 | private long mPanicTime; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 68 | private WindowManager mWindowManager; |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 69 | private int mCurrentUserId; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 70 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 71 | public ImmersiveModeConfirmation(Context context) { |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 72 | mContext = context; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 73 | mHandler = new H(); |
| 74 | mShowDelayMs = getNavBarExitDuration() * 3; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 75 | mPanicThresholdMs = context.getResources() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 76 | .getInteger(R.integer.config_immersive_mode_confirmation_panic); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 77 | mWindowManager = (WindowManager) |
| 78 | mContext.getSystemService(Context.WINDOW_SERVICE); |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | private long getNavBarExitDuration() { |
| 82 | Animation exit = AnimationUtils.loadAnimation(mContext, R.anim.dock_bottom_exit); |
| 83 | return exit != null ? exit.getDuration() : 0; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 84 | } |
| 85 | |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 86 | public void loadSetting(int currentUserId) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 87 | mConfirmed = false; |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 88 | mCurrentUserId = currentUserId; |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 89 | if (DEBUG) Slog.d(TAG, String.format("loadSetting() mCurrentUserId=%d resetForPanic=%s", |
| 90 | mCurrentUserId, mUserPanicResets.get(mCurrentUserId, false))); |
| 91 | String value = null; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 92 | try { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 93 | value = Settings.Secure.getStringForUser(mContext.getContentResolver(), |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 94 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS, |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 95 | UserHandle.USER_CURRENT); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 96 | mConfirmed = CONFIRMED.equals(value); |
| 97 | if (DEBUG) Slog.d(TAG, "Loaded mConfirmed=" + mConfirmed); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 98 | } catch (Throwable t) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 99 | Slog.w(TAG, "Error loading confirmations, value=" + value, t); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | private void saveSetting() { |
| 104 | if (DEBUG) Slog.d(TAG, "saveSetting()"); |
| 105 | try { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 106 | final String value = mConfirmed ? CONFIRMED : null; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 107 | Settings.Secure.putStringForUser(mContext.getContentResolver(), |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 108 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS, |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 109 | value, |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 110 | UserHandle.USER_CURRENT); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 111 | if (DEBUG) Slog.d(TAG, "Saved value=" + value); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 112 | } catch (Throwable t) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 113 | Slog.w(TAG, "Error saving confirmations, mConfirmed=" + mConfirmed, t); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 117 | public void immersiveModeChanged(String pkg, boolean isImmersiveMode, |
| 118 | boolean userSetupComplete) { |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 119 | mHandler.removeMessages(H.SHOW); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 120 | if (isImmersiveMode) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 121 | final boolean disabled = PolicyControl.disableImmersiveConfirmation(pkg); |
| 122 | if (DEBUG) Slog.d(TAG, String.format("immersiveModeChanged() disabled=%s mConfirmed=%s", |
| 123 | disabled, mConfirmed)); |
Maurice Lam | 99c6e07 | 2014-04-28 18:24:28 -0700 | [diff] [blame] | 124 | if (!disabled && (DEBUG_SHOW_EVERY_TIME || !mConfirmed) && userSetupComplete) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 125 | mHandler.sendEmptyMessageDelayed(H.SHOW, mShowDelayMs); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 126 | } |
| 127 | } else { |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 128 | mHandler.sendEmptyMessage(H.HIDE); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 132 | public boolean onPowerKeyDown(boolean isScreenOn, long time, boolean inImmersiveMode) { |
| 133 | if (!isScreenOn && (time - mPanicTime < mPanicThresholdMs)) { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 134 | // turning the screen back on within the panic threshold |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 135 | mHandler.sendEmptyMessage(H.PANIC); |
| 136 | return mClingWindow == null; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 137 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 138 | if (isScreenOn && inImmersiveMode) { |
| 139 | // turning the screen off, remember if we were in immersive mode |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 140 | mPanicTime = time; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 141 | } else { |
| 142 | mPanicTime = 0; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 143 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 144 | return false; |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public void confirmCurrentPrompt() { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 148 | if (mClingWindow != null) { |
| 149 | if (DEBUG) Slog.d(TAG, "confirmCurrentPrompt()"); |
| 150 | mHandler.post(mConfirm); |
| 151 | } |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 152 | } |
| 153 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 154 | private void handlePanic() { |
| 155 | if (DEBUG) Slog.d(TAG, "handlePanic()"); |
| 156 | if (mUserPanicResets.get(mCurrentUserId, false)) return; // already reset for panic |
| 157 | mUserPanicResets.put(mCurrentUserId, true); |
| 158 | mConfirmed = false; |
| 159 | saveSetting(); |
| 160 | } |
| 161 | |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 162 | private void handleHide() { |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 163 | if (mClingWindow != null) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 164 | if (DEBUG) Slog.d(TAG, "Hiding immersive mode confirmation"); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 165 | mWindowManager.removeView(mClingWindow); |
| 166 | mClingWindow = null; |
| 167 | } |
| 168 | } |
| 169 | |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 170 | public WindowManager.LayoutParams getClingWindowLayoutParams() { |
| 171 | final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 172 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 173 | ViewGroup.LayoutParams.MATCH_PARENT, |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 174 | WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 175 | 0 |
| 176 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 177 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 178 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED |
| 179 | , |
| 180 | PixelFormat.TRANSLUCENT); |
John Spurlock | 0513d5a | 2013-12-09 11:59:45 -0500 | [diff] [blame] | 181 | lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 182 | lp.setTitle("ImmersiveModeConfirmation"); |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 183 | lp.windowAnimations = com.android.internal.R.style.Animation_ImmersiveModeConfirmation; |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 184 | return lp; |
| 185 | } |
| 186 | |
| 187 | public FrameLayout.LayoutParams getBubbleLayoutParams() { |
| 188 | return new FrameLayout.LayoutParams( |
| 189 | mContext.getResources().getDimensionPixelSize( |
| 190 | R.dimen.immersive_mode_cling_width), |
| 191 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 192 | Gravity.CENTER_HORIZONTAL | Gravity.TOP); |
| 193 | } |
| 194 | |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 195 | private class ClingWindowView extends FrameLayout { |
| 196 | private static final int BGCOLOR = 0x80000000; |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 197 | private static final int OFFSET_DP = 96; |
| 198 | private static final int ANIMATION_DURATION = 250; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 199 | |
John Spurlock | 47e3de2 | 2013-10-13 19:20:04 -0400 | [diff] [blame] | 200 | private final Runnable mConfirm; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 201 | private final ColorDrawable mColor = new ColorDrawable(0); |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 202 | private final Interpolator mInterpolator; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 203 | private ValueAnimator mColorAnim; |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 204 | private ViewGroup mClingLayout; |
| 205 | |
Daniel Sandler | da35dde | 2013-10-18 12:05:04 -0400 | [diff] [blame] | 206 | private Runnable mUpdateLayoutRunnable = new Runnable() { |
| 207 | @Override |
| 208 | public void run() { |
| 209 | if (mClingLayout != null && mClingLayout.getParent() != null) { |
| 210 | mClingLayout.setLayoutParams(getBubbleLayoutParams()); |
| 211 | } |
| 212 | } |
| 213 | }; |
| 214 | |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 215 | private BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 216 | @Override |
| 217 | public void onReceive(Context context, Intent intent) { |
| 218 | if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) { |
Daniel Sandler | da35dde | 2013-10-18 12:05:04 -0400 | [diff] [blame] | 219 | post(mUpdateLayoutRunnable); |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | }; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 223 | |
John Spurlock | 47e3de2 | 2013-10-13 19:20:04 -0400 | [diff] [blame] | 224 | public ClingWindowView(Context context, Runnable confirm) { |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 225 | super(context); |
John Spurlock | 47e3de2 | 2013-10-13 19:20:04 -0400 | [diff] [blame] | 226 | mConfirm = confirm; |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 227 | setBackground(mColor); |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 228 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 229 | mInterpolator = AnimationUtils |
| 230 | .loadInterpolator(mContext, android.R.interpolator.linear_out_slow_in); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public void onAttachedToWindow() { |
| 235 | super.onAttachedToWindow(); |
| 236 | |
| 237 | DisplayMetrics metrics = new DisplayMetrics(); |
| 238 | mWindowManager.getDefaultDisplay().getMetrics(metrics); |
| 239 | float density = metrics.density; |
| 240 | |
| 241 | // create the confirmation cling |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 242 | mClingLayout = (ViewGroup) |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 243 | View.inflate(getContext(), R.layout.immersive_mode_cling, null); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 244 | |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 245 | final Button ok = (Button) mClingLayout.findViewById(R.id.ok); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 246 | ok.setOnClickListener(new OnClickListener() { |
| 247 | @Override |
| 248 | public void onClick(View v) { |
John Spurlock | 47e3de2 | 2013-10-13 19:20:04 -0400 | [diff] [blame] | 249 | mConfirm.run(); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 250 | } |
| 251 | }); |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 252 | addView(mClingLayout, getBubbleLayoutParams()); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 253 | |
| 254 | if (ActivityManager.isHighEndGfx()) { |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 255 | final View cling = mClingLayout; |
| 256 | cling.setAlpha(0f); |
| 257 | cling.setTranslationY(-OFFSET_DP * density); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 258 | |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 259 | postOnAnimation(new Runnable() { |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 260 | @Override |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 261 | public void run() { |
| 262 | cling.animate() |
| 263 | .alpha(1f) |
| 264 | .translationY(0) |
| 265 | .setDuration(ANIMATION_DURATION) |
| 266 | .setInterpolator(mInterpolator) |
| 267 | .withLayer() |
| 268 | .start(); |
| 269 | |
| 270 | mColorAnim = ValueAnimator.ofObject(new ArgbEvaluator(), 0, BGCOLOR); |
| 271 | mColorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 272 | @Override |
| 273 | public void onAnimationUpdate(ValueAnimator animation) { |
| 274 | final int c = (Integer) animation.getAnimatedValue(); |
| 275 | mColor.setColor(c); |
| 276 | } |
| 277 | }); |
| 278 | mColorAnim.setDuration(ANIMATION_DURATION); |
| 279 | mColorAnim.setInterpolator(mInterpolator); |
| 280 | mColorAnim.start(); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 281 | } |
| 282 | }); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 283 | } else { |
| 284 | mColor.setColor(BGCOLOR); |
| 285 | } |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 286 | |
Adrian Roos | 62b65e4 | 2015-02-25 18:05:34 +0100 | [diff] [blame] | 287 | mContext.registerReceiver(mReceiver, |
| 288 | new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void onDetachedFromWindow() { |
| 293 | mContext.unregisterReceiver(mReceiver); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public boolean onTouchEvent(MotionEvent motion) { |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 298 | return true; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 299 | } |
| 300 | } |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 301 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 302 | private void handleShow() { |
| 303 | if (DEBUG) Slog.d(TAG, "Showing immersive mode confirmation"); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 304 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 305 | mClingWindow = new ClingWindowView(mContext, mConfirm); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 306 | |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 307 | // we will be hiding the nav bar, so layout as if it's already hidden |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 308 | mClingWindow.setSystemUiVisibility( |
| 309 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 310 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 311 | |
| 312 | // show the confirmation |
Daniel Sandler | b83f5c6 | 2013-10-13 22:04:36 -0400 | [diff] [blame] | 313 | WindowManager.LayoutParams lp = getClingWindowLayoutParams(); |
Daniel Sandler | a953b6d | 2013-10-11 14:27:53 -0400 | [diff] [blame] | 314 | mWindowManager.addView(mClingWindow, lp); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 315 | } |
| 316 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 317 | private final Runnable mConfirm = new Runnable() { |
| 318 | @Override |
| 319 | public void run() { |
| 320 | if (DEBUG) Slog.d(TAG, "mConfirm.run()"); |
| 321 | if (!mConfirmed) { |
| 322 | mConfirmed = true; |
| 323 | saveSetting(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 324 | } |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 325 | handleHide(); |
| 326 | } |
| 327 | }; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 328 | |
| 329 | private final class H extends Handler { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 330 | private static final int SHOW = 1; |
| 331 | private static final int HIDE = 2; |
| 332 | private static final int PANIC = 3; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 333 | |
| 334 | @Override |
| 335 | public void handleMessage(Message msg) { |
| 336 | switch(msg.what) { |
| 337 | case SHOW: |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 338 | handleShow(); |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 339 | break; |
| 340 | case HIDE: |
| 341 | handleHide(); |
| 342 | break; |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 343 | case PANIC: |
| 344 | handlePanic(); |
| 345 | break; |
John Spurlock | 4cf6a94 | 2013-08-13 20:02:46 -0400 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | } |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 349 | } |