Merge "Align task thumbnails to edge when cropped." into sc-dev
This commit is contained in:
commit
b4254cd504
3 files changed
+42
-20
No files matched your search
@@ -271,10 +271,12 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
|
||||
mSizeStrategy.calculateGridSize(mContext, mDp, mGridRect);
|
||||
mThumbnailData.rotation = mOrientationState.getDisplayRotation();
|
||||
|
||||
// mIsRecentsRtl is the inverse of TaskView RTL.
|
||||
boolean isRtlEnabled = !mIsRecentsRtl;
|
||||
mPositionHelper.updateThumbnailMatrix(
|
||||
mThumbnailPosition, mThumbnailData,
|
||||
mTaskRect.width(), mTaskRect.height(),
|
||||
mDp, mOrientationState.getRecentsActivityRotation());
|
||||
mDp, mOrientationState.getRecentsActivityRotation(), isRtlEnabled);
|
||||
mPositionHelper.getMatrix().invert(mInversePositionMatrix);
|
||||
|
||||
PagedOrientationHandler poh = mOrientationState.getOrientationHandler();
|
||||
|
||||
@@ -379,9 +379,10 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
|
||||
mThumbnailData.thumbnail.getHeight());
|
||||
int currentRotation = getTaskView().getRecentsView().getPagedViewOrientedState()
|
||||
.getRecentsActivityRotation();
|
||||
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
|
||||
mPreviewPositionHelper.updateThumbnailMatrix(mPreviewRect, mThumbnailData,
|
||||
getMeasuredWidth(), getMeasuredHeight(), mActivity.getDeviceProfile(),
|
||||
currentRotation);
|
||||
currentRotation, isRtl);
|
||||
|
||||
mBitmapShader.setLocalMatrix(mPreviewPositionHelper.mMatrix);
|
||||
mPaint.setShader(mBitmapShader);
|
||||
@@ -466,7 +467,8 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
|
||||
* Updates the matrix based on the provided parameters
|
||||
*/
|
||||
public void updateThumbnailMatrix(Rect thumbnailBounds, ThumbnailData thumbnailData,
|
||||
int canvasWidth, int canvasHeight, DeviceProfile dp, int currentRotation) {
|
||||
int canvasWidth, int canvasHeight, DeviceProfile dp, int currentRotation,
|
||||
boolean isRtl) {
|
||||
boolean isRotated = false;
|
||||
boolean isOrientationDifferent;
|
||||
|
||||
@@ -500,6 +502,17 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
|
||||
float availableHeight = surfaceHeight
|
||||
- (thumbnailClipHint.top + thumbnailClipHint.bottom);
|
||||
|
||||
if (isRotated) {
|
||||
float canvasAspect = canvasWidth / (float) canvasHeight;
|
||||
float availableAspect = availableHeight / availableWidth;
|
||||
// Do not rotate thumbnail if it would not improve fit
|
||||
if (Utilities.isRelativePercentDifferenceGreaterThan(canvasAspect,
|
||||
availableAspect, 0.1f)) {
|
||||
isRotated = false;
|
||||
isOrientationDifferent = false;
|
||||
}
|
||||
}
|
||||
|
||||
final float targetW, targetH;
|
||||
if (isOrientationDifferent) {
|
||||
targetW = canvasHeight;
|
||||
@@ -535,28 +548,25 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
|
||||
}
|
||||
}
|
||||
|
||||
// Update the clip hints
|
||||
float halfExtraW = (availableWidth - croppedWidth) / 2;
|
||||
thumbnailClipHint.left += halfExtraW;
|
||||
thumbnailClipHint.right += halfExtraW;
|
||||
if (thumbnailClipHint.left < 0) {
|
||||
thumbnailClipHint.right += thumbnailClipHint.left;
|
||||
thumbnailClipHint.left = 0;
|
||||
} else if (thumbnailClipHint.right < 0) {
|
||||
thumbnailClipHint.left += thumbnailClipHint.right;
|
||||
// Update the clip hints. Align to 0,0, crop the remaining.
|
||||
if (isRtl) {
|
||||
if (thumbnailClipHint.right < 0) {
|
||||
thumbnailClipHint.left += thumbnailClipHint.right;
|
||||
}
|
||||
thumbnailClipHint.right = 0;
|
||||
thumbnailClipHint.left += availableWidth - croppedWidth;
|
||||
} else {
|
||||
if (thumbnailClipHint.left < 0) {
|
||||
thumbnailClipHint.right += thumbnailClipHint.left;
|
||||
}
|
||||
thumbnailClipHint.left = 0;
|
||||
thumbnailClipHint.right += availableWidth - croppedWidth;
|
||||
}
|
||||
|
||||
float halfExtraH = (availableHeight - croppedHeight) / 2;
|
||||
thumbnailClipHint.top += halfExtraH;
|
||||
thumbnailClipHint.bottom += halfExtraH;
|
||||
if (thumbnailClipHint.top < 0) {
|
||||
thumbnailClipHint.bottom += thumbnailClipHint.top;
|
||||
thumbnailClipHint.top = 0;
|
||||
} else if (thumbnailClipHint.bottom < 0) {
|
||||
thumbnailClipHint.top += thumbnailClipHint.bottom;
|
||||
thumbnailClipHint.bottom = 0;
|
||||
}
|
||||
thumbnailClipHint.top = 0;
|
||||
thumbnailClipHint.bottom += availableHeight - croppedHeight;
|
||||
|
||||
thumbnailScale = targetW / (croppedWidth * scale);
|
||||
}
|
||||
|
||||
@@ -690,6 +690,16 @@ public final class Utilities {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the ratio of two quantities and returns whether that ratio is greater than the
|
||||
* provided bound. Order of quantities does not matter. Bound should be a decimal representation
|
||||
* of a percentage.
|
||||
*/
|
||||
public static boolean isRelativePercentDifferenceGreaterThan(float first, float second,
|
||||
float bound) {
|
||||
return (Math.abs(first - second) / Math.abs((first + second) / 2.0f)) > bound;
|
||||
}
|
||||
|
||||
private static class FixedSizeEmptyDrawable extends ColorDrawable {
|
||||
|
||||
private final int mSize;
|
||||
|
||||
Reference in new issue
Block a user