From ce725a47f6eee75a6ef86397e9b9fe471aeb1f84 Mon Sep 17 00:00:00 2001 From: George Mount Date: Wed, 27 Aug 2014 16:10:46 -0700 Subject: [PATCH] Allow arbitrarily-added shared elements. Bug 17112782 This allows the application developer to set any view as a shared element so that it will avoid the enter and/or exit transition. This will allow it to be transitioned along with the shared element transition as well. It will also allow the called Activity to return different shared elements than those passed in. Change-Id: I7b1f4f029af50dc6e2d5f025062b5669486f6427 --- .../app/ActivityTransitionCoordinator.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/core/java/android/app/ActivityTransitionCoordinator.java b/core/java/android/app/ActivityTransitionCoordinator.java index e4f2b88199828..a09a2e7d090c5 100644 --- a/core/java/android/app/ActivityTransitionCoordinator.java +++ b/core/java/android/app/ActivityTransitionCoordinator.java @@ -217,7 +217,10 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { } protected void viewsReady(ArrayMap sharedElements) { - setSharedElements(sharedElements); + sharedElements.retainAll(mAllSharedElementNames); + mListener.remapSharedElements(mAllSharedElementNames, sharedElements); + mSharedElementNames.addAll(sharedElements.keySet()); + mSharedElements.addAll(sharedElements.values()); if (getViewsTransition() != null) { getDecor().captureTransitioningViews(mTransitioningViews); mTransitioningViews.removeAll(mSharedElements); @@ -339,32 +342,16 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { protected ArrayMap mapSharedElements(ArrayList accepted, ArrayList localViews) { ArrayMap sharedElements = new ArrayMap(); - if (!mAllSharedElementNames.isEmpty()) { - if (accepted != null) { - for (int i = 0; i < accepted.size(); i++) { - sharedElements.put(accepted.get(i), localViews.get(i)); - } - } else { - getDecor().findNamedViews(sharedElements); + if (accepted != null) { + for (int i = 0; i < accepted.size(); i++) { + sharedElements.put(accepted.get(i), localViews.get(i)); } + } else { + getDecor().findNamedViews(sharedElements); } return sharedElements; } - private void setSharedElements(ArrayMap sharedElements) { - sharedElements.retainAll(mAllSharedElementNames); - mListener.remapSharedElements(mAllSharedElementNames, sharedElements); - sharedElements.retainAll(mAllSharedElementNames); - for (int i = 0; i < mAllSharedElementNames.size(); i++) { - String name = mAllSharedElementNames.get(i); - View sharedElement = sharedElements.get(name); - if (sharedElement != null) { - mSharedElementNames.add(name); - mSharedElements.add(sharedElement); - } - } - } - protected void setResultReceiver(ResultReceiver resultReceiver) { mResultReceiver = resultReceiver; }