Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 17 | import android.annotation.Nullable; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 18 | import android.content.Context; |
| 19 | import android.content.res.Configuration; |
| 20 | import android.content.res.Resources; |
| 21 | import android.util.AttributeSet; |
| 22 | import android.util.SparseArray; |
| 23 | import android.view.LayoutInflater; |
| 24 | import android.view.View; |
| 25 | import android.view.ViewGroup; |
| 26 | import android.widget.FrameLayout; |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 27 | import android.widget.LinearLayout; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 28 | import android.widget.Space; |
Annie Chin | 1ea4935 | 2016-05-27 15:23:35 -0700 | [diff] [blame] | 29 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 30 | import com.android.systemui.R; |
Annie Chin | 1ea4935 | 2016-05-27 15:23:35 -0700 | [diff] [blame] | 31 | import com.android.systemui.SystemUIFactory; |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 32 | import com.android.systemui.statusbar.policy.KeyButtonView; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 33 | import com.android.systemui.tuner.TunerService; |
| 34 | |
| 35 | import java.util.Objects; |
| 36 | |
| 37 | public class NavigationBarInflaterView extends FrameLayout implements TunerService.Tunable { |
| 38 | |
| 39 | private static final String TAG = "NavBarInflater"; |
| 40 | |
| 41 | public static final String NAV_BAR_VIEWS = "sysui_nav_bar"; |
| 42 | |
Jason Monk | 3ebd239 | 2016-01-22 10:01:44 -0500 | [diff] [blame] | 43 | public static final String MENU_IME = "menu_ime"; |
| 44 | public static final String BACK = "back"; |
| 45 | public static final String HOME = "home"; |
| 46 | public static final String RECENT = "recent"; |
| 47 | public static final String NAVSPACE = "space"; |
Jason Monk | 3b58714 | 2016-01-23 16:47:59 -0500 | [diff] [blame] | 48 | public static final String CLIPBOARD = "clipboard"; |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 49 | public static final String KEY = "key"; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 50 | |
| 51 | public static final String GRAVITY_SEPARATOR = ";"; |
| 52 | public static final String BUTTON_SEPARATOR = ","; |
| 53 | |
Jason Monk | 46a196e | 2016-01-23 15:28:10 -0500 | [diff] [blame] | 54 | public static final String SIZE_MOD_START = "["; |
| 55 | public static final String SIZE_MOD_END = "]"; |
| 56 | |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 57 | public static final String KEY_CODE_START = "("; |
| 58 | public static final String KEY_IMAGE_DELIM = ":"; |
| 59 | public static final String KEY_CODE_END = ")"; |
| 60 | |
Jason Monk | 67a1cce | 2016-02-05 13:31:03 -0500 | [diff] [blame] | 61 | protected LayoutInflater mLayoutInflater; |
| 62 | protected LayoutInflater mLandscapeInflater; |
| 63 | private int mDensity; |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 64 | |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 65 | protected FrameLayout mRot0; |
| 66 | protected FrameLayout mRot90; |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 67 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 68 | private SparseArray<ButtonDispatcher> mButtonDispatchers; |
| 69 | private String mCurrentLayout; |
| 70 | |
Jason Monk | c62cf80 | 2016-05-10 11:02:24 -0400 | [diff] [blame] | 71 | private View mLastRot0; |
| 72 | private View mLastRot90; |
| 73 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 74 | public NavigationBarInflaterView(Context context, AttributeSet attrs) { |
| 75 | super(context, attrs); |
Jason Monk | 67a1cce | 2016-02-05 13:31:03 -0500 | [diff] [blame] | 76 | mDensity = context.getResources().getConfiguration().densityDpi; |
| 77 | createInflaters(); |
| 78 | } |
| 79 | |
| 80 | private void createInflaters() { |
| 81 | mLayoutInflater = LayoutInflater.from(mContext); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 82 | Configuration landscape = new Configuration(); |
Jason Monk | 67a1cce | 2016-02-05 13:31:03 -0500 | [diff] [blame] | 83 | landscape.setTo(mContext.getResources().getConfiguration()); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 84 | landscape.orientation = Configuration.ORIENTATION_LANDSCAPE; |
Jason Monk | 67a1cce | 2016-02-05 13:31:03 -0500 | [diff] [blame] | 85 | mLandscapeInflater = LayoutInflater.from(mContext.createConfigurationContext(landscape)); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | protected void onConfigurationChanged(Configuration newConfig) { |
| 90 | super.onConfigurationChanged(newConfig); |
| 91 | if (mDensity != newConfig.densityDpi) { |
| 92 | mDensity = newConfig.densityDpi; |
| 93 | createInflaters(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 94 | inflateChildren(); |
Jason Monk | 67a1cce | 2016-02-05 13:31:03 -0500 | [diff] [blame] | 95 | clearViews(); |
| 96 | inflateLayout(mCurrentLayout); |
| 97 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | protected void onFinishInflate() { |
| 102 | super.onFinishInflate(); |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 103 | inflateChildren(); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 104 | clearViews(); |
| 105 | inflateLayout(getDefaultLayout()); |
| 106 | } |
| 107 | |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 108 | private void inflateChildren() { |
| 109 | removeAllViews(); |
| 110 | mRot0 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout, this, false); |
| 111 | mRot0.setId(R.id.rot0); |
| 112 | addView(mRot0); |
| 113 | mRot90 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_rot90, this, |
| 114 | false); |
| 115 | mRot90.setId(R.id.rot90); |
| 116 | addView(mRot90); |
| 117 | if (getParent() instanceof NavigationBarView) { |
| 118 | ((NavigationBarView) getParent()).updateRotatedViews(); |
| 119 | } |
| 120 | } |
| 121 | |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 122 | protected String getDefaultLayout() { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 123 | return mContext.getString(R.string.config_navBarLayout); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | protected void onAttachedToWindow() { |
| 128 | super.onAttachedToWindow(); |
| 129 | TunerService.get(getContext()).addTunable(this, NAV_BAR_VIEWS); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | protected void onDetachedFromWindow() { |
| 134 | TunerService.get(getContext()).removeTunable(this); |
| 135 | super.onDetachedFromWindow(); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void onTuningChanged(String key, String newValue) { |
| 140 | if (NAV_BAR_VIEWS.equals(key)) { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 141 | if (!Objects.equals(mCurrentLayout, newValue)) { |
| 142 | clearViews(); |
| 143 | inflateLayout(newValue); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | public void setButtonDispatchers(SparseArray<ButtonDispatcher> buttonDisatchers) { |
| 149 | mButtonDispatchers = buttonDisatchers; |
| 150 | for (int i = 0; i < buttonDisatchers.size(); i++) { |
| 151 | initiallyFill(buttonDisatchers.valueAt(i)); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | private void initiallyFill(ButtonDispatcher buttonDispatcher) { |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 156 | addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.ends_group)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 157 | addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.center_group)); |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 158 | addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.ends_group)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 159 | addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.center_group)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) { |
| 163 | for (int i = 0; i < parent.getChildCount(); i++) { |
| 164 | // Need to manually search for each id, just in case each group has more than one |
| 165 | // of a single id. It probably mostly a waste of time, but shouldn't take long |
| 166 | // and will only happen once. |
| 167 | if (parent.getChildAt(i).getId() == buttonDispatcher.getId()) { |
| 168 | buttonDispatcher.addView(parent.getChildAt(i)); |
| 169 | } else if (parent.getChildAt(i) instanceof ViewGroup) { |
| 170 | addAll(buttonDispatcher, (ViewGroup) parent.getChildAt(i)); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 175 | protected void inflateLayout(String newLayout) { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 176 | mCurrentLayout = newLayout; |
Jason Monk | 9a6552d | 2016-05-20 11:21:59 -0400 | [diff] [blame] | 177 | if (newLayout == null) { |
| 178 | newLayout = getDefaultLayout(); |
| 179 | } |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 180 | String[] sets = newLayout.split(GRAVITY_SEPARATOR, 3); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 181 | String[] start = sets[0].split(BUTTON_SEPARATOR); |
| 182 | String[] center = sets[1].split(BUTTON_SEPARATOR); |
| 183 | String[] end = sets[2].split(BUTTON_SEPARATOR); |
Jason Monk | c62cf80 | 2016-05-10 11:02:24 -0400 | [diff] [blame] | 184 | // Inflate these in start to end order or accessibility traversal will be messed up. |
Jason Monk | 5332e59 | 2016-02-15 15:16:57 -0500 | [diff] [blame] | 185 | inflateButtons(start, (ViewGroup) mRot0.findViewById(R.id.ends_group), false); |
| 186 | inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group), true); |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 187 | |
Jason Monk | 5332e59 | 2016-02-15 15:16:57 -0500 | [diff] [blame] | 188 | inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group), false); |
| 189 | inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group), true); |
Xiaohui Chen | 0691703 | 2016-01-26 11:20:39 -0800 | [diff] [blame] | 190 | |
| 191 | addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group)); |
| 192 | addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group)); |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 193 | |
Jason Monk | 5332e59 | 2016-02-15 15:16:57 -0500 | [diff] [blame] | 194 | inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group), false); |
| 195 | inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group), true); |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 196 | } |
| 197 | |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 198 | private void addGravitySpacer(LinearLayout layout) { |
| 199 | layout.addView(new Space(mContext), new LinearLayout.LayoutParams(0, 0, 1)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Jason Monk | 5332e59 | 2016-02-15 15:16:57 -0500 | [diff] [blame] | 202 | private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape) { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 203 | for (int i = 0; i < buttons.length; i++) { |
Yorke Lee | 0681c09 | 2016-04-06 15:15:19 -0700 | [diff] [blame] | 204 | inflateButton(buttons[i], parent, landscape, i); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 208 | private ViewGroup.LayoutParams copy(ViewGroup.LayoutParams layoutParams) { |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 209 | if (layoutParams instanceof LinearLayout.LayoutParams) { |
| 210 | return new LinearLayout.LayoutParams(layoutParams.width, layoutParams.height, |
| 211 | ((LinearLayout.LayoutParams) layoutParams).weight); |
| 212 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 213 | return new LayoutParams(layoutParams.width, layoutParams.height); |
| 214 | } |
| 215 | |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 216 | @Nullable |
Yorke Lee | 0681c09 | 2016-04-06 15:15:19 -0700 | [diff] [blame] | 217 | protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape, |
| 218 | int indexInParent) { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 219 | LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater; |
Jason Monk | 46a196e | 2016-01-23 15:28:10 -0500 | [diff] [blame] | 220 | float size = extractSize(buttonSpec); |
| 221 | String button = extractButton(buttonSpec); |
| 222 | View v = null; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 223 | if (HOME.equals(button)) { |
Annie Chin | b6ab24f | 2016-06-01 17:46:27 -0700 | [diff] [blame^] | 224 | v = inflater.inflate(R.layout.home, parent, false); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 225 | if (landscape && isSw600Dp()) { |
| 226 | setupLandButton(v); |
| 227 | } |
| 228 | } else if (BACK.equals(button)) { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 229 | v = inflater.inflate(R.layout.back, parent, false); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 230 | if (landscape && isSw600Dp()) { |
| 231 | setupLandButton(v); |
| 232 | } |
| 233 | } else if (RECENT.equals(button)) { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 234 | v = inflater.inflate(R.layout.recent_apps, parent, false); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 235 | if (landscape && isSw600Dp()) { |
| 236 | setupLandButton(v); |
| 237 | } |
| 238 | } else if (MENU_IME.equals(button)) { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 239 | v = inflater.inflate(R.layout.menu_ime, parent, false); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 240 | } else if (NAVSPACE.equals(button)) { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 241 | v = inflater.inflate(R.layout.nav_key_space, parent, false); |
Jason Monk | 3b58714 | 2016-01-23 16:47:59 -0500 | [diff] [blame] | 242 | } else if (CLIPBOARD.equals(button)) { |
| 243 | v = inflater.inflate(R.layout.clipboard, parent, false); |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 244 | } else if (button.startsWith(KEY)) { |
| 245 | String uri = extractImage(button); |
| 246 | int code = extractKeycode(button); |
| 247 | v = inflater.inflate(R.layout.custom_key, parent, false); |
| 248 | ((KeyButtonView) v).setCode(code); |
| 249 | if (uri != null) { |
| 250 | ((KeyButtonView) v).loadAsync(uri); |
| 251 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 252 | } else { |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 253 | return null; |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 254 | } |
Xiaohui Chen | 5481600 | 2016-01-25 11:11:11 -0800 | [diff] [blame] | 255 | |
Jason Monk | 46a196e | 2016-01-23 15:28:10 -0500 | [diff] [blame] | 256 | if (size != 0) { |
| 257 | ViewGroup.LayoutParams params = v.getLayoutParams(); |
| 258 | params.width = (int) (params.width * size); |
| 259 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 260 | parent.addView(v); |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 261 | addToDispatchers(v); |
Jason Monk | c62cf80 | 2016-05-10 11:02:24 -0400 | [diff] [blame] | 262 | View lastView = landscape ? mLastRot90 : mLastRot0; |
| 263 | if (lastView != null) { |
| 264 | v.setAccessibilityTraversalAfter(lastView.getId()); |
| 265 | } |
| 266 | if (landscape) { |
| 267 | mLastRot90 = v; |
| 268 | } else { |
| 269 | mLastRot0 = v; |
| 270 | } |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 271 | return v; |
| 272 | } |
| 273 | |
Jason Monk | 8457ad8 | 2016-01-24 10:15:55 -0500 | [diff] [blame] | 274 | public static String extractImage(String buttonSpec) { |
| 275 | if (!buttonSpec.contains(KEY_IMAGE_DELIM)) { |
| 276 | return null; |
| 277 | } |
| 278 | final int start = buttonSpec.indexOf(KEY_IMAGE_DELIM); |
| 279 | String subStr = buttonSpec.substring(start + 1, buttonSpec.indexOf(KEY_CODE_END)); |
| 280 | return subStr; |
| 281 | } |
| 282 | |
| 283 | public static int extractKeycode(String buttonSpec) { |
| 284 | if (!buttonSpec.contains(KEY_CODE_START)) { |
| 285 | return 1; |
| 286 | } |
| 287 | final int start = buttonSpec.indexOf(KEY_CODE_START); |
| 288 | String subStr = buttonSpec.substring(start + 1, buttonSpec.indexOf(KEY_IMAGE_DELIM)); |
| 289 | return Integer.parseInt(subStr); |
| 290 | } |
| 291 | |
Jason Monk | 46a196e | 2016-01-23 15:28:10 -0500 | [diff] [blame] | 292 | public static float extractSize(String buttonSpec) { |
| 293 | if (!buttonSpec.contains(SIZE_MOD_START)) { |
| 294 | return 1; |
| 295 | } |
| 296 | final int sizeStart = buttonSpec.indexOf(SIZE_MOD_START); |
| 297 | String sizeStr = buttonSpec.substring(sizeStart + 1, buttonSpec.indexOf(SIZE_MOD_END)); |
| 298 | return Float.parseFloat(sizeStr); |
| 299 | } |
| 300 | |
| 301 | public static String extractButton(String buttonSpec) { |
| 302 | if (!buttonSpec.contains(SIZE_MOD_START)) { |
| 303 | return buttonSpec; |
| 304 | } |
| 305 | return buttonSpec.substring(0, buttonSpec.indexOf(SIZE_MOD_START)); |
| 306 | } |
| 307 | |
Jason Monk | 4f878ef | 2016-01-23 14:37:38 -0500 | [diff] [blame] | 308 | private void addToDispatchers(View v) { |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 309 | if (mButtonDispatchers != null) { |
| 310 | final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId()); |
| 311 | if (indexOfKey >= 0) { |
| 312 | mButtonDispatchers.valueAt(indexOfKey).addView(v); |
Keisuke Kuroyanagi | 47bd733 | 2016-05-06 10:49:54 -0700 | [diff] [blame] | 313 | } else if (v instanceof ViewGroup) { |
| 314 | final ViewGroup viewGroup = (ViewGroup)v; |
| 315 | final int N = viewGroup.getChildCount(); |
| 316 | for (int i = 0; i < N; i++) { |
| 317 | addToDispatchers(viewGroup.getChildAt(i)); |
| 318 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 319 | } |
| 320 | } |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | private boolean isSw600Dp() { |
| 324 | Configuration configuration = mContext.getResources().getConfiguration(); |
| 325 | return (configuration.smallestScreenWidthDp >= 600); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * This manually sets the width of sw600dp landscape buttons because despite |
| 330 | * overriding the configuration from the overridden resources aren't loaded currently. |
| 331 | */ |
| 332 | private void setupLandButton(View v) { |
| 333 | Resources res = mContext.getResources(); |
| 334 | v.getLayoutParams().width = res.getDimensionPixelOffset( |
| 335 | R.dimen.navigation_key_width_sw600dp_land); |
| 336 | int padding = res.getDimensionPixelOffset(R.dimen.navigation_key_padding_sw600dp_land); |
| 337 | v.setPadding(padding, v.getPaddingTop(), padding, v.getPaddingBottom()); |
| 338 | } |
| 339 | |
| 340 | private void clearViews() { |
| 341 | if (mButtonDispatchers != null) { |
| 342 | for (int i = 0; i < mButtonDispatchers.size(); i++) { |
| 343 | mButtonDispatchers.valueAt(i).clear(); |
| 344 | } |
| 345 | } |
| 346 | clearAllChildren((ViewGroup) mRot0.findViewById(R.id.nav_buttons)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 347 | clearAllChildren((ViewGroup) mRot90.findViewById(R.id.nav_buttons)); |
Jason Monk | a208182 | 2016-01-18 14:41:03 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | private void clearAllChildren(ViewGroup group) { |
| 351 | for (int i = 0; i < group.getChildCount(); i++) { |
| 352 | ((ViewGroup) group.getChildAt(i)).removeAllViews(); |
| 353 | } |
| 354 | } |
| 355 | } |