FileDocCategorySizeDatePackage
ReferenceCountedTrigger.javaAPI DocAndroid 5.1 API4076Thu Mar 12 22:22:42 GMT 2015com.android.systemui.recents.misc

ReferenceCountedTrigger

public class ReferenceCountedTrigger extends Object
A ref counted trigger that does some logic when the count is first incremented, or last decremented. Not thread safe as it's not currently needed.

Fields Summary
android.content.Context
mContext
int
mCount
ArrayList
mFirstIncRunnables
ArrayList
mLastDecRunnables
Runnable
mErrorRunnable
Runnable
mIncrementRunnable
Runnable
mDecrementRunnable
Constructors Summary
public ReferenceCountedTrigger(android.content.Context context, Runnable firstIncRunnable, Runnable lastDecRunnable, Runnable errorRunanable)


        
                                       
        mContext = context;
        if (firstIncRunnable != null) mFirstIncRunnables.add(firstIncRunnable);
        if (lastDecRunnable != null) mLastDecRunnables.add(lastDecRunnable);
        mErrorRunnable = errorRunanable;
    
Methods Summary
public voidaddLastDecrementRunnable(java.lang.Runnable r)
Adds a runnable to the last-decrement runnables list.

        // To ensure that the last decrement always calls, we increment and decrement after setting
        // the last decrement runnable
        boolean ensureLastDecrement = (mCount == 0);
        if (ensureLastDecrement) increment();
        mLastDecRunnables.add(r);
        if (ensureLastDecrement) decrement();
    
public voiddecrement()
Decrements the ref count

        mCount--;
        if (mCount == 0 && !mLastDecRunnables.isEmpty()) {
            int numRunnables = mLastDecRunnables.size();
            for (int i = 0; i < numRunnables; i++) {
                mLastDecRunnables.get(i).run();
            }
        } else if (mCount < 0) {
            if (mErrorRunnable != null) {
                mErrorRunnable.run();
            } else {
                new Throwable("Invalid ref count").printStackTrace();
                Console.logError(mContext, "Invalid ref count");
            }
        }
    
public java.lang.RunnabledecrementAsRunnable()
Convenience method to decrement this trigger as a runnable.

        return mDecrementRunnable;
    
public Animator.AnimatorListenerdecrementOnAnimationEnd()
Convenience method to decrement this trigger as a animator listener.

        return new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                decrement();
            }
        };
    
public intgetCount()
Returns the current ref count

        return mCount;
    
public voidincrement()
Increments the ref count

        if (mCount == 0 && !mFirstIncRunnables.isEmpty()) {
            int numRunnables = mFirstIncRunnables.size();
            for (int i = 0; i < numRunnables; i++) {
                mFirstIncRunnables.get(i).run();
            }
        }
        mCount++;
    
public java.lang.RunnableincrementAsRunnable()
Convenience method to increment this trigger as a runnable

        return mIncrementRunnable;