1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| if (numChanges > 0) { Animator anim; if (!mResizeClip) { view.setLeftTopRightBottom(startLeft, startTop, startRight, startBottom); if (numChanges == 2) { if (startWidth == endWidth && startHeight == endHeight) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimator.ofObject(view, POSITION_PROPERTY, null, topLeftPath); } else { final ViewBounds viewBounds = new ViewBounds(view); Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); ObjectAnimator topLeftAnimator = ObjectAnimator .ofObject(viewBounds, TOP_LEFT_PROPERTY, null, topLeftPath);
Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); ObjectAnimator bottomRightAnimator = ObjectAnimator.ofObject(viewBounds, BOTTOM_RIGHT_PROPERTY, null, bottomRightPath); AnimatorSet set = new AnimatorSet(); set.playTogether(topLeftAnimator, bottomRightAnimator); anim = set; set.addListener(new AnimatorListenerAdapter() { private ViewBounds mViewBounds = viewBounds; }); } } else if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimator.ofObject(view, TOP_LEFT_ONLY_PROPERTY, null, topLeftPath); } else { Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); anim = ObjectAnimator.ofObject(view, BOTTOM_RIGHT_ONLY_PROPERTY, null, bottomRight); } } else { int maxWidth = Math.max(startWidth, endWidth); int maxHeight = Math.max(startHeight, endHeight);
view.setLeftTopRightBottom(startLeft, startTop, startLeft + maxWidth, startTop + maxHeight);
ObjectAnimator positionAnimator = null; if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); positionAnimator = ObjectAnimator.ofObject(view, POSITION_PROPERTY, null, topLeftPath); } final Rect finalClip = endClip; if (startClip == null) { startClip = new Rect(0, 0, startWidth, startHeight); } if (endClip == null) { endClip = new Rect(0, 0, endWidth, endHeight); } ObjectAnimator clipAnimator = null; if (!startClip.equals(endClip)) { view.setClipBounds(startClip); clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator, startClip, endClip); clipAnimator.addListener(new AnimatorListenerAdapter() { private boolean mIsCanceled;
@Override public void onAnimationCancel(Animator animation) { mIsCanceled = true; }
@Override public void onAnimationEnd(Animator animation) { if (!mIsCanceled) { view.setClipBounds(finalClip); view.setLeftTopRightBottom(endLeft, endTop, endRight, endBottom); } } }); } anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator); } if (view.getParent() instanceof ViewGroup) { final ViewGroup parent = (ViewGroup) view.getParent(); parent.suppressLayout(true); TransitionListener transitionListener = new TransitionListenerAdapter() { boolean mCanceled = false;
@Override public void onTransitionCancel(Transition transition) { parent.suppressLayout(false); mCanceled = true; }
@Override public void onTransitionEnd(Transition transition) { if (!mCanceled) { parent.suppressLayout(false); } }
@Override public void onTransitionPause(Transition transition) { parent.suppressLayout(false); }
@Override public void onTransitionResume(Transition transition) { parent.suppressLayout(true); } }; addListener(transitionListener); } return anim; } } else { sceneRoot.getLocationInWindow(tempLocation); int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0]; int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1]; int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0]; int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1]; if (startX != endX || startY != endY) { final int width = view.getWidth(); final int height = view.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); final BitmapDrawable drawable = new BitmapDrawable(bitmap); drawable.setBounds(startX, startY, startX + width, startY + height); final float transitionAlpha = view.getTransitionAlpha(); view.setTransitionAlpha(0); sceneRoot.getOverlay().add(drawable); Path topLeftPath = getPathMotion().getPath(startX, startY, endX, endY); PropertyValuesHolder origin = PropertyValuesHolder.ofObject( DRAWABLE_ORIGIN_PROPERTY, null, topLeftPath); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { sceneRoot.getOverlay().remove(drawable); view.setTransitionAlpha(transitionAlpha); } }); return anim; } }
|