diff options
author | George Mount <mount@google.com> | 2014-09-12 10:54:54 -0700 |
---|---|---|
committer | George Mount <mount@google.com> | 2014-09-12 12:46:09 -0700 |
commit | 48bd13c9cb2627847cf1f7707a084eb354e9c303 (patch) | |
tree | 6ca48540c43caffb0f6a606e6a7aea0becac2b81 | |
parent | 04c9d29bf3d8c1107e35e3f9c73439e97255a9ef (diff) | |
download | frameworks_base-48bd13c9cb2627847cf1f7707a084eb354e9c303.zip frameworks_base-48bd13c9cb2627847cf1f7707a084eb354e9c303.tar.gz frameworks_base-48bd13c9cb2627847cf1f7707a084eb354e9c303.tar.bz2 |
Fixed: getDecor() NullPointeExceptions.
Bug 17481173
Change-Id: Ie6e1710cadb7d1e52515c2927dce733b3ec3eabb
3 files changed, 140 insertions, 98 deletions
diff --git a/core/java/android/app/ActivityTransitionCoordinator.java b/core/java/android/app/ActivityTransitionCoordinator.java index 43fa3f0..e819a6d 100644 --- a/core/java/android/app/ActivityTransitionCoordinator.java +++ b/core/java/android/app/ActivityTransitionCoordinator.java @@ -223,7 +223,10 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { mSharedElementNames.addAll(sharedElements.keySet()); mSharedElements.addAll(sharedElements.values()); if (getViewsTransition() != null) { - getDecor().captureTransitioningViews(mTransitioningViews); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.captureTransitioningViews(mTransitioningViews); + } mTransitioningViews.removeAll(mSharedElements); } setEpicenter(); @@ -350,7 +353,10 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { sharedElements.put(accepted.get(i), localViews.get(i)); } } else { - getDecor().findNamedViews(sharedElements); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.findNamedViews(sharedElements); + } } return sharedElements; } @@ -471,16 +477,18 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { protected void scheduleSetSharedElementEnd(final ArrayList<View> snapshots) { final View decorView = getDecor(); - decorView.getViewTreeObserver().addOnPreDrawListener( - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - decorView.getViewTreeObserver().removeOnPreDrawListener(this); - notifySharedElementEnd(snapshots); - return true; + if (decorView != null) { + decorView.getViewTreeObserver().addOnPreDrawListener( + new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + decorView.getViewTreeObserver().removeOnPreDrawListener(this); + notifySharedElementEnd(snapshots); + return true; + } } - } - ); + ); + } } private static SharedElementOriginalState getOldSharedElementState(View view, String name, @@ -523,7 +531,10 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { ArrayList<View> snapshots = new ArrayList<View>(numSharedElements); Context context = getWindow().getContext(); int[] decorLoc = new int[2]; - getDecor().getLocationOnScreen(decorLoc); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.getLocationOnScreen(decorLoc); + } for (String name: names) { Bundle sharedElementBundle = state.getBundle(name); if (sharedElementBundle != null) { @@ -746,15 +757,17 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver { protected void scheduleGhostVisibilityChange(final int visibility) { final View decorView = getDecor(); - decorView.getViewTreeObserver() - .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - decorView.getViewTreeObserver().removeOnPreDrawListener(this); - setGhostVisibility(visibility); - return true; - } - }); + if (decorView != null) { + decorView.getViewTreeObserver() + .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + decorView.getViewTreeObserver().removeOnPreDrawListener(this); + setGhostVisibility(visibility); + return true; + } + }); + } } protected class ContinueTransitionListener extends Transition.TransitionListenerAdapter { diff --git a/core/java/android/app/EnterTransitionCoordinator.java b/core/java/android/app/EnterTransitionCoordinator.java index 9ca150d..bfdb0eb 100644 --- a/core/java/android/app/EnterTransitionCoordinator.java +++ b/core/java/android/app/EnterTransitionCoordinator.java @@ -70,16 +70,18 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { resultReceiverBundle.putParcelable(KEY_REMOTE_RECEIVER, this); mResultReceiver.send(MSG_SET_REMOTE_RECEIVER, resultReceiverBundle); final View decorView = getDecor(); - decorView.getViewTreeObserver().addOnPreDrawListener( - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - if (mIsReadyForTransition) { - decorView.getViewTreeObserver().removeOnPreDrawListener(this); + if (decorView != null) { + decorView.getViewTreeObserver().addOnPreDrawListener( + new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + if (mIsReadyForTransition) { + decorView.getViewTreeObserver().removeOnPreDrawListener(this); + } + return mIsReadyForTransition; } - return mIsReadyForTransition; - } - }); + }); + } } public void viewInstancesReady(ArrayList<String> accepted, ArrayList<String> localNames, @@ -152,7 +154,10 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { private ArrayMap<String, View> mapNamedElements(ArrayList<String> accepted, ArrayList<String> localNames) { ArrayMap<String, View> sharedElements = new ArrayMap<String, View>(); - getDecor().findNamedViews(sharedElements); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.findNamedViews(sharedElements); + } if (accepted != null) { for (int i = 0; i < localNames.size(); i++) { String localName = localNames.get(i); @@ -170,10 +175,13 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { private void sendSharedElementDestination() { boolean allReady; + final View decorView = getDecor(); if (allowOverlappingTransitions() && getEnterViewsTransition() != null) { allReady = false; + } else if (decorView == null) { + allReady = true; } else { - allReady = !getDecor().isLayoutRequested(); + allReady = !decorView.isLayoutRequested(); if (allReady) { for (int i = 0; i < mSharedElements.size(); i++) { if (mSharedElements.get(i).isLayoutRequested()) { @@ -188,8 +196,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { setSharedElementMatrices(); moveSharedElementsToOverlay(); mResultReceiver.send(MSG_SHARED_ELEMENT_DESTINATION, state); - } else { - final View decorView = getDecor(); + } else if (decorView != null) { decorView.getViewTreeObserver() .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override @@ -291,6 +298,10 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { } private void startSharedElementTransition(Bundle sharedElementState) { + ViewGroup decorView = getDecor(); + if (decorView == null) { + return; + } // Remove rejected shared elements ArrayList<String> rejectedNames = new ArrayList<String>(mAllSharedElementNames); rejectedNames.removeAll(mSharedElementNames); @@ -311,7 +322,8 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { boolean startSharedElementTransition = true; setGhostVisibility(View.INVISIBLE); scheduleGhostVisibilityChange(View.INVISIBLE); - Transition transition = beginTransition(startEnterTransition, startSharedElementTransition); + Transition transition = beginTransition(decorView, startEnterTransition, + startSharedElementTransition); scheduleGhostVisibilityChange(View.VISIBLE); setGhostVisibility(View.VISIBLE); @@ -324,8 +336,9 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { if (mResultReceiver != null) { // We can't trust that the view will disappear on the same frame that the shared // element appears here. Assure that we get at least 2 frames for double-buffering. - getDecor().postOnAnimation(new Runnable() { + decorView.postOnAnimation(new Runnable() { int mAnimations; + @Override public void run() { if (mAnimations++ < MIN_ANIMATION_FRAMES) { @@ -349,21 +362,23 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { final Bundle sharedElementState = mSharedElementsBundle; mSharedElementsBundle = null; final View decorView = getDecor(); - decorView.getViewTreeObserver() - .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - decorView.getViewTreeObserver().removeOnPreDrawListener(this); - startTransition(new Runnable() { - @Override - public void run() { - startSharedElementTransition(sharedElementState); - } - }); - return false; - } - }); - decorView.invalidate(); + if (decorView != null) { + decorView.getViewTreeObserver() + .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + decorView.getViewTreeObserver().removeOnPreDrawListener(this); + startTransition(new Runnable() { + @Override + public void run() { + startSharedElementTransition(sharedElementState); + } + }); + return false; + } + }); + decorView.invalidate(); + } } private void requestLayoutForSharedElements() { @@ -373,7 +388,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { } } - private Transition beginTransition(boolean startEnterTransition, + private Transition beginTransition(ViewGroup decorView, boolean startEnterTransition, boolean startSharedElementTransition) { Transition sharedElementTransition = null; if (startSharedElementTransition) { @@ -433,7 +448,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { Transition transition = mergeTransitions(sharedElementTransition, viewsTransition); if (transition != null) { transition.addListener(new ContinueTransitionListener()); - TransitionManager.beginDelayedTransition(getDecor(), transition); + TransitionManager.beginDelayedTransition(decorView, transition); if (startSharedElementTransition && !mSharedElementNames.isEmpty()) { mSharedElements.get(0).invalidate(); } else if (startEnterTransition && !mTransitioningViews.isEmpty()) { @@ -467,8 +482,9 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { } private void startEnterTransition(Transition transition) { - if (!mIsReturning) { - Drawable background = getDecor().getBackground(); + ViewGroup decorView = getDecor(); + if (!mIsReturning && decorView != null) { + Drawable background = decorView.getBackground(); if (background != null) { background = background.mutate(); getWindow().setBackgroundDrawable(background); @@ -539,25 +555,28 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { if (rejectedSnapshots == null || rejectedSnapshots.isEmpty()) { return; } - ViewGroupOverlay overlay = getDecor().getOverlay(); - ObjectAnimator animator = null; - int numRejected = rejectedSnapshots.size(); - for (int i = 0; i < numRejected; i++) { - View snapshot = rejectedSnapshots.get(i); - overlay.add(snapshot); - animator = ObjectAnimator.ofFloat(snapshot, View.ALPHA, 1, 0); - animator.start(); - } - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - ViewGroupOverlay overlay = getDecor().getOverlay(); - int numRejected = rejectedSnapshots.size(); - for (int i = 0; i < numRejected; i++) { - overlay.remove(rejectedSnapshots.get(i)); - } + final ViewGroup decorView = getDecor(); + if (decorView != null) { + ViewGroupOverlay overlay = decorView.getOverlay(); + ObjectAnimator animator = null; + int numRejected = rejectedSnapshots.size(); + for (int i = 0; i < numRejected; i++) { + View snapshot = rejectedSnapshots.get(i); + overlay.add(snapshot); + animator = ObjectAnimator.ofFloat(snapshot, View.ALPHA, 1, 0); + animator.start(); } - }); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + ViewGroupOverlay overlay = decorView.getOverlay(); + int numRejected = rejectedSnapshots.size(); + for (int i = 0; i < numRejected; i++) { + overlay.remove(rejectedSnapshots.get(i)); + } + } + }); + } } protected void onRemoteExitTransitionComplete() { @@ -572,9 +591,12 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { public void run() { boolean startEnterTransition = true; boolean startSharedElementTransition = false; - Transition transition = beginTransition(startEnterTransition, - startSharedElementTransition); - startEnterTransition(transition); + ViewGroup decorView = getDecor(); + if (decorView != null) { + Transition transition = beginTransition(decorView, startEnterTransition, + startSharedElementTransition); + startEnterTransition(transition); + } } }); } diff --git a/core/java/android/app/ExitTransitionCoordinator.java b/core/java/android/app/ExitTransitionCoordinator.java index e85ec63..41b0db6 100644 --- a/core/java/android/app/ExitTransitionCoordinator.java +++ b/core/java/android/app/ExitTransitionCoordinator.java @@ -129,22 +129,25 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { showViews(mTransitioningViews, true); showViews(mSharedElements, true); mIsHidden = true; - if (!mIsReturning && getDecor() != null) { - getDecor().suppressLayout(false); + ViewGroup decorView = getDecor(); + if (!mIsReturning && decorView != null) { + decorView.suppressLayout(false); } moveSharedElementsFromOverlay(); clearState(); } private void sharedElementExitBack() { - if (getDecor() != null) { - getDecor().suppressLayout(true); + final ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.suppressLayout(true); } - if (mExitSharedElementBundle != null && !mExitSharedElementBundle.isEmpty() && + if (decorView != null && mExitSharedElementBundle != null && + !mExitSharedElementBundle.isEmpty() && !mSharedElements.isEmpty() && getSharedElementTransition() != null) { startTransition(new Runnable() { public void run() { - startSharedElementExit(); + startSharedElementExit(decorView); } }); } else { @@ -152,7 +155,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { } } - private void startSharedElementExit() { + private void startSharedElementExit(final ViewGroup decorView) { Transition transition = getSharedElementExitTransition(); transition.addListener(new Transition.TransitionListenerAdapter() { @Override @@ -165,7 +168,6 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { }); final ArrayList<View> sharedElementSnapshots = createSnapshots(mExitSharedElementBundle, mSharedElementNames); - final View decorView = getDecor(); decorView.getViewTreeObserver() .addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override @@ -178,10 +180,10 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { setGhostVisibility(View.INVISIBLE); scheduleGhostVisibilityChange(View.INVISIBLE); mListener.onSharedElementEnd(mSharedElementNames, mSharedElements, sharedElementSnapshots); - TransitionManager.beginDelayedTransition(getDecor(), transition); + TransitionManager.beginDelayedTransition(decorView, transition); scheduleGhostVisibilityChange(View.VISIBLE); setGhostVisibility(View.VISIBLE); - getDecor().invalidate(); + decorView.invalidate(); } private void hideSharedElements() { @@ -196,8 +198,9 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { public void startExit() { if (!mIsExitStarted) { mIsExitStarted = true; - if (getDecor() != null) { - getDecor().suppressLayout(true); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.suppressLayout(true); } moveSharedElementsToOverlay(); startTransition(new Runnable() { @@ -212,8 +215,9 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { public void startExit(int resultCode, Intent data) { if (!mIsExitStarted) { mIsExitStarted = true; - if (getDecor() != null) { - getDecor().suppressLayout(true); + ViewGroup decorView = getDecor(); + if (decorView != null) { + decorView.suppressLayout(true); } mHandler = new Handler() { @Override @@ -224,7 +228,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { }; delayCancel(); moveSharedElementsToOverlay(); - if (getDecor().getBackground() == null) { + if (decorView != null && decorView.getBackground() == null) { getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); } ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(mActivity, this, @@ -248,8 +252,9 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { private void startExitTransition() { Transition transition = getExitTransition(); - if (transition != null) { - TransitionManager.beginDelayedTransition(getDecor(), transition); + ViewGroup decorView = getDecor(); + if (transition != null && decorView != null) { + TransitionManager.beginDelayedTransition(decorView, transition); mTransitioningViews.get(0).invalidate(); } else { transitionStarted(); @@ -337,13 +342,14 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { Transition viewsTransition = getExitTransition(); Transition transition = mergeTransitions(sharedElementTransition, viewsTransition); - if (transition != null) { + ViewGroup decorView = getDecor(); + if (transition != null && decorView != null) { setGhostVisibility(View.INVISIBLE); scheduleGhostVisibilityChange(View.INVISIBLE); - TransitionManager.beginDelayedTransition(getDecor(), transition); + TransitionManager.beginDelayedTransition(decorView, transition); scheduleGhostVisibilityChange(View.VISIBLE); setGhostVisibility(View.VISIBLE); - getDecor().invalidate(); + decorView.invalidate(); } else { transitionStarted(); } @@ -392,8 +398,9 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { mExitNotified = true; mResultReceiver.send(MSG_EXIT_TRANSITION_COMPLETE, null); mResultReceiver = null; // done talking - if (!mIsReturning && getDecor() != null) { - getDecor().suppressLayout(false); + ViewGroup decorView = getDecor(); + if (!mIsReturning && decorView != null) { + decorView.suppressLayout(false); } finishIfNecessary(); } |