List of usage examples for android.widget ListView getAdapter
@Override
public ListAdapter getAdapter()
From source file:com.learn.mobile.customview.DSwipeRefreshLayout.java
private void initTarget() { if (mTarget instanceof RecyclerView) { RecyclerView recyclerView = (RecyclerView) mTarget; recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override/*from ww w .j av a2s . c om*/ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (!bEnableLoadMore) { return; } if (dy < 0) { return; } if (bLoadMoreProcessing == true) { return; } if (!canLoadMore) { return; } LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); int visibleItemCount = recyclerView.getChildCount(); int totalItemCount = linearLayoutManager.getItemCount(); int firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition(); if ((visibleItemCount + firstVisibleItem) >= totalItemCount) { onLoadMore(); } } }); } else if (mTarget instanceof ListView) { ListView listView = (ListView) mTarget; listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!bEnableLoadMore) { return; } if (bLoadMoreProcessing == true) { return; } if (!canLoadMore) { return; } ListView listView1 = (ListView) mTarget; if (listView1.getAdapter() == null) { stopLoadMore(); return; } if (listView1.getAdapter().getCount() == 0) { stopLoadMore(); return; } int l = visibleItemCount + firstVisibleItem; if (l >= totalItemCount) { onLoadMore(); } else { stopLoadMore(); return; } } }); } }
From source file:com.achep.header2actionbar.HeaderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Activity activity = getActivity(); assert activity != null; mFrameLayout = new FrameLayout(activity); mHeader = onCreateHeaderView(inflater, mFrameLayout); mHeaderHeader = mHeader.findViewById(android.R.id.title); mHeaderBackground = mHeader.findViewById(android.R.id.background); assert mHeader.getLayoutParams() != null; mHeaderHeight = mHeader.getLayoutParams().height; mFakeHeader = new Space(activity); mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight)); View content = onCreateContentView(inflater, mFrameLayout); if (content instanceof ListView) { isListViewEmpty = true;//from ww w .j a v a 2 s.c o m final ListView listView = (ListView) content; listView.addHeaderView(mFakeHeader); onSetAdapter(); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } isListViewEmpty = listView.getAdapter() == null; if (isListViewEmpty) { scrollHeaderTo(0); } else { final View child = absListView.getChildAt(0); assert child != null; scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight); // Log.v("header height",String.format("mHeaderHeight:%s",mHeaderHeight)); } } }); } else if (content instanceof GridView) { isListViewEmpty = true; final GridView grid = (GridView) content; //isListViewEmpty = grid.getAdapter() == null; // grid.addHeaderView(mFakeHeader); // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(grid); grid.setOnScrollListener(new AbsListView.OnScrollListener() { private ListViewScrollTracker mScrollTracker;; @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } public int getGridScrollY(GridView grid) { Method privateStringMethod = null; Integer scrollOffset = null; Integer scrollExtent = null; Integer scrollRange = null; try { privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollOffset", null); privateStringMethod.setAccessible(true); scrollOffset = (Integer) privateStringMethod.invoke(grid, null); privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollExtent", null); privateStringMethod.setAccessible(true); scrollExtent = (Integer) privateStringMethod.invoke(grid, null); privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollRange", null); privateStringMethod.setAccessible(true); scrollRange = (Integer) privateStringMethod.invoke(grid, null); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return scrollRange;//scrollExtent*scrollOffset; } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mScrollTracker == null) mScrollTracker = new ListViewScrollTracker(absListView); mScrollPosition = mScrollTracker.calculateIncrementalOffset(firstVisibleItem, visibleItemCount); Log.v("header", "scrollPosition:" + mScrollPosition); if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } final View child = absListView.getChildAt(0); if (child != null) { int gridScrollY = mScrollPosition;//getGridScrollY((GridView) absListView); scrollHeaderTo(-gridScrollY); //change the size of the fake header on scrolling int currentHeight = mFakeHeader.getLayoutParams().height; Integer fakeHeaderHeight = (int) (mHeaderHeight - (gridScrollY * 2)); mFakeHeader.setLayoutParams(new android.widget.LinearLayout.LayoutParams( mFakeHeader.getWidth(), fakeHeaderHeight)); // setViewTranslationY(mFrameLayout, -1*(gridScrollY)); } else scrollHeaderTo(0); } }); content = view; } else { // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(content); // Put merged content to ScrollView final NotifyingScrollView scrollView = new NotifyingScrollView(activity); scrollView.addView(view); scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { scrollHeaderTo(-t); } }); content = scrollView; } mFrameLayout.addView(content); mFrameLayout.addView(mHeader); // Content overlay view always shows at the top of content. if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) { mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } // Post initial scroll mFrameLayout.post(new Runnable() { @Override public void run() { scrollHeaderTo(0, true); } }); return mFrameLayout; }
From source file:android.transitions.everywhere.Transition.java
static void addViewValues(TransitionValuesMaps transitionValuesMaps, View view, TransitionValues transitionValues) { transitionValuesMaps.viewValues.put(view, transitionValues); int id = view.getId(); if (id >= 0) { if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) { // Duplicate IDs cannot match by ID. transitionValuesMaps.idValues.put(id, null); } else {//from ww w . jav a 2 s .c om transitionValuesMaps.idValues.put(id, view); } } String name = ViewUtils.getTransitionName(view); if (name != null) { if (transitionValuesMaps.nameValues.containsKey(name)) { // Duplicate transitionNames: cannot match by transitionName. transitionValuesMaps.nameValues.put(name, null); } else { transitionValuesMaps.nameValues.put(name, view); } } if (view.getParent() instanceof ListView) { ListView listview = (ListView) view.getParent(); if (listview.getAdapter().hasStableIds()) { int position = listview.getPositionForView(view); long itemId = listview.getItemIdAtPosition(position); if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) { // Duplicate item IDs: cannot match by item ID. View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId); if (alreadyMatched != null) { android.support.v4.view.ViewCompat.setHasTransientState(alreadyMatched, false); transitionValuesMaps.itemIdValues.put(itemId, null); } } else { android.support.v4.view.ViewCompat.setHasTransientState(view, true); transitionValuesMaps.itemIdValues.put(itemId, view); } } } }
From source file:android.support.transition.TransitionPort.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(ViewGroup, TransitionValues, 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 www . j a va 2s .c o m*/ * * @hide */ @RestrictTo(GROUP_ID) protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues, TransitionValuesMaps endValues) { if (DBG) { Log.d(LOG_TAG, "createAnimators() for " + this); } ArrayMap<View, TransitionValues> endCopy = new ArrayMap<>(endValues.viewValues); SparseArray<TransitionValues> endIdCopy = new SparseArray<>(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<>(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<>(); ArrayList<TransitionValues> endValuesList = new ArrayList<>(); for (View view : startValues.viewValues.keySet()) { TransitionValues start; 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; 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.view; } if (animator != null) { AnimationInfo info = new AnimationInfo(view, getName(), WindowIdPort.getWindowId(sceneRoot), infoValues); runningAnimators.put(animator, info); mAnimators.add(animator); } } } } } }
From source file:com.transitionseverywhere.Transition.java
static void addViewValues(TransitionValuesMaps transitionValuesMaps, View view, TransitionValues transitionValues) { transitionValuesMaps.viewValues.put(view, transitionValues); int id = view.getId(); if (id >= 0) { if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) { // Duplicate IDs cannot match by ID. transitionValuesMaps.idValues.put(id, null); } else {/*from w w w. j a v a2 s. com*/ transitionValuesMaps.idValues.put(id, view); } } String name = ViewUtils.getTransitionName(view); if (name != null) { if (transitionValuesMaps.nameValues.containsKey(name)) { // Duplicate transitionNames: cannot match by transitionName. transitionValuesMaps.nameValues.put(name, null); } else { transitionValuesMaps.nameValues.put(name, view); } } if (view.getParent() instanceof ListView) { ListView listview = (ListView) view.getParent(); if (listview.getAdapter().hasStableIds()) { int position = listview.getPositionForView(view); long itemId = listview.getItemIdAtPosition(position); if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) { // Duplicate item IDs: cannot match by item ID. View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId); if (alreadyMatched != null) { ViewUtils.setHasTransientState(alreadyMatched, false); transitionValuesMaps.itemIdValues.put(itemId, null); } } else { ViewUtils.setHasTransientState(view, true); transitionValuesMaps.itemIdValues.put(itemId, view); } } } }
From source file:com.tweetlanes.android.view.TweetFeedFragment.java
@Override public void onJumpToTop() { if (mTweetFeedListView != null) { ListView listView = mTweetFeedListView.getRefreshableView(); if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) { listView.setSelection(0);// w w w . j a va 2 s. c o m } } }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java
/** * Load the calibrated swatches from the calibration text file * * @param callback callback to be initiated once the loading is complete *//* w w w. ja va2 s . com*/ private void loadCalibration(@NonNull final Context context, @NonNull final Handler.Callback callback) { try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, R.layout.row_text); final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, CaddisflyApp.getApp().getCurrentTestInfo().getId()); File[] listFilesTemp = null; if (path.exists() && path.isDirectory()) { listFilesTemp = path.listFiles(); } final File[] listFiles = listFilesTemp; if (listFiles != null && listFiles.length > 0) { Arrays.sort(listFiles); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); try { final List<Swatch> swatchList = SwatchHelper.loadCalibrationFromFile(getBaseContext(), fileName); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { SwatchHelper.saveCalibratedSwatches(context, swatchList); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } catch (Exception ex) { AlertUtil.showError(context, R.string.error, getString(R.string.errorLoadingFile), null, R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }, null, null); } } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alertDialog.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtil.askQuestion(context, R.string.delete, R.string.deleteConfirm, R.string.delete, R.string.cancel, true, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtil.deleteFile(path, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); alertDialog.dismiss(); Toast.makeText(context, R.string.deleted, Toast.LENGTH_SHORT) .show(); } }, null); return true; } }); } }); alertDialog.show(); } else { AlertUtil.showMessage(context, R.string.notFound, R.string.loadFilesNotAvailable); } } catch (ActivityNotFoundException ignored) { } callback.handleMessage(null); }
From source file:com.juick.android.MessagesFragment.java
public MessageListBackingData getMessageListBackingData() { MessageListBackingData mlbd = new MessageListBackingData(); mlbd.messagesSource = messagesSource; mlbd.topMessageId = topMessageId;// ww w. j av a2s .c o m ListView lv = null; try { lv = getListView(); ListAdapter adapter = lv.getAdapter(); if (adapter == null) adapter = listAdapter; int firstVisiblePosition = lv.getFirstVisiblePosition(); JuickMessage jm = (JuickMessage) adapter.getItem(firstVisiblePosition); mlbd.topMessageId = jm.getMID(); for (int i = 0; i < lv.getChildCount(); i++) { View thatView = lv.getChildAt(i); int positionForView = lv.getPositionForView(thatView); if (positionForView == firstVisiblePosition) { mlbd.topMessageScrollPos = thatView.getTop(); break; } } } catch (Exception e) { // various conditions } if (lv == null) { return null; } int firstVisiblePosition = Math.max(0, lv.getFirstVisiblePosition() - 120); mlbd.messages = new ArrayList<JuickMessage>(); for (int i = firstVisiblePosition; i < listAdapter.getCount(); i++) { mlbd.messages.add(listAdapter.getItem(i)); } return mlbd; }
From source file:com.wewow.MainActivity.java
public void fixListViewHeight(ListView listView) { // ??ListView? ListAdapter listAdapter = listView.getAdapter(); int totalHeight = 0; if (listAdapter == null) { return;/*w ww.j ava 2 s . c o m*/ } for (int i = 0, len = listAdapter.getCount(); i < len; i++) { View listViewItem = listAdapter.getView(i, null, listView); // ?View listViewItem.measure(0, 0); // ? totalHeight += listViewItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); // listView.getDividerHeight()?? // params.heightListView? params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); viewPager.setFocusable(true); viewPager.setFocusableInTouchMode(true); viewPager.requestFocus(); }
From source file:android.support.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.support.transition.TransitionValues, android.support.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./*w ww .ja v a 2 s. co m*/ * * @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); } } } } } }