diff --git a/Android.mk b/Android.mk index 282b878dd9..13540f4bfe 100644 --- a/Android.mk +++ b/Android.mk @@ -38,7 +38,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ - $(call all-java-files-under, src_config) \ + $(call all-java-files-under, src_ui_overrides) \ $(call all-java-files-under, src_flags) \ $(call all-proto-files-under, protos) \ $(call all-proto-files-under, proto_overrides) @@ -83,7 +83,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ - $(call all-java-files-under, src_config) \ + $(call all-java-files-under, src_ui_overrides) \ $(call all-java-files-under, go/src_flags) \ $(call all-proto-files-under, protos) \ $(call all-proto-files-under, proto_overrides) @@ -134,9 +134,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ - $(call all-java-files-under, src_config) \ $(call all-java-files-under, quickstep/src) \ - $(call all-java-files-under, quickstep/src_flags) \ $(call all-proto-files-under, protos) \ $(call all-proto-files-under, proto_overrides) diff --git a/src/com/android/launcher3/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java similarity index 98% rename from src/com/android/launcher3/states/OverviewState.java rename to quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 344a4f95fd..0e7035a465 100644 --- a/src/com/android/launcher3/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.states; +package com.android.launcher3.uioverrides; import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; import static com.android.launcher3.Utilities.isAccessibilityEnabled; diff --git a/src_config/com/android/launcher3/BuildConfig.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java similarity index 62% rename from src_config/com/android/launcher3/BuildConfig.java rename to quickstep/src/com/android/launcher3/uioverrides/UiFactory.java index 4df75a1a12..e43023a13c 100644 --- a/src_config/com/android/launcher3/BuildConfig.java +++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java @@ -14,11 +14,15 @@ * limitations under the License. */ -package com.android.launcher3; +package com.android.launcher3.uioverrides; -/** - * Config file used by Make. This file is automatically generated when using gradle. - */ -public class BuildConfig { - public static final String APPLICATION_ID = "com.android.launcher3"; +import com.android.launcher3.Launcher; +import com.android.launcher3.VerticalSwipeController; +import com.android.launcher3.util.TouchController; + +public class UiFactory { + + public static TouchController[] createTouchControllers(Launcher launcher) { + return new TouchController[] {new VerticalSwipeController(launcher)}; + } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1542703c52..ca75603c74 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -167,7 +167,6 @@ import java.util.concurrent.Executor; public class Launcher extends BaseActivity implements LauncherExterns, View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, View.OnTouchListener, LauncherProviderChangeListener, - AccessibilityManager.AccessibilityStateChangeListener, WallpaperColorInfo.OnThemeChangeListener { public static final String TAG = "Launcher"; static final boolean LOGD = false; @@ -361,9 +360,6 @@ public class Launcher extends BaseActivity mPopupDataProvider = new PopupDataProvider(this); - ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)) - .addAccessibilityStateChangeListener(this); - restoreState(savedInstanceState); // We only load the page synchronously if the user rotates (or triggers a @@ -1552,10 +1548,6 @@ public class Launcher extends BaseActivity mAppWidgetHost = null; TextKeyListener.getInstance().release(); - - ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)) - .removeAccessibilityStateChangeListener(this); - WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null); LauncherAnimUtils.onDestroyActivity(); @@ -2190,11 +2182,6 @@ public class Launcher extends BaseActivity startActivity(intent, getActivityLaunchOptions(v)); } - @Override - public void onAccessibilityStateChanged(boolean enabled) { - mDragLayer.onAccessibilityStateChanged(enabled); - } - private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) { try { StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy(); diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 25a698b159..98568e4363 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -44,7 +44,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Process; -import android.os.Trace; import android.os.UserHandle; import android.os.UserManager; import android.text.TextUtils; @@ -86,7 +85,7 @@ public class LauncherProvider extends ContentProvider { */ public static final int SCHEMA_VERSION = 27; - public static final String AUTHORITY = (BuildConfig.APPLICATION_ID + ".settings").intern(); + public static final String AUTHORITY = FeatureFlags.AUTHORITY; static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED"; diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index 63c232d3f6..bb09a9f860 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -21,9 +21,9 @@ import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CH import android.view.View; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.states.AllAppsState; import com.android.launcher3.states.SpringLoadedState; +import com.android.launcher3.uioverrides.OverviewState; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import java.util.Arrays; @@ -49,7 +49,7 @@ public class LauncherState { public static final LauncherState SPRING_LOADED = new SpringLoadedState(2); - public static final LauncherState OVERVIEW = FeatureFlags.createOverviewState(3); + public static final LauncherState OVERVIEW = new OverviewState(3); public final int ordinal; diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index fd940677aa..b99df717ac 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -179,7 +179,7 @@ public class LauncherStateManager { * @param duration intended duration for normal playback. Use higher duration for better * accuracy. */ - protected AnimatorPlaybackController createAnimationToNewWorkspace( + public AnimatorPlaybackController createAnimationToNewWorkspace( LauncherState state, long duration) { mConfig.reset(); mConfig.userControlled = true; diff --git a/src/com/android/launcher3/VerticalSwipeController.java b/src/com/android/launcher3/VerticalSwipeController.java index 12c6916764..b3dc176b70 100644 --- a/src/com/android/launcher3/VerticalSwipeController.java +++ b/src/com/android/launcher3/VerticalSwipeController.java @@ -75,7 +75,7 @@ public class VerticalSwipeController extends AnimatorListenerAdapter private boolean canInterceptTouch(MotionEvent ev) { if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(ALL_APPS)) { - // Don't listen for the pinch gesture if on all apps, widget picker, -1, etc. + // Don't listen for the swipe gesture if we are already in some other state. return false; } if (mCurrentAnimation != null) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 24c470408a..32f96df61f 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -54,7 +54,6 @@ import android.util.SparseArray; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.ViewDebug; import android.view.ViewGroup; import android.widget.Toast; @@ -82,7 +81,7 @@ import com.android.launcher3.graphics.DragPreviewProvider; import com.android.launcher3.graphics.PreloadIconDrawable; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; -import com.android.launcher3.states.OverviewState; +import com.android.launcher3.uioverrides.OverviewState; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java index 4fbab390e5..a03dabb2bb 100644 --- a/src/com/android/launcher3/config/BaseFlags.java +++ b/src/com/android/launcher3/config/BaseFlags.java @@ -16,9 +16,6 @@ package com.android.launcher3.config; -import com.android.launcher3.LauncherState; -import com.android.launcher3.states.OverviewState; - /** * Defines a set of flags used to control various launcher behaviors. * @@ -32,10 +29,10 @@ abstract class BaseFlags { BaseFlags() {} public static final boolean IS_DOGFOOD_BUILD = false; + public static final String AUTHORITY = "com.android.launcher3.settings".intern(); // Custom flags go below this public static boolean LAUNCHER3_DISABLE_ICON_NORMALIZATION = false; - public static boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false; // When enabled allows to use any point on the fast scrollbar to start dragging. public static final boolean LAUNCHER3_DIRECT_SCROLL = true; // When enabled the promise icon is visible in all apps while installation an app. @@ -62,7 +59,4 @@ abstract class BaseFlags { // Features to control Launcher3Go behavior public static final boolean GO_DISABLE_WIDGETS = false; - public static LauncherState createOverviewState(int id) { - return new OverviewState(id); - } } diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index 0f0b20d2bf..8189b236e9 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -42,17 +42,15 @@ import com.android.launcher3.CellLayout; import com.android.launcher3.DropTargetBar; import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.Launcher; -import com.android.launcher3.PinchToOverviewListener; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.Utilities; -import com.android.launcher3.VerticalSwipeController; import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.anim.Interpolators; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.keyboard.ViewGroupFocusHelper; +import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.TouchController; @@ -92,13 +90,10 @@ public class DragLayer extends InsettableFrameLayout { private final ViewGroupFocusHelper mFocusIndicatorHelper; private final PageCutOutScrimDrawable mPageCutOutScrim; - // Related to pinch-to-go-to-overview gesture. - private PinchToOverviewListener mPinchListener = null; - // Handles all apps pull up interaction private AllAppsTransitionController mAllAppsController; - private VerticalSwipeController mVerticalSwipeController; + protected TouchController[] mControllers; private TouchController mActiveController; /** * Used to create a new DragLayer from XML. @@ -123,11 +118,7 @@ public class DragLayer extends InsettableFrameLayout { mLauncher = launcher; mDragController = dragController; mAllAppsController = allAppsTransitionController; - mVerticalSwipeController = new VerticalSwipeController(mLauncher); - - boolean isAccessibilityEnabled = ((AccessibilityManager) mLauncher.getSystemService( - Context.ACCESSIBILITY_SERVICE)).isEnabled(); - onAccessibilityStateChanged(isAccessibilityEnabled); + mControllers = UiFactory.createTouchControllers(mLauncher); } public ViewGroupFocusHelper getFocusIndicatorHelper() { @@ -144,11 +135,6 @@ public class DragLayer extends InsettableFrameLayout { return super.verifyDrawable(who) || who == mPageCutOutScrim; } - public void onAccessibilityStateChanged(boolean isAccessibilityEnabled) { - mPinchListener = FeatureFlags.LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW || isAccessibilityEnabled - ? null : new PinchToOverviewListener(mLauncher); - } - public boolean isEventOverHotseat(MotionEvent ev) { return isEventOverView(mLauncher.getHotseat(), ev); } @@ -194,15 +180,11 @@ public class DragLayer extends InsettableFrameLayout { return true; } - if (mVerticalSwipeController.onControllerInterceptTouchEvent(ev)) { - mActiveController = mVerticalSwipeController; - return true; - } - - if (mPinchListener != null && mPinchListener.onControllerInterceptTouchEvent(ev)) { - // Stop listening for scrolling etc. (onTouchEvent() handles the rest of the pinch.) - mActiveController = mPinchListener; - return true; + for (TouchController controller : mControllers) { + if (controller.onControllerInterceptTouchEvent(ev)) { + mActiveController = controller; + return true; + } } return false; } diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java new file mode 100644 index 0000000000..0e7035a465 --- /dev/null +++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 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.launcher3.uioverrides; + +import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; +import static com.android.launcher3.Utilities.isAccessibilityEnabled; + +import android.graphics.Rect; +import android.view.View; +import android.view.accessibility.AccessibilityNodeInfo; + +import com.android.launcher3.DeviceProfile; +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherState; +import com.android.launcher3.Workspace; +import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; + +/** + * Definition for overview state + */ +public class OverviewState extends LauncherState { + + // The percent to shrink the workspace during overview mode + public static final float SCALE_FACTOR = 0.7f; + + private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | FLAG_HIDE_HOTSEAT; + + public OverviewState(int id) { + super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS); + } + + @Override + public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { + DeviceProfile grid = launcher.getDeviceProfile(); + Workspace ws = launcher.getWorkspace(); + Rect insets = launcher.getDragLayer().getInsets(); + + int overviewButtonBarHeight = grid.getOverviewModeButtonBarHeight(); + int scaledHeight = (int) (SCALE_FACTOR * ws.getNormalChildHeight()); + Rect workspacePadding = grid.getWorkspacePadding(null); + int workspaceTop = insets.top + workspacePadding.top; + int workspaceBottom = ws.getViewportHeight() - insets.bottom - workspacePadding.bottom; + int overviewTop = insets.top; + int overviewBottom = ws.getViewportHeight() - insets.bottom - overviewButtonBarHeight; + int workspaceOffsetTopEdge = + workspaceTop + ((workspaceBottom - workspaceTop) - scaledHeight) / 2; + int overviewOffsetTopEdge = overviewTop + (overviewBottom - overviewTop - scaledHeight) / 2; + return new float[] {SCALE_FACTOR, -workspaceOffsetTopEdge + overviewOffsetTopEdge }; + } + + @Override + public void onStateEnabled(Launcher launcher) { + launcher.getWorkspace().setPageRearrangeEnabled(true); + + if (isAccessibilityEnabled(launcher)) { + launcher.getOverviewPanel().getChildAt(0).performAccessibilityAction( + AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null); + } + } + + @Override + public void onStateDisabled(Launcher launcher) { + launcher.getWorkspace().setPageRearrangeEnabled(false); + } + + @Override + public View getFinalFocus(Launcher launcher) { + return launcher.getOverviewPanel(); + } +} diff --git a/src/com/android/launcher3/PinchToOverviewListener.java b/src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java similarity index 91% rename from src/com/android/launcher3/PinchToOverviewListener.java rename to src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java index 27edaf69a1..40bf057286 100644 --- a/src/com/android/launcher3/PinchToOverviewListener.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java @@ -14,19 +14,23 @@ * limitations under the License. */ -package com.android.launcher3; +package com.android.launcher3.uioverrides; import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; import static com.android.launcher3.LauncherState.NORMAL; import static com.android.launcher3.LauncherState.OVERVIEW; +import static com.android.launcher3.Utilities.isAccessibilityEnabled; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.animation.AnimatorSet; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.ScaleGestureDetector.OnScaleGestureListener; +import com.android.launcher3.AbstractFloatingView; +import com.android.launcher3.Launcher; +import com.android.launcher3.LauncherState; +import com.android.launcher3.Workspace; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.util.TouchController; @@ -70,8 +74,10 @@ public class PinchToOverviewListener extends AnimatorListenerAdapter @Override public boolean onScaleBegin(ScaleGestureDetector detector) { - if (!mLauncher.isInState(NORMAL) - && !mLauncher.isInState(OVERVIEW)) { + if (isAccessibilityEnabled(mLauncher)) { + return false; + } + if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(OVERVIEW)) { // Don't listen for the pinch gesture if on all apps, widget picker, -1, etc. return false; } @@ -86,7 +92,7 @@ public class PinchToOverviewListener extends AnimatorListenerAdapter if (mWorkspace == null) { mWorkspace = mLauncher.getWorkspace(); } - if (mWorkspace.isSwitchingState() || mWorkspace.mScrollInteractionBegan) { + if (mWorkspace.isSwitchingState()) { // Don't listen for the pinch gesture while switching state, as it will cause a jump // once the state switching animation is complete. return false; diff --git a/quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java similarity index 59% rename from quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java rename to src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java index 1edf592b9b..e217f708ea 100644 --- a/quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java @@ -14,19 +14,16 @@ * limitations under the License. */ -package com.android.launcher3.config; +package com.android.launcher3.uioverrides; -import com.android.launcher3.LauncherState; -import com.android.launcher3.states.OverviewState; +import com.android.launcher3.Launcher; +import com.android.launcher3.VerticalSwipeController; +import com.android.launcher3.util.TouchController; -/** - * Defines a set of flags used to control various launcher behaviors - */ -public final class FeatureFlags extends BaseFlags { +public class UiFactory { - private FeatureFlags() {} - - public static LauncherState createOverviewState(int id) { - return new OverviewState(id); + public static TouchController[] createTouchControllers(Launcher launcher) { + return new TouchController[] { + new VerticalSwipeController(launcher), new PinchToOverviewListener(launcher)}; } }