use of android.util.Rational in project android_frameworks_base by crdroidandroid.
the class RationalTest method testSerialize.
@SmallTest
public void testSerialize() throws ClassNotFoundException, IOException {
/*
* Check correct [de]serialization
*/
assertEqualsAfterSerializing(ZERO);
assertEqualsAfterSerializing(NaN);
assertEqualsAfterSerializing(NEGATIVE_INFINITY);
assertEqualsAfterSerializing(POSITIVE_INFINITY);
assertEqualsAfterSerializing(UNIT);
assertEqualsAfterSerializing(new Rational(100, 200));
assertEqualsAfterSerializing(new Rational(-100, 200));
assertEqualsAfterSerializing(new Rational(5, 1));
assertEqualsAfterSerializing(new Rational(Integer.MAX_VALUE, Integer.MIN_VALUE));
/*
* Check bad deserialization fails
*/
try {
// [0, 100] , should be [0, 1]
Rational badZero = createIllegalRational(0, 100);
Rational results = serializeRoundTrip(badZero);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [100, 0] , should be [1, 0]
Rational badPosInfinity = createIllegalRational(100, 0);
Rational results = serializeRoundTrip(badPosInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
Rational badNegInfinity = // [-100, 0] , should be [-1, 0]
createIllegalRational(-100, 0);
Rational results = serializeRoundTrip(badNegInfinity);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [2,4] , should be [1, 2]
Rational badReduced = createIllegalRational(2, 4);
Rational results = serializeRoundTrip(badReduced);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
try {
// [-2, 4] should be [-1, 2]
Rational badReducedNeg = createIllegalRational(-2, 4);
Rational results = serializeRoundTrip(badReducedNeg);
fail("Deserializing " + results + " should not have succeeded");
} catch (InvalidObjectException e) {
// OK
}
}
use of android.util.Rational in project vlc-android by GeoffreyMetais.
the class VideoPlayerActivity method switchToPopup.
@TargetApi(Build.VERSION_CODES.N)
public void switchToPopup() {
final MediaWrapper mw = mService != null ? mService.getCurrentMediaWrapper() : null;
if (mw == null)
return;
if (AndroidDevices.hasPiP) {
if (AndroidUtil.isOOrLater)
try {
final int height = mVideoHeight != 0 ? mVideoHeight : mw.getHeight();
final int width = Math.min(mVideoWidth != 0 ? mVideoWidth : mw.getWidth(), (int) (height * 2.39f));
enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(new Rational(width, height)).build());
} catch (IllegalArgumentException e) {
// Fallback with default parameters
// noinspection deprecation
enterPictureInPictureMode();
}
else {
// noinspection deprecation
enterPictureInPictureMode();
}
} else {
if (Permissions.canDrawOverlays(this)) {
mSwitchingView = true;
mSwitchToPopup = true;
if (mService != null && !mService.isPlaying())
mw.addFlags(MediaWrapper.MEDIA_PAUSED);
cleanUI();
exitOK();
} else
Permissions.checkDrawOverlaysPermission(this);
}
}
use of android.util.Rational in project Signal-Android by WhisperSystems.
the class SignalCameraXModule method updateViewInfo.
// Update view related information used in use cases
private void updateViewInfo() {
if (mImageCapture != null) {
mImageCapture.setCropAspectRatio(new Rational(getWidth(), getHeight()));
mImageCapture.setTargetRotation(getDisplaySurfaceRotation());
}
if (mVideoCapture != null) {
mVideoCapture.setTargetRotation(getDisplaySurfaceRotation());
}
}
use of android.util.Rational in project Signal-Android by WhisperSystems.
the class WebRtcCallActivity method enterPipModeIfPossible.
private boolean enterPipModeIfPossible() {
if (viewModel.canEnterPipMode() && isSystemPipEnabledAndAvailable()) {
PictureInPictureParams params = new PictureInPictureParams.Builder().setAspectRatio(new Rational(9, 16)).build();
enterPictureInPictureMode(params);
CallParticipantsListDialog.dismiss(getSupportFragmentManager());
return true;
}
return false;
}
use of android.util.Rational in project Conversations by siacs.
the class RtpSessionActivity method onAspectRatioChanged.
@Override
public void onAspectRatioChanged(final Rational rational) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isPictureInPicture()) {
final Rational clippedRational = Rationals.clip(rational);
Log.d(Config.LOGTAG, "suggested rational after aspect ratio change " + rational + ". clipped to " + clippedRational);
setPictureInPictureParams(new PictureInPictureParams.Builder().setAspectRatio(clippedRational).build());
}
}
Aggregations