Example usage for android.view View setHasTransientState

List of usage examples for android.view View setHasTransientState

Introduction

In this page you can find the example usage for android.view View setHasTransientState.

Prototype

public void setHasTransientState(boolean hasTransientState) 

Source Link

Document

Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible.

Usage

From source file:com.givewaygames.transition.Transition.java

/**
 * This method is called automatically by the Transition and
 * TransitionSet classes when a transition finishes, either because
 * a transition did nothing (returned a null Animator from
 * {@link com.hirevue.manager.tmp.transition.Transition#createAnimator(android.view.ViewGroup, android.transition.TransitionValues,
 * android.transition.TransitionValues)}) or because the transition returned a valid
 * Animator and end() was called in the onAnimationEnd()
 * callback of the AnimatorListener.//  ww  w .  j ava2s  .c  o m
 *
 * @hide
 */
protected void end() {
    --mNumInstances;
    if (mNumInstances == 0) {
        if (mListeners != null && mListeners.size() > 0) {
            ArrayList<TransitionListener> tmpListeners = (ArrayList<TransitionListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onTransitionEnd(this);
            }
        }
        for (int i = 0; i < mStartValues.itemIdValues.size(); ++i) {
            TransitionValues tv = mStartValues.itemIdValues.valueAt(i);
            View v = tv.view;
            if (v.hasTransientState()) {
                v.setHasTransientState(false);
            }
        }
        for (int i = 0; i < mEndValues.itemIdValues.size(); ++i) {
            TransitionValues tv = mEndValues.itemIdValues.valueAt(i);
            View v = tv.view;
            if (v.hasTransientState()) {
                v.setHasTransientState(false);
            }
        }
        mEnded = true;
    }
}

From source file:com.givewaygames.transition.Transition.java

/**
 * Recursive method which captures values for an entire view hierarchy,
 * starting at some root view. Transitions without targetIDs will use this
 * method to capture values for all possible views.
 *
 * @param view The view for which to capture values. Children of this View
 * will also be captured, recursively down to the leaf nodes.
 * @param start true if values are being captured in the start scene, false
 * otherwise./* w  w  w .j a  va 2  s  .co m*/
 */
private void captureHierarchy(View view, boolean start) {
    if (view == null) {
        return;
    }
    boolean isListViewItem = false;
    if (view.getParent() instanceof ListView) {
        isListViewItem = true;
    }
    if (isListViewItem && !((ListView) view.getParent()).getAdapter().hasStableIds()) {
        // ignore listview children unless we can track them with stable IDs
        return;
    }
    int id = View.NO_ID;
    long itemId = View.NO_ID;
    if (!isListViewItem) {
        id = view.getId();
    } else {
        ListView listview = (ListView) view.getParent();
        int position = listview.getPositionForView(view);
        itemId = listview.getItemIdAtPosition(position);
        view.setHasTransientState(true);
    }
    if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) {
        return;
    }
    if (mTargetExcludes != null && mTargetExcludes.contains(view)) {
        return;
    }
    if (mTargetTypeExcludes != null && view != null) {
        int numTypes = mTargetTypeExcludes.size();
        for (int i = 0; i < numTypes; ++i) {
            if (mTargetTypeExcludes.get(i).isInstance(view)) {
                return;
            }
        }
    }
    TransitionValues values = new TransitionValues();
    values.view = view;
    if (start) {
        captureStartValues(values);
    } else {
        captureEndValues(values);
    }
    if (start) {
        if (!isListViewItem) {
            mStartValues.viewValues.put(view, values);
            if (id >= 0) {
                mStartValues.idValues.put((int) id, values);
            }
        } else {
            mStartValues.itemIdValues.put(itemId, values);
        }
    } else {
        if (!isListViewItem) {
            mEndValues.viewValues.put(view, values);
            if (id >= 0) {
                mEndValues.idValues.put((int) id, values);
            }
        } else {
            mEndValues.itemIdValues.put(itemId, values);
        }
    }
    if (view instanceof ViewGroup) {
        // Don't traverse child hierarchy if there are any child-excludes on this view
        if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) {
            return;
        }
        if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) {
            return;
        }
        if (mTargetTypeChildExcludes != null && view != null) {
            int numTypes = mTargetTypeChildExcludes.size();
            for (int i = 0; i < numTypes; ++i) {
                if (mTargetTypeChildExcludes.get(i).isInstance(view)) {
                    return;
                }
            }
        }
        ViewGroup parent = (ViewGroup) view;
        for (int i = 0; i < parent.getChildCount(); ++i) {
            captureHierarchy(parent.getChildAt(i), start);
        }
    }
}