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; |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 24 | import android.app.ActivityManagerNative; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 25 | import android.app.StatusBarManager; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 26 | import android.content.Context; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 28 | import android.content.res.Resources; |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 29 | import android.graphics.Point; |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 30 | import android.graphics.Rect; |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 34 | import android.os.RemoteException; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 35 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 36 | import android.util.Log; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 37 | import android.view.Display; |
Jorim Jaggi | ca8c626 | 2014-10-27 16:53:18 +0100 | [diff] [blame] | 38 | import android.view.Gravity; |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 39 | import android.view.MotionEvent; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 40 | import android.view.Surface; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 41 | import android.view.View; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 42 | import android.view.ViewGroup; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 43 | import android.view.WindowManager; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 44 | import android.view.inputmethod.InputMethodManager; |
Jorim Jaggi | ca8c626 | 2014-10-27 16:53:18 +0100 | [diff] [blame] | 45 | import android.widget.FrameLayout; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 46 | import android.widget.ImageView; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 47 | import android.widget.LinearLayout; |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 48 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 49 | import com.android.systemui.R; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 50 | import com.android.systemui.RecentsComponent; |
| 51 | import com.android.systemui.stackdivider.Divider; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.DeadZone; |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 53 | import com.android.systemui.statusbar.policy.KeyButtonView; |
| 54 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 55 | import java.io.FileDescriptor; |
| 56 | import java.io.PrintWriter; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 57 | import java.util.ArrayList; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 58 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 59 | public class NavigationBarView extends LinearLayout { |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 60 | final static boolean DEBUG = false; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 61 | final static String TAG = "PhoneStatusBar/NavigationBarView"; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 62 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 63 | // slippery nav bar when everything is disabled, e.g. during setup |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 64 | final static boolean SLIPPERY_WHEN_DISABLED = true; |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 65 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 66 | final Display mDisplay; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 67 | View mCurrentView = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 68 | View[] mRotatedViews = new View[4]; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 69 | |
| 70 | int mBarSize; |
| 71 | boolean mVertical; |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 72 | boolean mScreenOn; |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 73 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 74 | boolean mShowMenu; |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 75 | int mDisabledFlags = 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 76 | int mNavigationIconHints = 0; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 77 | |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 78 | private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 79 | private Drawable mRecentIcon; |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 80 | private Drawable mRecentLandIcon; |
| 81 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 82 | private NavigationBarGestureHelper mGestureHelper; |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 83 | private DeadZone mDeadZone; |
John Spurlock | 89835dd | 2013-08-16 15:06:51 -0400 | [diff] [blame] | 84 | private final NavigationBarTransitions mBarTransitions; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 85 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 86 | // workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288) |
| 87 | final static boolean WORKAROUND_INVALID_LAYOUT = true; |
| 88 | final static int MSG_CHECK_INVALID_LAYOUT = 8686; |
| 89 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 90 | // performs manual animation in sync with layout transitions |
| 91 | private final NavTransitionListener mTransitionListener = new NavTransitionListener(); |
| 92 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 93 | private OnVerticalChangedListener mOnVerticalChangedListener; |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 94 | private boolean mIsLayoutRtl; |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 95 | private boolean mLayoutTransitionsEnabled = true; |
| 96 | private boolean mWakeAndUnlocking; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 97 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 98 | private class NavTransitionListener implements TransitionListener { |
| 99 | private boolean mBackTransitioning; |
| 100 | private boolean mHomeAppearing; |
| 101 | private long mStartDelay; |
| 102 | private long mDuration; |
| 103 | private TimeInterpolator mInterpolator; |
| 104 | |
| 105 | @Override |
| 106 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 107 | View view, int transitionType) { |
| 108 | if (view.getId() == R.id.back) { |
| 109 | mBackTransitioning = true; |
| 110 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 111 | mHomeAppearing = true; |
| 112 | mStartDelay = transition.getStartDelay(transitionType); |
| 113 | mDuration = transition.getDuration(transitionType); |
| 114 | mInterpolator = transition.getInterpolator(transitionType); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 120 | View view, int transitionType) { |
| 121 | if (view.getId() == R.id.back) { |
| 122 | mBackTransitioning = false; |
| 123 | } else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) { |
| 124 | mHomeAppearing = false; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public void onBackAltCleared() { |
| 129 | // When dismissing ime during unlock, force the back button to run the same appearance |
| 130 | // animation as home (if we catch this condition early enough). |
| 131 | if (!mBackTransitioning && getBackButton().getVisibility() == VISIBLE |
| 132 | && mHomeAppearing && getHomeButton().getAlpha() == 0) { |
| 133 | getBackButton().setAlpha(0); |
| 134 | ValueAnimator a = ObjectAnimator.ofFloat(getBackButton(), "alpha", 0, 1); |
| 135 | a.setStartDelay(mStartDelay); |
| 136 | a.setDuration(mDuration); |
| 137 | a.setInterpolator(mInterpolator); |
| 138 | a.start(); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 143 | private final OnClickListener mImeSwitcherClickListener = new OnClickListener() { |
| 144 | @Override |
| 145 | public void onClick(View view) { |
Yohei Yukawa | 777ef95 | 2015-11-25 20:32:24 -0800 | [diff] [blame^] | 146 | mContext.getSystemService(InputMethodManager.class) |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 147 | .showInputMethodPicker(true /* showAuxiliarySubtypes */); |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 148 | } |
| 149 | }; |
| 150 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 151 | private class H extends Handler { |
| 152 | public void handleMessage(Message m) { |
| 153 | switch (m.what) { |
| 154 | case MSG_CHECK_INVALID_LAYOUT: |
| 155 | final String how = "" + m.obj; |
| 156 | final int w = getWidth(); |
| 157 | final int h = getHeight(); |
| 158 | final int vw = mCurrentView.getWidth(); |
| 159 | final int vh = mCurrentView.getHeight(); |
| 160 | |
| 161 | if (h != vh || w != vw) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 162 | Log.w(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 163 | "*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)", |
| 164 | how, w, h, vw, vh)); |
| 165 | if (WORKAROUND_INVALID_LAYOUT) { |
| 166 | requestLayout(); |
| 167 | } |
| 168 | } |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 174 | public NavigationBarView(Context context, AttributeSet attrs) { |
| 175 | super(context, attrs); |
| 176 | |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 177 | mDisplay = ((WindowManager)context.getSystemService( |
| 178 | Context.WINDOW_SERVICE)).getDefaultDisplay(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 179 | |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 180 | final Resources res = getContext().getResources(); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 181 | mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size); |
| 182 | mVertical = false; |
| 183 | mShowMenu = false; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 184 | mGestureHelper = new NavigationBarGestureHelper(context); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 185 | |
| 186 | getIcons(res); |
| 187 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 188 | mBarTransitions = new NavigationBarTransitions(this); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public BarTransitions getBarTransitions() { |
| 192 | return mBarTransitions; |
| 193 | } |
| 194 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 195 | public void setComponents(RecentsComponent recentsComponent, Divider divider) { |
| 196 | mGestureHelper.setComponents(recentsComponent, divider); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 199 | public void setOnVerticalChangedListener(OnVerticalChangedListener onVerticalChangedListener) { |
| 200 | mOnVerticalChangedListener = onVerticalChangedListener; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 201 | notifyVerticalChangedListener(mVertical); |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 204 | @Override |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 205 | public boolean onTouchEvent(MotionEvent event) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 206 | if (mGestureHelper.onTouchEvent(event)) { |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 207 | return true; |
| 208 | } |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 209 | if (mDeadZone != null && event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
| 210 | mDeadZone.poke(event); |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 211 | } |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 212 | return super.onTouchEvent(event); |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 216 | public boolean onInterceptTouchEvent(MotionEvent event) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 217 | return mGestureHelper.onInterceptTouchEvent(event); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 220 | public void abortCurrentGesture() { |
Xiyuan Xia | ee7dd05 | 2015-05-15 09:46:27 -0700 | [diff] [blame] | 221 | getHomeButton().abortCurrentGesture(); |
| 222 | } |
| 223 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 224 | private H mHandler = new H(); |
| 225 | |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 226 | public View getCurrentView() { |
| 227 | return mCurrentView; |
| 228 | } |
| 229 | |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 230 | public View getRecentsButton() { |
| 231 | return mCurrentView.findViewById(R.id.recent_apps); |
| 232 | } |
| 233 | |
| 234 | public View getMenuButton() { |
| 235 | return mCurrentView.findViewById(R.id.menu); |
| 236 | } |
| 237 | |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 238 | public View getBackButton() { |
| 239 | return mCurrentView.findViewById(R.id.back); |
| 240 | } |
| 241 | |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 242 | public KeyButtonView getHomeButton() { |
| 243 | return (KeyButtonView) mCurrentView.findViewById(R.id.home); |
Mike Lockwood | e3646dd | 2011-09-01 12:46:28 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 246 | public View getImeSwitchButton() { |
| 247 | return mCurrentView.findViewById(R.id.ime_switcher); |
| 248 | } |
| 249 | |
James Cook | 968403d | 2015-07-08 15:10:33 -0700 | [diff] [blame] | 250 | public View getAppShelf() { |
| 251 | return mCurrentView.findViewById(R.id.app_shelf); |
| 252 | } |
| 253 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 254 | private void getIcons(Resources res) { |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 255 | mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back); |
Dan Sandler | c263a08 | 2015-09-03 10:51:57 -0400 | [diff] [blame] | 256 | mBackLandIcon = mBackIcon; |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 257 | mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime); |
Dan Sandler | c263a08 | 2015-09-03 10:51:57 -0400 | [diff] [blame] | 258 | mBackAltLandIcon = mBackAltIcon; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 259 | mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent); |
Dan Sandler | c263a08 | 2015-09-03 10:51:57 -0400 | [diff] [blame] | 260 | mRecentLandIcon = mRecentIcon; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void setLayoutDirection(int layoutDirection) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 265 | getIcons(getContext().getResources()); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 266 | |
| 267 | super.setLayoutDirection(layoutDirection); |
Daniel Sandler | 1d4d30a | 2011-04-28 12:35:29 -0400 | [diff] [blame] | 268 | } |
| 269 | |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 270 | public void notifyScreenOn(boolean screenOn) { |
| 271 | mScreenOn = screenOn; |
| 272 | setDisabledFlags(mDisabledFlags, true); |
| 273 | } |
| 274 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 275 | public void setNavigationIconHints(int hints) { |
| 276 | setNavigationIconHints(hints, false); |
| 277 | } |
| 278 | |
| 279 | public void setNavigationIconHints(int hints, boolean force) { |
| 280 | if (!force && hints == mNavigationIconHints) return; |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 281 | final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0; |
| 282 | if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) { |
| 283 | mTransitionListener.onBackAltCleared(); |
| 284 | } |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 285 | if (DEBUG) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 286 | android.widget.Toast.makeText(getContext(), |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 287 | "Navigation icon hints = " + hints, |
| 288 | 500).show(); |
| 289 | } |
| 290 | |
| 291 | mNavigationIconHints = hints; |
| 292 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 293 | ((ImageView)getBackButton()).setImageDrawable(backAlt |
Daniel Sandler | 2c9ae75 | 2012-04-27 00:14:54 -0400 | [diff] [blame] | 294 | ? (mVertical ? mBackAltLandIcon : mBackAltIcon) |
| 295 | : (mVertical ? mBackLandIcon : mBackIcon)); |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 296 | |
Fabrice Di Meglio | 18d9824 | 2013-01-17 10:57:40 -0800 | [diff] [blame] | 297 | ((ImageView)getRecentsButton()).setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 298 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 299 | final boolean showImeButton = ((hints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0); |
| 300 | getImeSwitchButton().setVisibility(showImeButton ? View.VISIBLE : View.INVISIBLE); |
| 301 | // Update menu button in case the IME state has changed. |
| 302 | setMenuVisibility(mShowMenu, true); |
| 303 | |
| 304 | |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 305 | setDisabledFlags(mDisabledFlags, true); |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 308 | public void setDisabledFlags(int disabledFlags) { |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 309 | setDisabledFlags(disabledFlags, false); |
| 310 | } |
| 311 | |
| 312 | public void setDisabledFlags(int disabledFlags, boolean force) { |
| 313 | if (!force && mDisabledFlags == disabledFlags) return; |
| 314 | |
| 315 | mDisabledFlags = disabledFlags; |
| 316 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 317 | final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0); |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 318 | boolean disableRecent = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0); |
John Spurlock | a9b4682 | 2012-11-02 10:42:39 -0400 | [diff] [blame] | 319 | final boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) |
| 320 | && ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0); |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 321 | final boolean disableSearch = ((disabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 322 | |
Daniel Sandler | c3fc322 | 2012-10-25 13:28:33 -0400 | [diff] [blame] | 323 | if (SLIPPERY_WHEN_DISABLED) { |
| 324 | setSlippery(disableHome && disableRecent && disableBack && disableSearch); |
| 325 | } |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 326 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 327 | ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons); |
| 328 | if (navButtons != null) { |
| 329 | LayoutTransition lt = navButtons.getLayoutTransition(); |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 330 | if (lt != null) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 331 | if (!lt.getTransitionListeners().contains(mTransitionListener)) { |
| 332 | lt.addTransitionListener(mTransitionListener); |
| 333 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 334 | } |
| 335 | } |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 336 | if (inLockTask() && disableRecent && !disableHome) { |
| 337 | // Don't hide recents when in lock task, it is used for exiting. |
| 338 | // Unless home is hidden, then in DPM locked mode and no exit available. |
| 339 | disableRecent = false; |
| 340 | } |
John Spurlock | 1bbd49d | 2012-10-19 11:09:32 -0400 | [diff] [blame] | 341 | |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 342 | getBackButton() .setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE); |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 343 | getHomeButton() .setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
| 344 | getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE); |
James Cook | 968403d | 2015-07-08 15:10:33 -0700 | [diff] [blame] | 345 | |
| 346 | // The app shelf, if it exists, follows the visibility of the home button. |
| 347 | View appShelf = getAppShelf(); |
| 348 | if (appShelf != null) { |
| 349 | appShelf.setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE); |
| 350 | } |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 351 | } |
| 352 | |
Jason Monk | 17488b9 | 2014-11-06 11:26:14 -0500 | [diff] [blame] | 353 | private boolean inLockTask() { |
| 354 | try { |
| 355 | return ActivityManagerNative.getDefault().isInLockTaskMode(); |
| 356 | } catch (RemoteException e) { |
| 357 | return false; |
| 358 | } |
| 359 | } |
| 360 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 361 | private void setVisibleOrGone(View view, boolean visible) { |
| 362 | if (view != null) { |
| 363 | view.setVisibility(visible ? VISIBLE : GONE); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 367 | public void setLayoutTransitionsEnabled(boolean enabled) { |
| 368 | mLayoutTransitionsEnabled = enabled; |
| 369 | updateLayoutTransitionsEnabled(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 372 | public void setWakeAndUnlocking(boolean wakeAndUnlocking) { |
| 373 | setUseFadingAnimations(wakeAndUnlocking); |
| 374 | mWakeAndUnlocking = wakeAndUnlocking; |
| 375 | updateLayoutTransitionsEnabled(); |
| 376 | } |
| 377 | |
| 378 | private void updateLayoutTransitionsEnabled() { |
| 379 | boolean enabled = !mWakeAndUnlocking && mLayoutTransitionsEnabled; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 380 | ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons); |
| 381 | LayoutTransition lt = navButtons.getLayoutTransition(); |
Julia Reynolds | 8478aba | 2015-07-31 09:17:20 -0400 | [diff] [blame] | 382 | if (lt != null) { |
| 383 | if (enabled) { |
| 384 | lt.enableTransitionType(LayoutTransition.APPEARING); |
| 385 | lt.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 386 | lt.enableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 387 | lt.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 388 | } else { |
| 389 | lt.disableTransitionType(LayoutTransition.APPEARING); |
| 390 | lt.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 391 | lt.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 392 | lt.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 393 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | private void setUseFadingAnimations(boolean useFadingAnimations) { |
| 398 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); |
| 399 | if (lp != null) { |
| 400 | boolean old = lp.windowAnimations != 0; |
| 401 | if (!old && useFadingAnimations) { |
| 402 | lp.windowAnimations = R.style.Animation_NavigationBarFadeIn; |
| 403 | } else if (old && !useFadingAnimations) { |
| 404 | lp.windowAnimations = 0; |
| 405 | } else { |
| 406 | return; |
| 407 | } |
| 408 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
| 409 | wm.updateViewLayout(this, lp); |
| 410 | } |
| 411 | } |
| 412 | |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 413 | public void setSlippery(boolean newSlippery) { |
| 414 | WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); |
| 415 | if (lp != null) { |
| 416 | boolean oldSlippery = (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) != 0; |
| 417 | if (!oldSlippery && newSlippery) { |
| 418 | lp.flags |= WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 419 | } else if (oldSlippery && !newSlippery) { |
| 420 | lp.flags &= ~WindowManager.LayoutParams.FLAG_SLIPPERY; |
| 421 | } else { |
| 422 | return; |
| 423 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 424 | WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE); |
| 425 | wm.updateViewLayout(this, lp); |
John Spurlock | d5ef546 | 2012-06-13 11:19:51 -0400 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 429 | public void setMenuVisibility(final boolean show) { |
| 430 | setMenuVisibility(show, false); |
| 431 | } |
| 432 | |
| 433 | public void setMenuVisibility(final boolean show, final boolean force) { |
| 434 | if (!force && mShowMenu == show) return; |
| 435 | |
| 436 | mShowMenu = show; |
| 437 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 438 | // Only show Menu if IME switcher not shown. |
| 439 | final boolean shouldShow = mShowMenu && |
| 440 | ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) == 0); |
| 441 | getMenuButton().setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE); |
Daniel Sandler | 029d587 | 2011-09-12 00:58:58 -0400 | [diff] [blame] | 442 | } |
| 443 | |
Jim Miller | 960892c | 2012-05-23 15:50:04 -0700 | [diff] [blame] | 444 | @Override |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 445 | public void onFinishInflate() { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 446 | mRotatedViews[Surface.ROTATION_0] = |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 447 | mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0); |
| 448 | |
| 449 | mRotatedViews[Surface.ROTATION_90] = findViewById(R.id.rot90); |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 450 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 451 | mRotatedViews[Surface.ROTATION_270] = mRotatedViews[Surface.ROTATION_90]; |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 452 | |
| 453 | mCurrentView = mRotatedViews[Surface.ROTATION_0]; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 454 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 455 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 456 | |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 457 | updateRTLOrder(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 458 | } |
| 459 | |
John Spurlock | dcf4f21 | 2013-05-21 17:19:53 -0400 | [diff] [blame] | 460 | public boolean isVertical() { |
| 461 | return mVertical; |
| 462 | } |
| 463 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 464 | public void reorient() { |
| 465 | final int rot = mDisplay.getRotation(); |
| 466 | for (int i=0; i<4; i++) { |
| 467 | mRotatedViews[i].setVisibility(View.GONE); |
| 468 | } |
Daniel Sandler | 5c8da94 | 2011-06-28 00:29:04 -0400 | [diff] [blame] | 469 | mCurrentView = mRotatedViews[rot]; |
| 470 | mCurrentView.setVisibility(View.VISIBLE); |
Jorim Jaggi | 37c1180 | 2015-08-18 20:27:54 -0700 | [diff] [blame] | 471 | updateLayoutTransitionsEnabled(); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 472 | |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 473 | getImeSwitchButton().setOnClickListener(mImeSwitcherClickListener); |
| 474 | |
Daniel Sandler | c26185b | 2012-08-29 15:49:53 -0400 | [diff] [blame] | 475 | mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone); |
| 476 | |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 477 | // force the low profile & disabled states into compliance |
Adrian Roos | 8a8ffd4 | 2015-05-26 18:30:37 -0700 | [diff] [blame] | 478 | mBarTransitions.init(); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 479 | setDisabledFlags(mDisabledFlags, true /* force */); |
Daniel Sandler | 56598cd | 2011-09-15 16:02:56 -0400 | [diff] [blame] | 480 | setMenuVisibility(mShowMenu, true /* force */); |
Daniel Sandler | 6da2b76 | 2011-09-14 16:04:59 -0400 | [diff] [blame] | 481 | |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 482 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 483 | Log.d(TAG, "reorient(): rot=" + mDisplay.getRotation()); |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 484 | } |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 485 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 486 | updateTaskSwitchHelper(); |
Michael Jurka | a5d0ddb | 2012-03-09 17:41:41 -0800 | [diff] [blame] | 487 | setNavigationIconHints(mNavigationIconHints, true); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 488 | } |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 489 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 490 | private void updateTaskSwitchHelper() { |
| 491 | boolean isRtl = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 492 | mGestureHelper.setBarState(mVertical, isRtl); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 495 | @Override |
| 496 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 497 | if (DEBUG) Log.d(TAG, String.format( |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 498 | "onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh)); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 499 | |
| 500 | final boolean newVertical = w > 0 && h > w; |
| 501 | if (newVertical != mVertical) { |
| 502 | mVertical = newVertical; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 503 | //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] | 504 | reorient(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 505 | notifyVerticalChangedListener(newVertical); |
Daniel Sandler | e03bc95 | 2012-04-27 16:11:22 -0400 | [diff] [blame] | 506 | } |
| 507 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 508 | postCheckForInvalidLayout("sizeChanged"); |
| 509 | super.onSizeChanged(w, h, oldw, oldh); |
| 510 | } |
| 511 | |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 512 | private void notifyVerticalChangedListener(boolean newVertical) { |
| 513 | if (mOnVerticalChangedListener != null) { |
| 514 | mOnVerticalChangedListener.onVerticalChanged(newVertical); |
| 515 | } |
| 516 | } |
| 517 | |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 518 | @Override |
| 519 | protected void onConfigurationChanged(Configuration newConfig) { |
| 520 | super.onConfigurationChanged(newConfig); |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 521 | updateRTLOrder(); |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 522 | updateTaskSwitchHelper(); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /** |
| 526 | * In landscape, the LinearLayout is not auto mirrored since it is vertical. Therefore we |
| 527 | * have to do it manually |
| 528 | */ |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 529 | private void updateRTLOrder() { |
| 530 | boolean isLayoutRtl = getResources().getConfiguration() |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 531 | .getLayoutDirection() == LAYOUT_DIRECTION_RTL; |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 532 | if (mIsLayoutRtl != isLayoutRtl) { |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 533 | |
| 534 | // We swap all children of the 90 and 270 degree layouts, since they are vertical |
| 535 | View rotation90 = mRotatedViews[Surface.ROTATION_90]; |
| 536 | swapChildrenOrderIfVertical(rotation90.findViewById(R.id.nav_buttons)); |
Jorim Jaggi | ca8c626 | 2014-10-27 16:53:18 +0100 | [diff] [blame] | 537 | adjustExtraKeyGravity(rotation90, isLayoutRtl); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 538 | |
| 539 | View rotation270 = mRotatedViews[Surface.ROTATION_270]; |
| 540 | if (rotation90 != rotation270) { |
| 541 | swapChildrenOrderIfVertical(rotation270.findViewById(R.id.nav_buttons)); |
Jorim Jaggi | ca8c626 | 2014-10-27 16:53:18 +0100 | [diff] [blame] | 542 | adjustExtraKeyGravity(rotation270, isLayoutRtl); |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 543 | } |
Selim Cinek | 74c92d6 | 2014-09-01 23:53:43 +0200 | [diff] [blame] | 544 | mIsLayoutRtl = isLayoutRtl; |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
Jorim Jaggi | ca8c626 | 2014-10-27 16:53:18 +0100 | [diff] [blame] | 548 | private void adjustExtraKeyGravity(View navBar, boolean isLayoutRtl) { |
| 549 | View menu = navBar.findViewById(R.id.menu); |
| 550 | View imeSwitcher = navBar.findViewById(R.id.ime_switcher); |
| 551 | if (menu != null) { |
| 552 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) menu.getLayoutParams(); |
| 553 | lp.gravity = isLayoutRtl ? Gravity.BOTTOM : Gravity.TOP; |
| 554 | menu.setLayoutParams(lp); |
| 555 | } |
| 556 | if (imeSwitcher != null) { |
| 557 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) imeSwitcher.getLayoutParams(); |
| 558 | lp.gravity = isLayoutRtl ? Gravity.BOTTOM : Gravity.TOP; |
| 559 | imeSwitcher.setLayoutParams(lp); |
| 560 | } |
| 561 | } |
Selim Cinek | 17a327a | 2014-08-25 15:03:48 +0200 | [diff] [blame] | 562 | |
| 563 | /** |
| 564 | * Swaps the children order of a LinearLayout if it's orientation is Vertical |
| 565 | * |
| 566 | * @param group The LinearLayout to swap the children from. |
| 567 | */ |
| 568 | private void swapChildrenOrderIfVertical(View group) { |
| 569 | if (group instanceof LinearLayout) { |
| 570 | LinearLayout linearLayout = (LinearLayout) group; |
| 571 | if (linearLayout.getOrientation() == VERTICAL) { |
| 572 | int childCount = linearLayout.getChildCount(); |
| 573 | ArrayList<View> childList = new ArrayList<>(childCount); |
| 574 | for (int i = 0; i < childCount; i++) { |
| 575 | childList.add(linearLayout.getChildAt(i)); |
| 576 | } |
| 577 | linearLayout.removeAllViews(); |
| 578 | for (int i = childCount - 1; i >= 0; i--) { |
| 579 | linearLayout.addView(childList.get(i)); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 585 | /* |
| 586 | @Override |
| 587 | 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] | 588 | if (DEBUG) Log.d(TAG, String.format( |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 589 | "onLayout: %s (%d,%d,%d,%d)", |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 590 | changed?"changed":"notchanged", left, top, right, bottom)); |
| 591 | super.onLayout(changed, left, top, right, bottom); |
| 592 | } |
| 593 | |
| 594 | // uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else |
| 595 | // fails, any touch on the display will fix the layout. |
| 596 | @Override |
| 597 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 598 | if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString()); |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 599 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 600 | postCheckForInvalidLayout("touch"); |
| 601 | } |
| 602 | return super.onInterceptTouchEvent(ev); |
| 603 | } |
| 604 | */ |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 605 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 606 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 607 | private String getResourceName(int resId) { |
| 608 | if (resId != 0) { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 609 | final android.content.res.Resources res = getContext().getResources(); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 610 | try { |
| 611 | return res.getResourceName(resId); |
| 612 | } catch (android.content.res.Resources.NotFoundException ex) { |
| 613 | return "(unknown)"; |
| 614 | } |
| 615 | } else { |
| 616 | return "(null)"; |
| 617 | } |
| 618 | } |
| 619 | |
Daniel Sandler | 0b69b59 | 2012-01-23 21:08:36 -0500 | [diff] [blame] | 620 | private void postCheckForInvalidLayout(final String how) { |
| 621 | mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget(); |
| 622 | } |
| 623 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 624 | private static String visibilityToString(int vis) { |
| 625 | switch (vis) { |
| 626 | case View.INVISIBLE: |
| 627 | return "INVISIBLE"; |
| 628 | case View.GONE: |
| 629 | return "GONE"; |
| 630 | default: |
| 631 | return "VISIBLE"; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 636 | pw.println("NavigationBarView {"); |
| 637 | final Rect r = new Rect(); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 638 | final Point size = new Point(); |
| 639 | mDisplay.getRealSize(size); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 640 | |
| 641 | pw.println(String.format(" this: " + PhoneStatusBar.viewInfo(this) |
| 642 | + " " + visibilityToString(getVisibility()))); |
| 643 | |
| 644 | getWindowVisibleDisplayFrame(r); |
Jeff Brown | a8b9def | 2012-07-23 14:22:49 -0700 | [diff] [blame] | 645 | final boolean offscreen = r.right > size.x || r.bottom > size.y; |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 646 | pw.println(" window: " |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 647 | + r.toShortString() |
| 648 | + " " + visibilityToString(getWindowVisibility()) |
| 649 | + (offscreen ? " OFFSCREEN!" : "")); |
| 650 | |
| 651 | pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s", |
| 652 | getResourceName(mCurrentView.getId()), |
| 653 | mCurrentView.getWidth(), mCurrentView.getHeight(), |
| 654 | visibilityToString(mCurrentView.getVisibility()))); |
| 655 | |
John Spurlock | 41c1e35 | 2013-09-16 13:57:13 -0400 | [diff] [blame] | 656 | pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 657 | mDisabledFlags, |
| 658 | mVertical ? "true" : "false", |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 659 | mShowMenu ? "true" : "false")); |
| 660 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 661 | dumpButton(pw, "back", getBackButton()); |
| 662 | dumpButton(pw, "home", getHomeButton()); |
| 663 | dumpButton(pw, "rcnt", getRecentsButton()); |
| 664 | dumpButton(pw, "menu", getMenuButton()); |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 665 | |
Daniel Sandler | 4885295 | 2011-12-01 14:34:23 -0500 | [diff] [blame] | 666 | pw.println(" }"); |
| 667 | } |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 668 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 669 | private static void dumpButton(PrintWriter pw, String caption, View button) { |
| 670 | pw.print(" " + caption + ": "); |
| 671 | if (button == null) { |
| 672 | pw.print("null"); |
| 673 | } else { |
| 674 | pw.print(PhoneStatusBar.viewInfo(button) |
| 675 | + " " + visibilityToString(button.getVisibility()) |
| 676 | + " alpha=" + button.getAlpha() |
| 677 | ); |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 678 | } |
| 679 | pw.println(); |
| 680 | } |
| 681 | |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 682 | public interface OnVerticalChangedListener { |
| 683 | void onVerticalChanged(boolean isVertical); |
| 684 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 685 | } |