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

Commit a4e8763d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Updating the card size logic" into ub-launcher3-master

parents eec189c0 d792a772
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
    <dimen name="task_thumbnail_icon_size">48dp</dimen>
    <dimen name="task_menu_background_radius">12dp</dimen>
    <dimen name="task_corner_radius">2dp</dimen>
    <dimen name="task_fade_length">20dp</dimen>
    <dimen name="recents_page_spacing">10dp</dimen>

    <!-- The speed in dp/s at which the user needs to be scrolling in recents such that we start
@@ -37,4 +36,13 @@
    <dimen name="recents_empty_message_text_size">16sp</dimen>
    <dimen name="recents_empty_message_text_padding">16dp</dimen>

    <!-- Total space (start + end) between the task card and the edge of the screen
         in various configurations -->
    <dimen name="task_card_vert_space">40dp</dimen>
    <dimen name="portrait_task_card_horz_space">136dp</dimen>
    <dimen name="landscape_task_card_horz_space">200dp</dimen>
    <dimen name="multi_window_task_card_horz_space">100dp</dimen>
    <!-- Copied from framework resource:
       docked_stack_divider_thickness - 2 * docked_stack_divider_insets -->
    <dimen name="multi_window_task_divider_size">10dp</dimen>
</resources>
+2 −24
Original line number Diff line number Diff line
@@ -19,13 +19,11 @@ import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
import static com.android.launcher3.anim.Interpolators.DEACCEL_2;
import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE;

import android.graphics.Rect;
import android.view.View;

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;
import com.android.quickstep.views.RecentsView;

@@ -47,14 +45,8 @@ public class OverviewState extends LauncherState {

    @Override
    public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
        Rect pageRect = new Rect();
        RecentsView.getPageRect(launcher.getDeviceProfile(), launcher, pageRect);

        if (launcher.getWorkspace().getNormalChildWidth() <= 0 || pageRect.isEmpty()) {
            return super.getWorkspaceScaleAndTranslation(launcher);
        }

        return getScaleAndTranslationForPageRect(launcher, pageRect);
        // TODO: provide a valid value
        return new float[]{1, 0, -launcher.getDeviceProfile().hotseatBarSizePx / 2};
    }

    @Override
