blob: 5fb99dabfeab1433da2e4244059562a8d875f120 [file] [log] [blame]
Jason Monka2081822016-01-18 14:41:03 -05001/*
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
15package com.android.systemui.statusbar.phone;
16
Xiaohui Chen54816002016-01-25 11:11:11 -080017import android.annotation.Nullable;
Jason Monka2081822016-01-18 14:41:03 -050018import android.content.Context;
19import android.content.res.Configuration;
Jason Monkea05f872017-01-24 19:43:36 -050020import android.graphics.drawable.Icon;
Jason Monka2081822016-01-18 14:41:03 -050021import android.util.AttributeSet;
22import android.util.SparseArray;
Xiaohui Chen40e978e2016-11-29 15:10:04 -080023import android.view.Display;
24import android.view.Display.Mode;
Jason Monka2081822016-01-18 14:41:03 -050025import android.view.LayoutInflater;
26import android.view.View;
27import android.view.ViewGroup;
Xiaohui Chen40e978e2016-11-29 15:10:04 -080028import android.view.WindowManager;
Jason Monka2081822016-01-18 14:41:03 -050029import android.widget.FrameLayout;
Jason Monk4f878ef2016-01-23 14:37:38 -050030import android.widget.LinearLayout;
Jason Monka2081822016-01-18 14:41:03 -050031import android.widget.Space;
Annie Chin1ea49352016-05-27 15:23:35 -070032
Jason Monkde850bb2017-02-01 19:26:30 -050033import com.android.systemui.Dependency;
Jason Monka2081822016-01-18 14:41:03 -050034import com.android.systemui.R;
Jason Monk197f4db2016-08-26 13:28:20 -040035import com.android.systemui.plugins.PluginListener;
36import com.android.systemui.plugins.PluginManager;
37import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider;
Jason Monk8457ad82016-01-24 10:15:55 -050038import com.android.systemui.statusbar.policy.KeyButtonView;
Jason Monka2081822016-01-18 14:41:03 -050039import com.android.systemui.tuner.TunerService;
Jason Monk197f4db2016-08-26 13:28:20 -040040import com.android.systemui.tuner.TunerService.Tunable;
Jason Monka2081822016-01-18 14:41:03 -050041
Jason Monk197f4db2016-08-26 13:28:20 -040042import java.util.ArrayList;
43import java.util.List;
Jason Monka2081822016-01-18 14:41:03 -050044import java.util.Objects;
45
Jason Monk197f4db2016-08-26 13:28:20 -040046public class NavigationBarInflaterView extends FrameLayout
47 implements Tunable, PluginListener<NavBarButtonProvider> {
Jason Monka2081822016-01-18 14:41:03 -050048
49 private static final String TAG = "NavBarInflater";
50
51 public static final String NAV_BAR_VIEWS = "sysui_nav_bar";
Jason Monkea05f872017-01-24 19:43:36 -050052 public static final String NAV_BAR_LEFT = "sysui_nav_bar_left";
53 public static final String NAV_BAR_RIGHT = "sysui_nav_bar_right";
Jason Monka2081822016-01-18 14:41:03 -050054
Jason Monk3ebd2392016-01-22 10:01:44 -050055 public static final String MENU_IME = "menu_ime";
56 public static final String BACK = "back";
57 public static final String HOME = "home";
58 public static final String RECENT = "recent";
59 public static final String NAVSPACE = "space";
Jason Monk3b587142016-01-23 16:47:59 -050060 public static final String CLIPBOARD = "clipboard";
Jason Monk8457ad82016-01-24 10:15:55 -050061 public static final String KEY = "key";
Jason Monkea05f872017-01-24 19:43:36 -050062 public static final String LEFT = "left";
63 public static final String RIGHT = "right";
Jason Monka2081822016-01-18 14:41:03 -050064
65 public static final String GRAVITY_SEPARATOR = ";";
66 public static final String BUTTON_SEPARATOR = ",";
67
Jason Monk46a196e2016-01-23 15:28:10 -050068 public static final String SIZE_MOD_START = "[";
69 public static final String SIZE_MOD_END = "]";
70
Jason Monk8457ad82016-01-24 10:15:55 -050071 public static final String KEY_CODE_START = "(";
72 public static final String KEY_IMAGE_DELIM = ":";
73 public static final String KEY_CODE_END = ")";
74
Jason Monk197f4db2016-08-26 13:28:20 -040075 private final List<NavBarButtonProvider> mPlugins = new ArrayList<>();
76
Jason Monk67a1cce2016-02-05 13:31:03 -050077 protected LayoutInflater mLayoutInflater;
78 protected LayoutInflater mLandscapeInflater;
Jason Monk8457ad82016-01-24 10:15:55 -050079
Xiaohui Chen54816002016-01-25 11:11:11 -080080 protected FrameLayout mRot0;
81 protected FrameLayout mRot90;
Xiaohui Chen40e978e2016-11-29 15:10:04 -080082 private boolean isRot0Landscape;
Jason Monk8457ad82016-01-24 10:15:55 -050083
Jason Monka2081822016-01-18 14:41:03 -050084 private SparseArray<ButtonDispatcher> mButtonDispatchers;
85 private String mCurrentLayout;
86
Xiaohui Chen40e978e2016-11-29 15:10:04 -080087 private View mLastPortrait;
88 private View mLastLandscape;
Jason Monkc62cf802016-05-10 11:02:24 -040089
Adrian Roosdb12b152016-07-12 15:38:55 -070090 private boolean mAlternativeOrder;
91
Jason Monka2081822016-01-18 14:41:03 -050092 public NavigationBarInflaterView(Context context, AttributeSet attrs) {
93 super(context, attrs);
Jason Monk67a1cce2016-02-05 13:31:03 -050094 createInflaters();
Xiaohui Chen40e978e2016-11-29 15:10:04 -080095 Display display = ((WindowManager)
96 context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
97 Mode displayMode = display.getMode();
98 isRot0Landscape = displayMode.getPhysicalWidth() > displayMode.getPhysicalHeight();
Jason Monk67a1cce2016-02-05 13:31:03 -050099 }
100
101 private void createInflaters() {
102 mLayoutInflater = LayoutInflater.from(mContext);
Jason Monka2081822016-01-18 14:41:03 -0500103 Configuration landscape = new Configuration();
Jason Monk67a1cce2016-02-05 13:31:03 -0500104 landscape.setTo(mContext.getResources().getConfiguration());
Jason Monka2081822016-01-18 14:41:03 -0500105 landscape.orientation = Configuration.ORIENTATION_LANDSCAPE;
Jason Monk67a1cce2016-02-05 13:31:03 -0500106 mLandscapeInflater = LayoutInflater.from(mContext.createConfigurationContext(landscape));
107 }
108
109 @Override
Jason Monka2081822016-01-18 14:41:03 -0500110 protected void onFinishInflate() {
111 super.onFinishInflate();
Jason Monk9a6552d2016-05-20 11:21:59 -0400112 inflateChildren();
Jason Monka2081822016-01-18 14:41:03 -0500113 clearViews();
114 inflateLayout(getDefaultLayout());
115 }
116
Jason Monk9a6552d2016-05-20 11:21:59 -0400117 private void inflateChildren() {
118 removeAllViews();
119 mRot0 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout, this, false);
120 mRot0.setId(R.id.rot0);
121 addView(mRot0);
122 mRot90 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_rot90, this,
123 false);
124 mRot90.setId(R.id.rot90);
125 addView(mRot90);
Adrian Roosdb12b152016-07-12 15:38:55 -0700126 updateAlternativeOrder();
Jason Monk9a6552d2016-05-20 11:21:59 -0400127 if (getParent() instanceof NavigationBarView) {
128 ((NavigationBarView) getParent()).updateRotatedViews();
129 }
130 }
131
Xiaohui Chen54816002016-01-25 11:11:11 -0800132 protected String getDefaultLayout() {
Jason Monka2081822016-01-18 14:41:03 -0500133 return mContext.getString(R.string.config_navBarLayout);
134 }
135
136 @Override
137 protected void onAttachedToWindow() {
138 super.onAttachedToWindow();
Jason Monkde850bb2017-02-01 19:26:30 -0500139 Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT,
Jason Monkea05f872017-01-24 19:43:36 -0500140 NAV_BAR_RIGHT);
Jason Monkde850bb2017-02-01 19:26:30 -0500141 Dependency.get(PluginManager.class).addPluginListener(NavBarButtonProvider.ACTION, this,
Jason Monk197f4db2016-08-26 13:28:20 -0400142 NavBarButtonProvider.VERSION, true /* Allow multiple */);
Jason Monka2081822016-01-18 14:41:03 -0500143 }
144
145 @Override
146 protected void onDetachedFromWindow() {
Jason Monkde850bb2017-02-01 19:26:30 -0500147 Dependency.get(TunerService.class).removeTunable(this);
148 Dependency.get(PluginManager.class).removePluginListener(this);
Jason Monka2081822016-01-18 14:41:03 -0500149 super.onDetachedFromWindow();
150 }
151
152 @Override
153 public void onTuningChanged(String key, String newValue) {
154 if (NAV_BAR_VIEWS.equals(key)) {
Jason Monka2081822016-01-18 14:41:03 -0500155 if (!Objects.equals(mCurrentLayout, newValue)) {
156 clearViews();
157 inflateLayout(newValue);
158 }
Jason Monkea05f872017-01-24 19:43:36 -0500159 } else if (NAV_BAR_LEFT.equals(key) || NAV_BAR_RIGHT.equals(key)) {
160 clearViews();
161 inflateLayout(mCurrentLayout);
Jason Monka2081822016-01-18 14:41:03 -0500162 }
163 }
164
165 public void setButtonDispatchers(SparseArray<ButtonDispatcher> buttonDisatchers) {
166 mButtonDispatchers = buttonDisatchers;
167 for (int i = 0; i < buttonDisatchers.size(); i++) {
168 initiallyFill(buttonDisatchers.valueAt(i));
169 }
170 }
171
Adrian Roosdb12b152016-07-12 15:38:55 -0700172 public void setAlternativeOrder(boolean alternativeOrder) {
173 if (alternativeOrder != mAlternativeOrder) {
174 mAlternativeOrder = alternativeOrder;
175 updateAlternativeOrder();
176 }
177 }
178
179 private void updateAlternativeOrder() {
180 updateAlternativeOrder(mRot0.findViewById(R.id.ends_group));
181 updateAlternativeOrder(mRot0.findViewById(R.id.center_group));
182 updateAlternativeOrder(mRot90.findViewById(R.id.ends_group));
183 updateAlternativeOrder(mRot90.findViewById(R.id.center_group));
184 }
185
186 private void updateAlternativeOrder(View v) {
187 if (v instanceof ReverseLinearLayout) {
188 ((ReverseLinearLayout) v).setAlternativeOrder(mAlternativeOrder);
189 }
190 }
191
Jason Monka2081822016-01-18 14:41:03 -0500192 private void initiallyFill(ButtonDispatcher buttonDispatcher) {
Jason Monk4f878ef2016-01-23 14:37:38 -0500193 addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.ends_group));
Jason Monka2081822016-01-18 14:41:03 -0500194 addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.center_group));
Jason Monk4f878ef2016-01-23 14:37:38 -0500195 addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.ends_group));
Jason Monka2081822016-01-18 14:41:03 -0500196 addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.center_group));
Jason Monka2081822016-01-18 14:41:03 -0500197 }
198
199 private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) {
200 for (int i = 0; i < parent.getChildCount(); i++) {
201 // Need to manually search for each id, just in case each group has more than one
202 // of a single id. It probably mostly a waste of time, but shouldn't take long
203 // and will only happen once.
204 if (parent.getChildAt(i).getId() == buttonDispatcher.getId()) {
205 buttonDispatcher.addView(parent.getChildAt(i));
206 } else if (parent.getChildAt(i) instanceof ViewGroup) {
207 addAll(buttonDispatcher, (ViewGroup) parent.getChildAt(i));
208 }
209 }
210 }
211
Xiaohui Chen54816002016-01-25 11:11:11 -0800212 protected void inflateLayout(String newLayout) {
Jason Monka2081822016-01-18 14:41:03 -0500213 mCurrentLayout = newLayout;
Jason Monk9a6552d2016-05-20 11:21:59 -0400214 if (newLayout == null) {
215 newLayout = getDefaultLayout();
216 }
Xiaohui Chen54816002016-01-25 11:11:11 -0800217 String[] sets = newLayout.split(GRAVITY_SEPARATOR, 3);
Jason Monka2081822016-01-18 14:41:03 -0500218 String[] start = sets[0].split(BUTTON_SEPARATOR);
219 String[] center = sets[1].split(BUTTON_SEPARATOR);
220 String[] end = sets[2].split(BUTTON_SEPARATOR);
Jason Monkc62cf802016-05-10 11:02:24 -0400221 // Inflate these in start to end order or accessibility traversal will be messed up.
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800222 inflateButtons(start, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape);
223 inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape);
Jason Monk4f878ef2016-01-23 14:37:38 -0500224
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800225 inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group), isRot0Landscape);
226 inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group), !isRot0Landscape);
Xiaohui Chen06917032016-01-26 11:20:39 -0800227
228 addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group));
229 addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group));
Jason Monk4f878ef2016-01-23 14:37:38 -0500230
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800231 inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape);
232 inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape);
Jason Monk4f878ef2016-01-23 14:37:38 -0500233 }
234
Jason Monk4f878ef2016-01-23 14:37:38 -0500235 private void addGravitySpacer(LinearLayout layout) {
236 layout.addView(new Space(mContext), new LinearLayout.LayoutParams(0, 0, 1));
Jason Monka2081822016-01-18 14:41:03 -0500237 }
238
Jason Monk5332e592016-02-15 15:16:57 -0500239 private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape) {
Jason Monka2081822016-01-18 14:41:03 -0500240 for (int i = 0; i < buttons.length; i++) {
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800241 inflateButton(buttons[i], parent, landscape);
Jason Monka2081822016-01-18 14:41:03 -0500242 }
243 }
244
Jason Monka2081822016-01-18 14:41:03 -0500245 private ViewGroup.LayoutParams copy(ViewGroup.LayoutParams layoutParams) {
Jason Monk4f878ef2016-01-23 14:37:38 -0500246 if (layoutParams instanceof LinearLayout.LayoutParams) {
247 return new LinearLayout.LayoutParams(layoutParams.width, layoutParams.height,
248 ((LinearLayout.LayoutParams) layoutParams).weight);
249 }
Jason Monka2081822016-01-18 14:41:03 -0500250 return new LayoutParams(layoutParams.width, layoutParams.height);
251 }
252
Xiaohui Chen54816002016-01-25 11:11:11 -0800253 @Nullable
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800254 protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape) {
Xiaohui Chen54816002016-01-25 11:11:11 -0800255 LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
Jason Monk46a196e2016-01-23 15:28:10 -0500256 float size = extractSize(buttonSpec);
Jason Monk197f4db2016-08-26 13:28:20 -0400257 View v = createView(buttonSpec, parent, inflater, landscape);
258 if (v == null) return null;
259
260 if (size != 0) {
261 ViewGroup.LayoutParams params = v.getLayoutParams();
262 params.width = (int) (params.width * size);
263 }
264 parent.addView(v);
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800265 addToDispatchers(v);
266 View lastView = landscape ? mLastLandscape : mLastPortrait;
Jason Monk197f4db2016-08-26 13:28:20 -0400267 if (lastView != null) {
268 v.setAccessibilityTraversalAfter(lastView.getId());
269 }
270 if (landscape) {
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800271 mLastLandscape = v;
Jason Monk197f4db2016-08-26 13:28:20 -0400272 } else {
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800273 mLastPortrait = v;
Jason Monk197f4db2016-08-26 13:28:20 -0400274 }
275 return v;
276 }
277
278 private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater,
279 boolean landscape) {
Jason Monk46a196e2016-01-23 15:28:10 -0500280 View v = null;
Jason Monk197f4db2016-08-26 13:28:20 -0400281 String button = extractButton(buttonSpec);
Jason Monkea05f872017-01-24 19:43:36 -0500282 if (LEFT.equals(button)) {
Jason Monkde850bb2017-02-01 19:26:30 -0500283 buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE);
Jason Monkea05f872017-01-24 19:43:36 -0500284 button = extractButton(buttonSpec);
285 } else if (RIGHT.equals(button)) {
Jason Monkde850bb2017-02-01 19:26:30 -0500286 buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME);
Jason Monkea05f872017-01-24 19:43:36 -0500287 button = extractButton(buttonSpec);
288 }
Jason Monk197f4db2016-08-26 13:28:20 -0400289 // Let plugins go first so they can override a standard view if they want.
290 for (NavBarButtonProvider provider : mPlugins) {
291 v = provider.createView(buttonSpec, parent);
292 if (v != null) return v;
293 }
Jason Monka2081822016-01-18 14:41:03 -0500294 if (HOME.equals(button)) {
Annie Chinb6ab24f2016-06-01 17:46:27 -0700295 v = inflater.inflate(R.layout.home, parent, false);
Jason Monka2081822016-01-18 14:41:03 -0500296 } else if (BACK.equals(button)) {
Xiaohui Chen54816002016-01-25 11:11:11 -0800297 v = inflater.inflate(R.layout.back, parent, false);
Jason Monka2081822016-01-18 14:41:03 -0500298 } else if (RECENT.equals(button)) {
Xiaohui Chen54816002016-01-25 11:11:11 -0800299 v = inflater.inflate(R.layout.recent_apps, parent, false);
Jason Monka2081822016-01-18 14:41:03 -0500300 } else if (MENU_IME.equals(button)) {
Xiaohui Chen54816002016-01-25 11:11:11 -0800301 v = inflater.inflate(R.layout.menu_ime, parent, false);
Jason Monka2081822016-01-18 14:41:03 -0500302 } else if (NAVSPACE.equals(button)) {
Xiaohui Chen54816002016-01-25 11:11:11 -0800303 v = inflater.inflate(R.layout.nav_key_space, parent, false);
Jason Monk3b587142016-01-23 16:47:59 -0500304 } else if (CLIPBOARD.equals(button)) {
305 v = inflater.inflate(R.layout.clipboard, parent, false);
Jason Monk8457ad82016-01-24 10:15:55 -0500306 } else if (button.startsWith(KEY)) {
307 String uri = extractImage(button);
308 int code = extractKeycode(button);
309 v = inflater.inflate(R.layout.custom_key, parent, false);
310 ((KeyButtonView) v).setCode(code);
311 if (uri != null) {
Jason Monkea05f872017-01-24 19:43:36 -0500312 if (uri.contains(":")) {
313 ((KeyButtonView) v).loadAsync(Icon.createWithContentUri(uri));
314 } else if (uri.contains("/")) {
315 int index = uri.indexOf('/');
316 String pkg = uri.substring(0, index);
317 int id = Integer.parseInt(uri.substring(index + 1));
318 ((KeyButtonView) v).loadAsync(Icon.createWithResource(pkg, id));
319 }
Jason Monk8457ad82016-01-24 10:15:55 -0500320 }
Jason Monkc62cf802016-05-10 11:02:24 -0400321 }
Jason Monk4f878ef2016-01-23 14:37:38 -0500322 return v;
323 }
324
Jason Monk8457ad82016-01-24 10:15:55 -0500325 public static String extractImage(String buttonSpec) {
326 if (!buttonSpec.contains(KEY_IMAGE_DELIM)) {
327 return null;
328 }
329 final int start = buttonSpec.indexOf(KEY_IMAGE_DELIM);
330 String subStr = buttonSpec.substring(start + 1, buttonSpec.indexOf(KEY_CODE_END));
331 return subStr;
332 }
333
334 public static int extractKeycode(String buttonSpec) {
335 if (!buttonSpec.contains(KEY_CODE_START)) {
336 return 1;
337 }
338 final int start = buttonSpec.indexOf(KEY_CODE_START);
339 String subStr = buttonSpec.substring(start + 1, buttonSpec.indexOf(KEY_IMAGE_DELIM));
340 return Integer.parseInt(subStr);
341 }
342
Jason Monk46a196e2016-01-23 15:28:10 -0500343 public static float extractSize(String buttonSpec) {
344 if (!buttonSpec.contains(SIZE_MOD_START)) {
345 return 1;
346 }
347 final int sizeStart = buttonSpec.indexOf(SIZE_MOD_START);
348 String sizeStr = buttonSpec.substring(sizeStart + 1, buttonSpec.indexOf(SIZE_MOD_END));
349 return Float.parseFloat(sizeStr);
350 }
351
352 public static String extractButton(String buttonSpec) {
353 if (!buttonSpec.contains(SIZE_MOD_START)) {
354 return buttonSpec;
355 }
356 return buttonSpec.substring(0, buttonSpec.indexOf(SIZE_MOD_START));
357 }
358
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800359 private void addToDispatchers(View v) {
Jason Monka2081822016-01-18 14:41:03 -0500360 if (mButtonDispatchers != null) {
361 final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
362 if (indexOfKey >= 0) {
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800363 mButtonDispatchers.valueAt(indexOfKey).addView(v);
Keisuke Kuroyanagi47bd7332016-05-06 10:49:54 -0700364 } else if (v instanceof ViewGroup) {
365 final ViewGroup viewGroup = (ViewGroup)v;
366 final int N = viewGroup.getChildCount();
367 for (int i = 0; i < N; i++) {
Xiaohui Chen40e978e2016-11-29 15:10:04 -0800368 addToDispatchers(viewGroup.getChildAt(i));
Keisuke Kuroyanagi47bd7332016-05-06 10:49:54 -0700369 }
Jason Monka2081822016-01-18 14:41:03 -0500370 }
371 }
Jason Monka2081822016-01-18 14:41:03 -0500372 }
373
Jason Monka2081822016-01-18 14:41:03 -0500374
Jason Monka2081822016-01-18 14:41:03 -0500375
376 private void clearViews() {
377 if (mButtonDispatchers != null) {
378 for (int i = 0; i < mButtonDispatchers.size(); i++) {
379 mButtonDispatchers.valueAt(i).clear();
380 }
381 }
382 clearAllChildren((ViewGroup) mRot0.findViewById(R.id.nav_buttons));
Jason Monka2081822016-01-18 14:41:03 -0500383 clearAllChildren((ViewGroup) mRot90.findViewById(R.id.nav_buttons));
Jason Monka2081822016-01-18 14:41:03 -0500384 }
385
386 private void clearAllChildren(ViewGroup group) {
387 for (int i = 0; i < group.getChildCount(); i++) {
388 ((ViewGroup) group.getChildAt(i)).removeAllViews();
389 }
390 }
Jason Monk197f4db2016-08-26 13:28:20 -0400391
392 @Override
Jason Monk20ff3f92017-01-09 15:13:23 -0500393 public void onPluginConnected(NavBarButtonProvider plugin, Context context) {
Jason Monk197f4db2016-08-26 13:28:20 -0400394 mPlugins.add(plugin);
395 clearViews();
396 inflateLayout(mCurrentLayout);
397 }
398
399 @Override
400 public void onPluginDisconnected(NavBarButtonProvider plugin) {
401 mPlugins.remove(plugin);
402 clearViews();
403 inflateLayout(mCurrentLayout);
404 }
Jason Monka2081822016-01-18 14:41:03 -0500405}