FileDocCategorySizeDatePackage
CameraStateHolder.javaAPI DocAndroid 5.1 API4475Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.portability

CameraStateHolder

public abstract class CameraStateHolder extends Object

Fields Summary
private static final Log.Tag
TAG
private int
mState
private boolean
mInvalid
Constructors Summary
public CameraStateHolder(int state)
Construct a new instance of @{link CameraStateHolder} with an initial state.

param
state The initial state.


                         
       
        setState(state);
        mInvalid = false;
    
Methods Summary
public synchronized intgetState()
Obtain the current state.

return
The current state.

        return mState;
    
public synchronized voidinvalidate()
Change the state to be invalid. Once invalidated, the state will be invalid forever.

        mInvalid = true;
    
public synchronized booleanisInvalid()
Whether the state is invalid.

return
True if the state is invalid.

        return mInvalid;
    
public synchronized voidsetState(int state)
Change to a new state.

param
state The new state.

        if (mState != state) {
            Log.v(TAG, "setState - state = " + Integer.toBinaryString(state));
        }
        mState = state;
        this.notifyAll();
    
private booleanwaitForCondition(com.android.ex.camera2.portability.CameraStateHolder$ConditionChecker stateChecker, long timeoutMs)
A helper method used by {@link #waitToAvoidStates(int)} and {@link #waitForStates(int)}. This method will wait until the condition is successful.

param
stateChecker The state checker to be used.
param
timeoutMs The timeout limit in milliseconds.
return
{@code false} if the wait is interrupted or timeout limit is reached.

        long timeBound = SystemClock.uptimeMillis() + timeoutMs;
        synchronized (this) {
            while (!stateChecker.success()) {
                try {
                    this.wait(timeoutMs);
                } catch (InterruptedException ex) {
                    if (SystemClock.uptimeMillis() > timeBound) {
                        // Timeout.
                        Log.w(TAG, "Timeout waiting.");
                    }
                    return false;
                }
            }
        }
        return true;
    
public booleanwaitForStates(int states)
Block the current thread until the state becomes one of the specified.

param
states Expected states.
return
{@code false} if the wait is interrupted or timeout limit is reached.

        Log.v(TAG, "waitForStates - states = " + Integer.toBinaryString(states));
        return waitForCondition(new ConditionChecker() {
            @Override
            public boolean success() {
                return (states | getState()) == states;
            }
        }, CameraAgent.CAMERA_OPERATION_TIMEOUT_MS);
    
public booleanwaitToAvoidStates(int states)
Block the current thread until the state becomes NOT one of the specified.

param
states States to avoid.
return
{@code false} if the wait is interrupted or timeout limit is reached.

        Log.v(TAG, "waitToAvoidStates - states = " + Integer.toBinaryString(states));
        return waitForCondition(new ConditionChecker() {
            @Override
            public boolean success() {
                return (states & getState()) == 0;
            }
        }, CameraAgent.CAMERA_OPERATION_TIMEOUT_MS);