List of usage examples for android.animation ValueAnimator cancel
@Override public void cancel()
From source file:Main.java
public static void cancel(ValueAnimator... animators) { for (ValueAnimator animator : animators) { animator.cancel(); }/*from w ww.j av a 2 s .com*/ }
From source file:Main.java
public static void cancelWithoutListenersNotified(ValueAnimator animator) { animator.removeAllUpdateListeners(); animator.removeAllListeners();/* w w w .ja v a2s . c o m*/ animator.cancel(); }
From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*from w w w . j a v a 2 s . c o m*/ */ private static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:nuclei.ui.view.ButtonBarView.java
private void setSelected(final Item item, boolean selected) { if (mItems.length < 5) return;/*from ww w . j a va2 s .c om*/ if (selected) { item.imageView.setColorFilter(mSelectedTint, PorterDuff.Mode.SRC_ATOP); if (item.textView != null) { item.textView.setTextColor(mSelectedTint); item.textView.setVisibility(View.VISIBLE); item.textView.setTextSize(0); ValueAnimator animator = mLabelAnimators.get(item); if (animator != null) animator.cancel(); animator = new ValueAnimator(); mLabelAnimators.put(item, animator); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (Integer) valueAnimator.getAnimatedValue(); item.textView.setTextSize(animatedValue); } }); animator.setIntValues(0, 14); animator.start(); } } else { item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP); if (item.textView != null) { item.textView.setTextColor(mUnselectedTint); ValueAnimator animator = mLabelAnimators.get(item); if (animator != null) animator.cancel(); animator = new ValueAnimator(); mLabelAnimators.put(item, animator); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (Integer) valueAnimator.getAnimatedValue(); item.textView.setTextSize(animatedValue); if (animatedValue == 0) item.textView.setVisibility(View.GONE); } }); animator.setIntValues(14, 0); animator.start(); } } }
From source file:com.rbware.github.androidcouchpotato.widget.AbstractMediaItemPresenter.java
/** * Each media item row can have multiple focusable elements; the details on the left and a set * of optional custom actions on the right. * The selector is a highlight that moves to highlight to cover whichever views is in focus. * * @param selectorView the selector view used to highlight an individual element within a row. * @param focusChangedView The component within the media row whose focus got changed. * @param layoutAnimator the ValueAnimator producing animation frames for the selector's width * and x-translation, generated by this method and stored for the each * {@link ViewHolder}. * @param isDetails Whether the changed-focused view is for a media item details (true) or * an action (false)./*from w w w . j a va2 s. c o m*/ */ static ValueAnimator updateSelector(final View selectorView, View focusChangedView, ValueAnimator layoutAnimator, boolean isDetails) { int animationDuration = focusChangedView.getContext().getResources() .getInteger(android.R.integer.config_shortAnimTime); DecelerateInterpolator interpolator = new DecelerateInterpolator(); int layoutDirection = ViewCompat.getLayoutDirection(selectorView); if (!focusChangedView.hasFocus()) { // if neither of the details or action views are in focus (ie. another row is in focus), // animate the selector out. selectorView.animate().cancel(); selectorView.animate().alpha(0f).setDuration(animationDuration).setInterpolator(interpolator).start(); // keep existing layout animator return layoutAnimator; } else { // cancel existing layout animator if (layoutAnimator != null) { layoutAnimator.cancel(); layoutAnimator = null; } float currentAlpha = selectorView.getAlpha(); selectorView.animate().alpha(1f).setDuration(animationDuration).setInterpolator(interpolator).start(); final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) selectorView.getLayoutParams(); ViewGroup rootView = (ViewGroup) selectorView.getParent(); sTempRect.set(0, 0, focusChangedView.getWidth(), focusChangedView.getHeight()); rootView.offsetDescendantRectToMyCoords(focusChangedView, sTempRect); if (isDetails) { if (layoutDirection == View.LAYOUT_DIRECTION_RTL) { sTempRect.right += rootView.getHeight(); sTempRect.left -= rootView.getHeight() / 2; } else { sTempRect.left -= rootView.getHeight(); sTempRect.right += rootView.getHeight() / 2; } } final int targetLeft = sTempRect.left; final int targetWidth = sTempRect.width(); final float deltaWidth = lp.width - targetWidth; final float deltaLeft = lp.leftMargin - targetLeft; if (deltaLeft == 0f && deltaWidth == 0f) { // no change needed } else if (currentAlpha == 0f) { // change selector to the proper width and marginLeft without animation. lp.width = targetWidth; lp.leftMargin = targetLeft; selectorView.requestLayout(); } else { // animate the selector to the proper width and marginLeft. layoutAnimator = ValueAnimator.ofFloat(0f, 1f); layoutAnimator.setDuration(animationDuration); layoutAnimator.setInterpolator(interpolator); layoutAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // Set width to the proper width for this animation step. float fractionToEnd = 1f - valueAnimator.getAnimatedFraction(); lp.leftMargin = Math.round(targetLeft + deltaLeft * fractionToEnd); lp.width = Math.round(targetWidth + deltaWidth * fractionToEnd); selectorView.requestLayout(); } }); layoutAnimator.start(); } return layoutAnimator; } }
From source file:com.marlonjones.voidlauncher.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);// ww w .j a va2 s. c om setClipToPadding(false); mLauncher = Launcher.getLauncher(context); DeviceProfile grid = mLauncher.getDeviceProfile(); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = grid.inv.numColumns; mCountY = grid.inv.numRows; mOccupied = new GridOccupancy(mCountX, mCountY); mTmpOccupied = new GridOccupancy(mCountX, mCountY); mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; mFolderLeaveBehind.delegateCellX = -1; mFolderLeaveBehind.delegateCellY = -1; setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable( FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ? R.drawable.bg_screenpanel : R.drawable.bg_celllayout); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } mDragOutlinePaint.setColor(getResources().getColor(R.color.outline_color)); // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { if (LOGD) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }
From source file:com.android.launcher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);//from w ww .jav a 2s.co m setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { if (LOGD) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }
From source file:com.android.mylauncher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);/*w w w. j a v a 2 s. c o m*/ setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; a.recycle(); setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }
From source file:com.android.zlauncher.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);/* w w w . ja va 2 s . c o m*/ setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; a.recycle(); setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mBackground.setAlpha((int) (mBackgroundAlpha * 255)); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); /* mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView);*/ addView(mShortcutsAndWidgets); }
From source file:com.klinker.android.launcher.launcher3.CellLayout.java
public CellLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show // the user where a dragged item will land when dropped. setWillNotDraw(false);//from w w w. j av a 2 s . c om setClipToPadding(false); mLauncher = (Launcher) context; DeviceProfile grid = mLauncher.getDeviceProfile(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; mWidthGap = mOriginalWidthGap = 0; mHeightGap = mOriginalHeightGap = 0; mMaxGap = Integer.MAX_VALUE; mCountX = (int) grid.inv.numColumns; mCountY = (int) grid.inv.numRows; mOccupied = new boolean[mCountX][mCountY]; mTmpOccupied = new boolean[mCountX][mCountY]; mPreviousReorderDirection[0] = INVALID_DIRECTION; mPreviousReorderDirection[1] = INVALID_DIRECTION; a.recycle(); setAlwaysDrawnWithCacheEnabled(false); final Resources res = getResources(); mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx; mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel); mBackground.setCallback(this); mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx); // Initialize the data structures used for the drag visualization. mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out mDragCell[0] = mDragCell[1] = -1; for (int i = 0; i < mDragOutlines.length; i++) { mDragOutlines[i] = new Rect(-1, -1, -1, -1); } // When dragging things around the home screens, we show a green outline of // where the item will land. The outlines gradually fade out, leaving a trail // behind the drag path. // Set up all the animations that are used to implement this fading. final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime); final float fromAlphaValue = 0; final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha); Arrays.fill(mDragOutlineAlphas, fromAlphaValue); for (int i = 0; i < mDragOutlineAnims.length; i++) { final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue, toAlphaValue); anim.getAnimator().setInterpolator(mEaseOutInterpolator); final int thisIndex = i; anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { final Bitmap outline = (Bitmap) anim.getTag(); // If an animation is started and then stopped very quickly, we can still // get spurious updates we've cleared the tag. Guard against this. if (outline == null) { @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { Object val = animation.getAnimatedValue(); Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped()); } // Try to prevent it from continuing to run animation.cancel(); } else { mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue(); CellLayout.this.invalidate(mDragOutlines[thisIndex]); } } }); // The animation holds a reference to the drag outline bitmap as long is it's // running. This way the bitmap can be GCed when the animations are complete. anim.getAnimator().addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) { anim.setTag(null); } } }); mDragOutlineAnims[i] = anim; } mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context); mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); mStylusEventHelper = new StylusEventHelper(this); mTouchFeedbackView = new ClickShadowView(context); addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); }