Java Code Examples for android.support.v4.util.ArrayMap#keyAt()

The following examples show how to use android.support.v4.util.ArrayMap#keyAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharedElementUtils.java    From scene with Apache License 2.0 6 votes vote down vote up
/**
 * Guarantee order: Parent -> Child
 * Make sure that Parent will not overwrite Child when adding Overlay
 */
public static List<NonNullPair<String, View>> sortSharedElementList(ArrayMap<String, View> sharedElements) {
    List<NonNullPair<String, View>> list = new ArrayList<>();
    boolean isFirstRun = true;
    while (!sharedElements.isEmpty()) {
        final int numSharedElements = sharedElements.size();
        for (int i = numSharedElements - 1; i >= 0; i--) {
            final View view = sharedElements.valueAt(i);
            final String name = sharedElements.keyAt(i);
            if (isFirstRun && (view == null || !view.isAttachedToWindow() || name == null)) {
                sharedElements.removeAt(i);
            } else if (!isNested(view, sharedElements)) {
                list.add(NonNullPair.create(name, view));
                sharedElements.removeAt(i);
            }
        }
        isFirstRun = false;
    }
    return list;
}
 
Example 2
Source File: BaseExpandableAdapter.java    From ExpandableRecyclerview with Apache License 2.0 6 votes vote down vote up
/**
 * check has item is expanded by default
 */
private void checkDefaultExpand() {
    ArrayMap<Object, List<?>> childArrayMap = new ArrayMap<>();
    Iterator<Object> iterator = mDataList.iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (next instanceof ExpandableListItem) {
            ExpandableListItem expandableListItem = (ExpandableListItem) next;
            if (expandableListItem.isExpanded()) {
                List<?> childItemList = expandableListItem.getChildItemList();
                if (childItemList != null && !childItemList.isEmpty()) {
                    childArrayMap.put(next, childItemList);
                }
            }
        }
    }
    int size = childArrayMap.size();
    if (size == 0) return;
    for (int i = 0; i < size; i++) {
        Object o = childArrayMap.keyAt(i);
        List<?> objects = childArrayMap.valueAt(i);
        int indexOf = mDataList.indexOf(o);
        mDataList.addAll(indexOf + 1, objects);
    }

}
 
Example 3
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Pauses this transition, sending out calls to {@link
 * TransitionListener#onTransitionPause(Transition)} to all listeners
 * and pausing all running animators started by this transition.
 *
 * @hide
 */
public void pause(@NonNull View sceneRoot) {
    if (!mEnded) {
        synchronized (sRunningAnimators) {
            ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
            int numOldAnims = runningAnimators.size();
            Object windowId = ViewUtils.getWindowId(sceneRoot);
            for (int i = numOldAnims - 1; i >= 0; i--) {
                AnimationInfo info = runningAnimators.valueAt(i);
                if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                    Animator anim = runningAnimators.keyAt(i);
                    AnimatorUtils.pause(anim);
                }
            }
        }
        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).onTransitionPause(this);
            }
        }
        mPaused = true;
    }
}
 
Example 4
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Resumes this transition, sending out calls to {@link
 * TransitionListener#onTransitionPause(Transition)} to all listeners
 * and pausing all running animators started by this transition.
 *
 * @hide
 */
public void resume(@NonNull View sceneRoot) {
    if (mPaused) {
        if (!mEnded) {
            ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
            int numOldAnims = runningAnimators.size();
            Object windowId = ViewUtils.getWindowId(sceneRoot);
            for (int i = numOldAnims - 1; i >= 0; i--) {
                AnimationInfo info = runningAnimators.valueAt(i);
                if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                    Animator anim = runningAnimators.keyAt(i);
                    AnimatorUtils.resume(anim);
                }
            }
            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).onTransitionResume(this);
                }
            }
        }
        mPaused = false;
    }
}
 
