FileDocCategorySizeDatePackage
Camera2RequestSettingsSet.javaAPI DocAndroid 5.1 API9574Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.utils

Camera2RequestSettingsSet

public class Camera2RequestSettingsSet extends Object
A set of settings to be used when filing a {@link CaptureRequest}.

Fields Summary
private final Map
mDictionary
private long
mRevision
Constructors Summary
public Camera2RequestSettingsSet()
Create a new instance with no settings defined.

Creating a request from this object without first specifying any properties on it is equivalent to just creating a request directly from the template of choice. Its revision identifier is initially {@code 0}, and will remain thus until its first modification.

        mDictionary = new HashMap<>();
        mRevision = 0;
    
public Camera2RequestSettingsSet(Camera2RequestSettingsSet other)
Perform a deep copy of the defined settings and revision number.

param
other The reference instance.
throws
NullPointerException If {@code other} is {@code null}.

        if (other == null) {
            throw new NullPointerException("Tried to copy null Camera2RequestSettingsSet");
        }

        mDictionary = new HashMap<>(other.mDictionary);
        mRevision = other.mRevision;
    
Methods Summary
public booleancontains(android.hardware.camera2.CaptureRequest.Key key)
Query this instance for whether it prefers a particular choice for the given request parameter.

This method can be used to detect whether a particular field is forced to its default value or simply unset. While {@link #get} will return {@code null} in both these cases, this method will return {@code true} and {@code false}, respectively.

param
key Which setting to look for.
return
Whether that setting has a value that will propagate with unions.
throws
NullPointerException If {@code key} is {@code null}.

        if (key == null) {
            throw new NullPointerException("Received a null key");
        }
        return mDictionary.containsKey(key);
    
public android.hardware.camera2.CaptureRequestcreateRequest(android.hardware.camera2.CameraDevice camera, int template, android.view.Surface targets)
Create a {@link CaptureRequest} specialized for the specified {@link CameraDevice} and targeting the given {@link Surface}s.

param
camera The camera from which to capture.
param
template A {@link CaptureRequest} template defined in {@link CameraDevice}.
param
targets The location(s) to draw the resulting image onto.
return
The request, ready to be passed to the camera framework.
throws
CameraAccessException Upon an underlying framework API failure.
throws
NullPointerException If any argument is {@code null}.

        if (camera == null) {
            throw new NullPointerException("Tried to create request using null CameraDevice");
        }

        Builder reqBuilder = camera.createCaptureRequest(template);
        for (Key<?> key : mDictionary.keySet()) {
            setRequestFieldIfNonNull(reqBuilder, key);
        }
        for (Surface target : targets) {
            if (target == null) {
                throw new NullPointerException("Tried to add null Surface as request target");
            }
            reqBuilder.addTarget(target);
        }
        return reqBuilder.build();
    
public Tget(android.hardware.camera2.CaptureRequest.Key key)
Interrogate the current specialization of a setting.

param
key Which setting to check.
return
The current selection for that setting, or {@code null} if the setting is unset or forced to the template-defined default.
throws
NullPointerException If {@code key} is {@code null}.

        if (key == null) {
            throw new NullPointerException("Received a null key");
        }
        return (T) mDictionary.get(key);
    
public longgetRevision()
Get this set of settings's revision identifier, which can be compared against cached past values to determine whether it has been modified.

Distinct revisions across the same object do not necessarily indicate that the object's key/value pairs have changed at all, but the same revision on the same object does imply that they've stayed the same.

return
The number of modifications made since the beginning of this object's heritage.

        return mRevision;
    
public booleanmatches(android.hardware.camera2.CaptureRequest.Key key, T value)
Check whether the value of the specified setting matches the given one.

This method uses the {@code T} type's {@code equals} method, but is {@code null}-tolerant.

param
key Which of this class's settings to check.
param
value Value to test for equality against.
return
Whether they are the same.

        return Objects.equals(get(key), value);
    
public booleanset(android.hardware.camera2.CaptureRequest.Key key, T value)
Specify a setting, potentially overriding the template's default choice.

Providing a {@code null} {@code value} will indicate a forced use of the template's selection for that {@code key}; the difference here is that this information will be propagated with unions as documented in {@link #union}. This method increments the revision identifier if the new choice is different than the existing selection.

param
key Which setting to alter.
param
value The new selection for that setting, or {@code null} to force the use of the template's default selection for this field.
return
Whether the settings were updated, which only occurs if the {@code value} is different from any already stored.
throws
NullPointerException If {@code key} is {@code null}.

        if (key == null) {
            throw new NullPointerException("Received a null key");
        }

        Object currentValue = get(key);
        // Only save the value if it's different from the one we already have
        if (!mDictionary.containsKey(key) || !Objects.equals(value, currentValue)) {
            mDictionary.put(key, value);
            ++mRevision;
            return true;
        }
        return false;
    
private voidsetRequestFieldIfNonNull(android.hardware.camera2.CaptureRequest.Builder requestBuilder, android.hardware.camera2.CaptureRequest.Key key)

        T value = get(key);
        if (value != null) {
            requestBuilder.set(key, value);
        }
    
public booleanunion(com.android.ex.camera2.utils.Camera2RequestSettingsSet moreSettings)
Add all settings choices defined by {@code moreSettings} to this object.

For any settings defined in both, the choice stored in the argument to this method take precedence. Unset settings are not propagated, but those forced to default as described in {@link set} are also forced to default in {@code this} set. Invoking this method increments {@code this} object's revision counter, but leaves the argument's unchanged.

param
moreSettings The source of the additional settings ({@code null} is allowed here).
return
Whether these settings were updated, which can only fail if the target itself is also given as the argument.

        if (moreSettings == null || moreSettings == this) {
            return false;
        }

        mDictionary.putAll(moreSettings.mDictionary);
        ++mRevision;
        return true;
    
public booleanunset(android.hardware.camera2.CaptureRequest.Key key)
Unsets a setting, preventing it from being propagated with unions or from overriding the default when creating a capture request.

This method increments the revision identifier if a selection had previously been made for that parameter.

param
key Which setting to reset.
return
Whether the settings were updated, which only occurs if the specified setting already had a value or was forced to default.
throws
NullPointerException If {@code key} is {@code null}.

        if (key == null) {
            throw new NullPointerException("Received a null key");
        }

        if (mDictionary.containsKey(key)) {
            mDictionary.remove(key);
            ++mRevision;
            return true;
        }
        return false;