diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-10-17 12:05:38 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-10-21 11:10:21 -0700 |
commit | 210e174c9cb5bc4fdbacb1fa585865880ae9c81b (patch) | |
tree | 58893fa7ca288a3506f6a9f68aac1495f2a01a86 /src_ui_overrides | |
parent | 221823c33733938083eb5354a758638287f3c2bd (diff) | |
download | Launcher3-210e174c9cb5bc4fdbacb1fa585865880ae9c81b.tar.gz |
Subclassing Launcher instead of using UiFactory
Allows us to override only the required methods, instead of providing
a proxy method for everything
Change-Id: I816dcdb2a8d5432496050118ded0f2bbe7122cf7
Diffstat (limited to 'src_ui_overrides')
3 files changed, 36 insertions, 178 deletions
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/AllAppsSwipeController.java b/src_ui_overrides/com/android/launcher3/uioverrides/AllAppsSwipeController.java deleted file mode 100644 index bd6ea502e4..0000000000 --- a/src_ui_overrides/com/android/launcher3/uioverrides/AllAppsSwipeController.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.android.launcher3.uioverrides; - -import static com.android.launcher3.LauncherState.ALL_APPS; -import static com.android.launcher3.LauncherState.NORMAL; - -import android.view.MotionEvent; - -import com.android.launcher3.AbstractFloatingView; -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherState; -import com.android.launcher3.LauncherStateManager.AnimationComponents; -import com.android.launcher3.touch.AbstractStateChangeTouchController; -import com.android.launcher3.touch.SwipeDetector; -import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; - -/** - * TouchController to switch between NORMAL and ALL_APPS state. - */ -public class AllAppsSwipeController extends AbstractStateChangeTouchController { - - private MotionEvent mTouchDownEvent; - - public AllAppsSwipeController(Launcher l) { - super(l, SwipeDetector.VERTICAL); - } - - @Override - protected boolean canInterceptTouch(MotionEvent ev) { - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - mTouchDownEvent = ev; - } - if (mCurrentAnimation != null) { - // If we are already animating from a previous state, we can intercept. - return true; - } - if (AbstractFloatingView.getTopOpenView(mLauncher) != null) { - return false; - } - if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(ALL_APPS)) { - // Don't listen for the swipe gesture if we are already in some other state. - return false; - } - if (mLauncher.isInState(ALL_APPS) && !mLauncher.getAppsView().shouldContainerScroll(ev)) { - return false; - } - return true; - } - - @Override - protected LauncherState getTargetState(LauncherState fromState, boolean isDragTowardPositive) { - if (fromState == NORMAL && isDragTowardPositive) { - return ALL_APPS; - } else if (fromState == ALL_APPS && !isDragTowardPositive) { - return NORMAL; - } - return fromState; - } - - @Override - protected int getLogContainerTypeForNormalState(MotionEvent ev) { - return mLauncher.getDragLayer().isEventOverView(mLauncher.getHotseat(), mTouchDownEvent) ? - ContainerType.HOTSEAT : ContainerType.WORKSPACE; - } - - @Override - protected float initCurrentAnimation(@AnimationComponents int animComponents) { - float range = getShiftRange(); - long maxAccuracy = (long) (2 * range); - mCurrentAnimation = mLauncher.getStateManager() - .createAnimationToNewWorkspace(mToState, maxAccuracy, animComponents); - float startVerticalShift = mFromState.getVerticalProgress(mLauncher) * range; - float endVerticalShift = mToState.getVerticalProgress(mLauncher) * range; - float totalShift = endVerticalShift - startVerticalShift; - return 1 / totalShift; - } -} diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java b/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java new file mode 100644 index 0000000000..5407ea3182 --- /dev/null +++ b/src_ui_overrides/com/android/launcher3/uioverrides/ApiWrapper.java @@ -0,0 +1,36 @@ +/* + * 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 android.app.Activity; +import android.app.Person; +import android.content.pm.ShortcutInfo; + +import com.android.launcher3.Utilities; + +import java.io.PrintWriter; + +public class ApiWrapper { + + public static boolean dumpActivity(Activity activity, PrintWriter writer) { + return false; + } + + public static Person[] getPersons(ShortcutInfo si) { + return Utilities.EMPTY_PERSON_ARRAY; + } +} diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java deleted file mode 100644 index 606c9905f1..0000000000 --- a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java +++ /dev/null @@ -1,102 +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.uioverrides; - -import android.app.Activity; -import android.app.Person; -import android.content.Context; -import android.content.Intent; -import android.content.IntentSender; -import android.content.pm.ShortcutInfo; -import android.os.Bundle; -import android.os.CancellationSignal; - -import com.android.launcher3.DeviceProfile; -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherState.ScaleAndTranslation; -import com.android.launcher3.LauncherStateManager.StateHandler; -import com.android.launcher3.Utilities; -import com.android.launcher3.graphics.RotationMode; -import com.android.launcher3.util.TouchController; - -import java.io.PrintWriter; - -public class UiFactory { - - public static TouchController[] createTouchControllers(Launcher launcher) { - return new TouchController[] { - launcher.getDragController(), new AllAppsSwipeController(launcher)}; - } - - public static Runnable enableLiveUIChanges(Launcher l) { - return null; - } - - public static StateHandler[] getStateHandler(Launcher launcher) { - return new StateHandler[] { - launcher.getAllAppsController(), launcher.getWorkspace() }; - } - - public static void resetOverview(Launcher launcher) { } - - public static void onLauncherStateOrFocusChanged(Launcher launcher) { } - - public static void onCreate(Launcher launcher) { } - - public static void onStart(Launcher launcher) { } - - public static void onEnterAnimationComplete(Context context) {} - - public static void onLauncherStateOrResumeChanged(Launcher launcher) { } - - public static void onTrimMemory(Launcher launcher, int level) { } - - public static void useFadeOutAnimationForLauncherStart(Launcher launcher, - CancellationSignal cancellationSignal) { } - - public static boolean dumpActivity(Activity activity, PrintWriter writer) { - return false; - } - - public static void setBackButtonAlpha(Launcher launcher, float alpha, boolean animate) { } - - - public static ScaleAndTranslation getOverviewScaleAndTranslationForNormalState(Launcher l) { - return new ScaleAndTranslation(1.1f, 0f, 0f); - } - - public static RotationMode getRotationMode(DeviceProfile dp) { - return RotationMode.NORMAL; - } - - public static boolean startIntentSenderForResult(Activity activity, IntentSender intent, - int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, - Bundle options) { - return false; - } - - public static boolean startActivityForResult(Activity activity, Intent intent, int requestCode, - Bundle options) { - return false; - } - - public static void resetPendingActivityResults(Launcher launcher, int requestCode) { } - - public static Person[] getPersons(ShortcutInfo si) { - return Utilities.EMPTY_PERSON_ARRAY; - } -} |