Example 5
Source File: BackStackRecord.java    From letv with Apache License 2.0 5 votes vote down vote up
private void setNameOverrides(TransitionState state, ArrayMap<String, View> namedViews, boolean isEnd) {
    int count = namedViews.size();
    for (int i = 0; i < count; i++) {
        String source = (String) namedViews.keyAt(i);
        String target = FragmentTransitionCompat21.getTransitionName((View) namedViews.valueAt(i));
        if (isEnd) {
            setNameOverride(state.nameOverrides, source, target);
        } else {
            setNameOverride(state.nameOverrides, target, source);
        }
    }
}
 
Example 6
Source File: BackStackRecord.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void setNameOverrides(TransitionState state, ArrayMap<String, View> namedViews,
        boolean isEnd) {
    int count = namedViews.size();
    for (int i = 0; i < count; i++) {
        String source = namedViews.keyAt(i);
        String target = FragmentTransitionCompat21.getTransitionName(namedViews.valueAt(i));
        if (isEnd) {
            setNameOverride(state.nameOverrides, source, target);
        } else {
            setNameOverride(state.nameOverrides, target, source);
        }
    }
}
 
Example 7
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
/**
 * Match start/end values by View instance. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd.
 */
private void matchInstances(@NonNull ArrayMap<View, TransitionValues> unmatchedStart,
                            @NonNull ArrayMap<View, TransitionValues> unmatchedEnd) {
    for (int i = unmatchedStart.size() - 1; i >= 0; i--) {
        View view = unmatchedStart.keyAt(i);
        if (view != null && isValidTarget(view)) {
            TransitionValues end = unmatchedEnd.remove(view);
            if (end != null && isValidTarget(end.view)) {
                TransitionValues start = unmatchedStart.removeAt(i);
                mStartValuesList.add(start);
                mEndValuesList.add(end);
            }
        }
    }
}
 
Example 8
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
/**
 * Force the transition to move to its end state, ending all the animators.
 */
void forceToEnd(@Nullable ViewGroup sceneRoot) {
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    if (sceneRoot != null) {
        Object windowId = ViewUtils.getWindowId(sceneRoot);
        for (int i = numOldAnims - 1; i >= 0; i--) {
            AnimationInfo info = runningAnimators.valueAt(i);
            if (info.view != null && windowId != null && windowId.equals(info.windowId)) {
                Animator anim = runningAnimators.keyAt(i);
                anim.end();
            }
        }
    }
}
 
Example 9
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 */
void playTransition(@NonNull ViewGroup sceneRoot) {
    mStartValuesList = new ArrayList<TransitionValues>();
    mEndValuesList = new ArrayList<TransitionValues>();
    matchStartAndEnd(mStartValues, mEndValues);

    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    synchronized (sRunningAnimators) {
        int numOldAnims = runningAnimators.size();
        Object windowId = ViewUtils.getWindowId(sceneRoot);
        for (int i = numOldAnims - 1; i >= 0; i--) {
            Animator anim = runningAnimators.keyAt(i);
            if (anim != null) {
                AnimationInfo oldInfo = runningAnimators.get(anim);
                if (oldInfo != null && oldInfo.view != null && oldInfo.windowId == windowId) {
                    TransitionValues oldValues = oldInfo.values;
                    View oldView = oldInfo.view;
                    TransitionValues startValues = getTransitionValues(oldView, true);
                    TransitionValues endValues = getMatchedTransitionValues(oldView, true);
                    if (startValues == null && endValues == null) {
                        endValues = mEndValues.viewValues.get(oldView);
                    }
                    boolean cancel = (startValues != null || endValues != null) &&
                            oldInfo.transition.isTransitionRequired(oldValues, endValues);
                    if (cancel) {
                        if (anim.isRunning() || AnimatorUtils.isAnimatorStarted(anim)) {
                            if (DBG) {
                                Log.d(LOG_TAG, "Canceling anim " + anim);
                            }
                            anim.cancel();
                        } else {
                            if (DBG) {
                                Log.d(LOG_TAG, "removing anim from info list: " + anim);
                            }
                            runningAnimators.remove(anim);
                        }
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues, mStartValuesList, mEndValuesList);
    runAnimators();
}