Remove plugin logical from NavigationBarView (1/2)
Fixes: 129860064
Test: manual
Change-Id: I8cfa77cf40f62ab1e5f1ad8d1957107aca1557f2
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavBarButtonProvider.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavBarButtonProvider.java
deleted file mode 100644
index e25930c..0000000
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavBarButtonProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.systemui.plugins.statusbar.phone;
-
-import android.annotation.Nullable;
-import android.graphics.drawable.Drawable;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.systemui.plugins.Plugin;
-import com.android.systemui.plugins.annotations.ProvidesInterface;
-
-@ProvidesInterface(action = NavBarButtonProvider.ACTION, version = NavBarButtonProvider.VERSION)
-public interface NavBarButtonProvider extends Plugin {
-
- public static final String ACTION = "com.android.systemui.action.PLUGIN_NAV_BUTTON";
-
- public static final int VERSION = 2;
-
- /**
- * Returns a view in the nav bar. If the id is set "back", "home", "recent_apps", "menu",
- * or "ime_switcher", it is expected to implement ButtonInterface.
- */
- public View createView(String spec, ViewGroup parent);
-
- /**
- * Interface for button actions.
- */
- interface ButtonInterface {
-
- void setImageDrawable(@Nullable Drawable drawable);
-
- void abortCurrentGesture();
-
- void setVertical(boolean vertical);
-
- default void setCarMode(boolean carMode) {
- }
-
- void setDarkIntensity(float intensity);
-
- void setDelayTouchFeedback(boolean shouldDelay);
- }
-}
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java
deleted file mode 100644
index 99cc3a3..0000000
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/phone/NavGesture.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.systemui.plugins.statusbar.phone;
-
-import android.graphics.Canvas;
-import android.view.MotionEvent;
-import android.view.View;
-
-import com.android.systemui.plugins.Plugin;
-import com.android.systemui.plugins.annotations.ProvidesInterface;
-import java.io.PrintWriter;
-
-@ProvidesInterface(action = NavGesture.ACTION, version = NavGesture.VERSION)
-public interface NavGesture extends Plugin {
-
- public static final String ACTION = "com.android.systemui.action.PLUGIN_NAV_GESTURE";
-
- public static final int VERSION = 1;
-
- public GestureHelper getGestureHelper();
-
- public interface GestureHelper {
- public boolean onTouchEvent(MotionEvent event);
-
- public boolean onInterceptTouchEvent(MotionEvent event);
-
- public void setBarState(boolean isRtl, int navBarPosition);
-
- public void onDraw(Canvas canvas);
-
- public void onDarkIntensityChange(float intensity);
-
- public void onLayout(boolean changed, int left, int top, int right, int bottom);
-
- public void onNavigationButtonLongPress(View v);
-
- public default void destroy() { }
-
- public default void dump(PrintWriter pw) { }
- }
-
-}
diff --git a/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml b/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml
deleted file mode 100644
index 133b215..0000000
--- a/packages/SystemUI/res/layout/nav_bar_tuner_inflater.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<com.android.systemui.tuner.PreviewNavInflater
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:systemui="http://schemas.android.com/apk/res-auto"
- android:background="@android:color/black"
- android:layout_width="match_parent"
- android:layout_height="@dimen/navigation_bar_size">
-
- <include android:id="@+id/horizontal" layout="@layout/navigation_layout" />
-
- <include android:id="@+id/vertical" layout="@layout/navigation_layout_vertical" />
-
-</com.android.systemui.tuner.PreviewNavInflater>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonDispatcher.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonDispatcher.java
index 6a93c7c..539bc7b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonDispatcher.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonDispatcher.java
@@ -23,7 +23,6 @@
import android.view.View;
import android.view.View.AccessibilityDelegate;
-import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
import java.util.ArrayList;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonInterface.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonInterface.java
new file mode 100644
index 0000000..150a960
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ButtonInterface.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.statusbar.phone;
+
+import android.annotation.Nullable;
+import android.graphics.drawable.Drawable;
+
+public interface ButtonInterface {
+
+ void setImageDrawable(@Nullable Drawable drawable);
+
+ void abortCurrentGesture();
+
+ void setVertical(boolean vertical);
+
+ void setDarkIntensity(float intensity);
+
+ void setDelayTouchFeedback(boolean shouldDelay);
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
index 8aa4f03..03d607d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -709,7 +709,6 @@
if (shouldDisableNavbarGestures()) {
return false;
}
- mNavigationBarView.onNavigationButtonLongPress(v);
mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Bundle args = new Bundle();
args.putInt(
@@ -749,12 +748,10 @@
}
private boolean onLongPressBackHome(View v) {
- mNavigationBarView.onNavigationButtonLongPress(v);
return onLongPressNavigationButtons(v, R.id.back, R.id.home);
}
private boolean onLongPressBackRecents(View v) {
- mNavigationBarView.onNavigationButtonLongPress(v);
return onLongPressNavigationButtons(v, R.id.back, R.id.recent_apps);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
index 7ab8da9..a12ae96 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
@@ -35,23 +35,15 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.R;
-import com.android.systemui.plugins.PluginListener;
-import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider;
import com.android.systemui.recents.OverviewProxyService;
-import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.statusbar.phone.ReverseLinearLayout.ReverseRelativeLayout;
import com.android.systemui.statusbar.policy.KeyButtonView;
-import com.android.systemui.tuner.TunerService;
-import com.android.systemui.tuner.TunerService.Tunable;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Objects;
public class NavigationBarInflaterView extends FrameLayout
- implements Tunable, PluginListener<NavBarButtonProvider>,
- NavigationModeController.ModeChangedListener {
+ implements NavigationModeController.ModeChangedListener {
private static final String TAG = "NavBarInflater";
@@ -87,8 +79,6 @@
private static final String ABSOLUTE_SUFFIX = "A";
private static final String ABSOLUTE_VERTICAL_CENTERED_SUFFIX = "C";
- private final List<NavBarButtonProvider> mPlugins = new ArrayList<>();
-
protected LayoutInflater mLayoutInflater;
protected LayoutInflater mLandscapeInflater;
@@ -160,32 +150,11 @@
}
@Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT,
- NAV_BAR_RIGHT);
- Dependency.get(PluginManager.class).addPluginListener(this,
- NavBarButtonProvider.class, true /* Allow multiple */);
- }
-
- @Override
protected void onDetachedFromWindow() {
- Dependency.get(TunerService.class).removeTunable(this);
- Dependency.get(PluginManager.class).removePluginListener(this);
Dependency.get(NavigationModeController.class).removeListener(this);
super.onDetachedFromWindow();
}
- @Override
- public void onTuningChanged(String key, String newValue) {
- if (NAV_BAR_VIEWS.equals(key)) {
- setNavigationBarLayout(newValue);
- } else if (NAV_BAR_LEFT.equals(key) || NAV_BAR_RIGHT.equals(key)) {
- clearViews();
- inflateLayout(mCurrentLayout);
- }
- }
-
public void setNavigationBarLayout(String layoutValue) {
if (!Objects.equals(mCurrentLayout, layoutValue)) {
mUsingCustomLayout = layoutValue != null;
@@ -404,16 +373,9 @@
View v = null;
String button = extractButton(buttonSpec);
if (LEFT.equals(button)) {
- String s = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE);
- button = extractButton(s);
+ button = extractButton(NAVSPACE);
} else if (RIGHT.equals(button)) {
- String s = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME_ROTATE);
- button = extractButton(s);
- }
- // Let plugins go first so they can override a standard view if they want.
- for (NavBarButtonProvider provider : mPlugins) {
- v = provider.createView(buttonSpec, parent);
- if (v != null) return v;
+ button = extractButton(MENU_IME_ROTATE);
}
if (HOME.equals(button)) {
v = inflater.inflate(R.layout.home, parent, false);
@@ -522,18 +484,4 @@
private static float convertDpToPx(Context context, float dp) {
return dp * context.getResources().getDisplayMetrics().density;
}
-
- @Override
- public void onPluginConnected(NavBarButtonProvider plugin, Context context) {
- mPlugins.add(plugin);
- clearViews();
- inflateLayout(mCurrentLayout);
- }
-
- @Override
- public void onPluginDisconnected(NavBarButtonProvider plugin) {
- mPlugins.remove(plugin);
- clearViews();
- inflateLayout(mCurrentLayout);
- }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
index 4e4a6aec..9e0aff0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarTransitions.java
@@ -174,7 +174,6 @@
if (mAutoDim) {
applyLightsOut(false, true);
}
- mView.onDarkIntensityChange(darkIntensity);
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 831d882..0b8ad58 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.phone;
-import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
@@ -38,10 +37,8 @@
import android.graphics.Region;
import android.graphics.Region.Op;
import android.os.Bundle;
-import android.os.RemoteException;
import android.util.AttributeSet;
import android.util.Log;
-import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;
import android.view.MotionEvent;
@@ -52,7 +49,6 @@
import android.view.ViewTreeObserver.OnComputeInternalInsetsListener;
import android.view.WindowInsets;
import android.view.WindowManager;
-import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.view.inputmethod.InputMethodManager;
@@ -65,13 +61,9 @@
import com.android.systemui.R;
import com.android.systemui.SysUiServiceProvider;
import com.android.systemui.assist.AssistManager;
-import com.android.systemui.plugins.PluginListener;
-import com.android.systemui.plugins.statusbar.phone.NavGesture;
-import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsOnboarding;
-import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.WindowManagerWrapper;
@@ -82,7 +74,7 @@
import java.io.PrintWriter;
import java.util.function.Consumer;
-public class NavigationBarView extends FrameLayout implements PluginListener<NavGesture>,
+public class NavigationBarView extends FrameLayout implements
NavigationModeController.ModeChangedListener {
final static boolean DEBUG = false;
final static String TAG = "StatusBar/NavBarView";
@@ -118,7 +110,6 @@
private KeyButtonDrawable mDockedIcon;
private final EdgeBackGestureHandler mEdgeBackGestureHandler;
- private GestureHelper mGestureHelper;
private final DeadZone mDeadZone;
private boolean mDeadZoneConsuming = false;
private final NavigationBarTransitions mBarTransitions;
@@ -349,9 +340,6 @@
@Override
public boolean onTouchEvent(MotionEvent event) {
shouldDeadZoneConsumeTouchEvents(event);
- if (mGestureHelper != null && mGestureHelper.onTouchEvent(event)) {
- return true;
- }
return super.onTouchEvent(event);
}
@@ -708,12 +696,6 @@
}
}
- public void onNavigationButtonLongPress(View v) {
- if (mGestureHelper != null) {
- mGestureHelper.onNavigationButtonLongPress(v);
- }
- }
-
public void onPanelExpandedChange() {
updateSlippery();
mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED,
@@ -809,17 +791,8 @@
reloadNavIcons();
}
- public void onDarkIntensityChange(float intensity) {
- if (mGestureHelper != null) {
- mGestureHelper.onDarkIntensityChange(intensity);
- }
- }
-
@Override
protected void onDraw(Canvas canvas) {
- if (mGestureHelper != null) {
- mGestureHelper.onDraw(canvas);
- }
mDeadZone.onDraw(canvas);
super.onDraw(canvas);
}
@@ -835,9 +808,6 @@
updateButtonLocation(getRotateSuggestionButton(), mRotationButtonBounds, true);
// TODO: Handle button visibility changes
mOverviewProxyService.onActiveNavBarRegionChanges(mActiveRegion);
- if (mGestureHelper != null) {
- mGestureHelper.onLayout(changed, left, top, right, bottom);
- }
mRecentsOnboarding.setNavBarHeight(getMeasuredHeight());
}
@@ -936,25 +906,11 @@
if (!isLayoutDirectionResolved()) {
resolveLayoutDirection();
}
- updateTaskSwitchHelper();
updateNavButtonIcons();
getHomeButton().setVertical(mIsVertical);
}
- private void updateTaskSwitchHelper() {
- if (mGestureHelper == null) return;
- boolean isRtl = (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
- int navBarPos = NAV_BAR_INVALID;
- try {
- navBarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(
- getContext().getDisplayId());
- } catch (RemoteException e) {
- Slog.e(TAG, "Failed to get nav bar position.", e);
- }
- mGestureHelper.setBarState(isRtl, navBarPos);
- }
-
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int w = MeasureSpec.getSize(widthMeasureSpec);
@@ -1001,7 +957,6 @@
mTmpLastConfiguration.updateFrom(mConfiguration);
mConfiguration.updateFrom(newConfig);
boolean uiCarModeChanged = updateCarMode();
- updateTaskSwitchHelper();
updateIcons(mTmpLastConfiguration);
updateRecentsIcon();
mRecentsOnboarding.onConfigurationChanged(mConfiguration);
@@ -1070,9 +1025,6 @@
super.onAttachedToWindow();
requestApplyInsets();
reorient();
- onPluginDisconnected(null); // Create default gesture helper
- Dependency.get(PluginManager.class).addPluginListener(this,
- NavGesture.class, false /* Only one */);
onNavigationModeChanged(mNavBarMode);
setUpSwipeUpOnboarding(isQuickStepSwipeUpEnabled());
@@ -1083,11 +1035,7 @@
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- Dependency.get(PluginManager.class).removePluginListener(this);
Dependency.get(NavigationModeController.class).removeListener(this);
- if (mGestureHelper != null) {
- mGestureHelper.destroy();
- }
setUpSwipeUpOnboarding(false);
for (int i = 0; i < mButtonDispatchers.size(); ++i) {
mButtonDispatchers.valueAt(i).onDestroy();
@@ -1105,21 +1053,6 @@
}
}
- @Override
- public void onPluginConnected(NavGesture plugin, Context context) {
- mGestureHelper = plugin.getGestureHelper();
- updateTaskSwitchHelper();
- }
-
- @Override
- public void onPluginDisconnected(NavGesture plugin) {
- if (mGestureHelper != null) {
- mGestureHelper.destroy();
- mGestureHelper = null;
- }
- updateTaskSwitchHelper();
- }
-
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("NavigationBarView {");
final Rect r = new Rect();
@@ -1156,9 +1089,6 @@
pw.println(" }");
mContextualButtonGroup.dump(pw);
- if (mGestureHelper != null) {
- mGestureHelper.dump(pw);
- }
mRecentsOnboarding.dump(pw);
mTintController.dump(pw);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java
index 7dc71f5..0fe1294 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java
@@ -29,7 +29,6 @@
import com.android.settingslib.Utils;
import com.android.systemui.R;
-import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;
public class NavigationHandle extends View implements ButtonInterface {
private float mDarkIntensity = -1;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
index 22a0b991..c9579fd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
@@ -56,9 +56,9 @@
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.bubbles.BubbleController;
-import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.shared.system.QuickStepContract;
+import com.android.systemui.statusbar.phone.ButtonInterface;
public class KeyButtonView extends ImageView implements ButtonInterface {
private static final String TAG = KeyButtonView.class.getSimpleName();
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/PreviewNavInflater.java b/packages/SystemUI/src/com/android/systemui/tuner/PreviewNavInflater.java
deleted file mode 100644
index e7a695f..0000000
--- a/packages/SystemUI/src/com/android/systemui/tuner/PreviewNavInflater.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.systemui.tuner;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-
-import com.android.systemui.Dependency;
-import com.android.systemui.statusbar.phone.NavigationBarInflaterView;
-
-public class PreviewNavInflater extends NavigationBarInflaterView {
-
- public PreviewNavInflater(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- @Override
- protected void onAttachedToWindow() {
- super.onAttachedToWindow();
- // Immediately remove tuner listening, since this is a preview, all values will be injected
- // manually.
- Dependency.get(TunerService.class).removeTunable(this);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- // Only a preview, not interactable.
- return true;
- }
-
- @Override
- public void onTuningChanged(String key, String newValue) {
- if (NAV_BAR_VIEWS.equals(key)) {
- // Since this is a preview we might get a bunch of random stuff, validate before sending
- // for inflation.
- if (isValidLayout(newValue)) {
- super.onTuningChanged(key, newValue);
- }
- } else {
- super.onTuningChanged(key, newValue);
- }
- }
-
- private boolean isValidLayout(String newValue) {
- if (newValue == null) {
- return true;
- }
- int separatorCount = 0;
- int lastGravitySeparator = 0;
- for (int i = 0; i < newValue.length(); i++) {
- if (newValue.charAt(i) == GRAVITY_SEPARATOR.charAt(0)) {
- if (i == 0 || (i - lastGravitySeparator) == 1) {
- return false;
- }
- lastGravitySeparator = i;
- separatorCount++;
- }
- }
- return separatorCount == 2 && (newValue.length() - lastGravitySeparator) != 1;
- }
-}