List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter
AnimatorListenerAdapter
From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissListViewTouchListener.java
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/*from ww w. jav a 2 s . c o m*/ public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } mCallback.onDismiss(mListView, dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation setAlpha(pendingDismiss.view, 1f); setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingDismisses.clear(); } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:bottombar.BottomBarTab.java
void updateWidth(float endWidth, boolean animated) { if (!animated) { getLayoutParams().width = (int) endWidth; if (!isActive && badge != null) { badge.adjustPositionAndSize(this); badge.show();/*from ww w .ja v a 2 s.c om*/ } return; } float start = getWidth(); ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth); animator.setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ViewGroup.LayoutParams params = getLayoutParams(); if (params == null) return; params.width = Math.round((float) animator.getAnimatedValue()); setLayoutParams(params); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!isActive && badge != null) { badge.adjustPositionAndSize(BottomBarTab.this); badge.show(); } } }); animator.start(); }
From source file:arun.com.chromer.webheads.ui.views.BaseWebHead.java
/** * Opposite of {@link #getRevealAnimator(int)}. Reveal goes from max scale to 0 appearing to be * revealing in.//from w w w.j a v a2s. c o m * * @param newWebHeadColor New themeColor of reveal * @param start Runnable to run on start * @param end Runnable to run on end */ void revealInAnimation(@ColorInt final int newWebHeadColor, @NonNull final Runnable start, @NonNull final Runnable end) { if (revealView == null || circleBg == null) { start.run(); end.run(); } revealView.clearAnimation(); revealView.setColor(circleBg.getColor()); revealView.setScaleX(1f); revealView.setScaleY(1f); revealView.setAlpha(1f); circleBg.setColor(newWebHeadColor); final AnimatorSet animator = new AnimatorSet(); animator.playTogether(ObjectAnimator.ofFloat(revealView, "scaleX", 0f), ObjectAnimator.ofFloat(revealView, "scaleY", 0f)); revealView.setLayerType(LAYER_TYPE_HARDWARE, null); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { start.run(); } @Override public void onAnimationEnd(Animator animation) { webHeadColor = newWebHeadColor; indicator.setTextColor(getForegroundWhiteOrBlack(newWebHeadColor)); revealView.setLayerType(LAYER_TYPE_NONE, null); revealView.setScaleX(0f); revealView.setScaleY(0f); end.run(); } }); animator.setInterpolator(new LinearOutSlowInInterpolator()); animator.setDuration(400); animator.setStartDelay(100); animator.start(); }
From source file:com.hippo.android.animator.AnimatorsBase.java
static Animator crossFade(final View from, final View to, ViewGroup ancestor, final boolean toIsTop) { // Ensure views is laid out if (!ViewCompat.isLaidOut(from) || !ViewCompat.isLaidOut(to)) { Log.w(LOG_TAG, "From view and to view must be laid out before calling crossFade()."); return null; }//w ww.j ava2s .co m // Get overlay final ViewOverlayCompat overlay = ViewOverlayCompat.from(ancestor); if (overlay == null) { Log.w(LOG_TAG, "The ancestor in crossFade() must be able to create a ViewOverlay."); return null; } // Get the location of from view if (!Utils.getLocationInAncestor(from, ancestor, TEMP_LOCATION)) { Log.w(LOG_TAG, "From view must be in ancestor in crossFade()."); return null; } int fromX = TEMP_LOCATION[0]; int fromY = TEMP_LOCATION[1]; // Get the location of to view if (!Utils.getLocationInAncestor(to, ancestor, TEMP_LOCATION)) { Log.w(LOG_TAG, "From view must be in ancestor in crossFade()."); return null; } int toX = TEMP_LOCATION[0]; int toY = TEMP_LOCATION[1]; // Get the screenshot of from view final Bitmap fromBitmap = Utils.screenshot(from); if (fromBitmap == null) { Log.w(LOG_TAG, "Can't screenshot from view in crossFade()."); return null; } // Get the screenshot of to view final Bitmap toBitmap = Utils.screenshot(to); if (toBitmap == null) { Log.w(LOG_TAG, "Can't screenshot to view in crossFade()."); fromBitmap.recycle(); return null; } // Create start drawables final Drawable fromDrawable = new BitmapDrawable(from.getContext().getResources(), fromBitmap); int fromWidth = fromBitmap.getWidth(); int fromHeight = fromBitmap.getHeight(); fromDrawable.setBounds(fromX, fromY, fromX + fromWidth, fromY + fromHeight); int fromCenterX = fromX + fromWidth / 2; int fromCenterY = fromY + fromHeight / 2; // Create end drawable final Drawable toDrawable = new BitmapDrawable(to.getContext().getResources(), toBitmap); int toWidth = toBitmap.getWidth(); int toHeight = toBitmap.getHeight(); int toStartX = fromCenterX - toWidth / 2; int toStartY = fromCenterY - toHeight / 2; toDrawable.setBounds(toStartX, toStartY, toStartX + toWidth, toStartY + toHeight); int toCenterX = toX + toWidth / 2; int toCenterY = toY + toHeight / 2; List<Animator> set = new ArrayList<>(4); // Create alpha animators Animator fromAlpha = ObjectAnimator.ofInt(fromDrawable, DRAWABLE_ALPHA_PROPERTY, 255, 0); Animator toAlpha = ObjectAnimator.ofInt(toDrawable, DRAWABLE_ALPHA_PROPERTY, 0, 255); set.add(fromAlpha); set.add(toAlpha); // Create position animators if (fromCenterX != toCenterX || fromCenterY != toCenterY) { Path path = ACR_PATH_MOTION.getPath(fromCenterX, fromCenterY, toCenterX, toCenterY); Animator fromPosition = Animators.ofPointF(fromDrawable, DRAWABLE_POSITION_PROPERTY, path); Animator toPosition = Animators.ofPointF(toDrawable, DRAWABLE_POSITION_PROPERTY, path); set.add(fromPosition); set.add(toPosition); } Animator animator = Animators.playTogether(set); animator.addListener(new AnimatorListenerAdapter() { float fromAlpha; float toAlpha; @Override public void onAnimationStart(Animator animation) { // Add drawables to overlay if (toIsTop) { overlay.add(fromDrawable); overlay.add(toDrawable); } else { overlay.add(toDrawable); overlay.add(fromDrawable); } // Hide from view and to view fromAlpha = from.getAlpha(); toAlpha = to.getAlpha(); from.setAlpha(0.0f); to.setAlpha(0.0f); } @Override public void onAnimationEnd(Animator animation) { // Remove drawables from overlay overlay.remove(fromDrawable); overlay.remove(toDrawable); // Show from view and to view from.setAlpha(fromAlpha); to.setAlpha(toAlpha); // Recycle bitmaps fromBitmap.recycle(); toBitmap.recycle(); } }); return animator; }
From source file:android.support.transition.ChangeBounds.java
@Override @Nullable/*from w ww. ja v a 2 s . com*/ public Animator createAnimator(@NonNull final ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) { if (startValues == null || endValues == null) { return null; } Map<String, Object> startParentVals = startValues.values; Map<String, Object> endParentVals = endValues.values; ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT); ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT); if (startParent == null || endParent == null) { return null; } final View view = endValues.view; if (parentMatches(startParent, endParent)) { Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS); Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS); final int startLeft = startBounds.left; final int endLeft = endBounds.left; final int startTop = startBounds.top; final int endTop = endBounds.top; final int startRight = startBounds.right; final int endRight = endBounds.right; final int startBottom = startBounds.bottom; final int endBottom = endBounds.bottom; final int startWidth = startRight - startLeft; final int startHeight = startBottom - startTop; final int endWidth = endRight - endLeft; final int endHeight = endBottom - endTop; Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP); Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP); int numChanges = 0; if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) { if (startLeft != endLeft || startTop != endTop) ++numChanges; if (startRight != endRight || startBottom != endBottom) ++numChanges; } if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) { ++numChanges; } if (numChanges > 0) { Animator anim; if (!mResizeClip) { ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom); if (numChanges == 2) { if (startWidth == endWidth && startHeight == endHeight) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath); } else { final ViewBounds viewBounds = new ViewBounds(view); Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); ObjectAnimator topLeftAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, TOP_LEFT_PROPERTY, topLeftPath); Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, BOTTOM_RIGHT_PROPERTY, bottomRightPath); AnimatorSet set = new AnimatorSet(); set.playTogether(topLeftAnimator, bottomRightAnimator); anim = set; set.addListener(new AnimatorListenerAdapter() { // We need a strong reference to viewBounds until the // animator ends (The ObjectAnimator holds only a weak reference). @SuppressWarnings("unused") private ViewBounds mViewBounds = viewBounds; }); } } else if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, topLeftPath); } else { Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, bottomRight); } } else { int maxWidth = Math.max(startWidth, endWidth); int maxHeight = Math.max(startHeight, endHeight); ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth, startTop + maxHeight); ObjectAnimator positionAnimator = null; if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, 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)) { ViewCompat.setClipBounds(view, 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) { ViewCompat.setClipBounds(view, finalClip); ViewUtils.setLeftTopRightBottom(view, endLeft, endTop, endRight, endBottom); } } }); } anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator); } if (view.getParent() instanceof ViewGroup) { final ViewGroup parent = (ViewGroup) view.getParent(); ViewGroupUtils.suppressLayout(parent, true); TransitionListener transitionListener = new TransitionListenerAdapter() { boolean mCanceled = false; @Override public void onTransitionCancel(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); mCanceled = true; } @Override public void onTransitionEnd(@NonNull Transition transition) { if (!mCanceled) { ViewGroupUtils.suppressLayout(parent, false); } transition.removeListener(this); } @Override public void onTransitionPause(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); } @Override public void onTransitionResume(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, true); } }; addListener(transitionListener); } return anim; } } else { int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X); int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y); int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X); int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y); // TODO: also handle size changes: check bounds and animate size changes if (startX != endX || startY != endY) { sceneRoot.getLocationInWindow(mTempLocation); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); @SuppressWarnings("deprecation") final BitmapDrawable drawable = new BitmapDrawable(bitmap); final float transitionAlpha = ViewUtils.getTransitionAlpha(view); ViewUtils.setTransitionAlpha(view, 0); ViewUtils.getOverlay(sceneRoot).add(drawable); Path topLeftPath = getPathMotion().getPath(startX - mTempLocation[0], startY - mTempLocation[1], endX - mTempLocation[0], endY - mTempLocation[1]); PropertyValuesHolder origin = PropertyValuesHolderUtils.ofPointF(DRAWABLE_ORIGIN_PROPERTY, topLeftPath); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ViewUtils.getOverlay(sceneRoot).remove(drawable); ViewUtils.setTransitionAlpha(view, transitionAlpha); } }); return anim; } } return null; }
From source file:com.commit451.springy.CompanionWatchFaceConfigActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void updateUIToSelectedTheme(final String themeId, final boolean animate) { for (final ThemeUiHolder holder : mThemeUiHolders) { boolean selected = holder.theme.id.equals(themeId); holder.button.setSelected(selected); if (holder.selected != selected && selected) { if (mCurrentRevealAnimator != null) { mCurrentRevealAnimator.end(); updatePreviewView(mAnimatingTheme, mMainClockContainerView); }/*from w w w .j a va 2 s. co m*/ if (animate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mAnimatingTheme = holder.theme; updatePreviewView(mAnimatingTheme, mAnimateClockContainerView); Rect buttonRect = new Rect(); Rect clockContainerRect = new Rect(); holder.button.getGlobalVisibleRect(buttonRect); mMainClockContainerView.getGlobalVisibleRect(clockContainerRect); int cx = buttonRect.centerX() - clockContainerRect.left; int cy = buttonRect.centerY() - clockContainerRect.top; clockContainerRect.offsetTo(0, 0); mCurrentRevealAnimator = ViewAnimationUtils.createCircularReveal(mAnimateClockContainerView, cx, cy, 0, MathUtil.maxDistanceToCorner(clockContainerRect, cx, cy)); mAnimateClockContainerView.setVisibility(View.VISIBLE); mCurrentRevealAnimator.setDuration(300); mCurrentRevealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (mCurrentRevealAnimator == animation) { mAnimateClockContainerView.setVisibility(View.INVISIBLE); updatePreviewView(holder.theme, mMainClockContainerView); } } }); mAnimateClockView.postInvalidateOnAnimation(); mCurrentRevealAnimator.start(); } else { updatePreviewView(holder.theme, mMainClockContainerView); } } holder.selected = selected; } }
From source file:com.itude.mobile.mobbl.blueprint.app.view.listeners.SwipeDismissRecyclerViewTouchListener.java
private void performDismiss(final View dismissView, final int dismissPosition) { // Animate the dismissed list item to zero-height and fire the dismiss callback when // all dismissed list item animations have completed. This triggers layout on each animation // frame; in the future we may want to do something smarter and more performant. final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight; if (mIsVertical) originalHeight = dismissView.getWidth(); else//from ww w.j av a2 s . c om originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingDismisses); int[] dismissPositions = new int[mPendingDismisses.size()]; for (int i = mPendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = mPendingDismisses.get(i).position; } mCallbacks.onDismiss(dismissView, dismissPosition); // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss // animation with a stale position mDownPosition = ListView.INVALID_POSITION; ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation pendingDismiss.view.setAlpha(1f); if (mIsVertical) pendingDismiss.view.setTranslationY(0); else pendingDismiss.view.setTranslationX(0); lp = pendingDismiss.view.getLayoutParams(); if (mIsVertical) lp.width = originalHeight; else lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } // Send a cancel event long time = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0); mRecyclerView.dispatchTouchEvent(cancelEvent); mPendingDismisses.clear(); } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { if (mIsVertical) lp.width = (Integer) valueAnimator.getAnimatedValue(); else lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
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 www. j a v a 2 s . 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.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);//from w w w . ja va 2s .co 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.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);//from w w w . j av a 2 s.com 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); }