List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter
AnimatorListenerAdapter
From source file:com.odoo.OdooActivity.java
private void accountBoxToggle() { ImageView boxIndicator = (ImageView) findViewById(R.id.expand_account_box_indicator); boxIndicator.setImageResource(mAccountBoxExpanded ? R.drawable.ic_drawer_accounts_collapse : R.drawable.ic_drawer_accounts_expand); int hideTranslateY = -mDrawerAccountContainer.getHeight() / 4; if (mAccountBoxExpanded && mDrawerAccountContainer.getTranslationY() == 0) { // initial setup mDrawerAccountContainer.setAlpha(0); mDrawerAccountContainer.setTranslationY(hideTranslateY); }/* w ww . ja va2s. c om*/ AnimatorSet set = new AnimatorSet(); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDrawerItemContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE); mDrawerAccountContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } }); if (mAccountBoxExpanded) { mDrawerAccountContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mDrawerAccountContainer, View.ALPHA, 1) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION), ObjectAnimator.ofFloat(mDrawerAccountContainer, View.TRANSLATION_Y, 0) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION)); set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemContainer, View.ALPHA, 0) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION), subSet); set.start(); } else { mDrawerItemContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mDrawerAccountContainer, View.ALPHA, 0) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION), ObjectAnimator.ofFloat(mDrawerAccountContainer, View.TRANSLATION_Y, hideTranslateY) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION)); set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemContainer, View.ALPHA, 1) .setDuration(DRAWER_ACCOUNT_BOX_ANIMATION_DURATION)); set.start(); } set.start(); }
From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java
/** * Animate the dismissal of the given item. *//*from www . j ava 2s . c o m*/ private void animateDismiss(final ConversationListItemView itemView, final int swipeDirection, final float velocityX) { Assert.isTrue(swipeDirection != SWIPE_DIRECTION_NONE); onSwipeAnimationStart(itemView); final float animateTo = (swipeDirection == SWIPE_DIRECTION_RIGHT) ? mRecyclerView.getWidth() : -mRecyclerView.getWidth(); final long duration; if (velocityX != 0) { final float deltaX = animateTo - itemView.getSwipeTranslationX(); duration = calculateTranslationDuration(deltaX, velocityX); } else { duration = mDefaultDismissAnimationDuration; } final ObjectAnimator animator = getSwipeTranslationXAnimator(itemView, animateTo, duration, UiUtils.DEFAULT_INTERPOLATOR); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { onSwipeAnimationEnd(itemView); } }); animator.start(); }
From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java
public void setOnTabStripSelectedIndexListener( final OnTabStripSelectedIndexListener onTabStripSelectedIndexListener) { mOnTabStripSelectedIndexListener = onTabStripSelectedIndexListener; if (mAnimatorListener == null) mAnimatorListener = new AnimatorListenerAdapter() { @Override//w w w . j a v a 2 s .c om public void onAnimationStart(final Animator animation) { if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onStartTabSelected(mTitles[mIndex], mIndex); animation.removeListener(this); animation.addListener(this); } @Override public void onAnimationEnd(final Animator animation) { if (mIsViewPagerMode) return; animation.removeListener(this); animation.addListener(this); if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onEndTabSelected(mTitles[mIndex], mIndex); } }; mAnimator.removeListener(mAnimatorListener); mAnimator.addListener(mAnimatorListener); }
From source file:com.hamzahrmalik.calculator2.Calculator.java
private void reveal(View sourceView, int colorRes, AnimatorListener listener) { final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay(); final Rect displayRect = new Rect(); mDisplayView.getGlobalVisibleRect(displayRect); // Make reveal cover the display and status bar. final View revealView = new View(this); revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(getResources().getColor(colorRes)); groupOverlay.add(revealView);//from w ww .ja v a 2s.c o m final int[] clearLocation = new int[2]; sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; final int revealCenterX = clearLocation[0] - revealView.getLeft(); final int revealCenterY = clearLocation[1] - revealView.getTop(); final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { groupOverlay.remove(revealView); mCurrentAnimator = null; } }); mResultEditText.setText(""); mFormulaEditText.setText(""); mCurrentAnimator = animatorSet; animatorSet.start(); }
From source file:android.support.transition.ChangeTransform.java
private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues, final boolean handleParentChange) { Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX); Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX); if (startMatrix == null) { startMatrix = MatrixUtils.IDENTITY_MATRIX; }/*from ww w . j av a 2s . com*/ if (endMatrix == null) { endMatrix = MatrixUtils.IDENTITY_MATRIX; } if (startMatrix.equals(endMatrix)) { return null; } final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS); // clear the transform properties so that we can use the animation matrix instead final View view = endValues.view; setIdentityTransforms(view); final float[] startMatrixValues = new float[9]; startMatrix.getValues(startMatrixValues); final float[] endMatrixValues = new float[9]; endMatrix.getValues(endMatrixValues); final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues); PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY, new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues); Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y], endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]); PropertyValuesHolder translationProperty = PropertyValuesHolderUtils.ofPointF(TRANSLATIONS_PROPERTY, path); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty, translationProperty); final Matrix finalEndMatrix = endMatrix; AnimatorListenerAdapter listener = new AnimatorListenerAdapter() { private boolean mIsCanceled; private Matrix mTempMatrix = new Matrix(); @Override public void onAnimationCancel(Animator animation) { mIsCanceled = true; } @Override public void onAnimationEnd(Animator animation) { if (!mIsCanceled) { if (handleParentChange && mUseOverlay) { setCurrentMatrix(finalEndMatrix); } else { view.setTag(R.id.transition_transform, null); view.setTag(R.id.parent_matrix, null); } } ViewUtils.setAnimationMatrix(view, null); transforms.restore(view); } @Override public void onAnimationPause(Animator animation) { Matrix currentMatrix = pathAnimatorMatrix.getMatrix(); setCurrentMatrix(currentMatrix); } @Override public void onAnimationResume(Animator animation) { setIdentityTransforms(view); } private void setCurrentMatrix(Matrix currentMatrix) { mTempMatrix.set(currentMatrix); view.setTag(R.id.transition_transform, mTempMatrix); transforms.restore(view); } }; animator.addListener(listener); AnimatorUtils.addPauseListener(animator, listener); return animator; }
From source file:com.appunite.appunitevideoplayer.PlayerActivity.java
private void animatePlayButton(boolean visible) { if (visible) { playButton.animate().alpha(1.f).setDuration(ANIMATION_DURATION_FAST) .setListener(new AnimatorListenerAdapter() { @Override/*from w ww.j av a 2 s.co m*/ public void onAnimationStart(Animator animation) { playButton.setVisibility(View.VISIBLE); } }).start(); } else { playButton.animate().alpha(0.f).setDuration(ANIMATION_DURATION_FAST) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { playButton.setVisibility(View.GONE); } }).start(); } }
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);/*w w w. j a v a 2 s . 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); 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.l4digital.fastscroll.FastScroller.java
private void showBubble() { mBubbleView.setVisibility(VISIBLE);//ww w . j a v a 2 s .c om mBubbleAnimator = mBubbleView.animate().alpha(1f).setDuration(sBubbleAnimDuration) .setListener(new AnimatorListenerAdapter() { // adapter required for new alpha value to stick }); }
From source file:com.example.volunteerhandbook.MainActivity.java
void loop_what_I_thought() { thoughts = getResources().getStringArray(R.array.what_I_thought); int lines = thoughts.length / 4; container = (FrameLayout) findViewById(R.id.main_content_frame); LinearLayout[] textBox = new LinearLayout[3]; endY = container.getHeight() - 100f; h = (float) container.getHeight(); hBox = 0;/*from w ww. j a v a 2s . c om*/ /* for (int k=0; k<3; k++){ textBox[k]=new LinearLayout(this); textBox[k].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); textBox[k].setOrientation(1); } */ //LinearLayout tmp=(LinearLayout) getLayoutInflater().inflate(R.layout.one_line, null); //TextView tmpTxt=(TextView)tmp.findViewById(R.id.oneLine); //tmp.removeView(tmpTxt); int[] color = new int[4]; color[3] = Color.parseColor("#66FF66"); color[1] = Color.parseColor("#FF9900"); color[2] = Color.parseColor("#0099FF"); color[0] = Color.parseColor("#00FF00"); toMove = new TextView[thoughts.length]; int textSize = 24; for (int i = 0; i < thoughts.length; i++) { toMove[i] = new TextView(this); toMove[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toMove[i].setText(thoughts[i]); toMove[i].setTextSize(textSize); toMove[i].getPaint().setFakeBoldText(true); toMove[i].setTextColor(color[1] - 0x20202 * i); //textBox.addView(toMove); } int boxHeight = (lines + 1) * (int) (textSize * 1.5); for (int k = 0; k < 3; k++) { textBox[k].removeAllViews(); for (int i = 0; i < thoughts.length / 4; i++) { TextView v = toMove[iTh++ % thoughts.length]; v.setTextColor(color[k]); textBox[k].addView(v); } //toMove.setTranslationY(600); //container.addView(textBox); container.addView(textBox[k]); textBox[k].setX(20); textBox[k].setY(2 * boxHeight + hBox); hBox += boxHeight; //textBox[k].getHeight(); float startY = textBox[k].getY(); endY = (-1) * boxHeight; int duration = (int) (((startY - endY) / (3 * boxHeight)) * 20000); ValueAnimator bounceAnim = ObjectAnimator.ofFloat(textBox[k], "y", startY, endY); bounceAnim.setDuration(duration); bounceAnim.setInterpolator(new LinearInterpolator()); final LinearLayout iBox = textBox[k]; bounceAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { loopNewBox(iBox); } }); bounceAnim.start(); } }
From source file:arun.com.chromer.webheads.ui.views.WebHead.java
/** * Same as {@link #setContentScale(float)} but with animations and ability to listen when animation * finishes by giving a Runnable. {@param end} * * @param scale Scale to set/*from w ww . j av a2s. c o m*/ * @param endAction End runnable to execute after animations */ private void animateContentScale(final float scale, @Nullable final Runnable endAction) { contentRoot.animate().scaleX(scale).scaleY(scale).setInterpolator(new SpringInterpolator(0.2, 5)) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (endAction != null) { endAction.run(); } } }).start(); }