Merge pull request #3187 from stellabei/stellabei/aspect-ratio-crop

Support zoom mode for AspectRatioFrameLayout
This commit is contained in:
ojw28 2017-09-04 10:31:21 +01:00 committed by GitHub
commit 21363d2f8e

View File

@ -32,7 +32,7 @@ public final class AspectRatioFrameLayout extends FrameLayout {
* Resize modes for {@link AspectRatioFrameLayout}. * Resize modes for {@link AspectRatioFrameLayout}.
*/ */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({RESIZE_MODE_FIT, RESIZE_MODE_FIXED_WIDTH, RESIZE_MODE_FIXED_HEIGHT, RESIZE_MODE_FILL}) @IntDef({RESIZE_MODE_FIT, RESIZE_MODE_FIXED_WIDTH, RESIZE_MODE_FIXED_HEIGHT, RESIZE_MODE_FILL, RESIZE_MODE_ZOOM})
public @interface ResizeMode {} public @interface ResizeMode {}
/** /**
@ -51,6 +51,10 @@ public final class AspectRatioFrameLayout extends FrameLayout {
* The specified aspect ratio is ignored. * The specified aspect ratio is ignored.
*/ */
public static final int RESIZE_MODE_FILL = 3; public static final int RESIZE_MODE_FILL = 3;
/**
* Either height or width is increased to obtain the desired aspect ratio.
*/
public static final int RESIZE_MODE_ZOOM = 4;
/** /**
* The {@link FrameLayout} will not resize itself if the fractional difference between its natural * The {@link FrameLayout} will not resize itself if the fractional difference between its natural
@ -96,6 +100,15 @@ public final class AspectRatioFrameLayout extends FrameLayout {
} }
} }
/**
* Gets the resize mode.
*
* @return The resize mode.
*/
public int getResizeMode() {
return this.resizeMode;
}
/** /**
* Sets the resize mode. * Sets the resize mode.
* *
@ -132,6 +145,13 @@ public final class AspectRatioFrameLayout extends FrameLayout {
case RESIZE_MODE_FIXED_HEIGHT: case RESIZE_MODE_FIXED_HEIGHT:
width = (int) (height * videoAspectRatio); width = (int) (height * videoAspectRatio);
break; break;
case RESIZE_MODE_ZOOM:
if (videoAspectRatio > viewAspectRatio) {
width = (int) (height * videoAspectRatio);
} else {
height = (int) (width / videoAspectRatio);
}
break;
default: default:
if (aspectDeformation > 0) { if (aspectDeformation > 0) {
height = (int) (width / videoAspectRatio); height = (int) (width / videoAspectRatio);