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

The following examples show how to use android.support.v4.util.ArrayMap#size() . 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
/**
 * Match start/end values by Adapter transitionName. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startNames and endNames as a guide for which Views have unique transitionNames.
 */
private void matchNames(@NonNull ArrayMap<View, TransitionValues> unmatchedStart,
                        @NonNull ArrayMap<View, TransitionValues> unmatchedEnd,
                        @NonNull ArrayMap<String, View> startNames,
                        @NonNull ArrayMap<String, View> endNames) {
    int numStartNames = startNames.size();
    for (int i = 0; i < numStartNames; i++) {
        View startView = startNames.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endNames.get(startNames.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}
 
Example 4
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 5
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 6
Source File: BackStackRecord.java    From letv with Apache License 2.0 5 votes vote down vote up
private static void setNameOverride(ArrayMap<String, String> overrides, String source, String target) {
    if (source != null && target != null) {
        for (int index = 0; index < overrides.size(); index++) {
            if (source.equals(overrides.valueAt(index))) {
                overrides.setValueAt(index, target);
                return;
            }
        }
        overrides.put(source, target);
    }
}
 
Example 7
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 8
Source File: AbsElement.java    From android-databinding with Apache License 2.0 5 votes vote down vote up
protected void writeAttrs(XmlWriter writer) {
	try {
		final ArrayMap<String, String> attrMap = getAttributeMap();
		for(int i=0,size=attrMap.size() ;  i< size ;i++){
			writer.attribute(attrMap.keyAt(i),attrMap.valueAt(i));
		}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 9
Source File: BackStackRecord.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private static void setNameOverride(ArrayMap<String, String> overrides,
        String source, String target) {
    if (source != null && target != null && !source.equals(target)) {
        for (int index = 0; index < overrides.size(); index++) {
            if (source.equals(overrides.valueAt(index))) {
                overrides.setValueAt(index, target);
                return;
            }
        }
        overrides.put(source, target);
    }
}
 
Example 10
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 11
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 12
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
/**
 * Adds all values from unmatchedStart and unmatchedEnd to mStartValuesList and mEndValuesList,
 * assuming that there is no match between values in the list.
 */
private void addUnmatched(@NonNull ArrayMap<View, TransitionValues> unmatchedStart,
                          @NonNull ArrayMap<View, TransitionValues> unmatchedEnd) {
    // Views that only exist in the start Scene
    for (int i = 0; i < unmatchedStart.size(); i++) {
        mStartValuesList.add(unmatchedStart.valueAt(i));
        mEndValuesList.add(null);
    }

    // Views that only exist in the end Scene
    for (int i = 0; i < unmatchedEnd.size(); i++) {
        mEndValuesList.add(unmatchedEnd.valueAt(i));
        mStartValuesList.add(null);
    }
}
 
Example 13
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 14
Source File: MainActivity.java    From FabulousFilter with Apache License 2.0 4 votes vote down vote up
@Override
public void onResult(Object result) {
    Log.d("k9res", "onResult: " + result.toString());
    if (result.toString().equalsIgnoreCase("swiped_down")) {
        //do something or nothing
    } else {
        if (result != null) {
            ArrayMap<String, List<String>> applied_filters = (ArrayMap<String, List<String>>) result;
            if (applied_filters.size() != 0) {
                List<SingleMovie> filteredList = mData.getAllMovies();
                //iterate over arraymap
                for (Map.Entry<String, List<String>> entry : applied_filters.entrySet()) {
                    Log.d("k9res", "entry.key: " + entry.getKey());
                    switch (entry.getKey()) {
                        case "genre":
                            filteredList = mData.getGenreFilteredMovies(entry.getValue(), filteredList);
                            break;
                        case "rating":
                            filteredList = mData.getRatingFilteredMovies(entry.getValue(), filteredList);
                            break;
                        case "year":
                            filteredList = mData.getYearFilteredMovies(entry.getValue(), filteredList);
                            break;
                        case "quality":
                            filteredList = mData.getQualityFilteredMovies(entry.getValue(), filteredList);
                            break;
                    }
                }
                Log.d("k9res", "new size: " + filteredList.size());
                mList.clear();
                mList.addAll(filteredList);
                mAdapter.notifyDataSetChanged();

            } else {
                mList.addAll(mData.getAllMovies());
                mAdapter.notifyDataSetChanged();
            }
        }
        //handle result
    }
}
 
Example 15
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();
}