public class

MutableStateObservable<T>

extends StateObservable<java.lang.Object>

 java.lang.Object

androidx.camera.core.impl.StateObservable<java.lang.Object>

↳androidx.camera.core.impl.MutableStateObservable<T>

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 StateObservable whose state can be set.

Summary

Methods
public voidsetError(java.lang.Throwable error)

Posts a new java.lang.Throwable to be used in the new error state of this Observable.

public voidsetState(java.lang.Object state)

Posts a new state to be used as the current state of this Observable.

public static MutableStateObservable<java.lang.Object>withInitialError(java.lang.Throwable initialError)

Creates a mutable state observer in an initial error state containing the provided java.lang.Throwable.

public static MutableStateObservable<java.lang.Object>withInitialState(java.lang.Object initialState)

Creates a mutable state observer with the provided initial state.

from StateObservable<T>addObserver, fetchData, removeObserver, removeObservers
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static MutableStateObservable<java.lang.Object> withInitialState(java.lang.Object initialState)

Creates a mutable state observer with the provided initial state.

Parameters:

initialState: The initial state

Returns:

A mutable state observable initialized with the given initial state.

public static MutableStateObservable<java.lang.Object> withInitialError(java.lang.Throwable initialError)

Creates a mutable state observer in an initial error state containing the provided java.lang.Throwable.

Parameters:

initialError: The java.lang.Throwable contained by the error state.

Returns:

A mutable state observable initialized in an error state containing the provided java.lang.Throwable.

public void setState(java.lang.Object state)

Posts a new state to be used as the current state of this Observable.

public void setError(java.lang.Throwable error)

Posts a new java.lang.Throwable to be used in the new error state of this Observable.

Source

/*
 * Copyright 2021 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.impl;

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

/**
 * A {@link StateObservable} whose state can be set.
 *
 * @param <T> The state type.
 */
public class MutableStateObservable<T> extends StateObservable<T> {

    private MutableStateObservable(@Nullable Object initialState, boolean isError) {
        super(initialState, isError);
    }

    /**
     * Creates a mutable state observer with the provided initial state.
     *
     * @param initialState The initial state
     * @param <T>          The state type
     * @return A mutable state observable initialized with the given initial state.
     */
    @NonNull
    public static <T> MutableStateObservable<T> withInitialState(@Nullable T initialState) {
        return new MutableStateObservable<>(initialState, false);
    }

    /**
     * Creates a mutable state observer in an initial error state containing the provided
     * {@link Throwable}.
     *
     * @param initialError The {@link Throwable} contained by the error state.
     * @param <T>          The state type
     * @return A mutable state observable initialized in an error state containing the provided
     * {@link Throwable}.
     */
    @NonNull
    public static <T> MutableStateObservable<T> withInitialError(@NonNull Throwable initialError) {
        return new MutableStateObservable<>(initialError, true);
    }

    /**
     * Posts a new state to be used as the current state of this Observable.
     */
    public void setState(@Nullable T state) {
        updateState(state);
    }

    /**
     * Posts a new {@link Throwable} to be used in the new error state of this Observable.
     */
    public void setError(@NonNull Throwable error) {
        updateStateAsError(error);
    }

}