Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c723353 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Enabling swipe up from overview to all-apps

> Fixing wrong alpha interpolator when swiping down from all-apps

Change-Id: I7d4200c89797e5609fd7c4aa8681dea2ffd00bf7
parent d96072e6
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.uioverrides;

import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS;
import static com.android.launcher3.allapps.DiscoveryBounce.APPS_VIEW_SHOWN;
import static com.android.launcher3.anim.Interpolators.DEACCEL_2;

import android.view.View;

@@ -33,6 +34,13 @@ public class AllAppsState extends LauncherState {

    private static final int STATE_FLAGS = FLAG_DISABLE_ACCESSIBILITY;

    private static final PageAlphaProvider PAGE_ALPHA_PROVIDER = new PageAlphaProvider(DEACCEL_2) {
        @Override
        public float getPageAlpha(int pageIndex) {
            return 0;
        }
    };

    public AllAppsState(int id) {
        super(id, ContainerType.ALLAPPS, ALL_APPS_TRANSITION_MS, 0f, STATE_FLAGS);
    }
@@ -65,6 +73,6 @@ public class AllAppsState extends LauncherState {

    @Override
    public PageAlphaProvider getWorkspacePageAlphaProvider(Launcher launcher) {
        return (i) -> 0;
        return PAGE_ALPHA_PROVIDER;
    }
}
+61 −0
Original line number Diff line number Diff line
/*
 * 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.LauncherState.OVERVIEW;

import android.view.MotionEvent;

import com.android.launcher3.Launcher;
import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.VerticalSwipeController;

/**
 * Extension of {@link VerticalSwipeController} which allows swipe up from OVERVIEW to ALL_APPS
 * Note that the swipe down is handled by {@link TwoStepSwipeController}.
 */
public class OverviewSwipeUpController extends VerticalSwipeController {

    public OverviewSwipeUpController(Launcher l) {
        super(l, OVERVIEW);
    }

    @Override
    protected boolean shouldInterceptTouch(MotionEvent ev) {
        return mLauncher.isInState(OVERVIEW) && mLauncher.getDragLayer().isEventOverHotseat(ev);
    }

    @Override
    protected int getSwipeDirection(MotionEvent ev) {
        return SwipeDetector.DIRECTION_POSITIVE;
    }

    @Override
    protected void onTransitionComplete(boolean wasFling, boolean stateChanged) {
        if (stateChanged) {
            // Transition complete. log the action
            mLauncher.getUserEventDispatcher().logActionOnContainer(
                    wasFling ? Touch.FLING : Touch.SWIPE,
                    Direction.UP,
                    ContainerType.OVERVIEW,
                    mLauncher.getWorkspace().getCurrentPage());
        }

    }
}
+9 −1
Original line number Diff line number Diff line
@@ -30,7 +30,15 @@ import com.android.launcher3.widget.WidgetsFullSheet;
public class UiFactory {

    public static TouchController[] createTouchControllers(Launcher launcher) {

        if (launcher.getDeviceProfile().isVerticalBarLayout()) {
            // TODO: Allow swipe up from overview in transposed layout
            return new TouchController[] {new TwoStepSwipeController(launcher)};
        } else {
            return new TouchController[] {
                    new TwoStepSwipeController(launcher),
                    new OverviewSwipeUpController(launcher)};
        }
    }

    public static AccessibilityDelegate newPageIndicatorAccessibilityDelegate() {
+25 −5
Original line number Diff line number Diff line
@@ -19,7 +19,10 @@ import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;

import static com.android.launcher3.anim.Interpolators.ACCEL_2;

import android.view.View;
import android.view.animation.Interpolator;

import com.android.launcher3.uioverrides.AllAppsState;
import com.android.launcher3.states.SpringLoadedState;
@@ -41,7 +44,13 @@ public class LauncherState {
    protected static final int FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED = 1 << 4;
    protected static final int FLAG_DISABLE_PAGE_CLIPPING = 1 << 5;

    protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER = (i) -> 1f;
    protected static final PageAlphaProvider DEFAULT_ALPHA_PROVIDER =
            new PageAlphaProvider(ACCEL_2) {
                @Override
                public float getPageAlpha(int pageIndex) {
                    return 1;
                }
            };

    private static final LauncherState[] sAllStates = new LauncherState[4];

@@ -149,16 +158,27 @@ public class LauncherState {
        if (this != NORMAL || !launcher.getDeviceProfile().shouldFadeAdjacentWorkspaceScreens()) {
            return DEFAULT_ALPHA_PROVIDER;
        }
        int centerPage = launcher.getWorkspace().getPageNearestToCenterOfScreen();
        return (childIndex) ->  childIndex != centerPage ? 0 : 1f;
        final int centerPage = launcher.getWorkspace().getPageNearestToCenterOfScreen();
        return new PageAlphaProvider(ACCEL_2) {
            @Override
            public float getPageAlpha(int pageIndex) {
                return  pageIndex != centerPage ? 0 : 1f;
            }
        };
    }

    protected static void dispatchWindowStateChanged(Launcher launcher) {
        launcher.getWindow().getDecorView().sendAccessibilityEvent(TYPE_WINDOW_STATE_CHANGED);
    }

    public interface PageAlphaProvider {
    public static abstract class PageAlphaProvider {

        public final Interpolator interpolator;

        public PageAlphaProvider(Interpolator interpolator) {
            this.interpolator = interpolator;
        }

        float getPageAlpha(int pageIndex);
        public abstract float getPageAlpha(int pageIndex);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class WorkspaceStateTransitionAnimation {
        propertySetter.setInt(cl.getScrimBackground(),
                DRAWABLE_ALPHA, state.hasScrim ? 255 : 0, Interpolators.ZOOM_IN);
        propertySetter.setFloat(cl.getShortcutsAndWidgets(), View.ALPHA,
                pageAlphaProvider.getPageAlpha(childIndex), Interpolators.DEACCEL_2);
                pageAlphaProvider.getPageAlpha(childIndex), pageAlphaProvider.interpolator);
    }

    public static class PropertySetter {
Loading