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

Commit e15e2a82 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding an empty page in Recents view corresponding to workspace

The page is aligned to the workspace card and shows a widgets button
in the empty region

Change-Id: I479c47a2fbac4b3ef1aaf833d9fe82b5d7e10ddc
parent 9558a884
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 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.
*/
-->

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item android:id="@android:id/mask">
        <color android:color="#ffffffff" />
    </item>

    <item>
        <color android:color="#77FFFFFF" />
    </item>
</ripple>
+33 −1
Original line number Diff line number Diff line
@@ -22,4 +22,36 @@
    android:clipChildren="false"
    android:clipToPadding="false"
    android:alpha="0.0"
    android:visibility="invisible" />
 No newline at end of file
    android:visibility="invisible" >

    <com.android.launcher3.uioverrides.WorkspaceCard
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="@dimen/task_thumbnail_top_margin" >

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/workspace_click_target" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/widget_button"
            android:background="@drawable/bg_workspace_card_button" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/widget_button_text"
                android:drawableStart="@drawable/ic_widget"
                android:textColor="?attr/workspaceTextColor"
                android:drawableTint="?attr/workspaceTextColor"
                android:gravity="center"
                android:layout_gravity="center"
                android:drawablePadding="20dp" />
        </FrameLayout>

    </com.android.launcher3.uioverrides.WorkspaceCard>

</com.android.quickstep.RecentsView>
 No newline at end of file
+22 −11
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.View;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.quickstep.RecentsView;
@@ -31,8 +32,9 @@ import com.android.quickstep.RecentsView;
 */
public class OverviewState extends LauncherState {

    private static final int STATE_FLAGS = FLAG_SHOW_SCRIM
            | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED;
    public static final float WORKSPACE_SCALE_ON_SCROLL = 0.9f;

    private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED;