@@ -93,20 +85,6 @@ public class OverviewState extends LauncherState {
        };
    }

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

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

        float halfHeight = ws.getExpectedHeight() / 2;
        float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
        float translationY = pageRect.top - childTop;

        return new float[] {scale, 0, translationY};
    }

    @Override
    public int getVisibleElements(Launcher launcher) {
        if (launcher.getDeviceProfile().isVerticalBarLayout()) {
+3 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.quickstep.fallback.FallbackRecentsView;
import com.android.quickstep.util.RemoteAnimationProvider;
import com.android.quickstep.views.LauncherLayoutListener;
import com.android.quickstep.views.LauncherRecentsView;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -122,7 +123,7 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {

        @Override
        public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect) {
            RecentsView.getPageRect(dp, context, outRect);
            LauncherRecentsView.getPageRect(dp, context, outRect);
            if (dp.isVerticalBarLayout()) {
                Rect targetInsets = dp.getInsets();
                int hotseatInset = dp.isSeascape() ? targetInsets.left : targetInsets.right;
@@ -271,7 +272,7 @@ public interface ActivityControlHelper<T extends BaseDraggingActivity> {

        @Override
        public int getSwipeUpDestinationAndLength(DeviceProfile dp, Context context, Rect outRect) {
            FallbackRecentsView.getCenterPageRect(dp, context, outRect);
            FallbackRecentsView.getPageRect(dp, context, outRect);
            if (dp.isVerticalBarLayout()) {
                Rect targetInsets = dp.getInsets();
                int hotseatInset = dp.isSeascape() ? targetInsets.left : targetInsets.right;
+12 −23
Original line number Diff line number Diff line
@@ -18,15 +18,16 @@ package com.android.quickstep.fallback;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.annotation.AnyThread;
import android.util.AttributeSet;
import android.view.View;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.quickstep.RecentsActivity;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.views.RecentsView;

public class FallbackRecentsView extends RecentsView<RecentsActivity> implements Insettable {
public class FallbackRecentsView extends RecentsView<RecentsActivity> {

    public FallbackRecentsView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
@@ -56,30 +57,18 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity> implements
    }

    @Override
    public void setInsets(Rect insets) {
        mInsets.set(insets);
        DeviceProfile dp = mActivity.getDeviceProfile();
        Rect padding = getPadding(dp, getContext());
        verticalCenter(padding, dp);
        setPadding(padding.left, padding.top, padding.right, padding.bottom);
    }

    private static void verticalCenter(Rect padding, DeviceProfile dp) {
        Rect insets = dp.getInsets();
        int totalSpace = (padding.top + padding.bottom - insets.top - insets.bottom) / 2;
        padding.top = insets.top + totalSpace;
        padding.bottom = insets.bottom + totalSpace;
    public void draw(Canvas canvas) {
        maybeDrawEmptyMessage(canvas);
        super.draw(canvas);
    }

    public static void getCenterPageRect(DeviceProfile grid, Context context, Rect outRect) {
        Rect targetPadding = getPadding(grid, context);
        verticalCenter(targetPadding, grid);
        getPageRect(grid, context, outRect, targetPadding);
    @Override
    protected void getTaskSize(DeviceProfile dp, Rect outRect) {
        LayoutUtils.calculateTaskSize(getContext(), dp, 0, outRect);
    }

    @Override
    public void draw(Canvas canvas) {
        maybeDrawEmptyMessage(canvas);
        super.draw(canvas);
    @AnyThread
    public static void getPageRect(DeviceProfile grid, Context context, Rect outRect) {
        LayoutUtils.calculateTaskSize(context, grid, 0, outRect);
    }
}
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.quickstep.util;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.RectF;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;

public class LayoutUtils {

    public static void calculateLauncherTaskSize(Context context, DeviceProfile dp, Rect outRect) {
        float extraSpace = dp.isVerticalBarLayout() ? 0 : dp.hotseatBarSizePx;
        calculateTaskSize(context, dp, extraSpace, outRect);
    }

    public static void calculateTaskSize(Context context, DeviceProfile dp,
            float extraVerticalSpace, Rect outRect) {
        float taskWidth, taskHeight, paddingHorz;
        Resources res = context.getResources();
        Rect insets = dp.getInsets();

        if (dp.isMultiWindowMode) {
            DeviceProfile fullDp = dp.getFullScreenProfile();
            // Use availableWidthPx and availableHeightPx instead of widthPx and heightPx to
            // account for system insets
            taskWidth = fullDp.availableWidthPx;
            taskHeight = fullDp.availableHeightPx;
            float halfDividerSize = res.getDimension(R.dimen.multi_window_task_divider_size) / 2;

            if (fullDp.isLandscape) {
                taskWidth = taskWidth / 2 - halfDividerSize;
            } else {
                taskHeight = taskHeight / 2 - halfDividerSize;
            }
            paddingHorz = res.getDimension(R.dimen.multi_window_task_card_horz_space);
        } else {
            taskWidth = dp.availableWidthPx;
            taskHeight = dp.availableHeightPx;
            paddingHorz = res.getDimension(dp.isVerticalBarLayout()
                    ? R.dimen.landscape_task_card_horz_space
                    : R.dimen.portrait_task_card_horz_space);
        }

        float topIconMargin = res.getDimension(R.dimen.task_thumbnail_top_margin);
        float paddingVert = res.getDimension(R.dimen.task_card_vert_space);

        // Note this should be same as dp.availableWidthPx and dp.availableHeightPx unless
        // we override the insets ourselves.
        int launcherVisibleWidth = dp.widthPx - insets.left - insets.right;
        int launcherVisibleHeight = dp.heightPx - insets.top - insets.bottom;

        float availableHeight = launcherVisibleHeight
                - topIconMargin - extraVerticalSpace - paddingVert;
        float availableWidth = launcherVisibleWidth - paddingHorz;

        float scale = Math.min(availableWidth / taskWidth, availableHeight / taskHeight);
        float outWidth = scale * taskWidth;
        float outHeight = scale * taskHeight;

        // Center in the visible space
        float x = insets.left + (taskWidth - outWidth) / 2;
        float y = insets.top + Math.max(topIconMargin,
                (launcherVisibleHeight - extraVerticalSpace - outHeight) / 2);
        outRect.set(Math.round(x), Math.round(y),
                Math.round(x + outWidth), Math.round(y + outHeight));
    }
}
Loading