List of usage examples for android.animation ObjectAnimator ofFloat
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, float... values)
From source file:com.android.calculator2.Calculator.java
private void onResult(boolean animate) { // Calculate the textSize that would be used to display the result in the formula. // For scrollable results just use the minimum textSize to maximize the number of digits // that are visible on screen. float textSize = mFormulaText.getMinimumTextSize(); if (!mResultText.isScrollable()) { textSize = mFormulaText.getVariableTextSize(mResultText.getText().toString()); }// w w w. j a v a2 s. com // Scale the result to match the calculated textSize, minimizing the jump-cut transition // when a result is reused in a subsequent expression. final float resultScale = textSize / mResultText.getTextSize(); // Set the result's pivot to match its gravity. mResultText.setPivotX(mResultText.getWidth() - mResultText.getPaddingRight()); mResultText.setPivotY(mResultText.getHeight() - mResultText.getPaddingBottom()); // Calculate the necessary translations so the result takes the place of the formula and // the formula moves off the top of the screen. final float resultTranslationY = (mFormulaText.getBottom() - mResultText.getBottom()) - (mFormulaText.getPaddingBottom() - mResultText.getPaddingBottom()); final float formulaTranslationY = -mFormulaText.getBottom(); // Change the result's textColor to match the formula. final int formulaTextColor = mFormulaText.getCurrentTextColor(); if (animate) { mResultText.announceForAccessibility(getResources().getString(R.string.desc_eq)); mResultText.announceForAccessibility(mResultText.getText()); setState(CalculatorState.ANIMATE); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofPropertyValuesHolder(mResultText, PropertyValuesHolder.ofFloat(View.SCALE_X, resultScale), PropertyValuesHolder.ofFloat(View.SCALE_Y, resultScale), PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, resultTranslationY)), ObjectAnimator.ofArgb(mResultText, TEXT_COLOR, formulaTextColor), ObjectAnimator.ofFloat(mFormulaText, View.TRANSLATION_Y, formulaTranslationY)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setState(CalculatorState.RESULT); mCurrentAnimator = null; } }); mCurrentAnimator = animatorSet; animatorSet.start(); } else /* No animation desired; get there fast, e.g. when restarting */ { mResultText.setScaleX(resultScale); mResultText.setScaleY(resultScale); mResultText.setTranslationY(resultTranslationY); mResultText.setTextColor(formulaTextColor); mFormulaText.setTranslationY(formulaTranslationY); setState(CalculatorState.RESULT); } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static void shakeView(final View view, final float x, final int num) { if (num == 6) { view.setTranslationX(0);//ww w . j a v a2 s . co m return; } AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(view, "translationX", AndroidUtilities.dp(x))); animatorSet.setDuration(50); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { shakeView(view, num == 5 ? 0 : -x, num + 1); } }); animatorSet.start(); }
From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java
private void dismissCling(final Cling cling, final String flag, int duration) { setPagingEnabled(true);/* ww w.j ava 2 s. c o m*/ clingActive = false; if (cling != null) { cling.dismiss(); if (getActionBar() != null) { getActionBar().show(); } getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF"))); ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f); anim.setDuration(duration); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { cling.setVisibility(View.GONE); cling.cleanup(); CalculatorSettings.saveKey(getContext(), flag, true); } }); anim.start(); } }
From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java
Animator animateFAB(final View fabToAnimate, final boolean dismiss) { fabToAnimate.setVisibility(View.VISIBLE); float[] toFrom = dismiss ? new float[] { 1f, .2f } : new float[] { .2f, 1f }; AnimatorSet animatorSet = new AnimatorSet(); animatorSet.addListener(new AnimatorListenerAdapter() { @Override// w w w . j ava 2s.com public void onAnimationEnd(Animator animation) { fabToAnimate.setVisibility(dismiss ? View.GONE : View.VISIBLE); } }); ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(fabToAnimate, "alpha", toFrom); alphaAnimator.setDuration(200); alphaAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); // Create a scale + fade animation ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(fabToAnimate, PropertyValuesHolder.ofFloat("scaleX", toFrom), PropertyValuesHolder.ofFloat("scaleY", toFrom)); scaleDown.setDuration(200); scaleDown.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.playTogether(scaleDown, alphaAnimator); return animatorSet; }
From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/* w w w .ja v a2s.co m*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = stateIsOverview ? 1.0f : 0f; float finalPageIndicatorAlpha = stateIsOverview ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (state != State.NORMAL) { if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } } final int duration = getResources().getInteger(R.integer.config_overviewTransitionTime); for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); float finalAlpha = 1f; if (stateIsOverview) { cl.setVisibility(VISIBLE); cl.setTranslationX(0f); cl.setTranslationY(0f); cl.setPivotX(cl.getMeasuredWidth() * 0.5f); cl.setPivotY(cl.getMeasuredHeight() * 0.5f); cl.setRotation(0f); cl.setRotationY(0f); cl.setRotationX(0f); cl.setScaleX(1f); cl.setScaleY(1f); cl.setShortcutAndWidgetAlpha(1f); } mOldAlphas[i] = cl.getShortcutsAndWidgets().getAlpha(); mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View overviewPanel = mLauncher.getOverviewPanel(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); ValueAnimator invalidate = ValueAnimator.ofFloat(0f, 1f); invalidate.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { invalidate(); } }); anim.play(invalidate); ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalPageIndicatorAlpha); } ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(pageIndicatorAlpha); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.getShortcutsAndWidgets().setAlpha(mNewAlphas[i]); } else { LauncherViewPropertyAnimator a = new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets()); a.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator); anim.play(a); if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } return anim; }
From source file:cc.flydev.launcher.Page.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (DISABLE_TOUCH_INTERACTION) { return false; }/*from w w w. jav a2 s.co m*/ super.onTouchEvent(ev); // Skip touch handling if there are no pages to swipe if (getChildCount() <= 0) return super.onTouchEvent(ev); acquireVelocityTrackerAndAddMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mDownMotionX = mLastMotionX = ev.getX(); mDownMotionY = mLastMotionY = ev.getY(); mDownScrollX = getScrollX(); float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = p[0]; mParentDownMotionY = p[1]; mLastMotionXRemainder = 0; mTotalMotionX = 0; mActivePointerId = ev.getPointerId(0); if (mTouchState == TOUCH_STATE_SCROLLING) { pageBeginMoving(); } break; case MotionEvent.ACTION_MOVE: if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event final int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) return true; final float x = ev.getX(pointerIndex); final float deltaX = mLastMotionX + mLastMotionXRemainder - x; mTotalMotionX += Math.abs(deltaX); // Only scroll and update mLastMotionX if we have moved some discrete amount. We // keep the remainder because we are actually testing if we've moved from the last // scrolled position (which is discrete). if (Math.abs(deltaX) >= 1.0f) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (!mDeferScrollUpdate) { scrollBy((int) deltaX, 0); if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX); } else { invalidate(); } mLastMotionX = x; mLastMotionXRemainder = deltaX - (int) deltaX; } else { awakenScrollBars(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); // Find the closest page to the touch point final int dragViewIndex = indexOfChild(mDragView); // Change the drag view if we are hovering over the drop target boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY); setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete); if (DEBUG) Log.d(TAG, "mLastMotionX: " + mLastMotionX); if (DEBUG) Log.d(TAG, "mLastMotionY: " + mLastMotionY); if (DEBUG) Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX); if (DEBUG) Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY); final int pageUnderPointIndex = getNearestHoverOverPageIndex(); if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView) && !isHoveringOverDelete) { mTempVisiblePagesRange[0] = 0; mTempVisiblePagesRange[1] = getPageCount() - 1; getOverviewModePages(mTempVisiblePagesRange); if (mTempVisiblePagesRange[0] <= pageUnderPointIndex && pageUnderPointIndex <= mTempVisiblePagesRange[1] && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) { mSidePageHoverIndex = pageUnderPointIndex; mSidePageHoverRunnable = new Runnable() { @Override public void run() { // Setup the scroll to the correct page before we swap the views snapToPage(pageUnderPointIndex); // For each of the pages between the paged view and the drag view, // animate them from the previous position to the new position in // the layout (as a result of the drag view moving in the layout) int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1; int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1 : pageUnderPointIndex; int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1 : pageUnderPointIndex; for (int i = lowerIndex; i <= upperIndex; ++i) { View v = getChildAt(i); // dragViewIndex < pageUnderPointIndex, so after we remove the // drag view all subsequent views to pageUnderPointIndex will // shift down. int oldX = getViewportOffsetX() + getChildOffset(i); int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta); // Animate the view translation from its old position to its new // position AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY); if (anim != null) { anim.cancel(); } v.setTranslationX(oldX - newX); anim = new AnimatorSet(); anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION); anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f)); anim.start(); v.setTag(anim); } removeView(mDragView); onRemoveView(mDragView, false); addView(mDragView, pageUnderPointIndex); onAddView(mDragView, pageUnderPointIndex); mSidePageHoverIndex = -1; mPageIndicator.setActiveMarker(getNextPage()); } }; postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT); } } else { removeCallbacks(mSidePageHoverRunnable); mSidePageHoverIndex = -1; } } else { determineScrollingStart(ev); } break; case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_SCROLLING) { final int activePointerId = mActivePointerId; final int pointerIndex = ev.findPointerIndex(activePointerId); final float x = ev.getX(pointerIndex); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x); boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING && Math.abs(velocityX) > mFlingThresholdVelocity; if (!mFreeScroll) { // In the case that the page is moved far to one direction and then is flung // in the opposite direction, we use a threshold to determine whether we should // just return to the starting page, or if we should skip one further. boolean returnToOriginalPage = false; if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum(velocityX) != Math.signum(deltaX) && isFling) { returnToOriginalPage = true; } int finalPage; // We give flings precedence over large moves, which is why we short-circuit our // test for a large move if a fling has been registered. That is, a large // move to the left and fling to the right will register as a fling to the right. final boolean isRtl = isLayoutRtl(); boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0; boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0; if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; snapToPageWithVelocity(finalPage, velocityX); } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; snapToPageWithVelocity(finalPage, velocityX); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_PREV_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so // we can just page int nextPage = Math.max(0, mCurrentPage - 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } float scaleX = getScaleX(); int vX = (int) (-velocityX * scaleX); int initialScrollX = (int) (getScrollX() * scaleX); mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); invalidate(); } } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so // we can just page int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); boolean handledFling = false; if (!DISABLE_FLING_TO_DELETE) { // Check the velocity and see if we are flinging-to-delete PointF flingToDeleteVector = isFlingingToDelete(); if (flingToDeleteVector != null) { onFlingToDelete(flingToDeleteVector); handledFling = true; } } if (!handledFling && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) { onDropToDelete(); } } else { if (!mCancelTap) { onUnhandledTap(ev); } } // Remove the callback to wait for the side page hover timeout removeCallbacks(mSidePageHoverRunnable); // End any intermediate reordering states resetTouchState(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { snapToDestination(); } resetTouchState(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); releaseVelocityTracker(); break; } return true; }
From source file:com.n2hsu.launcher.Page.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (DISABLE_TOUCH_INTERACTION) { return false; }/* ww w.j a v a 2 s.c o m*/ super.onTouchEvent(ev); // Skip touch handling if there are no pages to swipe if (getChildCount() <= 0) return super.onTouchEvent(ev); acquireVelocityTrackerAndAddMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mDownMotionX = mLastMotionX = ev.getX(); mDownMotionY = mLastMotionY = ev.getY(); mDownScrollX = getScrollX(); float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = p[0]; mParentDownMotionY = p[1]; mLastMotionXRemainder = 0; mTotalMotionX = 0; mActivePointerId = ev.getPointerId(0); if (mTouchState == TOUCH_STATE_SCROLLING) { pageBeginMoving(); } break; case MotionEvent.ACTION_MOVE: if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event final int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) return true; final float x = ev.getX(pointerIndex); final float deltaX = mLastMotionX + mLastMotionXRemainder - x; mTotalMotionX += Math.abs(deltaX); // Only scroll and update mLastMotionX if we have moved some // discrete amount. We // keep the remainder because we are actually testing if we've // moved from the last // scrolled position (which is discrete). if (Math.abs(deltaX) >= 1.0f) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (!mDeferScrollUpdate) { scrollBy((int) deltaX, 0); if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX); } else { invalidate(); } mLastMotionX = x; mLastMotionXRemainder = deltaX - (int) deltaX; } else { awakenScrollBars(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this // new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); // Find the closest page to the touch point final int dragViewIndex = indexOfChild(mDragView); // Change the drag view if we are hovering over the drop target boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY); setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete); if (DEBUG) Log.d(TAG, "mLastMotionX: " + mLastMotionX); if (DEBUG) Log.d(TAG, "mLastMotionY: " + mLastMotionY); if (DEBUG) Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX); if (DEBUG) Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY); final int pageUnderPointIndex = getNearestHoverOverPageIndex(); if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView) && !isHoveringOverDelete) { mTempVisiblePagesRange[0] = 0; mTempVisiblePagesRange[1] = getPageCount() - 1; getOverviewModePages(mTempVisiblePagesRange); if (mTempVisiblePagesRange[0] <= pageUnderPointIndex && pageUnderPointIndex <= mTempVisiblePagesRange[1] && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) { mSidePageHoverIndex = pageUnderPointIndex; mSidePageHoverRunnable = new Runnable() { @Override public void run() { // Setup the scroll to the correct page before // we swap the views snapToPage(pageUnderPointIndex); // For each of the pages between the paged view // and the drag view, // animate them from the previous position to // the new position in // the layout (as a result of the drag view // moving in the layout) int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1; int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1 : pageUnderPointIndex; int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1 : pageUnderPointIndex; for (int i = lowerIndex; i <= upperIndex; ++i) { View v = getChildAt(i); // dragViewIndex < pageUnderPointIndex, so // after we remove the // drag view all subsequent views to // pageUnderPointIndex will // shift down. int oldX = getViewportOffsetX() + getChildOffset(i); int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta); // Animate the view translation from its old // position to its new // position AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY); if (anim != null) { anim.cancel(); } v.setTranslationX(oldX - newX); anim = new AnimatorSet(); anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION); anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f)); anim.start(); v.setTag(anim); } removeView(mDragView); onRemoveView(mDragView, false); addView(mDragView, pageUnderPointIndex); onAddView(mDragView, pageUnderPointIndex); mSidePageHoverIndex = -1; mPageIndicator.setActiveMarker(getNextPage()); } }; postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT); } } else { removeCallbacks(mSidePageHoverRunnable); mSidePageHoverIndex = -1; } } else { determineScrollingStart(ev); } break; case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_SCROLLING) { final int activePointerId = mActivePointerId; final int pointerIndex = ev.findPointerIndex(activePointerId); final float x = ev.getX(pointerIndex); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x); boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING && Math.abs(velocityX) > mFlingThresholdVelocity; if (!mFreeScroll) { // In the case that the page is moved far to one direction // and then is flung // in the opposite direction, we use a threshold to // determine whether we should // just return to the starting page, or if we should skip // one further. boolean returnToOriginalPage = false; if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum(velocityX) != Math.signum(deltaX) && isFling) { returnToOriginalPage = true; } int finalPage; // We give flings precedence over large moves, which is why // we short-circuit our // test for a large move if a fling has been registered. // That is, a large // move to the left and fling to the right will register as // a fling to the right. final boolean isRtl = isLayoutRtl(); boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0; boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0; if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; snapToPageWithVelocity(finalPage, velocityX); } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; snapToPageWithVelocity(finalPage, velocityX); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_PREV_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), // so // we can just page int nextPage = Math.max(0, mCurrentPage - 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } float scaleX = getScaleX(); int vX = (int) (-velocityX * scaleX); int initialScrollX = (int) (getScrollX() * scaleX); mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); invalidate(); } } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so // we can just page int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this // new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); boolean handledFling = false; if (!DISABLE_FLING_TO_DELETE) { // Check the velocity and see if we are flinging-to-delete PointF flingToDeleteVector = isFlingingToDelete(); if (flingToDeleteVector != null) { onFlingToDelete(flingToDeleteVector); handledFling = true; } } if (!handledFling && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) { onDropToDelete(); } } else { if (!mCancelTap) { onUnhandledTap(ev); } } // Remove the callback to wait for the side page hover timeout removeCallbacks(mSidePageHoverRunnable); // End any intermediate reordering states resetTouchState(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { snapToDestination(); } resetTouchState(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); releaseVelocityTracker(); break; } return true; }
From source file:com.wb.launcher3.Page.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (DISABLE_TOUCH_INTERACTION) { return false; }// w w w . j a v a2s . c om super.onTouchEvent(ev); // Skip touch handling if there are no pages to swipe if (getChildCount() <= 0) return super.onTouchEvent(ev); acquireVelocityTrackerAndAddMovement(ev); final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mDownMotionX = mLastMotionX = ev.getX(); mDownMotionY = mLastMotionY = ev.getY(); mDownScrollX = getScrollX(); float[] p = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = p[0]; mParentDownMotionY = p[1]; mLastMotionXRemainder = 0; mTotalMotionX = 0; mActivePointerId = ev.getPointerId(0); if (mTouchState == TOUCH_STATE_SCROLLING) { pageBeginMoving(); } break; case MotionEvent.ACTION_MOVE: //*/zhangwuba add 2014-5-8 if (getLauncherDeleteAppSate()) { return true; } //*/ if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event final int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) return true; final float x = ev.getX(pointerIndex); final float deltaX = mLastMotionX + mLastMotionXRemainder - x; mTotalMotionX += Math.abs(deltaX); // Only scroll and update mLastMotionX if we have moved some discrete amount. We // keep the remainder because we are actually testing if we've moved from the last // scrolled position (which is discrete). if (Math.abs(deltaX) >= 1.0f) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (!mDeferScrollUpdate) { scrollBy((int) deltaX, 0); if (DEBUG) Log.d(TAG, "onTouchEvent().Scrolling: " + deltaX); } else { invalidate(); } mLastMotionX = x; mLastMotionXRemainder = deltaX - (int) deltaX; } else { awakenScrollBars(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); // Find the closest page to the touch point final int dragViewIndex = indexOfChild(mDragView); // Change the drag view if we are hovering over the drop target boolean isHoveringOverDelete = isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY); setPageHoveringOverDeleteDropTarget(dragViewIndex, isHoveringOverDelete); if (DEBUG) Log.d(TAG, "mLastMotionX: " + mLastMotionX); if (DEBUG) Log.d(TAG, "mLastMotionY: " + mLastMotionY); if (DEBUG) Log.d(TAG, "mParentDownMotionX: " + mParentDownMotionX); if (DEBUG) Log.d(TAG, "mParentDownMotionY: " + mParentDownMotionY); final int pageUnderPointIndex = getNearestHoverOverPageIndex(); if (pageUnderPointIndex > -1 && pageUnderPointIndex != indexOfChild(mDragView) && !isHoveringOverDelete) { mTempVisiblePagesRange[0] = 0; mTempVisiblePagesRange[1] = getPageCount() - 1; getOverviewModePages(mTempVisiblePagesRange); if (mTempVisiblePagesRange[0] <= pageUnderPointIndex && pageUnderPointIndex <= mTempVisiblePagesRange[1] && pageUnderPointIndex != mSidePageHoverIndex && mScroller.isFinished()) { mSidePageHoverIndex = pageUnderPointIndex; mSidePageHoverRunnable = new Runnable() { @Override public void run() { // Setup the scroll to the correct page before we swap the views snapToPage(pageUnderPointIndex); // For each of the pages between the paged view and the drag view, // animate them from the previous position to the new position in // the layout (as a result of the drag view moving in the layout) int shiftDelta = (dragViewIndex < pageUnderPointIndex) ? -1 : 1; int lowerIndex = (dragViewIndex < pageUnderPointIndex) ? dragViewIndex + 1 : pageUnderPointIndex; int upperIndex = (dragViewIndex > pageUnderPointIndex) ? dragViewIndex - 1 : pageUnderPointIndex; for (int i = lowerIndex; i <= upperIndex; ++i) { View v = getChildAt(i); // dragViewIndex < pageUnderPointIndex, so after we remove the // drag view all subsequent views to pageUnderPointIndex will // shift down. int oldX = getViewportOffsetX() + getChildOffset(i); int newX = getViewportOffsetX() + getChildOffset(i + shiftDelta); // Animate the view translation from its old position to its new // position AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY); if (anim != null) { anim.cancel(); } v.setTranslationX(oldX - newX); anim = new AnimatorSet(); anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION); anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f)); anim.start(); v.setTag(anim); } removeView(mDragView); onRemoveView(mDragView, false); addView(mDragView, pageUnderPointIndex); onAddView(mDragView, pageUnderPointIndex); mSidePageHoverIndex = -1; mPageIndicator.setActiveMarker(getNextPage()); } }; postDelayed(mSidePageHoverRunnable, REORDERING_SIDE_PAGE_HOVER_TIMEOUT); } } else { removeCallbacks(mSidePageHoverRunnable); mSidePageHoverIndex = -1; } } else { determineScrollingStart(ev); } break; case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_SCROLLING) { final int activePointerId = mActivePointerId; final int pointerIndex = ev.findPointerIndex(activePointerId); final float x = ev.getX(pointerIndex); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x); boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING && Math.abs(velocityX) > mFlingThresholdVelocity; if (!mFreeScroll) { // In the case that the page is moved far to one direction and then is flung // in the opposite direction, we use a threshold to determine whether we should // just return to the starting page, or if we should skip one further. boolean returnToOriginalPage = false; if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum(velocityX) != Math.signum(deltaX) && isFling) { returnToOriginalPage = true; } //*/Added by tyd Greg 2014-03-20,for transition effect if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED) { m_moveNextDeltaX = deltaX; m_isSignificantMoveNext = (!returnToOriginalPage && (isSignificantMove || isFling)); } //*/ int finalPage; // We give flings precedence over large moves, which is why we short-circuit our // test for a large move if a fling has been registered. That is, a large // move to the left and fling to the right will register as a fling to the right. final boolean isRtl = isLayoutRtl(); boolean isDeltaXLeft = isRtl ? deltaX > 0 : deltaX < 0; boolean isVelocityXLeft = isRtl ? velocityX > 0 : velocityX < 0; if (((isSignificantMove && !isDeltaXLeft && !isFling) || (isFling && !isVelocityXLeft)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; snapToPageWithVelocity(finalPage, velocityX); } else if (((isSignificantMove && isDeltaXLeft && !isFling) || (isFling && isVelocityXLeft)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; snapToPageWithVelocity(finalPage, velocityX); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_PREV_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so // we can just page int nextPage = Math.max(0, mCurrentPage - 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else { if (!mScroller.isFinished()) { mScroller.abortAnimation(); } float scaleX = getScaleX(); int vX = (int) (-velocityX * scaleX); int initialScrollX = (int) (getScrollX() * scaleX); mScroller.fling(initialScrollX, getScrollY(), vX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); invalidate(); } } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) { // at this point we have not moved beyond the touch slop // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so // we can just page int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_REORDERING) { // Update the last motion position mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); // Update the parent down so that our zoom animations take this new movement into // account float[] pt = mapPointFromViewToParent(this, mLastMotionX, mLastMotionY); mParentDownMotionX = pt[0]; mParentDownMotionY = pt[1]; updateDragViewTranslationDuringDrag(); boolean handledFling = false; if (!DISABLE_FLING_TO_DELETE) { // Check the velocity and see if we are flinging-to-delete PointF flingToDeleteVector = isFlingingToDelete(); if (flingToDeleteVector != null) { onFlingToDelete(flingToDeleteVector); handledFling = true; } } if (!handledFling && isHoveringOverDeleteDropTarget((int) mParentDownMotionX, (int) mParentDownMotionY)) { onDropToDelete(); } } //*/Added by tyd Greg 2014-03-21,for support the touch swipe gesture else if (mTouchState == TOUCH_SWIPE_DOWN_GESTURE) { if (mOnTouchSwipeGestureListener != null) { mOnTouchSwipeGestureListener.fireSwipeDownAction(); } } else if (mTouchState == TOUCH_SWIPE_UP_GESTURE) { if (mOnTouchSwipeGestureListener != null) { mOnTouchSwipeGestureListener.fireSwipeUpAction(); } } //*/ else { if (!mCancelTap) { onUnhandledTap(ev); } } // Remove the callback to wait for the side page hover timeout removeCallbacks(mSidePageHoverRunnable); // End any intermediate reordering states resetTouchState(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { snapToDestination(); } resetTouchState(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); releaseVelocityTracker(); break; } return true; }
From source file:com.xhr.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from w w w.j a v a 2s. c o m*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } // mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }
From source file:cc.flydev.launcher.Workspace.java
Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { if (mState == state) { return null; }/*from w w w . j a v a 2 s . c o m*/ // Initialize animation arrays for the first time if necessary initAnimationArrays(); AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; final State oldState = mState; final boolean oldStateIsNormal = (oldState == State.NORMAL); final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); final boolean oldStateIsSmall = (oldState == State.SMALL); final boolean oldStateIsOverview = (oldState == State.OVERVIEW); setState(state); final boolean stateIsNormal = (state == State.NORMAL); final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); final boolean stateIsSmall = (state == State.SMALL); final boolean stateIsOverview = (state == State.OVERVIEW); float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f; float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0; boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall); boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal); boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); mNewScale = 1.0f; if (oldStateIsOverview) { disableFreeScroll(snapPage); } else if (stateIsOverview) { enableFreeScroll(); } if (state != State.NORMAL) { if (stateIsSpringLoaded) { mNewScale = mSpringLoadedShrinkFactor; } else if (stateIsOverview) { mNewScale = mOverviewModeShrinkFactor; } else if (stateIsSmall) { mNewScale = mOverviewModeShrinkFactor - 0.3f; } if (workspaceToAllApps) { updateChildrenLayersEnabled(false); } } final int duration; if (workspaceToAllApps) { duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); } else if (workspaceToOverview || overviewToWorkspace) { duration = getResources().getInteger(R.integer.config_overviewTransitionTime); } else { duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); } for (int i = 0; i < getChildCount(); i++) { final CellLayout cl = (CellLayout) getChildAt(i); boolean isCurrentPage = (i == getNextPage()); float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); float finalAlpha = stateIsSmall ? 0f : 1f; // If we are animating to/from the small state, then hide the side pages and fade the // current page in if (!mIsSwitchingState) { if (workspaceToAllApps || allAppsToWorkspace) { if (allAppsToWorkspace && isCurrentPage) { initialAlpha = 0f; } else if (!isCurrentPage) { initialAlpha = finalAlpha = 0f; } cl.setShortcutAndWidgetAlpha(initialAlpha); } } mOldAlphas[i] = initialAlpha; mNewAlphas[i] = finalAlpha; if (animated) { mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); mNewBackgroundAlphas[i] = finalBackgroundAlpha; } else { cl.setBackgroundAlpha(finalBackgroundAlpha); cl.setShortcutAndWidgetAlpha(finalAlpha); } } final View searchBar = mLauncher.getQsbBar(); final View overviewPanel = mLauncher.getOverviewPanel(); final View hotseat = mLauncher.getHotseat(); if (animated) { anim.setDuration(duration); LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY) .setInterpolator(mZoomInInterpolator); anim.play(scale); for (int index = 0; index < getChildCount(); index++) { final int i = index; final CellLayout cl = (CellLayout) getChildAt(i); float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); } else { if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator( cl.getShortcutsAndWidgets()); alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator); anim.play(alphaAnim); } if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) { ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f); bgAnim.setInterpolator(mZoomInInterpolator); bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { public void onAnimationUpdate(float a, float b) { cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]); } }); anim.play(bgAnim); } } } ObjectAnimator pageIndicatorAlpha = null; if (getPageIndicator() != null) { pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", finalHotseatAndPageIndicatorAlpha); } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha", finalHotseatAndPageIndicatorAlpha); ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); if (workspaceToOverview) { hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); } else if (overviewToWorkspace) { overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); } if (getPageIndicator() != null) { pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator())); } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(searchBarAlpha); anim.play(pageIndicatorAlpha); anim.setStartDelay(delay); } else { overviewPanel.setAlpha(finalOverviewPanelAlpha); AlphaUpdateListener.updateVisibility(overviewPanel); hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(hotseat); if (getPageIndicator() != null) { getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); AlphaUpdateListener.updateVisibility(getPageIndicator()); } searchBar.setAlpha(finalSearchBarAlpha); AlphaUpdateListener.updateVisibility(searchBar); updateCustomContentVisibility(); setScaleX(mNewScale); setScaleY(mNewScale); setTranslationY(finalWorkspaceTranslationY); } mLauncher.updateVoiceButtonProxyVisible(false); if (stateIsSpringLoaded) { // Right now we're covered by Apps Customize // Show the background gradient immediately, so the gradient will // be showing once AppsCustomize disappears animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); } else if (stateIsOverview) { animateBackgroundGradient( getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true); } else { // Fade the background gradient away animateBackgroundGradient(0f, animated); } return anim; }