From 4ec7134a776bbcc33e37b43bf71d4e85d4b60853 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 3 Dec 2015 15:31:25 -0800 Subject: [PATCH] Cleaning up the overlay interface Overlays are supposed to use their own UI and not interfere with the Launcher UI. If the UI needs to be put inside the Launcher, use customContent instead. Removing some unnecessary and unused methods related to overlays Bug: 25993953 Change-Id: I4d715cdee04eb7b0ebef673d885a4258c521ff1f --- res/layout-land/launcher.xml | 6 - res/layout-port/launcher.xml | 6 - res/layout-sw720dp/launcher.xml | 7 - res/layout/launcher_overlay.xml | 20 --- res/layout/launcher_overlay_example.xml | 39 ----- src/com/android/launcher3/DragLayer.java | 14 -- src/com/android/launcher3/Launcher.java | 79 ++-------- .../android/launcher3/LauncherCallbacks.java | 27 ---- .../launcher3/testing/LauncherExtension.java | 137 +----------------- 9 files changed, 16 insertions(+), 319 deletions(-) delete mode 100644 res/layout/launcher_overlay.xml delete mode 100644 res/layout/launcher_overlay_example.xml diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml index 1a951f1b7a..b1f85b4635 100644 --- a/res/layout-land/launcher.xml +++ b/res/layout-land/launcher.xml @@ -72,10 +72,4 @@ android:visibility="invisible" /> - diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml index 8bf9d6427c..962b5cea74 100644 --- a/res/layout-port/launcher.xml +++ b/res/layout-port/launcher.xml @@ -82,10 +82,4 @@ android:visibility="invisible" /> - diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml index 2fc62c5008..50daaa9050 100644 --- a/res/layout-sw720dp/launcher.xml +++ b/res/layout-sw720dp/launcher.xml @@ -80,11 +80,4 @@ android:visibility="invisible" /> - - diff --git a/res/layout/launcher_overlay.xml b/res/layout/launcher_overlay.xml deleted file mode 100644 index b35a2d8ae8..0000000000 --- a/res/layout/launcher_overlay.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - diff --git a/res/layout/launcher_overlay_example.xml b/res/layout/launcher_overlay_example.xml deleted file mode 100644 index 7d92d4f0dc..0000000000 --- a/res/layout/launcher_overlay_example.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java index ad9063c25a..9886c3fef1 100644 --- a/src/com/android/launcher3/DragLayer.java +++ b/src/com/android/launcher3/DragLayer.java @@ -95,8 +95,6 @@ public class DragLayer extends InsettableFrameLayout { private Drawable mLeftHoverDrawableActive; private Drawable mRightHoverDrawableActive; - private boolean mBlockTouches = false; - /** * Used to create a new DragLayer from XML. * @@ -166,19 +164,11 @@ public class DragLayer extends InsettableFrameLayout { return false; } - public void setBlockTouch(boolean block) { - mBlockTouches = block; - } - private boolean handleTouchDown(MotionEvent ev, boolean intercept) { Rect hitRect = new Rect(); int x = (int) ev.getX(); int y = (int) ev.getY(); - if (mBlockTouches) { - return true; - } - for (AppWidgetResizeFrame child: mResizeFrames) { child.getHitRect(hitRect); if (hitRect.contains(x, y)) { @@ -343,10 +333,6 @@ public class DragLayer extends InsettableFrameLayout { int x = (int) ev.getX(); int y = (int) ev.getY(); - if (mBlockTouches) { - return true; - } - if (action == MotionEvent.ACTION_DOWN) { if (handleTouchDown(ev, false)) { return true; diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 95e639ab5d..1bf23411eb 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -216,10 +216,6 @@ public class Launcher extends Activity private boolean mIsSafeModeEnabled; - LauncherOverlayCallbacks mLauncherOverlayCallbacks = new LauncherOverlayCallbacksImpl(); - LauncherOverlay mLauncherOverlay; - InsettableFrameLayout mLauncherOverlayContainer; - static final int APPWIDGET_HOST_ID = 1024; public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500; @@ -501,13 +497,6 @@ public class Launcher extends Activity if (mLauncherCallbacks != null) { mLauncherCallbacks.onCreate(savedInstanceState); - if (mLauncherCallbacks.hasLauncherOverlay()) { - ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub); - mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate(); - mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView( - mLauncherOverlayContainer, mLauncherOverlayCallbacks); - mWorkspace.setLauncherOverlay(mLauncherOverlay); - } } if (shouldShowIntroScreen()) { @@ -537,6 +526,16 @@ public class Launcher extends Activity } } + /** + * Call this after onCreate to set or clear overlay. + */ + public void setLauncherOverlay(LauncherOverlay overlay) { + if (overlay != null) { + overlay.setOverlayCallbacks(new LauncherOverlayCallbacksImpl()); + } + mWorkspace.setLauncherOverlay(overlay); + } + public boolean setLauncherCallbacks(LauncherCallbacks callbacks) { mLauncherCallbacks = callbacks; mLauncherCallbacks.setLauncherSearchCallback(new Launcher.LauncherSearchCallbacks() { @@ -889,8 +888,7 @@ public class Launcher extends Activity * @return the new screen, or screenId if it exists */ private long ensurePendingDropLayoutExists(long screenId) { - CellLayout dropLayout = - (CellLayout) mWorkspace.getScreenWithId(screenId); + CellLayout dropLayout = mWorkspace.getScreenWithId(screenId); if (dropLayout == null) { // it's possible that the add screen was removed because it was // empty and a re-bind occurred @@ -1133,10 +1131,10 @@ public class Launcher extends Activity public void onScrollSettled(); /** - * This method can be called by the Launcher in order to force the LauncherOverlay - * to exit fully immersive mode. + * Called when the launcher is ready to use the overlay + * @param callbacks A set of callbacks provided by Launcher in relation to the overlay */ - public void forceExitFullImmersion(); + public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks); } public interface LauncherSearchCallbacks { @@ -1152,51 +1150,11 @@ public class Launcher extends Activity } public interface LauncherOverlayCallbacks { - /** - * This method indicates whether a call to {@link #enterFullImmersion()} will succeed, - * however it doesn't modify any state within the launcher. - */ - public boolean canEnterFullImmersion(); - /** - * Should be called to tell Launcher that the LauncherOverlay will take over interaction, - * eg. by occupying the full screen and handling all touch events. - * - * @return true if Launcher allows the LauncherOverlay to become fully immersive. In this - * case, Launcher will modify any necessary state and assumes the overlay is - * handling all interaction. If false, the LauncherOverlay should cancel any - * - */ - public boolean enterFullImmersion(); - - /** - * Must be called when exiting fully immersive mode. Indicates to Launcher that it has - * full control over UI and state. - */ - public void exitFullImmersion(); } class LauncherOverlayCallbacksImpl implements LauncherOverlayCallbacks { - @Override - public boolean canEnterFullImmersion() { - return mState == State.WORKSPACE; - } - - @Override - public boolean enterFullImmersion() { - if (mState == State.WORKSPACE) { - // When fully immersed, disregard any touches which fall through. - mDragLayer.setBlockTouch(true); - return true; - } - return false; - } - - @Override - public void exitFullImmersion() { - mDragLayer.setBlockTouch(false); - } } protected boolean hasSettings() { @@ -4645,9 +4603,6 @@ public class Launcher extends Activity if (introScreen != null) { mDragLayer.showOverlayView(introScreen); } - if (mLauncherOverlayContainer != null) { - mLauncherOverlayContainer.setVisibility(View.INVISIBLE); - } } public void dismissIntroScreen() { @@ -4659,17 +4614,11 @@ public class Launcher extends Activity @Override public void run() { mDragLayer.dismissOverlayView(); - if (mLauncherOverlayContainer != null) { - mLauncherOverlayContainer.setVisibility(View.VISIBLE); - } showFirstRunClings(); } }, ACTIVITY_START_DELAY); } else { mDragLayer.dismissOverlayView(); - if (mLauncherOverlayContainer != null) { - mLauncherOverlayContainer.setVisibility(View.VISIBLE); - } showFirstRunClings(); } changeWallpaperVisiblity(true); diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java index 772fbf358f..74833e3a4e 100644 --- a/src/com/android/launcher3/LauncherCallbacks.java +++ b/src/com/android/launcher3/LauncherCallbacks.java @@ -69,18 +69,11 @@ public interface LauncherCallbacks { public void onInteractionBegin(); public void onInteractionEnd(); - /* - * Extension points for replacing the search experience - */ - @Deprecated - public boolean forceDisableVoiceButtonProxy(); public boolean providesSearch(); public boolean startSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds); @Deprecated public boolean startSearchFromAllApps(String query); - @Deprecated - public void startVoice(); public boolean hasCustomContentToLeft(); public void populateCustomContentContainer(); public View getQsbBar(); @@ -95,8 +88,6 @@ public interface LauncherCallbacks { public View getIntroScreen(); public boolean shouldMoveToDefaultScreenOnHomeIntent(); public boolean hasSettings(); - @Deprecated - public ComponentName getWallpaperPickerComponent(); public boolean overrideWallpaperDimensions(); public boolean isLauncherPreinstalled(); public AllAppsSearchBarController getAllAppsSearchBarController(); @@ -105,24 +96,6 @@ public interface LauncherCallbacks { /** Must return one of {@link #SEARCH_BAR_HEIGHT_NORMAL} or {@link #SEARCH_BAR_HEIGHT_TALL} */ public int getSearchBarHeight(); - /** - * Returning true will immediately result in a call to {@link #setLauncherOverlayView(ViewGroup, - * com.android.launcher3.Launcher.LauncherOverlayCallbacks)}. - * - * @return true if this launcher extension will provide an overlay - */ - public boolean hasLauncherOverlay(); - - /** - * Handshake to establish an overlay relationship - * - * @param container Full screen overlay ViewGroup into which custom views can be placed. - * @param callbacks A set of callbacks provided by Launcher in relation to the overlay - * @return an interface used to make requests and notify the Launcher in relation to the overlay - */ - public Launcher.LauncherOverlay setLauncherOverlayView(InsettableFrameLayout container, - Launcher.LauncherOverlayCallbacks callbacks); - /** * Sets the callbacks to allow reacting the actions of search overlays of the launcher. * diff --git a/src/com/android/launcher3/testing/LauncherExtension.java b/src/com/android/launcher3/testing/LauncherExtension.java index 1bb57874e3..279be70372 100644 --- a/src/com/android/launcher3/testing/LauncherExtension.java +++ b/src/com/android/launcher3/testing/LauncherExtension.java @@ -1,24 +1,16 @@ package com.android.launcher3.testing; -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ObjectAnimator; -import android.content.ComponentName; import android.content.Intent; import android.graphics.Color; import android.graphics.Rect; import android.os.Bundle; import android.view.Menu; import android.view.View; -import android.view.ViewGroup; import android.widget.FrameLayout; import com.android.launcher3.AppInfo; -import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAnimUtils; import com.android.launcher3.LauncherCallbacks; -import com.android.launcher3.R; import com.android.launcher3.allapps.AllAppsSearchBarController; import com.android.launcher3.util.ComponentKey; @@ -42,8 +34,6 @@ public class LauncherExtension extends Launcher { public class LauncherExtensionCallbacks implements LauncherCallbacks { - LauncherExtensionOverlay mLauncherOverlay = new LauncherExtensionOverlay(); - @Override public void preOnCreate() { } @@ -116,10 +106,6 @@ public class LauncherExtension extends Launcher { @Override public boolean handleBackPressed() { - if (mLauncherOverlay.isOverlayPanelShowing()) { - mLauncherOverlay.hideOverlayPanel(); - return true; - } return false; } @@ -187,14 +173,9 @@ public class LauncherExtension extends Launcher { public void onInteractionEnd() { } - @Override - public boolean forceDisableVoiceButtonProxy() { - return false; - } - @Override public boolean providesSearch() { - return true; + return false; } @Override @@ -208,10 +189,6 @@ public class LauncherExtension extends Launcher { return false; } - @Override - public void startVoice() { - } - CustomContentCallbacks mCustomContentCallbacks = new CustomContentCallbacks() { // Custom content is completely shown. {@code fromResume} indicates whether this was caused @@ -249,7 +226,7 @@ public class LauncherExtension extends Launcher { @Override public View getQsbBar() { - return mLauncherOverlay.getSearchBox(); + return null; } @Override @@ -287,11 +264,6 @@ public class LauncherExtension extends Launcher { return false; } - @Override - public ComponentName getWallpaperPickerComponent() { - return null; - } - @Override public boolean overrideWallpaperDimensions() { return false; @@ -317,114 +289,9 @@ public class LauncherExtension extends Launcher { return false; } - @Override - public boolean hasLauncherOverlay() { - return false; - } - - @Override - public LauncherOverlay setLauncherOverlayView(InsettableFrameLayout container, - LauncherOverlayCallbacks callbacks) { - - mLauncherOverlay.setOverlayCallbacks(callbacks); - mLauncherOverlay.setOverlayContainer(container); - - return mLauncherOverlay; - } - @Override public void setLauncherSearchCallback(Object callbacks) { // Do nothing } - - class LauncherExtensionOverlay implements LauncherOverlay { - LauncherOverlayCallbacks mLauncherOverlayCallbacks; - ViewGroup mOverlayView; - View mSearchBox; - View mSearchOverlay; - boolean mShowOverlayFeedback; - int mProgress; - boolean mOverlayPanelShowing; - - @Override - public void onScrollInteractionBegin() { - if (mLauncherOverlayCallbacks.canEnterFullImmersion()) { - mShowOverlayFeedback = true; - updatePanelOffset(0); - mSearchOverlay.setVisibility(View.VISIBLE); - mSearchOverlay.setLayerType(View.LAYER_TYPE_HARDWARE, null); - } - } - - @Override - public void onScrollChange(int progress, boolean rtl) { - mProgress = progress; - if (mShowOverlayFeedback) { - updatePanelOffset(progress); - } - } - - private void updatePanelOffset(int progress) { - int panelWidth = mSearchOverlay.getMeasuredWidth(); - int offset = (int) ((progress / 100f) * panelWidth); - mSearchOverlay.setTranslationX(- panelWidth + offset); - } - - @Override - public void onScrollInteractionEnd() { - if (mProgress > 25 && mLauncherOverlayCallbacks.enterFullImmersion()) { - ObjectAnimator oa = LauncherAnimUtils.ofFloat(mSearchOverlay, "translationX", 0); - oa.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator arg0) { - mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null); - } - }); - oa.start(); - mOverlayPanelShowing = true; - mShowOverlayFeedback = false; - } - } - - @Override - public void onScrollSettled() { - if (mShowOverlayFeedback) { - mSearchOverlay.setVisibility(View.INVISIBLE); - mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null); - } - mShowOverlayFeedback = false; - mProgress = 0; - } - - public void hideOverlayPanel() { - mLauncherOverlayCallbacks.exitFullImmersion(); - mSearchOverlay.setVisibility(View.INVISIBLE); - mOverlayPanelShowing = false; - } - - public boolean isOverlayPanelShowing() { - return mOverlayPanelShowing; - } - - @Override - public void forceExitFullImmersion() { - hideOverlayPanel(); - } - - public void setOverlayContainer(InsettableFrameLayout container) { - mOverlayView = (ViewGroup) getLayoutInflater().inflate( - R.layout.launcher_overlay_example, container); - mSearchOverlay = mOverlayView.findViewById(R.id.search_overlay); - mSearchBox = mOverlayView.findViewById(R.id.search_box); - } - - public View getSearchBox() { - return mSearchBox; - } - - public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) { - mLauncherOverlayCallbacks = callbacks; - } - }; } }