Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add new constants for video scaling #11148

Merged
merged 8 commits into from
Sep 11, 2019
34 changes: 31 additions & 3 deletions android/modules/media/src/java/android/widget/TiVideoView8.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
}
}

private void constantDeprecationWarning(int constant)
{
StringBuilder warningMessage = new StringBuilder();
warningMessage.append("has been deprecated. Use ");
switch (constant) {
case MediaModule.VIDEO_SCALING_ASPECT_FILL:
warningMessage.insert(0, "Ti.Media.VIDEO_SCALING_ASPECT_FILL ");
warningMessage.insert(warningMessage.length(), "Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL");
break;
case MediaModule.VIDEO_SCALING_ASPECT_FIT:
warningMessage.insert(0, "Ti.Media.VIDEO_SCALING_ASPECT_FIT ");
warningMessage.insert(warningMessage.length(), "Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FIT");
break;
case MediaModule.VIDEO_SCALING_MODE_FILL:
warningMessage.insert(0, "Ti.Media.VIDEO_SCALING_MODE_FILL ");
warningMessage.insert(warningMessage.length(), "Ti.Media.VIDEO_SCALING_RESIZE");
break;
default:
return;
}
warningMessage.append(" instead.");
Log.w("VideoPlayerProxy", warningMessage.toString());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constantDeprecationWarning() method will end up appending strings every time the video view gets resized or a request-layout occurs. Even if you are using a non-deprecated constant. I'd prefer to avoid this. How about rewriting it to something like the below?

String message = null;
final String MESSAGE_FORMAT = "%s has been deprecated. Use %s instead.";
switch (constant) {
	case MediaModule.VIDEO_SCALING_ASPECT_FILL:
		message = String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_ASPECT_FILL", "Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL");
		break;
	case MediaModule.VIDEO_SCALING_ASPECT_FIT:
		message = String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_ASPECT_FIT", "Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FIT");
		break;
	case MediaModule.VIDEO_SCALING_MODE_FILL:
		message = String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_MODE_FILL", "Ti.Media.VIDEO_SCALING_RESIZE");
		break;
}
if (message != null) {
	Log.w("VideoPlayerProxy", message);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's way better, yes. I also changed the default value of mScalingType to use the new constant counter part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed the default value of mScalingType

I didn't even notice that. It's looking good now. :)

protected void measureVideo(int videoWidth, int videoHeight, int widthMeasureSpec, int heightMeasureSpec)
{
Log.e(TAG,
Expand All @@ -196,28 +220,32 @@ protected void measureVideo(int videoWidth, int videoHeight, int widthMeasureSpe
height = videoHeight;
break;
}
case MediaModule.VIDEO_SCALING_ASPECT_FILL: {
case MediaModule.VIDEO_SCALING_ASPECT_FILL:
case MediaModule.VIDEO_SCALING_RESIZE_ASPECT_FILL: {
if (videoWidth * height > width * videoHeight) {
width = height * videoWidth / videoHeight;
} else if (videoWidth * height < width * videoHeight) {
height = width * videoHeight / videoWidth;
}
break;
}
case MediaModule.VIDEO_SCALING_ASPECT_FIT: {
case MediaModule.VIDEO_SCALING_ASPECT_FIT:
case MediaModule.VIDEO_SCALING_RESIZE_ASPECT: {
if (videoWidth * height > width * videoHeight) {
height = width * videoHeight / videoWidth;
} else if (videoWidth * height < width * videoHeight) {
width = height * videoWidth / videoHeight;
}
break;
}
case MediaModule.VIDEO_SCALING_MODE_FILL: {
case MediaModule.VIDEO_SCALING_MODE_FILL:
case MediaModule.VIDEO_SCALING_RESIZE: {
width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec);
break;
}
}
constantDeprecationWarning(mScalingMode);
}
String model = Build.MODEL;
if (model != null && model.equals("SPH-P100")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public class MediaModule extends KrollModule implements Handler.Callback
public static final int VIDEO_SCALING_ASPECT_FIT = 2;
@Kroll.constant
public static final int VIDEO_SCALING_MODE_FILL = 3;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE = 4;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE_ASPECT = 5;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE_ASPECT_FILL = 6;

@Kroll.constant
public static final int VIDEO_CONTROL_DEFAULT = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TiC.PROPERTY_URL,
TiC.PROPERTY_INITIAL_PLAYBACK_TIME,
TiC.PROPERTY_DURATION,
"contentURL",
TiC.PROPERTY_CONTENT_URL,
TiC.PROPERTY_AUTOPLAY,
TiC.PROPERTY_END_PLAYBACK_TIME,
TiC.PROPERTY_PLAYABLE_DURATION,
Expand Down