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

Commit 20bfde36 authored by Tony Wickham's avatar Tony Wickham
Browse files

Show overview tiles in the orientation screenshot was taken

If the orientation of the screenshot doesn't match the thumbnail view,
we rotate the screenshot 90 degrees. We don't know whether a landscape
screenshot was seascape, so we just assume it's not (i.e. landscape
screenshots always rotate +90 degrees when shown in portrait).

Portrait screenshots rotate so that the bottom aligns with the nav bar,
e.g. rotate +90 in seascape and -90 in landscape

Currently guarded by the flag OVERVIEW_USE_SCREENSHOT_ORIENTATION.

Bug: 74552612
Change-Id: I438e45d89b54ffe41950c8bb9abdbb9a1c33aa40
parent 61857f3f
Loading
Loading
Loading
Loading
+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,28 +157,55 @@ 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 (!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(
@@ -191,6 +222,7 @@ public class TaskThumbnailView extends View {
                            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;
}