Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 20 | import android.animation.LayoutTransition.TransitionListener; |
| 21 | import android.animation.ObjectAnimator; |
| 22 | import android.animation.TimeInterpolator; |
| 23 | import android.animation.ValueAnimator; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 24 | import android.app.ActivityManagerNative; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 25 | import android.app.StatusBarManager; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 26 | import android.app.admin.DevicePolicyManager; |
| 27 | import android.content.BroadcastReceiver; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 28 | import android.content.Context; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
| 30 | import android.content.IntentFilter; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 31 | import android.content.res.Resources; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 32 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 33 | import android.graphics.Rect; |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 35 | import android.os.Handler; |
| 36 | import android.os.Message; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 37 | import android.os.RemoteException; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 38 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 39 | import android.util.Log; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 40 | import android.view.Display; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 41 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 42 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 43 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 44 | import android.view.ViewGroup; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 45 | import android.view.WindowManager; |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 46 | import android.view.accessibility.AccessibilityManager; |
Jim Miller | 7d8abae | 2013-10-08 21:10:40 -0700 | [diff] [blame] | 47 | import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 48 | import android.widget.ImageView; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 49 | import android.widget.LinearLayout; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 50 | |
| 51 | import com.android.systemui.R; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 52 | import com.android.systemui.statusbar.BaseStatusBar; |
| 53 | import com.android.systemui.statusbar.DelegateViewHelper; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 54 | import com.android.systemui.statusbar.policy.DeadZone; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 56 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 57 | import java.io.FileDescriptor; |
| 58 | import java.io.PrintWriter; |
| 59 | |
Adrian Roos | 5b0acf0 | 2014-01-10 12:58:22 -0800 | [diff] [blame] | 60 | import static com.android.systemui.statusbar.phone.KeyguardTouchDelegate.OnKeyguardConnectionListener; |
| 61 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 62 | public class NavigationBarView extends LinearLayout { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 63 | final static boolean DEBUG = false; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 64 | final static String TAG = "PhoneStatusBar/NavigationBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 65 | |
Daniel Sandler | f86f898 | 2011-05-31 15:46:13 -0400 | [diff] [blame] | 66 | final static boolean NAVBAR_ALWAYS_AT_RIGHT = true; |
| 67 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 68 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 69 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 70 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 71 | final Display mDisplay; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 72 | View mCurrentView = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 73 | View[] mRotatedViews = new View[4]; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 74 | |
| 75 | int mBarSize; |
| 76 | boolean mVertical; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 77 | boolean mScreenOn; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 78 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 79 | boolean mShowMenu; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 80 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 81 | int mNavigationIconHints = 0; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 82 | |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 83 | private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 84 | private Drawable mRecentIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 85 | private Drawable mRecentLandIcon; |
| 86 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 87 | private DelegateViewHelper mDelegateHelper; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 88 | private DeadZone mDeadZone; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 89 | private final NavigationBarTransitions mBarTransitions; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 90 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 91 | // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288) |
| 92 | final static boolean WORKAROUND_INVALID_LAYOUT = true; |
| 93 | final static int MSG_CHECK_INVALID_LAYOUT = 8686; |
| 94 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 95 | // used to disable the camera icon in navbar when disabled by DPM |
| 96 | private boolean mCameraDisabledByDpm; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 97 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 98 | // performs manual animation in sync with layout transitions |
| 99 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 100 | |
| 101 | private class NavTransitionListener implements TransitionListener { |
| 102 | private boolean mBackTransitioning; |
| 103 | private boolean mHomeAppearing; |
| 104 | private long mStartDelay; |
| 105 | private long mDuration; |
| 106 | private TimeInterpolator mInterpolator; |
| 107 | |
| 108 | @Override |
| 109 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 110 | View view, int transitionType) { |
| 111 | if (view.getId() == R.id.back) { |
| 112 | mBackTransitioning = true; |
| 113 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 114 | mHomeAppearing = true; |
| 115 | mStartDelay = transition.getStartDelay(transitionType); |
| 116 | mDuration = transition.getDuration(transitionType); |
| 117 | mInterpolator = transition.getInterpolator(transitionType); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 123 | View view, int transitionType) { |
| 124 | if (view.getId() == R.id.back) { |
| 125 | mBackTransitioning = false; |
| 126 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 127 | mHomeAppearing = false; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | public void onBackAltCleared() { |
| 132 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 133 | // animation as home (if we catch this condition early enough). |
| 134 | if (!mBackTransitioning && getBackButton().getVisibility() == VISIBLE |
| 135 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
| 136 | getBackButton().setAlpha(0); |
| 137 | ValueAnimator a = ObjectAnimator.ofFloat(getBackButton(), "alpha", 0, 1); |
| 138 | a.setStartDelay(mStartDelay); |
| 139 | a.setDuration(mDuration); |
| 140 | a.setInterpolator(mInterpolator); |
| 141 | a.start(); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
Jim Miller | 7d8abae | 2013-10-08 21:10:40 -0700 | [diff] [blame] | 146 | // simplified click handler to be used when device is in accessibility mode |
| 147 | private final OnClickListener mAccessibilityClickListener = new OnClickListener() { |
| 148 | @Override |
| 149 | public void onClick(View v) { |
| 150 | if (v.getId() == R.id.camera_button) { |
| 151 | KeyguardTouchDelegate.getInstance(getContext()).launchCamera(); |
| 152 | } else if (v.getId() == R.id.search_light) { |
| 153 | KeyguardTouchDelegate.getInstance(getContext()).showAssistant(); |
| 154 | } |
| 155 | } |
| 156 | }; |
| 157 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 158 | private final OnTouchListener mCameraTouchListener = new OnTouchListener() { |
| 159 | @Override |
Jim Miller | f4db8f9 | 2013-09-20 14:21:50 -0700 | [diff] [blame] | 160 | public boolean onTouch(View cameraButtonView, MotionEvent event) { |
Jim Miller | f4db8f9 | 2013-09-20 14:21:50 -0700 | [diff] [blame] | 161 | switch (event.getAction()) { |
| 162 | case MotionEvent.ACTION_DOWN: |
| 163 | // disable search gesture while interacting with camera |
| 164 | mDelegateHelper.setDisabled(true); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 165 | mBarTransitions.setContentVisible(false); |
Jim Miller | f4db8f9 | 2013-09-20 14:21:50 -0700 | [diff] [blame] | 166 | break; |
| 167 | case MotionEvent.ACTION_UP: |
| 168 | case MotionEvent.ACTION_CANCEL: |
| 169 | mDelegateHelper.setDisabled(false); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 170 | mBarTransitions.setContentVisible(true); |
Jim Miller | f4db8f9 | 2013-09-20 14:21:50 -0700 | [diff] [blame] | 171 | break; |
| 172 | } |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 173 | return KeyguardTouchDelegate.getInstance(getContext()).dispatch(event); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 174 | } |
| 175 | }; |
| 176 | |
Adrian Roos | 5b0acf0 | 2014-01-10 12:58:22 -0800 | [diff] [blame] | 177 | private final OnKeyguardConnectionListener mKeyguardConnectionListener = |
| 178 | new OnKeyguardConnectionListener() { |
| 179 | @Override |
| 180 | public void onKeyguardServiceConnected( |
| 181 | KeyguardTouchDelegate keyguardTouchDelegate) { |
| 182 | post(new Runnable() { |
| 183 | @Override |
| 184 | public void run() { |
| 185 | mCameraDisabledByDpm = isCameraDisabledByDpm(); |
| 186 | } |
| 187 | }); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void onKeyguardServiceDisconnected( |
| 192 | KeyguardTouchDelegate keyguardTouchDelegate) { |
| 193 | } |
| 194 | }; |
| 195 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 196 | private class H extends Handler { |
| 197 | public void handleMessage(Message m) { |
| 198 | switch (m.what) { |
| 199 | case MSG_CHECK_INVALID_LAYOUT: |
| 200 | final String how = "" + m.obj; |
| 201 | final int w = getWidth(); |
| 202 | final int h = getHeight(); |
| 203 | final int vw = mCurrentView.getWidth(); |
| 204 | final int vh = mCurrentView.getHeight(); |
| 205 | |
| 206 | if (h != vh || w != vw) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 207 | Log.w(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 208 | "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)", |
| 209 | how, w, h, vw, vh)); |
| 210 | if (WORKAROUND_INVALID_LAYOUT) { |
| 211 | requestLayout(); |
| 212 | } |
| 213 | } |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 219 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 220 | super(context, attrs); |
| 221 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 222 | mDisplay = ((WindowManager)context.getSystemService( |
| 223 | Context.WINDOW_SERVICE)).getDefaultDisplay(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 224 | |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 225 | final Resources res = getContext().getResources(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 226 | mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size); |
| 227 | mVertical = false; |
| 228 | mShowMenu = false; |
| 229 | mDelegateHelper = new DelegateViewHelper(this); |
| 230 | |
| 231 | getIcons(res); |
| 232 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 233 | mBarTransitions = new NavigationBarTransitions(this); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 234 | |
Adrian Roos | 5b0acf0 | 2014-01-10 12:58:22 -0800 | [diff] [blame] | 235 | KeyguardTouchDelegate.addListener(mKeyguardConnectionListener); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 236 | mCameraDisabledByDpm = isCameraDisabledByDpm(); |
| 237 | watchForDevicePolicyChanges(); |
| 238 | } |
| 239 | |
| 240 | private void watchForDevicePolicyChanges() { |
| 241 | final IntentFilter filter = new IntentFilter(); |
| 242 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 243 | getContext().registerReceiver(new BroadcastReceiver() { |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 244 | public void onReceive(Context context, Intent intent) { |
| 245 | post(new Runnable() { |
| 246 | @Override |
| 247 | public void run() { |
| 248 | mCameraDisabledByDpm = isCameraDisabledByDpm(); |
| 249 | } |
| 250 | }); |
| 251 | } |
| 252 | }, filter); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | public BarTransitions getBarTransitions() { |
| 256 | return mBarTransitions; |
| 257 | } |
| 258 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 259 | public void setDelegateView(View view) { |
| 260 | mDelegateHelper.setDelegateView(view); |
| 261 | } |
| 262 | |
| 263 | public void setBar(BaseStatusBar phoneStatusBar) { |
| 264 | mDelegateHelper.setBar(phoneStatusBar); |
| 265 | } |
| 266 | |
| 267 | @Override |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 268 | public boolean onTouchEvent(MotionEvent event) { |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 269 | if (mDeadZone != null && event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
| 270 | mDeadZone.poke(event); |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 271 | } |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 272 | if (mDelegateHelper != null) { |
| 273 | boolean ret = mDelegateHelper.onInterceptTouchEvent(event); |
| 274 | if (ret) return true; |
| 275 | } |
| 276 | return super.onTouchEvent(event); |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Override |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 280 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 281 | return mDelegateHelper.onInterceptTouchEvent(event); |
| 282 | } |
| 283 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 284 | private H mHandler = new H(); |
| 285 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 286 | public View getCurrentView() { |
| 287 | return mCurrentView; |
| 288 | } |
| 289 | |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 290 | public View getRecentsButton() { |
| 291 | return mCurrentView.findViewById(R.id.recent_apps); |
| 292 | } |
| 293 | |
| 294 | public View getMenuButton() { |
| 295 | return mCurrentView.findViewById(R.id.menu); |
| 296 | } |
| 297 | |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 298 | public View getBackButton() { |
| 299 | return mCurrentView.findViewById(R.id.back); |
| 300 | } |
| 301 | |
| 302 | public View getHomeButton() { |
| 303 | return mCurrentView.findViewById(R.id.home); |
| 304 | } |
| 305 | |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 306 | // for when home is disabled, but search isn't |
| 307 | public View getSearchLight() { |
| 308 | return mCurrentView.findViewById(R.id.search_light); |
| 309 | } |
| 310 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 311 | // shown when keyguard is visible and camera is available |
| 312 | public View getCameraButton() { |
| 313 | return mCurrentView.findViewById(R.id.camera_button); |
| 314 | } |
| 315 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 316 | private void getIcons(Resources res) { |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 317 | mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back); |
| 318 | mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land); |
| 319 | mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime); |
| 320 | mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 321 | mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent); |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 322 | mRecentLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public void setLayoutDirection(int layoutDirection) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 327 | getIcons(getContext().getResources()); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 328 | |
| 329 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 330 | } |
| 331 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 332 | public void notifyScreenOn(boolean screenOn) { |
| 333 | mScreenOn = screenOn; |
| 334 | setDisabledFlags(mDisabledFlags, true); |
| 335 | } |
| 336 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 337 | public void setNavigationIconHints(int hints) { |
| 338 | setNavigationIconHints(hints, false); |
| 339 | } |
| 340 | |
| 341 | public void setNavigationIconHints(int hints, boolean force) { |
| 342 | if (!force && hints == mNavigationIconHints) return; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 343 | final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 344 | if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) { |
| 345 | mTransitionListener.onBackAltCleared(); |
| 346 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 347 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 348 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 349 | "Navigation icon hints = " + hints, |
| 350 | 500).show(); |
| 351 | } |
| 352 | |
| 353 | mNavigationIconHints = hints; |
| 354 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 355 | ((ImageView)getBackButton()).setImageDrawable(backAlt |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 356 | ? (mVertical ? mBackAltLandIcon : mBackAltIcon) |
| 357 | : (mVertical ? mBackLandIcon : mBackIcon)); |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 358 | |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 359 | ((ImageView)getRecentsButton()).setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 360 | |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 361 | setDisabledFlags(mDisabledFlags, true); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 364 | public void setDisabledFlags(int disabledFlags) { |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 365 | setDisabledFlags(disabledFlags, false); |
| 366 | } |
| 367 | |
| 368 | public void setDisabledFlags(int disabledFlags, boolean force) { |
| 369 | if (!force && mDisabledFlags == disabledFlags) return; |
| 370 | |
| 371 | mDisabledFlags = disabledFlags; |
| 372 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 373 | final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
| 374 | final boolean disableRecent = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0); |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 375 | final boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) |
| 376 | && ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0); |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 377 | final boolean disableSearch = ((disabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 378 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 379 | if (SLIPPERY_WHEN_DISABLED) { |
| 380 | setSlippery(disableHome && disableRecent && disableBack && disableSearch); |
| 381 | } |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 382 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 383 | ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons); |
| 384 | if (navButtons != null) { |
| 385 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 386 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 387 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 388 | lt.addTransitionListener(mTransitionListener); |
| 389 | } |
| 390 | if (!mScreenOn && mCurrentView != null) { |
| 391 | lt.disableTransitionType( |
| 392 | LayoutTransition.CHANGE_APPEARING | |
| 393 | LayoutTransition.CHANGE_DISAPPEARING | |
| 394 | LayoutTransition.APPEARING | |
| 395 | LayoutTransition.DISAPPEARING); |
| 396 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 400 | getBackButton() .setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 401 | getHomeButton() .setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
| 402 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 403 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 404 | final boolean showSearch = disableHome && !disableSearch; |
| 405 | final boolean showCamera = showSearch && !mCameraDisabledByDpm; |
| 406 | setVisibleOrGone(getSearchLight(), showSearch); |
| 407 | setVisibleOrGone(getCameraButton(), showCamera); |
| 408 | |
| 409 | mBarTransitions.applyBackButtonQuiescentAlpha(mBarTransitions.getMode(), true /*animate*/); |
| 410 | } |
| 411 | |
| 412 | private void setVisibleOrGone(View view, boolean visible) { |
| 413 | if (view != null) { |
| 414 | view.setVisibility(visible ? VISIBLE : GONE); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
| 418 | private boolean isCameraDisabledByDpm() { |
| 419 | final DevicePolicyManager dpm = |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 420 | (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 421 | if (dpm != null) { |
| 422 | try { |
| 423 | final int userId = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 424 | final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId); |
| 425 | final boolean disabledBecauseKeyguardSecure = |
| 426 | (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 |
Jim Miller | 6c9df50 | 2013-09-19 15:50:11 -0700 | [diff] [blame] | 427 | && KeyguardTouchDelegate.getInstance(getContext()).isSecure(); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 428 | return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure; |
| 429 | } catch (RemoteException e) { |
| 430 | Log.e(TAG, "Can't get userId", e); |
| 431 | } |
| 432 | } |
| 433 | return false; |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 434 | } |
| 435 | |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 436 | public void setSlippery(boolean newSlippery) { |
| 437 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); |
| 438 | if (lp != null) { |
| 439 | boolean oldSlippery = (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) != 0; |
| 440 | if (!oldSlippery && newSlippery) { |
| 441 | lp.flags |= WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 442 | } else if (oldSlippery && !newSlippery) { |
| 443 | lp.flags &= ~WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 444 | } else { |
| 445 | return; |
| 446 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 447 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
| 448 | wm.updateViewLayout(this, lp); |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 452 | public void setMenuVisibility(final boolean show) { |
| 453 | setMenuVisibility(show, false); |
| 454 | } |
| 455 | |
| 456 | public void setMenuVisibility(final boolean show, final boolean force) { |
| 457 | if (!force && mShowMenu == show) return; |
| 458 | |
| 459 | mShowMenu = show; |
| 460 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 461 | getMenuButton().setVisibility(mShowMenu ? View.VISIBLE : View.INVISIBLE); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 462 | } |
| 463 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 464 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 465 | public void onFinishInflate() { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 466 | mRotatedViews[Surface.ROTATION_0] = |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 467 | mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0); |
| 468 | |
| 469 | mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 470 | |
Daniel Sandler | f86f898 | 2011-05-31 15:46:13 -0400 | [diff] [blame] | 471 | mRotatedViews[Surface.ROTATION_270] = NAVBAR_ALWAYS_AT_RIGHT |
| 472 | ? findViewById(R.id.rot90) |
| 473 | : findViewById(R.id.rot270); |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 474 | |
| 475 | mCurrentView = mRotatedViews[Surface.ROTATION_0]; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 476 | |
Jim Miller | 7d8abae | 2013-10-08 21:10:40 -0700 | [diff] [blame] | 477 | watchForAccessibilityChanges(); |
Jim Miller | 138f25d | 2013-09-25 13:46:58 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Jim Miller | 7d8abae | 2013-10-08 21:10:40 -0700 | [diff] [blame] | 480 | private void watchForAccessibilityChanges() { |
| 481 | final AccessibilityManager am = |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 482 | (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
Jim Miller | 7d8abae | 2013-10-08 21:10:40 -0700 | [diff] [blame] | 483 | |
| 484 | // Set the initial state |
| 485 | enableAccessibility(am.isTouchExplorationEnabled()); |
| 486 | |
| 487 | // Watch for changes |
| 488 | am.addTouchExplorationStateChangeListener(new TouchExplorationStateChangeListener() { |
| 489 | @Override |
| 490 | public void onTouchExplorationStateChanged(boolean enabled) { |
| 491 | enableAccessibility(enabled); |
| 492 | } |
| 493 | }); |
| 494 | } |
| 495 | |
| 496 | private void enableAccessibility(boolean touchEnabled) { |
| 497 | Log.v(TAG, "touchEnabled:" + touchEnabled); |
| 498 | |
| 499 | // Add a touch handler or accessibility click listener for camera and search buttons |
| 500 | // for all view orientations. |
| 501 | final OnClickListener onClickListener = touchEnabled ? mAccessibilityClickListener : null; |
| 502 | final OnTouchListener onTouchListener = touchEnabled ? null : mCameraTouchListener; |
| 503 | boolean hasCamera = false; |
| 504 | for (int i = 0; i < mRotatedViews.length; i++) { |
| 505 | final View cameraButton = mRotatedViews[i].findViewById(R.id.camera_button); |
| 506 | final View searchLight = mRotatedViews[i].findViewById(R.id.search_light); |
| 507 | if (cameraButton != null) { |
| 508 | hasCamera = true; |
| 509 | cameraButton.setOnTouchListener(onTouchListener); |
| 510 | cameraButton.setOnClickListener(onClickListener); |
| 511 | } |
| 512 | if (searchLight != null) { |
| 513 | searchLight.setOnClickListener(onClickListener); |
| 514 | } |
| 515 | } |
| 516 | if (hasCamera) { |
| 517 | // Warm up KeyguardTouchDelegate so it's ready by the time the camera button is touched. |
| 518 | // This will connect to KeyguardService so that touch events are processed. |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 519 | KeyguardTouchDelegate.getInstance(getContext()); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 520 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 521 | } |
| 522 | |
John Spurlock | dcf4f21 | 2013-05-21 17:19:53 -0400 | [diff] [blame] | 523 | public boolean isVertical() { |
| 524 | return mVertical; |
| 525 | } |
| 526 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 527 | public void reorient() { |
| 528 | final int rot = mDisplay.getRotation(); |
| 529 | for (int i=0; i<4; i++) { |
| 530 | mRotatedViews[i].setVisibility(View.GONE); |
| 531 | } |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 532 | mCurrentView = mRotatedViews[rot]; |
| 533 | mCurrentView.setVisibility(View.VISIBLE); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 534 | |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 535 | mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone); |
| 536 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 537 | // force the low profile & disabled states into compliance |
John Spurlock | e631b41 | 2013-09-18 16:33:57 -0400 | [diff] [blame] | 538 | mBarTransitions.init(mVertical); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 539 | setDisabledFlags(mDisabledFlags, true /* force */); |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 540 | setMenuVisibility(mShowMenu, true /* force */); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 541 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 542 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 543 | Log.d(TAG, "reorient(): rot=" + mDisplay.getRotation()); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 544 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 545 | |
fisherson_lin | 10e71e0 | 2014-01-20 14:47:27 +0800 | [diff] [blame] | 546 | // swap to x coordinate if orientation is not in vertical |
| 547 | if (mDelegateHelper != null) { |
| 548 | mDelegateHelper.setSwapXY(!mVertical); |
| 549 | } |
| 550 | |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 551 | setNavigationIconHints(mNavigationIconHints, true); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 552 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 553 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 554 | @Override |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 555 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 556 | super.onLayout(changed, l, t, r, b); |
| 557 | mDelegateHelper.setInitialTouchRegion(getHomeButton(), getBackButton(), getRecentsButton()); |
| 558 | } |
| 559 | |
| 560 | @Override |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 561 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 562 | if (DEBUG) Log.d(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 563 | "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh)); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 564 | |
| 565 | final boolean newVertical = w > 0 && h > w; |
| 566 | if (newVertical != mVertical) { |
| 567 | mVertical = newVertical; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 568 | //Log.v(TAG, String.format("onSizeChanged: h=%d, w=%d, vert=%s", h, w, mVertical?"y":"n")); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 569 | reorient(); |
| 570 | } |
| 571 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 572 | postCheckForInvalidLayout("sizeChanged"); |
| 573 | super.onSizeChanged(w, h, oldw, oldh); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | @Override |
| 578 | protected void onLayout (boolean changed, int left, int top, int right, int bottom) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 579 | if (DEBUG) Log.d(TAG, String.format( |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 580 | "onLayout: %s (%d,%d,%d,%d)", |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 581 | changed?"changed":"notchanged", left, top, right, bottom)); |
| 582 | super.onLayout(changed, left, top, right, bottom); |
| 583 | } |
| 584 | |
| 585 | // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else |
| 586 | // fails, any touch on the display will fix the layout. |
| 587 | @Override |
| 588 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 589 | if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString()); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 590 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 591 | postCheckForInvalidLayout("touch"); |
| 592 | } |
| 593 | return super.onInterceptTouchEvent(ev); |
| 594 | } |
| 595 | */ |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 596 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 597 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 598 | private String getResourceName(int resId) { |
| 599 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 600 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 601 | try { |
| 602 | return res.getResourceName(resId); |
| 603 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 604 | return "(unknown)"; |
| 605 | } |
| 606 | } else { |
| 607 | return "(null)"; |
| 608 | } |
| 609 | } |
| 610 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 611 | private void postCheckForInvalidLayout(final String how) { |
| 612 | mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget(); |
| 613 | } |
| 614 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 615 | private static String visibilityToString(int vis) { |
| 616 | switch (vis) { |
| 617 | case View.INVISIBLE: |
| 618 | return "INVISIBLE"; |
| 619 | case View.GONE: |
| 620 | return "GONE"; |
| 621 | default: |
| 622 | return "VISIBLE"; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 627 | pw.println("NavigationBarView {"); |
| 628 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 629 | final Point size = new Point(); |
| 630 | mDisplay.getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 631 | |
| 632 | pw.println(String.format(" this: " + PhoneStatusBar.viewInfo(this) |
| 633 | + " " + visibilityToString(getVisibility()))); |
| 634 | |
| 635 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 636 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 637 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 638 | + r.toShortString() |
| 639 | + " " + visibilityToString(getWindowVisibility()) |
| 640 | + (offscreen ? " OFFSCREEN!" : "")); |
| 641 | |
| 642 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s", |
| 643 | getResourceName(mCurrentView.getId()), |
| 644 | mCurrentView.getWidth(), mCurrentView.getHeight(), |
| 645 | visibilityToString(mCurrentView.getVisibility()))); |
| 646 | |
John Spurlock | 41c1e35 | 2013-09-16 13:57:13 -0400 | [diff] [blame] | 647 | pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 648 | mDisabledFlags, |
| 649 | mVertical ? "true" : "false", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 650 | mShowMenu ? "true" : "false")); |
| 651 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 652 | dumpButton(pw, "back", getBackButton()); |
| 653 | dumpButton(pw, "home", getHomeButton()); |
| 654 | dumpButton(pw, "rcnt", getRecentsButton()); |
| 655 | dumpButton(pw, "menu", getMenuButton()); |
| 656 | dumpButton(pw, "srch", getSearchLight()); |
| 657 | dumpButton(pw, "cmra", getCameraButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 658 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 659 | pw.println(" }"); |
| 660 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 661 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 662 | private static void dumpButton(PrintWriter pw, String caption, View button) { |
| 663 | pw.print(" " + caption + ": "); |
| 664 | if (button == null) { |
| 665 | pw.print("null"); |
| 666 | } else { |
| 667 | pw.print(PhoneStatusBar.viewInfo(button) |
| 668 | + " " + visibilityToString(button.getVisibility()) |
| 669 | + " alpha=" + button.getAlpha() |
| 670 | ); |
| 671 | if (button instanceof KeyButtonView) { |
| 672 | pw.print(" drawingAlpha=" + ((KeyButtonView)button).getDrawingAlpha()); |
| 673 | pw.print(" quiescentAlpha=" + ((KeyButtonView)button).getQuiescentAlpha()); |
| 674 | } |
| 675 | } |
| 676 | pw.println(); |
| 677 | } |
| 678 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 679 | } |