android.util.SizeF Java Examples

The following examples show how to use android.util.SizeF. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android_9.0.0_r45   Author: lulululbj   File: Bundle.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value associated with the given key, or null if
 * no mapping of the desired type exists for the given key or a null
 * value is explicitly associated with the key.
 *
 * @param key a String, or null
 * @return a Size value, or null
 */
@Nullable
public SizeF getSizeF(@Nullable String key) {
    unparcel();
    final Object o = mMap.get(key);
    try {
        return (SizeF) o;
    } catch (ClassCastException e) {
        typeWarning(key, o, "SizeF", e);
        return null;
    }
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: MarshalQueryableSizeF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SizeF unmarshal(ByteBuffer buffer) {
    float width = buffer.getFloat();
    float height = buffer.getFloat();

    return new SizeF(width, height);
}
 
Example #3
Source Project: lyra   Author: fondesa   File: SizeFCoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializeSizeF() {
    SizeF expectedValue = new SizeF(9, 5);
    mCoder.serialize(bundle(), randomKey(), expectedValue);
    assertEquals(expectedValue, bundle().getSizeF(randomKey()));

}
 
Example #4
Source Project: lyra   Author: fondesa   File: StateCoderUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Config(minSdk = Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Test
public void testCoderApi21NotNullAbove21() throws CoderNotFoundException {
    assertCoderNotNull(Size.class);
    assertCoderNotNull(SizeF.class);
}
 
Example #5
Source Project: lyra   Author: fondesa   File: StateCoderUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Config(maxSdk = Build.VERSION_CODES.KITKAT)
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Test(expected = CoderNotFoundException.class)
public void testCoderApi21ThrowsBelowApi21() throws CoderNotFoundException {
    assertCoderNotNull(Size.class);
    assertCoderNotNull(SizeF.class);
}
 
Example #6
Source Project: paperparcel   Author: grandstaish   File: TypeAdapterTest.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Test public void sizeFIsCorrectlyParcelled() {
  TypeAdapter<SizeF> adapter = StaticAdapters.SIZE_F_ADAPTER;
  SizeF expected = new SizeF(10.f, 10.f);
  SizeF result = writeThenRead(adapter, expected);
  assertThat(result).isEqualTo(expected);
}
 
Example #7
Source Project: mobile-ar-sensor-logger   Author: OSUPCVLab   File: Camera2Proxy.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCaptureCompleted(CameraCaptureSession session,
                               CaptureRequest request,
                               TotalCaptureResult result) {
    Long timestamp = result.get(CaptureResult.SENSOR_TIMESTAMP);
    Long number = result.getFrameNumber();
    Long exposureTimeNs = result.get(CaptureResult.SENSOR_EXPOSURE_TIME);

    Long frmDurationNs = result.get(CaptureResult.SENSOR_FRAME_DURATION);
    Long frmReadoutNs = result.get(CaptureResult.SENSOR_ROLLING_SHUTTER_SKEW);
    Integer iso = result.get(CaptureResult.SENSOR_SENSITIVITY);
    if (expoStats.size() > kMaxExpoSamples) {
        expoStats.subList(0, kMaxExpoSamples / 2).clear();
    }
    expoStats.add(new NumExpoIso(number, exposureTimeNs, iso));

    Float fl = result.get(CaptureResult.LENS_FOCAL_LENGTH);

    Float fd = result.get(CaptureResult.LENS_FOCUS_DISTANCE);

    Integer afMode = result.get(CaptureResult.CONTROL_AF_MODE);

    Rect rect = result.get(CaptureResult.SCALER_CROP_REGION);
    mFocalLengthHelper.setmFocalLength(fl);
    mFocalLengthHelper.setmFocusDistance(fd);
    mFocalLengthHelper.setmCropRegion(rect);
    SizeF sz_focal_length = mFocalLengthHelper.getFocalLengthPixel();
    String delimiter = ",";
    StringBuilder sb = new StringBuilder();
    sb.append(timestamp);
    sb.append(delimiter + sz_focal_length.getWidth());
    sb.append(delimiter + sz_focal_length.getHeight());
    sb.append(delimiter + number);
    sb.append(delimiter + exposureTimeNs);
    sb.append(delimiter + frmDurationNs);
    sb.append(delimiter + frmReadoutNs);
    sb.append(delimiter + iso);
    sb.append(delimiter + fl);
    sb.append(delimiter + fd);
    sb.append(delimiter + afMode);
    String frame_info = sb.toString();
    if (mRecordingMetadata) {
        try {
            mFrameMetadataWriter.write(frame_info + "\n");
        } catch (IOException err) {
            System.err.println("Error writing captureResult: " + err.getMessage());
        }
    }
    ((CameraCaptureActivity) mActivity).updateCaptureResultPanel(
            sz_focal_length.getWidth(), exposureTimeNs, afMode);
}
 
Example #8
Source Project: bcm-android   Author: bcmapp   File: BcmRouterIntent.java    License: GNU General Public License v3.0 4 votes vote down vote up
public BcmRouterIntent putSizeF(String key, SizeF value) {
    bundle.putSizeF(key, value);
    return this;
}
 
Example #9
Source Project: android_9.0.0_r45   Author: lulululbj   File: Parcel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Flatten a SizeF into the parcel at the current dataPosition(),
 * growing dataCapacity() if needed.
 */
public final void writeSizeF(SizeF val) {
    writeFloat(val.getWidth());
    writeFloat(val.getHeight());
}
 
Example #10
Source Project: android_9.0.0_r45   Author: lulululbj   File: Parcel.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Read a SizeF from the parcel at the current dataPosition().
 */
public final SizeF readSizeF() {
    final float width = readFloat();
    final float height = readFloat();
    return new SizeF(width, height);
}
 
Example #11
Source Project: android_9.0.0_r45   Author: lulululbj   File: LegacyMetadataMapper.java    License: Apache License 2.0 4 votes vote down vote up
private static void mapSensor(CameraMetadataNative m, Parameters p) {
    // Use the largest jpeg size (by area) for both active array and pixel array
    Size largestJpegSize = getLargestSupportedJpegSizeByArea(p);
    /*
     * sensor.info.activeArraySize
     */
    {
        Rect activeArrayRect = ParamsUtils.createRect(largestJpegSize);
        m.set(SENSOR_INFO_ACTIVE_ARRAY_SIZE, activeArrayRect);
    }

    /*
     * sensor.availableTestPatternModes
     */
    {
        // Only "OFF" test pattern mode is available
        m.set(SENSOR_AVAILABLE_TEST_PATTERN_MODES, new int[] { SENSOR_TEST_PATTERN_MODE_OFF });
    }

    /*
     * sensor.info.pixelArraySize
     */
    m.set(SENSOR_INFO_PIXEL_ARRAY_SIZE, largestJpegSize);

    /*
     * sensor.info.physicalSize
     */
    {
        /*
         * Assume focal length is at infinity focus and that the lens is rectilinear.
         */
        float focalLength = p.getFocalLength(); // in mm
        double angleHor = p.getHorizontalViewAngle() * Math.PI / 180; // to radians
        double angleVer = p.getVerticalViewAngle() * Math.PI / 180; // to radians

        float height = (float)Math.abs(2 * focalLength * Math.tan(angleVer / 2));
        float width = (float)Math.abs(2 * focalLength * Math.tan(angleHor / 2));

        m.set(SENSOR_INFO_PHYSICAL_SIZE, new SizeF(width, height)); // in mm
    }

    /*
     * sensor.info.timestampSource
     */
    {
        m.set(SENSOR_INFO_TIMESTAMP_SOURCE, SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN);
    }
}
 
Example #12
Source Project: android_9.0.0_r45   Author: lulululbj   File: MarshalQueryableSizeF.java    License: Apache License 2.0 4 votes vote down vote up
protected MarshalerSizeF(TypeReference<SizeF> typeReference, int nativeType) {
    super(MarshalQueryableSizeF.this, typeReference, nativeType);
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: MarshalQueryableSizeF.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void marshal(SizeF value, ByteBuffer buffer) {
    buffer.putFloat(value.getWidth());
    buffer.putFloat(value.getHeight());
}
 
Example #14
Source Project: android_9.0.0_r45   Author: lulululbj   File: MarshalQueryableSizeF.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Marshaler<SizeF> createMarshaler(
        TypeReference<SizeF> managedType, int nativeType) {
    return new MarshalerSizeF(managedType, nativeType);
}
 
Example #15
Source Project: android_9.0.0_r45   Author: lulululbj   File: MarshalQueryableSizeF.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isTypeMappingSupported(TypeReference<SizeF> managedType, int nativeType) {
    return nativeType == TYPE_FLOAT && (SizeF.class.equals(managedType.getType()));
}
 
Example #16
Source Project: lyra   Author: fondesa   File: StateCoderUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Get the default {@link StateCoder} from a class.
 * If the class is equal to the coder class or the coder class extends/implements the class
 * passed as parameter, the class is supported.
 * In the other cases, you have to implement your own {@link StateCoder}.
 *
 * @param cls class that can be serialized/deserialized with a {@link StateCoder}
 * @return coder related to the class passed as parameter
 * @throws CoderNotFoundException if the coder wasn't found
 */
@NonNull
public static StateCoder getBasicCoderForClass(@NonNull Class<?> cls) throws CoderNotFoundException {
    if (boolean.class == cls || Boolean.class == cls)
        return new BooleanCoder();

    if (boolean[].class == cls)
        return new BooleanArrayCoder();

    if (byte.class == cls || Byte.class == cls)
        return new ByteCoder();

    if (byte[].class == cls)
        return new ByteArrayCoder();

    if (char.class == cls || Character.class == cls)
        return new CharCoder();

    if (char[].class == cls)
        return new CharArrayCoder();

    if (CharSequence.class == cls)
        return new CharSequenceCoder();

    if (CharSequence[].class == cls)
        return new CharSequenceArrayCoder();

    if (double.class == cls || Double.class == cls)
        return new DoubleCoder();

    if (double[].class == cls)
        return new DoubleArrayCoder();

    if (float.class == cls || Float.class == cls)
        return new FloatCoder();

    if (float[].class == cls)
        return new FloatArrayCoder();

    if (IBinder.class == cls)
        return new IBinderCoder();

    if (int.class == cls || Integer.class == cls)
        return new IntCoder();

    if (int[].class == cls)
        return new IntArrayCoder();

    if (long.class == cls || Long.class == cls)
        return new LongCoder();

    if (long[].class == cls)
        return new LongArrayCoder();

    if (Parcelable.class == cls)
        return new ParcelableCoder();

    if (Parcelable[].class == cls)
        return new ParcelableArrayCoder();

    if (Serializable.class == cls)
        return new SerializableCoder();

    if (short.class == cls || Short.class == cls)
        return new ShortCoder();

    if (short[].class == cls)
        return new ShortArrayCoder();

    if (String.class == cls)
        return new StringCoder();

    if (String[].class == cls)
        return new StringArrayCoder();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (Size.class == cls)
            return new SizeCoder();

        if (SizeF.class == cls)
            return new SizeFCoder();
    }

    return getBasicCoderForInheritedClass(cls);
}
 
Example #17
Source Project: lyra   Author: fondesa   File: SizeFCoderTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDeserializeSizeF() {
    SizeF expectedValue = new SizeF(9, 5);
    bundle().putSizeF(randomKey(), expectedValue);
    assertEquals(expectedValue, mCoder.deserialize(bundle(), randomKey()));
}
 
Example #18
Source Project: Meepo   Author: nekocode   File: MeepoUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void putValueToBundle(
        @NonNull Bundle bundle, @NonNull String key, @NonNull Object value) {
    if (value instanceof String) {
        bundle.putString(key, (String) value);
    } else if (value instanceof Integer) {
        bundle.putInt(key, (int) value);
    } else if (value instanceof Boolean) {
        bundle.putBoolean(key, (boolean) value);
    } else if (value instanceof Long) {
        bundle.putLong(key, (long) value);
    } else if (value instanceof Short) {
        bundle.putShort(key, (short) value);
    } else if (value instanceof Double) {
        bundle.putDouble(key, (double) value);
    } else if (value instanceof Float) {
        bundle.putFloat(key, (float) value);
    } else if (value instanceof Character) {
        bundle.putChar(key, (char) value);
    } else if (value instanceof Byte) {
        bundle.putByte(key, (byte) value);
    } else if (value instanceof CharSequence) {
        bundle.putCharSequence(key, (CharSequence) value);
    } else if (value instanceof Bundle) {
        bundle.putBundle(key, (Bundle) value);
    } else if (value instanceof Parcelable) {
        bundle.putParcelable(key, (Parcelable) value);
    } else if (value instanceof String[]) {
        bundle.putStringArray(key, (String[]) value);
    } else if (value instanceof int[]) {
        bundle.putIntArray(key, (int[]) value);
    } else if (value instanceof boolean[]) {
        bundle.putBooleanArray(key, (boolean[]) value);
    } else if (value instanceof long[]) {
        bundle.putLongArray(key, (long[]) value);
    } else if (value instanceof short[]) {
        bundle.putShortArray(key, (short[]) value);
    } else if (value instanceof double[]) {
        bundle.putDoubleArray(key, (double[]) value);
    } else if (value instanceof float[]) {
        bundle.putFloatArray(key, (float[]) value);
    } else if (value instanceof char[]) {
        bundle.putCharArray(key, (char[]) value);
    } else if (value instanceof byte[]) {
        bundle.putByteArray(key, (byte[]) value);
    } else if (value instanceof CharSequence[]) {
        bundle.putCharSequenceArray(key, (CharSequence[]) value);
    } else if (value instanceof Parcelable[]) {
        bundle.putParcelableArray(key, (Parcelable[]) value);
    } else if (value instanceof ArrayList) {
        bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
    } else if (value instanceof SparseArray) {
        bundle.putSparseParcelableArray(key, (SparseArray<? extends Parcelable>) value);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (value instanceof IBinder) {
                bundle.putBinder(key, (IBinder) value);
                return;
            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (value instanceof Size) {
                bundle.putSize(key, (Size) value);
                return;
            } else if (value instanceof SizeF) {
                bundle.putSizeF(key, (SizeF) value);
                return;
            }
        }
        if (value instanceof Serializable) {
            bundle.putSerializable(key, (Serializable) value);
            return;
        }

        throw new RuntimeException(String.format(Locale.getDefault(),
                "Arguments extra %s has wrong type %s.", key, value.getClass().getName()));
    }
}
 
Example #19
Source Project: OpenHub   Author: ThirtyDegreesRay   File: BundleHelper.java    License: GNU General Public License v3.0 4 votes vote down vote up
public BundleHelper put(@NonNull String key, @Nullable SizeF value){
    bundle.putSizeF(key, value);
    return this;
}
 
Example #20
Source Project: Akatsuki   Author: tom91136   File: Bundle.java    License: Apache License 2.0 4 votes vote down vote up
public void putSizeF(java.lang.String key, SizeF value){
	throw new RuntimeException("Stub!");
}
 
Example #21
Source Project: Akatsuki   Author: tom91136   File: Bundle.java    License: Apache License 2.0 4 votes vote down vote up
public SizeF getSizeF(java.lang.String key){
	throw new RuntimeException("Stub!");
}
 
Example #22
Source Project: paperparcel   Author: grandstaish   File: StaticAdapters.java    License: Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull @Override public SizeF readFromParcel(@NonNull Parcel source) {
  return source.readSizeF();
}
 
Example #23
Source Project: paperparcel   Author: grandstaish   File: StaticAdapters.java    License: Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override public void writeToParcel(@NonNull SizeF value, @NonNull Parcel dest, int flags) {
  dest.writeSizeF(value);
}
 
Example #24
Source Project: android_9.0.0_r45   Author: lulululbj   File: ParameterUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Returns the component-wise zoom ratio (each greater or equal than {@code 1.0});
 * largest values means more zoom.
 *
 * @param activeArraySize active array size of the sensor (e.g. max jpeg size)
 * @param cropSize size of the crop/zoom
 *
 * @return {@link SizeF} with width/height being the component-wise zoom ratio
 *
 * @throws NullPointerException if any of the args were {@code null}
 * @throws IllegalArgumentException if any component of {@code cropSize} was {@code 0}
 */
private static SizeF getZoomRatio(Size activeArraySize, Size cropSize) {
    checkNotNull(activeArraySize, "activeArraySize must not be null");
    checkNotNull(cropSize, "cropSize must not be null");
    checkArgumentPositive(cropSize.getWidth(), "cropSize.width must be positive");
    checkArgumentPositive(cropSize.getHeight(), "cropSize.height must be positive");

    float zoomRatioWidth = activeArraySize.getWidth() * 1.0f / cropSize.getWidth();
    float zoomRatioHeight = activeArraySize.getHeight() * 1.0f / cropSize.getHeight();

    return new SizeF(zoomRatioWidth, zoomRatioHeight);
}
 
Example #25
Source Project: android_9.0.0_r45   Author: lulululbj   File: Bundle.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Inserts a SizeF value into the mapping of this Bundle, replacing
 * any existing value for the given key.  Either key or value may be null.
 *
 * @param key a String, or null
 * @param value a SizeF object, or null
 */
public void putSizeF(@Nullable String key, @Nullable SizeF value) {
    unparcel();
    mMap.put(key, value);
}
 
Example #26
Source Project: lyra   Author: fondesa   File: SizeFCoder.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Write a field's value into the saved state {@link Bundle}.
 *
 * @param state      {@link Bundle} used to save the state
 * @param key        key retrieved from {@code fieldDeclaringClass#fieldName}
 * @param fieldValue value of field
 */
@Override
public void serialize(@NonNull Bundle state, @NonNull String key, @NonNull SizeF fieldValue) {
    state.putSizeF(key, fieldValue);
}
 
Example #27
Source Project: KUtils   Author: yibulaxi   File: Bundler.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Inserts a SizeF value into the mapping of this Bundle, replacing
 * any existing value for the given key.  Either key or value may be null.
 *
 * @param key   a String, or null
 * @param value a SizeF object, or null
 */
@TargetApi(21)
public Bundler putSizeF(String key, SizeF value) {
  bundle.putSizeF(key, value);
  return this;
}
 
Example #28
Source Project: KUtils   Author: yibulaxi   File: Bundler.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Inserts a SizeF value into the mapping of this Bundle, replacing
 * any existing value for the given key.  Either key or value may be null.
 *
 * @param key   a String, or null
 * @param value a SizeF object, or null
 */
@TargetApi(21)
public Bundler putSizeF(String key, SizeF value) {
  bundle.putSizeF(key, value);
  return this;
}
 
Example #29
Source Project: KUtils-master   Author: weileng11   File: Bundler.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Inserts a SizeF value into the mapping of this Bundle, replacing
 * any existing value for the given key.  Either key or value may be null.
 *
 * @param key   a String, or null
 * @param value a SizeF object, or null
 */
@TargetApi(21)
public Bundler putSizeF(String key, SizeF value) {
  bundle.putSizeF(key, value);
  return this;
}
 
Example #30
Source Project: KUtils-master   Author: weileng11   File: Bundler.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Inserts a SizeF value into the mapping of this Bundle, replacing
 * any existing value for the given key.  Either key or value may be null.
 *
 * @param key   a String, or null
 * @param value a SizeF object, or null
 */
@TargetApi(21)
public Bundler putSizeF(String key, SizeF value) {
  bundle.putSizeF(key, value);
  return this;
}