Rearranging the code structure to allow replacing state logic.

Change-Id: I6f83d0f77045ba189f02dd465bf70ffc2a239aa1
diff --git a/Android.mk b/Android.mk
index 282b878..13540f4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -38,7 +38,7 @@
 
 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_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_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 344a4f9..0e7035a 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/quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
similarity index 61%
rename from quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java
rename to quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
index 1edf592..e43023a 100644
--- a/quickstep/src_flags/com/android/launcher3/config/FeatureFlags.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
@@ -14,19 +14,15 @@
  * 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)};
     }
 }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 1542703..ca75603 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -167,7 +167,6 @@
 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 @@
 
         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 @@
         mAppWidgetHost = null;
 
         TextKeyListener.getInstance().release();
-
-        ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
-                .removeAccessibilityStateChangeListener(this);
-
         WallpaperColorInfo.getInstance(this).setOnThemeChangeListener(null);
 
         LauncherAnimUtils.onDestroyActivity();
@@ -2190,11 +2182,6 @@
         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 25a698b..98568e4 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -44,7 +44,6 @@
 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 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 63c232d..bb09a9f 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -21,9 +21,9 @@
 
 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 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 fd94067..b99df71 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -179,7 +179,7 @@
      * @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 12c6916..b3dc176 100644
--- a/src/com/android/launcher3/VerticalSwipeController.java
+++ b/src/com/android/launcher3/VerticalSwipeController.java
@@ -75,7 +75,7 @@
 
     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 24c4704..32f96df 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -54,7 +54,6 @@
 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.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 4fbab39..a03dabb 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 @@
     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 @@
     // 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 0f0b20d..8189b23 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.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 @@
     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 @@
         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 @@
         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 @@
             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_config/com/android/launcher3/BuildConfig.java b/src_config/com/android/launcher3/BuildConfig.java
deleted file mode 100644
index 4df75a1..0000000
--- a/src_config/com/android/launcher3/BuildConfig.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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;
-
-/**
- * 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";
-}
diff --git a/src/com/android/launcher3/states/OverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java
similarity index 98%
copy from src/com/android/launcher3/states/OverviewState.java
copy to src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java
index 344a4f9..0e7035a 100644
--- a/src/com/android/launcher3/states/OverviewState.java
+++ b/src_ui_overrides/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/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 27edaf6..40bf057 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 @@
 
     @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 @@
         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/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java
new file mode 100644
index 0000000..e217f70
--- /dev/null
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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 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), new PinchToOverviewListener(launcher)};
+    }
+}