diff options
| -rw-r--r-- | packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java | 23 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/SystemUIApplication.java | 42 |
2 files changed, 49 insertions, 16 deletions
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java index 61aa60bb9675..90fc86bc5b51 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/OverlayPlugin.java @@ -13,18 +13,28 @@ */ package com.android.systemui.plugins; -import com.android.systemui.plugins.annotations.ProvidesInterface; - import android.view.View; +import com.android.systemui.plugins.annotations.ProvidesInterface; + @ProvidesInterface(action = OverlayPlugin.ACTION, version = OverlayPlugin.VERSION) public interface OverlayPlugin extends Plugin { String ACTION = "com.android.systemui.action.PLUGIN_OVERLAY"; - int VERSION = 2; + int VERSION = 3; + /** + * Setup overlay plugin + */ void setup(View statusBar, View navBar); + /** + * Setup overlay plugin with callback + */ + default void setup(View statusBar, View navBar, Callback callback) { + setup(statusBar, navBar); + } + default boolean holdStatusBarOpen() { return false; } @@ -34,4 +44,11 @@ public interface OverlayPlugin extends Plugin { */ default void setCollapseDesired(boolean collapseDesired) { } + + /** + * Used to update system ui whether to hold status bar open + */ + interface Callback { + void onHoldStatusBarOpenChange(); + } } diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 12f40f385cb2..61a0f72315ea 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -205,7 +205,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv final Handler mainHandler = new Handler(Looper.getMainLooper()); Dependency.get(PluginManager.class).addPluginListener( new PluginListener<OverlayPlugin>() { - private ArraySet<OverlayPlugin> mOverlays; + private ArraySet<OverlayPlugin> mOverlays = new ArraySet<>(); @Override public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { @@ -215,18 +215,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv StatusBar statusBar = getComponent(StatusBar.class); if (statusBar != null) { plugin.setup(statusBar.getStatusBarWindow(), - statusBar.getNavigationBarView()); - } - // Lazy init. - if (mOverlays == null) mOverlays = new ArraySet<>(); - if (plugin.holdStatusBarOpen()) { - mOverlays.add(plugin); - Dependency.get(StatusBarWindowController.class) - .setStateListener(b -> mOverlays.forEach( - o -> o.setCollapseDesired(b))); - Dependency.get(StatusBarWindowController.class) - .setForcePluginOpen(mOverlays.size() != 0); - + statusBar.getNavigationBarView(), new Callback(plugin)); } } }); @@ -243,6 +232,33 @@ public class SystemUIApplication extends Application implements SysUiServiceProv } }); } + + class Callback implements OverlayPlugin.Callback { + private final OverlayPlugin mPlugin; + + Callback(OverlayPlugin plugin) { + mPlugin = plugin; + } + + @Override + public void onHoldStatusBarOpenChange() { + if (mPlugin.holdStatusBarOpen()) { + mOverlays.add(mPlugin); + } else { + mOverlays.remove(mPlugin); + } + mainHandler.post(new Runnable() { + @Override + public void run() { + Dependency.get(StatusBarWindowController.class) + .setStateListener(b -> mOverlays.forEach( + o -> o.setCollapseDesired(b))); + Dependency.get(StatusBarWindowController.class) + .setForcePluginOpen(mOverlays.size() != 0); + } + }); + } + } }, OverlayPlugin.class, true /* Allow multiple plugins */); mServicesStarted = true; |