Search in sources :

Example 91 with Rational

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
    }
}
Also used : Rational(android.util.Rational) InvalidObjectException(java.io.InvalidObjectException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 92 with Rational

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);
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Rational(android.util.Rational) TargetApi(android.annotation.TargetApi)

Example 93 with Rational

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());
    }
}
Also used : Rational(android.util.Rational)

Example 94 with Rational

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;
}
Also used : Rational(android.util.Rational) PictureInPictureParams(android.app.PictureInPictureParams)

Example 95 with Rational

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());
    }
}
Also used : Rational(android.util.Rational) PictureInPictureParams(android.app.PictureInPictureParams)

Aggregations

Rational (android.util.Rational)96 SmallTest (android.test.suitebuilder.annotation.SmallTest)50 Range (android.util.Range)15 Size (android.util.Size)6 Point (android.graphics.Point)5 Pair (android.util.Pair)5 InvalidObjectException (java.io.InvalidObjectException)5 PictureInPictureParams (android.app.PictureInPictureParams)4 TargetApi (android.annotation.TargetApi)3 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 RemoteAction (android.app.RemoteAction)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 RequiresApi (androidx.annotation.RequiresApi)1 RequiresPermission (androidx.annotation.RequiresPermission)1 CameraSelector (androidx.camera.core.CameraSelector)1 StringBuilder (java.lang.StringBuilder)1 DecimalFormat (java.text.DecimalFormat)1