Search in sources :

Example 16 with Rational

use of android.util.Rational in project android_frameworks_base by AOSPA.

the class ColorSpaceTransform method equals.

/**
     * Check if this {@link ColorSpaceTransform} is equal to another {@link ColorSpaceTransform}.
     *
     * <p>Two color space transforms are equal if and only if all of their elements are
     * {@link Object#equals equal}.</p>
     *
     * @return {@code true} if the objects were equal, {@code false} otherwise
     */
@Override
public boolean equals(final Object obj) {
    if (obj == null) {
        return false;
    }
    if (this == obj) {
        return true;
    }
    if (obj instanceof ColorSpaceTransform) {
        final ColorSpaceTransform other = (ColorSpaceTransform) obj;
        for (int i = 0, j = 0; i < COUNT; ++i, j += RATIONAL_SIZE) {
            int numerator = mElements[j + OFFSET_NUMERATOR];
            int denominator = mElements[j + OFFSET_DENOMINATOR];
            int numeratorOther = other.mElements[j + OFFSET_NUMERATOR];
            int denominatorOther = other.mElements[j + OFFSET_DENOMINATOR];
            Rational r = new Rational(numerator, denominator);
            Rational rOther = new Rational(numeratorOther, denominatorOther);
            if (!r.equals(rOther)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : Rational(android.util.Rational)

Example 17 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class CameraMetadataTest method testReadWritePrimitive.

@SmallTest
public void testReadWritePrimitive() {
    // int32 (single)
    checkKeyGetAndSet("android.control.aeExposureCompensation", Integer.TYPE, 0xC0FFEE);
    // byte (single)
    checkKeyGetAndSet("android.flash.maxEnergy", Byte.TYPE, (byte) 6);
    // int64 (single)
    checkKeyGetAndSet("android.flash.firingTime", Long.TYPE, 0xABCD12345678FFFFL);
    // float (single)
    checkKeyGetAndSet("android.lens.aperture", Float.TYPE, Float.MAX_VALUE);
    // double (single) -- technically double x 3, but we fake it
    checkKeyGetAndSet("android.jpeg.gpsCoordinates", Double.TYPE, Double.MAX_VALUE);
    // rational (single)
    checkKeyGetAndSet("android.sensor.baseGainFactor", Rational.class, new Rational(1, 2));
    /**
         * Weirder cases, that don't map 1:1 with the native types
         */
    // bool (single) -- with TYPE_BYTE
    checkKeyGetAndSet("android.control.aeLock", Boolean.TYPE, true);
    // integer (single) -- with TYPE_BYTE
    checkKeyGetAndSet("android.control.aePrecaptureTrigger", Integer.TYPE, 6);
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 18 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class RationalTest method testCompareTo.

@SmallTest
public void testCompareTo() {
    // unit is equal to itself
    assertCompareEquals(UNIT, new Rational(1, 1));
    // NaN is greater than anything but NaN
    assertCompareEquals(NaN, new Rational(0, 0));
    assertGreaterThan(NaN, UNIT);
    assertGreaterThan(NaN, POSITIVE_INFINITY);
    assertGreaterThan(NaN, NEGATIVE_INFINITY);
    assertGreaterThan(NaN, ZERO);
    // Positive infinity is greater than any other non-NaN
    assertCompareEquals(POSITIVE_INFINITY, new Rational(1, 0));
    assertGreaterThan(POSITIVE_INFINITY, UNIT);
    assertGreaterThan(POSITIVE_INFINITY, NEGATIVE_INFINITY);
    assertGreaterThan(POSITIVE_INFINITY, ZERO);
    // Negative infinity is smaller than any other non-NaN
    assertCompareEquals(NEGATIVE_INFINITY, new Rational(-1, 0));
    assertLessThan(NEGATIVE_INFINITY, UNIT);
    assertLessThan(NEGATIVE_INFINITY, POSITIVE_INFINITY);
    assertLessThan(NEGATIVE_INFINITY, ZERO);
    // A finite number with the same denominator is trivially comparable
    assertGreaterThan(new Rational(3, 100), new Rational(1, 100));
    assertGreaterThan(new Rational(3, 100), ZERO);
    // Compare finite numbers with different divisors
    assertGreaterThan(new Rational(5, 25), new Rational(1, 10));
    assertGreaterThan(new Rational(5, 25), ZERO);
    // Compare finite numbers with different signs
    assertGreaterThan(new Rational(5, 25), new Rational(-1, 10));
    assertLessThan(new Rational(-5, 25), ZERO);
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 19 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

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 20 with Rational

use of android.util.Rational in project platform_frameworks_base by android.

the class RationalTest method testConstructor.

@SmallTest
public void testConstructor() {
    // Simple case
    Rational r = new Rational(1, 2);
    assertEquals(1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    // Denominator negative
    r = new Rational(-1, 2);
    assertEquals(-1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    // Numerator negative
    r = new Rational(1, -2);
    assertEquals(-1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    // Both negative
    r = new Rational(-1, -2);
    assertEquals(1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    // Infinity.
    r = new Rational(1, 0);
    assertEquals(1, r.getNumerator());
    assertEquals(0, r.getDenominator());
    // Negative infinity.
    r = new Rational(-1, 0);
    assertEquals(-1, r.getNumerator());
    assertEquals(0, r.getDenominator());
    // NaN.
    r = new Rational(0, 0);
    assertEquals(0, r.getNumerator());
    assertEquals(0, r.getDenominator());
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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