Remove plugin logical from NavigationBarView (1/2)

Fixes: 129860064
Test: manual
Change-Id: I8cfa77cf40f62ab1e5f1ad8d1957107aca1557f2
This commit is contained in:
Matthew Ng
2019-05-08 15:13:22 -07:00
parent cd58d5a512
commit e0d5ccd331
12 changed files with 38 additions and 344 deletions

View File

@@ -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);
}
}

View File

@@ -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) { }
}
}

View File

@@ -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>

View File

@@ -23,7 +23,6 @@ import android.animation.ValueAnimator;
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;

View File

@@ -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);
}

View File

@@ -709,7 +709,6 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
if (shouldDisableNavbarGestures()) {
return false;
}
mNavigationBarView.onNavigationButtonLongPress(v);
mMetricsLogger.action(MetricsEvent.ACTION_ASSIST_LONG_PRESS);
Bundle args = new Bundle();
args.putInt(
@@ -749,12 +748,10 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
}
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);
}

View File

@@ -35,23 +35,15 @@ import android.widget.Space;
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 @@ public class NavigationBarInflaterView extends FrameLayout
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;
@@ -159,33 +149,12 @@ public class NavigationBarInflaterView extends FrameLayout
onLikelyDefaultLayoutChange();
}
@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 @@ public class NavigationBarInflaterView extends FrameLayout
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 @@ public class NavigationBarInflaterView extends FrameLayout
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);
}
}

View File

@@ -174,7 +174,6 @@ public final class NavigationBarTransitions extends BarTransitions implements
if (mAutoDim) {
applyLightsOut(false, true);
}
mView.onDarkIntensityChange(darkIntensity);
}
@Override

View File

@@ -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.Rect;
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.InternalInsetsInfo;
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.Interpolators;
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.FileDescriptor;
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
@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 class NavigationBarView extends FrameLayout implements PluginListener<Nav
}
}
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
mTmpLastConfiguration.updateFrom(mConfiguration);
mConfiguration.updateFrom(newConfig);
boolean uiCarModeChanged = updateCarMode();
updateTaskSwitchHelper();
updateIcons(mTmpLastConfiguration);
updateRecentsIcon();
mRecentsOnboarding.onConfigurationChanged(mConfiguration);
@@ -1070,9 +1025,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
@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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
}
}
@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 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
pw.println(" }");
mContextualButtonGroup.dump(pw);
if (mGestureHelper != null) {
mGestureHelper.dump(pw);
}
mRecentsOnboarding.dump(pw);
mTintController.dump(pw);
}

View File

@@ -29,7 +29,6 @@ import android.view.View;
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;

View File

@@ -56,9 +56,9 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
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();

View File

@@ -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;
}
}