List of usage examples for android.util LongSparseArray put
public void put(long key, E value)
From source file:com.appsimobile.appsii.module.apps.AppPageLoader.java
/** * Helper method to add items to a list in a long sparse array that maps keys to lists. *//*from ww w. j av a2s . co m*/ static <V> void addItemToLongSparseArray(LongSparseArray<List<V>> map, long key, V item) { List<V> list = map.get(key); if (list == null) { list = new ArrayList<>(); map.put(key, list); } list.add(item); }
From source file:android.databinding.ViewDataBinding.java
/** @hide */ @TargetApi(VERSION_CODES.JELLY_BEAN)/* ww w.ja va 2 s . c o m*/ protected static <T> void setTo(LongSparseArray<T> list, int index, T value) { if (list == null || index < 0 || index >= list.size()) { return; } list.put(index, value); }
From source file:android.databinding.ViewDataBinding.java
/** @hide */ protected static <T> void setTo(android.support.v4.util.LongSparseArray<T> list, int index, T value) { if (list == null || index < 0 || index >= list.size()) { return;/* ww w . j a va 2 s . com*/ } list.put(index, value); }
From source file:de.robbers.dashclock.stackextension.StackExtension.java
private void parseReputationResponse(String json) { if (json == null) { return;/*from w w w . ja v a2 s.c o m*/ } mExpandedBody = ""; LongSparseArray reputationArray = new LongSparseArray(); try { JSONArray items = new JSONObject(json).getJSONArray("items"); Log.i(TAG, items.toString(2)); for (int i = 0; i < items.length(); i++) { JSONObject reputation = items.getJSONObject(i); long postId = reputation.optLong("post_id"); int reputationChange = reputation.optInt("reputation_change"); int newValue = reputationChange; newValue += (Integer) reputationArray.get(postId, 0); reputationArray.put(postId, newValue); } List<Long> postIds = new ArrayList<Long>(); for (int i = 0; i < items.length(); i++) { JSONObject reputation = items.getJSONObject(i); long postId = reputation.optLong("post_id"); int reputationChange = reputation.optInt("reputation_change"); if (postIds.contains(postId) || reputationChange == 0) { continue; } postIds.add(postId); int reputationValue = (Integer) reputationArray.get(postId); String title = String.valueOf(Html.fromHtml(reputation.optString("title"))); mExpandedBody += buildExpandedBodyPost(reputationValue, title, postIds.size()); } } catch (JSONException e) { Log.i(TAG, json); e.printStackTrace(); } if (TextUtils.isEmpty(mExpandedBody)) { mExpandedBody = getString(R.string.no_recent_reputation_changes); } }
From source file:com.givewaygames.transition.Transition.java
/** * This method, essentially a wrapper around all calls to createAnimator for all * possible target views, is called with the entire set of start/end * values. The implementation in Transition iterates through these lists * and calls {@link #createAnimator(android.view.ViewGroup, android.transition.TransitionValues, android.transition.TransitionValues)} * with each set of start/end values on this transition. The * TransitionSet subclass overrides this method and delegates it to * each of its children in succession./*from w w w.j av a2 s.com*/ * * @hide */ protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues, TransitionValuesMaps endValues) { if (DBG) { Log.d(LOG_TAG, "createAnimators() for " + this); } ArrayMap<View, TransitionValues> endCopy = new ArrayMap<View, TransitionValues>(endValues.viewValues); SparseArray<TransitionValues> endIdCopy = new SparseArray<TransitionValues>(endValues.idValues.size()); for (int i = 0; i < endValues.idValues.size(); ++i) { int id = endValues.idValues.keyAt(i); endIdCopy.put(id, endValues.idValues.valueAt(i)); } LongSparseArray<TransitionValues> endItemIdCopy = new LongSparseArray<TransitionValues>( endValues.itemIdValues.size()); for (int i = 0; i < endValues.itemIdValues.size(); ++i) { long id = endValues.itemIdValues.keyAt(i); endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i)); } // Walk through the start values, playing everything we find // Remove from the end set as we go ArrayList<TransitionValues> startValuesList = new ArrayList<TransitionValues>(); ArrayList<TransitionValues> endValuesList = new ArrayList<TransitionValues>(); for (View view : startValues.viewValues.keySet()) { TransitionValues start = null; TransitionValues end = null; boolean isInListView = false; if (view.getParent() instanceof ListView) { isInListView = true; } if (!isInListView) { int id = view.getId(); start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view) : startValues.idValues.get(id); if (endValues.viewValues.get(view) != null) { end = endValues.viewValues.get(view); endCopy.remove(view); } else if (id != View.NO_ID) { end = endValues.idValues.get(id); View removeView = null; for (View viewToRemove : endCopy.keySet()) { if (viewToRemove.getId() == id) { removeView = viewToRemove; } } if (removeView != null) { endCopy.remove(removeView); } } endIdCopy.remove(id); if (isValidTarget(view, id)) { startValuesList.add(start); endValuesList.add(end); } } else { ListView parent = (ListView) view.getParent(); if (parent.getAdapter().hasStableIds()) { int position = parent.getPositionForView(view); long itemId = parent.getItemIdAtPosition(position); start = startValues.itemIdValues.get(itemId); endItemIdCopy.remove(itemId); // TODO: deal with targetIDs for itemIDs for ListView items startValuesList.add(start); endValuesList.add(end); } } } int startItemIdCopySize = startValues.itemIdValues.size(); for (int i = 0; i < startItemIdCopySize; ++i) { long id = startValues.itemIdValues.keyAt(i); if (isValidTarget(null, id)) { TransitionValues start = startValues.itemIdValues.get(id); TransitionValues end = endValues.itemIdValues.get(id); endItemIdCopy.remove(id); startValuesList.add(start); endValuesList.add(end); } } // Now walk through the remains of the end set for (View view : endCopy.keySet()) { int id = view.getId(); if (isValidTarget(view, id)) { TransitionValues start = startValues.viewValues.get(view) != null ? startValues.viewValues.get(view) : startValues.idValues.get(id); TransitionValues end = endCopy.get(view); endIdCopy.remove(id); startValuesList.add(start); endValuesList.add(end); } } int endIdCopySize = endIdCopy.size(); for (int i = 0; i < endIdCopySize; ++i) { int id = endIdCopy.keyAt(i); if (isValidTarget(null, id)) { TransitionValues start = startValues.idValues.get(id); TransitionValues end = endIdCopy.get(id); startValuesList.add(start); endValuesList.add(end); } } int endItemIdCopySize = endItemIdCopy.size(); for (int i = 0; i < endItemIdCopySize; ++i) { long id = endItemIdCopy.keyAt(i); // TODO: Deal with targetIDs and itemIDs TransitionValues start = startValues.itemIdValues.get(id); TransitionValues end = endItemIdCopy.get(id); startValuesList.add(start); endValuesList.add(end); } ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators(); for (int i = 0; i < startValuesList.size(); ++i) { TransitionValues start = startValuesList.get(i); TransitionValues end = endValuesList.get(i); // Only bother trying to animate with values that differ between start/end if (start != null || end != null) { if (start == null || !start.equals(end)) { if (DBG) { View view = (end != null) ? end.view : start.view; Log.d(LOG_TAG, " differing start/end values for view " + view); if (start == null || end == null) { Log.d(LOG_TAG, " " + ((start == null) ? "start null, end non-null" : "start non-null, end null")); } else { for (String key : start.values.keySet()) { Object startValue = start.values.get(key); Object endValue = end.values.get(key); if (startValue != endValue && !startValue.equals(endValue)) { Log.d(LOG_TAG, " " + key + ": start(" + startValue + "), end(" + endValue + ")"); } } } } // TODO: what to do about targetIds and itemIds? Animator animator = createAnimator(sceneRoot, start, end); if (animator != null) { // Save animation info for future cancellation purposes View view = null; TransitionValues infoValues = null; if (end != null) { view = end.view; String[] properties = getTransitionProperties(); if (view != null && properties != null && properties.length > 0) { infoValues = new TransitionValues(); infoValues.view = view; TransitionValues newValues = endValues.viewValues.get(view); if (newValues != null) { for (int j = 0; j < properties.length; ++j) { infoValues.values.put(properties[j], newValues.values.get(properties[j])); } } int numExistingAnims = runningAnimators.size(); for (int j = 0; j < numExistingAnims; ++j) { Animator anim = runningAnimators.keyAt(j); AnimationInfo info = runningAnimators.get(anim); if (info.values != null && info.view == view && ((info.name == null && getName() == null) || info.name.equals(getName()))) { if (info.values.equals(infoValues)) { // Favor the old animator animator = null; break; } } } } } else { view = (start != null) ? start.view : null; } if (animator != null) { AnimationInfo info = new AnimationInfo(view, getName(), infoValues); runningAnimators.put(animator, info); mAnimators.add(animator); } } } } } }
From source file:com.example.twoway.TwoWayView.java
@Override public Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); if (mPendingSync != null) { ss.selectedId = mPendingSync.selectedId; ss.firstId = mPendingSync.firstId; ss.viewStart = mPendingSync.viewStart; ss.position = mPendingSync.position; ss.height = mPendingSync.height; return ss; }/*from www . jav a2 s . c om*/ boolean haveChildren = (getChildCount() > 0 && mItemCount > 0); long selectedId = getSelectedItemId(); ss.selectedId = selectedId; ss.height = getHeight(); if (selectedId >= 0) { ss.viewStart = mSelectedStart; ss.position = getSelectedItemPosition(); ss.firstId = INVALID_POSITION; } else if (haveChildren && mFirstPosition > 0) { // Remember the position of the first child. // We only do this if we are not currently at the top of // the list, for two reasons: // // (1) The list may be in the process of becoming empty, in // which case mItemCount may not be 0, but if we try to // ask for any information about position 0 we will crash. // // (2) Being "at the top" seems like a special case, anyway, // and the user wouldn't expect to end up somewhere else when // they revisit the list even if its content has changed. View child = getChildAt(0); ss.viewStart = (mIsVertical ? child.getTop() : child.getLeft()); int firstPos = mFirstPosition; if (firstPos >= mItemCount) { firstPos = mItemCount - 1; } ss.position = firstPos; ss.firstId = mAdapter.getItemId(firstPos); } else { ss.viewStart = 0; ss.firstId = INVALID_POSITION; ss.position = 0; } if (mCheckStates != null) { ss.checkState = cloneCheckStates(); } if (mCheckedIdStates != null) { final LongSparseArray<Integer> idState = new LongSparseArray<Integer>(); final int count = mCheckedIdStates.size(); for (int i = 0; i < count; i++) { idState.put(mCheckedIdStates.keyAt(i), mCheckedIdStates.valueAt(i)); } ss.checkIdState = idState; } ss.checkedItemCount = mCheckedItemCount; return ss; }