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

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

Merge "Calculate task height directly off portrait height" into ub-launcher3-master

parents c8f33f7a 3172c681
Loading
Loading
Loading
Loading
+0 −42
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

/**
 * Layout manager for task list that restricts child height based off the max number of tasks the
 * recycler view should hold and the height of the recycler view.
 */
public final class TaskLayoutManager extends LinearLayoutManager {

    public TaskLayoutManager(Context context, int vertical, boolean b) {
        super(context, vertical, b);
    }

    @Override
    public void measureChildWithMargins(@NonNull View child, int widthUsed, int heightUsed) {
        // Request child view takes up 1 / MAX_TASKS of the total view height.
        int heightUsedByView = (int) (getHeight() *
                (TaskAdapter.MAX_TASKS_TO_DISPLAY - 1.0f) / TaskAdapter.MAX_TASKS_TO_DISPLAY);
        super.measureChildWithMargins(child, widthUsed, heightUsedByView);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener;
@@ -54,7 +55,6 @@ import com.android.quickstep.RecentsToActivityHelper;
import com.android.quickstep.TaskActionController;
import com.android.quickstep.TaskAdapter;
import com.android.quickstep.TaskHolder;
import com.android.quickstep.TaskLayoutManager;
import com.android.quickstep.TaskListLoader;
import com.android.quickstep.TaskSwipeCallback;
import com.android.systemui.shared.recents.model.Task;
@@ -155,7 +155,7 @@ public final class IconRecentsView extends FrameLayout {
            recyclerViewParams.height = getTaskListHeight(mDeviceProfile);
            mTaskRecyclerView.setAdapter(mTaskAdapter);
            mTaskRecyclerView.setLayoutManager(
                    new TaskLayoutManager(mContext, VERTICAL, true /* reverseLayout */));
                    new LinearLayoutManager(mContext, VERTICAL, true /* reverseLayout */));
            ItemTouchHelper helper = new ItemTouchHelper(
                    new TaskSwipeCallback(mTaskActionController));
            helper.attachToRecyclerView(mTaskRecyclerView);
+9 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.quickstep.views;

import static com.android.quickstep.views.TaskLayoutUtils.getTaskHeight;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -88,6 +90,13 @@ public final class TaskItemView extends LinearLayout {
        CONTENT_TRANSITION_PROGRESS.setValue(this, 1.0f);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int taskHeight = getTaskHeight(getContext());
        int newHeightSpec = MeasureSpec.makeMeasureSpec(taskHeight,MeasureSpec.EXACTLY);
        super.onMeasure(widthMeasureSpec, newHeightSpec);
    }

    /**
     * Resets task item view to empty, loading UI.
     */
+21 −1
Original line number Diff line number Diff line
@@ -15,8 +15,12 @@
 */
package com.android.quickstep.views;

import static com.android.quickstep.TaskAdapter.MAX_TASKS_TO_DISPLAY;

import android.content.Context;

import com.android.launcher3.DeviceProfile;
import com.android.quickstep.TaskAdapter;
import com.android.launcher3.InvariantDeviceProfile;

/**
 * Utils to determine dynamically task and view sizes based off the device height and width.
@@ -30,10 +34,26 @@ public final class TaskLayoutUtils {
    private TaskLayoutUtils() {}

    public static int getTaskListHeight(DeviceProfile dp) {
        // TODO: Remove this as task height is determined directly from device height.
        int clearAllSpace = getClearAllButtonHeight(dp) + 2 * getClearAllButtonTopBottomMargin(dp);
        return getDeviceLongWidth(dp) - clearAllSpace;
    }

    /**
     * Calculate task height based off the available height in portrait mode such that when the
     * recents list is full, the total height fills in the available device height perfectly. In
     * landscape mode, we keep the same task height so that tasks scroll off the top.
     *
     * @param context current context
     * @return task height
     */
    public static int getTaskHeight(Context context) {
        final int availableHeight =
                InvariantDeviceProfile.INSTANCE.get(context).portraitProfile.availableHeightPx;
        // TODO: Take into account clear all button height for task height
        return (int) (availableHeight * 1.0f / MAX_TASKS_TO_DISPLAY);
    }

    public static int getClearAllButtonHeight(DeviceProfile dp) {
        return (int) (BUTTON_TO_DEVICE_HEIGHT_RATIO * getDeviceLongWidth(dp));
    }