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

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

Merge changes I438e45d8,I1330cec3 into ub-launcher3-master

* changes:
  Show overview tiles in the orientation screenshot was taken
  Prevent edge gradient for screenshots in correct orientation
parents 0e4f33b3 20bfde36
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -373,11 +373,31 @@ public abstract class RecentsView<T extends BaseActivity>
        padding.bottom = profile.availableHeightPx - padding.top - sTempStableInsets.top
                - Math.round(overviewHeight);
        padding.left = padding.right = (int) ((profile.availableWidthPx - overviewWidth) / 2);

        // If the height ratio is larger than the width ratio, the screenshot will get cropped
        // at the bottom when swiping up. In this case, increase the top/bottom padding to make it
        // the same aspect ratio.
        Rect pageRect = new Rect();
        getPageRect(profile, context, pageRect, padding);
        float widthRatio = (float) pageRect.width() / taskWidth;
        float heightRatio = (float) pageRect.height() / taskHeight;
        if (heightRatio > widthRatio) {
            float additionalVerticalPadding = pageRect.height() - widthRatio * taskHeight;
            additionalVerticalPadding = Math.round(additionalVerticalPadding);
            padding.top += additionalVerticalPadding / 2;
            padding.bottom += additionalVerticalPadding / 2;
        }

        return padding;
    }

    public static void getPageRect(DeviceProfile grid, Context context, Rect outRect) {
        Rect targetPadding = getPadding(grid, context);
        getPageRect(grid, context, outRect, targetPadding);
    }

    private static void getPageRect(DeviceProfile grid, Context context, Rect outRect,
            Rect targetPadding) {
        Rect insets = grid.getInsets();
        outRect.set(
                targetPadding.left + insets.left,
+57 −25
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.View;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import com.android.quickstep.TaskOverlayFactory;
import com.android.quickstep.TaskOverlayFactory.TaskOverlay;
import com.android.systemui.shared.recents.model.Task;
@@ -146,6 +147,9 @@ public class TaskThumbnailView extends View {
                    (mThumbnailData.insets.top + mThumbnailData.insets.bottom) * scale;
            final float thumbnailScale;

            boolean rotate = false;
            final DeviceProfile profile = BaseActivity.fromContext(getContext())
                    .getDeviceProfile();
            if (getMeasuredWidth() == 0) {
                // If we haven't measured , skip the thumbnail drawing and only draw the background
                // color
@@ -153,29 +157,56 @@ public class TaskThumbnailView extends View {
            } else {
                final Configuration configuration =
                        getContext().getApplicationContext().getResources().getConfiguration();
                final DeviceProfile profile = BaseActivity.fromContext(getContext())
                        .getDeviceProfile();
                if (configuration.orientation == mThumbnailData.orientation) {
                    // If we are in the same orientation as the screenshot, just scale it to the
                    // width of the task view
                    thumbnailScale = getMeasuredWidth() / thumbnailWidth;
                } else if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
                    // Scale the landscape thumbnail up to app size, then scale that to the task
                    // view size to match other portrait screenshots
                } else {
                    if (FeatureFlags.OVERVIEW_USE_SCREENSHOT_ORIENTATION) {
                        rotate = true;
                        // Scale the height (will be width after rotation) to the width of this view
                        thumbnailScale = getMeasuredWidth() / thumbnailHeight;
                    } else {
                        if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
                            // Scale the landscape thumbnail up to app size, then scale that to the
                            // task view size to match other portrait screenshots
                            thumbnailScale = ((float) getMeasuredWidth() / profile.widthPx);
                        } else {
                            // Otherwise, scale the screenshot to fit 1:1 in the current orientation
                            thumbnailScale = 1;
                        }
                    }
                }
            }
            if (rotate) {
                int rotationDir = profile.isVerticalBarLayout() && !profile.isSeascape() ? -1 : 1;
                mMatrix.setRotate(90 * rotationDir);
                Rect thumbnailInsets  = mThumbnailData.insets;
                int newLeftInset = rotationDir == 1 ? thumbnailInsets.bottom : thumbnailInsets.top;
                int newTopInset = rotationDir == 1 ? thumbnailInsets.left : thumbnailInsets.right;
                mMatrix.postTranslate(-newLeftInset * scale, -newTopInset * scale);
                if (rotationDir == -1) {
                    // Crop the right/bottom side of the screenshot rather than left/top
                    float excessHeight = thumbnailWidth * thumbnailScale - getMeasuredHeight();
                    mMatrix.postTranslate(0, -excessHeight);
                }
                // Move the screenshot to the thumbnail window (rotation moved it out).
                if (rotationDir == 1) {
                    mMatrix.postTranslate(mThumbnailData.thumbnail.getHeight(), 0);
                } else {
                    mMatrix.postTranslate(0, mThumbnailData.thumbnail.getWidth());
                }
            } else {
                mMatrix.setTranslate(-mThumbnailData.insets.left * scale,
                        -mThumbnailData.insets.top * scale);
            }
            mMatrix.postScale(thumbnailScale, thumbnailScale);
            mBitmapShader.setLocalMatrix(mMatrix);

            float bitmapHeight = Math.max(thumbnailHeight * thumbnailScale, 0);
            Shader shader = mBitmapShader;
            if (bitmapHeight < getMeasuredHeight()) {
            if (!FeatureFlags.OVERVIEW_USE_SCREENSHOT_ORIENTATION) {
                float bitmapHeight = Math.max(thumbnailHeight * thumbnailScale, 0);
                if (Math.round(bitmapHeight) < getMeasuredHeight()) {
                    int color = mPaint.getColor();
                    LinearGradient fade = new LinearGradient(
                            0, bitmapHeight - mFadeLength, 0, bitmapHeight,
@@ -184,13 +215,14 @@ public class TaskThumbnailView extends View {
                }

                float bitmapWidth = Math.max(thumbnailWidth * thumbnailScale, 0);
            if (bitmapWidth < getMeasuredWidth()) {
                if (Math.round(bitmapWidth) < getMeasuredWidth()) {
                    int color = mPaint.getColor();
                    LinearGradient fade = new LinearGradient(
                            bitmapWidth - mFadeLength, 0, bitmapWidth, 0,
                            color & 0x00FFFFFF, color, Shader.TileMode.CLAMP);
                    shader = new ComposeShader(fade, shader, Mode.DST_OVER);
                }
            }
            mPaint.setShader(shader);
        }

+4 −0
Original line number Diff line number Diff line
@@ -51,4 +51,8 @@ abstract class BaseFlags {

    // When enabled shows a work profile tab in all apps
    public static final boolean ALL_APPS_TABS_ENABLED = true;

    // When true, overview shows screenshots in the orientation they were taken rather than
    // trying to make them fit the orientation the device is in.
    public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true;
}