    public OverviewState(int id) {
        super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, 1f, STATE_FLAGS);
@@ -42,18 +44,15 @@ public class OverviewState extends LauncherState {
    public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
        Rect pageRect = new Rect();
        RecentsView.getPageRect(launcher, pageRect);
        Workspace ws = launcher.getWorkspace();
        float childWidth = ws.getNormalChildWidth();
        if (childWidth <= 0 || pageRect.isEmpty()) {
        if (launcher.getWorkspace().getNormalChildWidth() <= 0 || pageRect.isEmpty()) {
            return super.getWorkspaceScaleAndTranslation(launcher);
        }

        Rect insets = launcher.getDragLayer().getInsets();
        float scale = pageRect.width() / childWidth;

        float halfHeight = ws.getHeight() / 2;
        float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
        return new float[] {scale, pageRect.top - childTop};
        RecentsView rv = launcher.getOverviewPanel();
        if (rv.getCurrentPage() >= rv.getFirstTaskIndex()) {
            Utilities.scaleRectAboutCenter(pageRect, WORKSPACE_SCALE_ON_SCROLL);
        }
        return getScaleAndTranslationForPageRect(launcher, pageRect);
    }

    @Override
@@ -77,4 +76,16 @@ public class OverviewState extends LauncherState {
    public View getFinalFocus(Launcher launcher) {
        return launcher.getOverviewPanel();
    }

    public static float[] getScaleAndTranslationForPageRect(Launcher launcher, Rect pageRect) {
        Workspace ws = launcher.getWorkspace();
        float childWidth = ws.getNormalChildWidth();

        Rect insets = launcher.getDragLayer().getInsets();
        float scale = pageRect.width() / childWidth;

        float halfHeight = ws.getHeight() / 2;
        float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
        return new float[] {scale, pageRect.top - childTop};
    }
}
+24 −5
Original line number Diff line number Diff line
@@ -30,10 +30,13 @@ import com.android.launcher3.anim.Interpolators;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.RecentsView;

import static com.android.launcher3.LauncherState.OVERVIEW;

public class RecentsViewStateController implements StateHandler {

    private final Launcher mLauncher;
    private final RecentsView mRecentsView;
    private final WorkspaceCard mWorkspaceCard;

    private final AnimatedFloat mTransitionProgress = new AnimatedFloat(this::applyProgress);
    // The fraction representing the visibility of the RecentsView. This allows delaying the
@@ -44,24 +47,40 @@ public class RecentsViewStateController implements StateHandler {
        mLauncher = launcher;
        mRecentsView = launcher.getOverviewPanel();
        mRecentsView.setStateController(this);

        mWorkspaceCard = (WorkspaceCard) mRecentsView.getChildAt(0);
        mWorkspaceCard.setup(launcher);
    }

    @Override
    public void setState(LauncherState state) {
        setVisibility(state == LauncherState.OVERVIEW);
        setTransitionProgress(state == LauncherState.OVERVIEW ? 1 : 0);
        mWorkspaceCard.setWorkspaceScrollingEnabled(state == OVERVIEW);
        setVisibility(state == OVERVIEW);
        setTransitionProgress(state == OVERVIEW ? 1 : 0);
    }

    @Override
    public void setStateWithAnimation(LauncherState toState,
    public void setStateWithAnimation(final LauncherState toState,
            AnimatorSetBuilder builder, AnimationConfig config) {
        ObjectAnimator progressAnim =
                mTransitionProgress.animateToValue(toState == LauncherState.OVERVIEW ? 1 : 0);
                mTransitionProgress.animateToValue(toState == OVERVIEW ? 1 : 0);
        progressAnim.setDuration(config.duration);
        progressAnim.setInterpolator(Interpolators.LINEAR);
        progressAnim.addListener(new AnimationSuccessListener() {

            @Override
            public void onAnimationStart(Animator animation) {
                mWorkspaceCard.setWorkspaceScrollingEnabled(false);
            }

            @Override
            public void onAnimationSuccess(Animator animator) {
                mWorkspaceCard.setWorkspaceScrollingEnabled(toState == OVERVIEW);
            }
        });
        builder.play(progressAnim);

        ObjectAnimator visibilityAnim = animateVisibility(toState == LauncherState.OVERVIEW);
        ObjectAnimator visibilityAnim = animateVisibility(toState == OVERVIEW);
        visibilityAnim.setDuration(config.duration);
        visibilityAnim.setInterpolator(Interpolators.LINEAR);
        builder.play(visibilityAnim);
+186 −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.NORMAL;
import static com.android.launcher3.uioverrides.OverviewState.WORKSPACE_SCALE_ON_SCROLL;
import static com.android.quickstep.RecentsView.SCROLL_TYPE_WORKSPACE;

import android.animation.FloatArrayEvaluator;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;

import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.widget.WidgetsFullSheet;
import com.android.quickstep.RecentsView;
import com.android.quickstep.RecentsView.PageCallbacks;
import com.android.quickstep.RecentsView.ScrollState;

public class WorkspaceCard extends FrameLayout implements PageCallbacks, OnClickListener {

    private final Rect mTempRect = new Rect();
    private final float[] mEvaluatedFloats = new float[2];
    private final FloatArrayEvaluator mEvaluator = new FloatArrayEvaluator(mEvaluatedFloats);

    // UI related information
    private float[] mScaleAndTranslatePage0, mScaleAndTranslatePage1;
    private boolean mUIDataValid = false;

    private Launcher mLauncher;
    private Workspace mWorkspace;

    private boolean mIsWorkspaceScrollingEnabled;

    private View mWorkspaceClickTarget;
    private View mWidgetsButton;

    public WorkspaceCard(Context context) {
        super(context);
    }

    public WorkspaceCard(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public WorkspaceCard(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        mWorkspaceClickTarget = findViewById(R.id.workspace_click_target);
        mWidgetsButton = findViewById(R.id.widget_button);

        mWorkspaceClickTarget.setOnClickListener(this);
        mWidgetsButton.setOnClickListener(this);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // We measure the dimensions of the PagedView to be larger than the pages so that when we
        // zoom out (and scale down), the view is still contained in the parent
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        if (widthMode == MeasureSpec.UNSPECIFIED || heightMode == MeasureSpec.UNSPECIFIED) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }

        // Return early if we aren't given a proper dimension
        if (widthSize <= 0 || heightSize <= 0) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }

        int childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);

        int pageHeight = mWorkspace.getNormalChildHeight() * widthSize /
                mWorkspace.getNormalChildWidth();
        mWorkspaceClickTarget.measure(childWidthSpec,
                MeasureSpec.makeMeasureSpec(pageHeight, MeasureSpec.EXACTLY));

        int buttonHeight = heightSize - pageHeight - getPaddingTop() - getPaddingBottom();
        mWidgetsButton.measure(childWidthSpec,
                MeasureSpec.makeMeasureSpec(buttonHeight, MeasureSpec.EXACTLY));

        setMeasuredDimension(widthSize, heightSize);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int y1 = getPaddingTop();
        int y2 = y1 + mWorkspaceClickTarget.getMeasuredHeight();

        mWorkspaceClickTarget.layout(getPaddingLeft(), y1,
                mWorkspaceClickTarget.getMeasuredWidth(), y2);

        mWidgetsButton.layout(getPaddingLeft(), y2, mWidgetsButton.getMeasuredWidth(),
                mWidgetsButton.getMeasuredHeight() + y2);

        mUIDataValid = false;
    }

    @Override
    public void onClick(View view) {
        if (view == mWorkspaceClickTarget) {
            mLauncher.getStateManager().goToState(NORMAL);
        } else if (view == mWidgetsButton) {
            WidgetsFullSheet.show(mLauncher, true);
        }
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mUIDataValid = false;
    }

    public void setup(Launcher launcher) {
        mLauncher = launcher;
        mWorkspace = mLauncher.getWorkspace();
    }

    public void setWorkspaceScrollingEnabled(boolean isEnabled) {
        mIsWorkspaceScrollingEnabled = isEnabled;
    }

    @Override
    public int onPageScroll(ScrollState scrollState) {
        setTranslationX(scrollState.distanceFromScreenCenter);

        float factor = scrollState.linearInterpolation;
        float scale = factor * WORKSPACE_SCALE_ON_SCROLL + (1 - factor);
        setScaleX(scale);
        setScaleY(scale);

        if (mIsWorkspaceScrollingEnabled) {
            initUiData();

            mEvaluator.evaluate(factor, mScaleAndTranslatePage0, mScaleAndTranslatePage1);
            mWorkspace.setScaleX(mEvaluatedFloats[0]);
            mWorkspace.setScaleY(mEvaluatedFloats[0]);
            mWorkspace.setTranslationY(mEvaluatedFloats[1]);
        }
        return SCROLL_TYPE_WORKSPACE;
    }

    private void initUiData() {
        if (mUIDataValid && mScaleAndTranslatePage0 != null) {
            return;
        }

        RecentsView.getPageRect(mLauncher, mTempRect);
        mScaleAndTranslatePage0 = OverviewState
                .getScaleAndTranslationForPageRect(mLauncher, mTempRect);
        Rect scaledDown = new Rect(mTempRect);
        Utilities.scaleRectAboutCenter(scaledDown, WORKSPACE_SCALE_ON_SCROLL);
        mScaleAndTranslatePage1 = OverviewState
                .getScaleAndTranslationForPageRect(mLauncher, scaledDown);
        mUIDataValid = true;
    }
}
Loading