Search in sources :

Example 26 with Rational

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

the class Utils method parseRationalRange.

static Range<Rational> parseRationalRange(Object o, Range<Rational> fallback) {
    try {
        String s = (String) o;
        int ix = s.indexOf('-');
        if (ix >= 0) {
            return Range.create(Rational.parseRational(s.substring(0, ix)), Rational.parseRational(s.substring(ix + 1)));
        }
        Rational value = Rational.parseRational(s);
        return Range.create(value, value);
    } catch (ClassCastException e) {
    } catch (NumberFormatException e) {
    } catch (NullPointerException e) {
        return fallback;
    } catch (IllegalArgumentException e) {
    }
    Log.w(TAG, "could not parse rational range '" + o + "'");
    return fallback;
}
Also used : Rational(android.util.Rational)

Example 27 with Rational

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

the class StaticMetadata method getAeCompensationStepChecked.

/**
     * Get value of key android.control.aeCompensationStep and do the sanity check.
     *
     * @return default value if the value is null.
     */
public Rational getAeCompensationStepChecked() {
    Key<Rational> key = CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP;
    Rational compensationStep = getValueFromKeyNonNull(key);
    if (compensationStep == null) {
        // Return default step.
        return CONTROL_AE_COMPENSATION_STEP_DEFAULT;
    }
    // Legacy devices don't have a minimum step requirement
    if (isHardwareLevelLimitedOrBetter()) {
        float compensationStepF = (float) compensationStep.getNumerator() / compensationStep.getDenominator();
        checkTrueForKey(key, " value must be no more than 1/2", compensationStepF <= 0.5f);
    }
    return compensationStep;
}
Also used : Rational(android.util.Rational)

Example 28 with Rational

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

the class RangeTest method testInRange.

@SmallTest
public void testInRange() {
    Range<Integer> hundredOneTwo = Range.create(100, 200);
    assertInRange(hundredOneTwo, 100);
    assertInRange(hundredOneTwo, 200);
    assertInRange(hundredOneTwo, 150);
    assertOutOfRange(hundredOneTwo, 99);
    assertOutOfRange(hundredOneTwo, 201);
    assertOutOfRange(hundredOneTwo, 100000);
    Range<Float> infinities = Range.create(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
    assertInRange(infinities, Float.NEGATIVE_INFINITY);
    assertInRange(infinities, Float.POSITIVE_INFINITY);
    assertInRange(infinities, 0.0f);
    assertOutOfRange(infinities, Float.NaN);
    Range<Rational> negativeOneTenthPositiveOneTenth = new Range<Rational>(new Rational(-1, 10), new Rational(1, 10));
    assertInRange(negativeOneTenthPositiveOneTenth, new Rational(-1, 10));
    assertInRange(negativeOneTenthPositiveOneTenth, new Rational(1, 10));
    assertInRange(negativeOneTenthPositiveOneTenth, Rational.ZERO);
    assertOutOfRange(negativeOneTenthPositiveOneTenth, new Rational(-100, 1));
    assertOutOfRange(negativeOneTenthPositiveOneTenth, new Rational(100, 1));
}
Also used : Rational(android.util.Rational) Range(android.util.Range) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 29 with Rational

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

the class RationalTest method testEquals.

@SmallTest
public void testEquals() {
    Rational r = new Rational(1, 2);
    assertEquals(1, r.getNumerator());
    assertEquals(2, r.getDenominator());
    assertEquals(r, r);
    assertFalse(r.equals(null));
    assertFalse(r.equals(new Object()));
    Rational twoThirds = new Rational(2, 3);
    assertFalse(r.equals(twoThirds));
    assertFalse(twoThirds.equals(r));
    Rational fourSixths = new Rational(4, 6);
    assertEquals(twoThirds, fourSixths);
    assertEquals(fourSixths, twoThirds);
    Rational moreComplicated = new Rational(5 * 6 * 7 * 8 * 9, 1 * 2 * 3 * 4 * 5);
    Rational moreComplicated2 = new Rational(5 * 6 * 7 * 8 * 9 * 78, 1 * 2 * 3 * 4 * 5 * 78);
    assertEquals(moreComplicated, moreComplicated2);
    assertEquals(moreComplicated2, moreComplicated);
    // Ensure negatives are fine
    twoThirds = new Rational(-2, 3);
    fourSixths = new Rational(-4, 6);
    assertEquals(twoThirds, fourSixths);
    assertEquals(fourSixths, twoThirds);
    moreComplicated = new Rational(-5 * 6 * 7 * 8 * 9, 1 * 2 * 3 * 4 * 5);
    moreComplicated2 = new Rational(-5 * 6 * 7 * 8 * 9 * 78, 1 * 2 * 3 * 4 * 5 * 78);
    assertEquals(moreComplicated, moreComplicated2);
    assertEquals(moreComplicated2, moreComplicated);
    // Zero is always equal to itself
    Rational zero2 = new Rational(0, 100);
    assertEquals(ZERO, zero2);
    assertEquals(zero2, ZERO);
    // NaN is always equal to itself
    Rational nan = NaN;
    Rational nan2 = new Rational(0, 0);
    assertTrue(nan.equals(nan));
    assertTrue(nan.equals(nan2));
    assertTrue(nan2.equals(nan));
    assertFalse(nan.equals(r));
    assertFalse(r.equals(nan));
    // Infinities of the same sign are equal.
    Rational posInf = POSITIVE_INFINITY;
    Rational posInf2 = new Rational(2, 0);
    Rational negInf = NEGATIVE_INFINITY;
    Rational negInf2 = new Rational(-2, 0);
    assertEquals(posInf, posInf);
    assertEquals(negInf, negInf);
    assertEquals(posInf, posInf2);
    assertEquals(negInf, negInf2);
    // Infinities aren't equal to anything else.
    assertFalse(posInf.equals(negInf));
    assertFalse(negInf.equals(posInf));
    assertFalse(negInf.equals(r));
    assertFalse(posInf.equals(r));
    assertFalse(r.equals(negInf));
    assertFalse(r.equals(posInf));
    assertFalse(posInf.equals(nan));
    assertFalse(negInf.equals(nan));
    assertFalse(nan.equals(posInf));
    assertFalse(nan.equals(negInf));
}
Also used : Rational(android.util.Rational) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 30 with Rational

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

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)

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