public abstract class

MeteringPointFactory

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.MeteringPointFactory

Subclasses:

TextureViewMeteringPointFactory, DisplayOrientedMeteringPointFactory, SensorOrientedMeteringPointFactory, SurfaceOrientedMeteringPointFactory

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-core:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A factory to create a MeteringPoint.

Users can call MeteringPointFactory.createPoint(float, float) to create a MeteringPoint with x, y, default size. There is also another variant, MeteringPointFactory.createPoint(float, float, float) for apps that want to also specify size.

Summary

Constructors
publicMeteringPointFactory()

Constructor that use Preview aspect ratio for MeteringPoint.

publicMeteringPointFactory(Rational surfaceAspectRatio)

Constructor that takes a custom surface aspect ratio for MeteringPoint.

Methods
protected abstract PointFconvertPoint(float x, float y)

Convert a (x, y) into the normalized surface (x, y) which can then be converted to sensor coordinates by CameraControl.

public final MeteringPointcreatePoint(float x, float y)

Creates a MeteringPoint by x, y.

public final MeteringPointcreatePoint(float x, float y, float size)

Creates a MeteringPoint by x, y, size.

public static floatgetDefaultPointSize()

Returns default point size.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public MeteringPointFactory()

Constructor that use Preview aspect ratio for MeteringPoint.

public MeteringPointFactory(Rational surfaceAspectRatio)

Constructor that takes a custom surface aspect ratio for MeteringPoint.

Methods

public static float getDefaultPointSize()

Returns default point size. It is the default size of the MeteringPoint width and height (ranging from 0 to 1) which is a (normalized) percentage of the sensor width/height (or crop region width/height if crop region is set).

See also: MeteringPoint.getSize()

protected abstract PointF convertPoint(float x, float y)

Convert a (x, y) into the normalized surface (x, y) which can then be converted to sensor coordinates by CameraControl.

The meaning of (x, y) is defined by MeteringPointFactory implementations. It is tailored by specific needs. For example, when performing focus and metering on a point in preview, the (x, y) could be defined as (x, y) in a View. Each implementations is responsible to convert this (x, y) into normalized surface coordinates. Implementation must implement this method for coordinates conversion.

Parameters:

x: x to be converted.
y: y to be converted.

Returns:

a consisting of converted normalized surface coordinates.

public final MeteringPoint createPoint(float x, float y)

Creates a MeteringPoint by x, y.

The (x, y) is a position from the area defined by the specific MeteringPointFactory implementation, such as DisplayOrientedMeteringPointFactory or SurfaceOrientedMeteringPointFactory.

Parameters:

x: x to be converted.
y: y to be converted.

Returns:

A MeteringPoint that is converted into normalized surface (x, y).

See also: DisplayOrientedMeteringPointFactory, SurfaceOrientedMeteringPointFactory

public final MeteringPoint createPoint(float x, float y, float size)

Creates a MeteringPoint by x, y, size.

The (x, y) is a position from the area defined by the specific MeteringPointFactory implementation, such as DisplayOrientedMeteringPointFactory or SurfaceOrientedMeteringPointFactory.

Parameters:

x: x to be converted.
y: y to be converted.
size: size of the MeteringPoint width and height(ranging from 0 to 1). It is the (normalized) percentage of the sensor width/height (or crop region width/height if crop region is set).

Returns:

A MeteringPoint that is converted into normalized surface (x, y).

See also: DisplayOrientedMeteringPointFactory, SurfaceOrientedMeteringPointFactory

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core;

import android.graphics.PointF;
import android.util.Rational;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

/**
 * A factory to create a {@link MeteringPoint}.
 *
 * <p>Users can call {@link #createPoint(float, float)} to
 * create a {@link MeteringPoint} with x, y, default size. There is also another
 * variant, {@link #createPoint(float, float, float)} for apps that want to also specify size.
 *
 * @see MeteringPoint
 * @see #createPoint(float, float)
 * @see #createPoint(float, float, float)
 */
public abstract class MeteringPointFactory {

    /**
     * Surface aspect ratio used to created {@link MeteringPoint}s. Null for using Preview
     * aspect ratio.
     *
     * @see MeteringPoint#getSurfaceAspectRatio()
     */
    @Nullable
    private Rational mSurfaceAspectRatio;

    /**
     * Constructor that use Preview aspect ratio for {@link MeteringPoint}.
     *
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public MeteringPointFactory() {
        this(null);
    }

    /**
     * Constructor that takes a custom surface aspect ratio for {@link MeteringPoint}.
     *
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    public MeteringPointFactory(@Nullable Rational surfaceAspectRatio) {
        mSurfaceAspectRatio = surfaceAspectRatio;
    }

    /**
     * Returns default point size. It is the default size of the MeteringPoint width and height
     * (ranging from 0 to 1) which is a (normalized) percentage of the sensor width/height (or crop
     * region width/height if crop region is set).
     *
     * @see MeteringPoint#getSize()
     */
    public static float getDefaultPointSize() {
        // width of MeteringPoint = 0.15 * cropRegion.width
        // height of MeteringPoint = 0.15 * cropRegion.height
        return 0.15f;
    }

    /**
     * Convert a (x, y) into the normalized surface (x, y) which can then be converted to sensor
     * coordinates by {@link CameraControl}.
     *
     * <p>The meaning of (x, y) is defined by {@link MeteringPointFactory} implementations. It is
     * tailored by specific needs. For example, when performing focus and metering on a point
     * in preview,  the (x, y) could be defined as (x, y) in a View. Each implementations is
     * responsible to convert this (x, y) into normalized surface coordinates.
     *
     * Implementation must implement this method for coordinates conversion.
     *
     * @param x x to be converted.
     * @param y y to be converted.
     * @return a {@link PointF} consisting of converted normalized surface coordinates.
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @NonNull
    protected abstract PointF convertPoint(float x, float y);

    /**
     * Creates a {@link MeteringPoint} by x, y.
     *
     * <p>The (x, y) is a position from the area defined by the specific
     * {@link MeteringPointFactory} implementation, such as
     * {@link DisplayOrientedMeteringPointFactory} or {@link SurfaceOrientedMeteringPointFactory}.
     *
     * @param x x to be converted.
     * @param y y to be converted.
     * @return A {@link MeteringPoint} that is converted into normalized surface (x, y).
     * @see DisplayOrientedMeteringPointFactory
     * @see SurfaceOrientedMeteringPointFactory
     */
    @NonNull
    public final MeteringPoint createPoint(float x, float y) {
        return createPoint(x, y, getDefaultPointSize());
    }

    /**
     * Creates a {@link MeteringPoint} by x, y, size.
     *
     * <p>The (x, y) is a position from the area defined by the specific
     * {@link MeteringPointFactory} implementation, such as
     * {@link DisplayOrientedMeteringPointFactory} or {@link SurfaceOrientedMeteringPointFactory}.
     *
     * @param x    x to be converted.
     * @param y    y to be converted.
     * @param size size of the MeteringPoint width and height(ranging from 0 to 1). It is the
     *             (normalized) percentage of the sensor width/height (or crop region
     *             width/height if crop region is set).
     * @return A {@link MeteringPoint} that is converted into normalized surface (x, y).
     * @see DisplayOrientedMeteringPointFactory
     * @see SurfaceOrientedMeteringPointFactory
     */
    @NonNull
    public final MeteringPoint createPoint(float x, float y, float size) {
        PointF convertedPoint = convertPoint(x, y);
        return new MeteringPoint(convertedPoint.x, convertedPoint.y, size, mSurfaceAspectRatio);
    }
}