List of usage examples for android.view.animation Animation cancel
public void cancel()
From source file:Main.java
public static void clearViewAnim(View view) { if (view == null) { return;/*from www . j av a 2 s . c o m*/ } Animation anim = view.getAnimation(); if (anim != null) { anim.cancel(); view.setAnimation(null); } anim = null; }
From source file:Main.java
/** * Cancel any previous animation.// w ww . jav a2 s . co m * @param view the view. */ public static void cancelAnimation(View view) { Animation animation = view.getAnimation(); if (animation != null) { animation.reset(); animation.cancel(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { view.animate().cancel(); } view.clearAnimation(); }
From source file:ca.rmen.android.scrumchatter.meeting.list.MeetingsCursorAdapter.java
/** * Fill the view holder's fields with data from the given meeting. *//* w w w.ja v a 2 s . co m*/ @Override public void onBindViewHolder(final MeetingViewHolder holder, int position) { getCursor().moveToPosition(position); Context context = holder.binding.getRoot().getContext(); // Get the data from the cursor MeetingCursorWrapper cursorWrapper = new MeetingCursorWrapper(getCursor()); final Meeting meeting = Meeting.read(context, cursorWrapper); String dateString = TextUtils.formatDateTime(context, meeting.getStartDate()); String duration = DateUtils.formatElapsedTime(meeting.getDuration()); String stateName = mMeetingStateNames[meeting.getState().ordinal()]; final MeetingListItemBinding binding = holder.binding; // Find the views we need to set up. binding.setMeeting(meeting); // Fill the date view. binding.tvMeetingDate.setText(dateString); // Fill the duration view. We will only show the duration if // the meeting is finished. For not-started or in-progress // meetings, we show the state. if (meeting.getState() == State.FINISHED) binding.tvMeetingDuration.setText(duration); else binding.tvMeetingDuration.setText(stateName); if (meeting.getState() == State.IN_PROGRESS) { Animation animBlink = AnimationUtils.loadAnimation(context, R.anim.blink); binding.tvMeetingDuration.startAnimation(animBlink); binding.tvMeetingDuration.setTextColor(mColorStateInProgress); } else { Animation anim = binding.tvMeetingDuration.getAnimation(); if (anim != null) { anim.cancel(); // Need to make sure the animation doesn't stay faded out. anim = AnimationUtils.loadAnimation(context, R.anim.show); binding.tvMeetingDuration.startAnimation(anim); } binding.tvMeetingDuration.setTextColor(mColorStateDefault); } if (binding.getRoot().getContext().getResources().getBoolean(R.bool.is_tablet) && Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { binding.getRoot().setActivated(mSelectedPosition == position); } binding.btnDeleteMeeting.setOnClickListener(v -> mMeetingListener.onMeetingDelete(meeting)); binding.getRoot().setOnClickListener(v -> { mSelectedPosition = holder.getAdapterPosition(); mMeetingListener.onMeetingOpen(meeting); notifyDataSetChanged(); }); }
From source file:com.spoiledmilk.ibikecph.controls.SortableListView.java
void translate(View v, float deltaY, final boolean finalAnim) { float newY = posY + deltaY; if (animation != null && animation.isInitialized()) animation.cancel(); animation = new TranslateAnimation(0, 0, posY, newY); animation.setDuration(finalAnim ? 0 : 100); animation.setAnimationListener(new AnimationListener() { @Override/*from ww w . j av a 2s . c om*/ public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (!finalAnim) { animation.setFillEnabled(true); animation.setFillAfter(true); } else { view.clearAnimation(); posY = 0; } } }); posY = newY; v.startAnimation(animation); }
From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_anm); orgnlImageView = (ImageView) findViewById(R.id.imageView); orgnlImageView.setMaxHeight(800);// w w w . j a v a 2 s. c om orgnlImageView.setMaxWidth(600); crt_ctx = this; BitmapFactory.Options bmp_opt = new BitmapFactory.Options(); bmp_opt.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT; // - Now we need to set the GUI ImageView data with data read from the picked file. DcodRszdBmpFil dcodRszdBmpFil = new DcodRszdBmpFil(); Bitmap bmp = dcodRszdBmpFil.DcodRszdBmpFil(SelectImageActivity.orgFil, bmp_opt); // Now we need to set the GUI ImageView data with the orginal file selection. orgnlImageView.setImageBitmap(bmp); orgnl_iv_wdth = bmp.getWidth(); orgnl_iv_hght = bmp.getHeight(); final RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo); scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener()); orgnlImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getPointerCount() > 1 || flgInScale) { scaleGestureDetector.onTouchEvent(event); return true; } int end_hrz; int end_vrt; final int pointerIndex; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: pointerIndex = MotionEventCompat.getActionIndex(event); bgn_hrz = (int) MotionEventCompat.getX(event, pointerIndex); bgn_vrt = (int) MotionEventCompat.getY(event, pointerIndex); String log_str = "Beginning coordinates: Horz = " + String.valueOf(bgn_hrz) + "; Vert = " + String.valueOf(bgn_vrt); Log.d("OnTouchListener", log_str); orlp = (RelativeLayout.LayoutParams) orgnlImageView.getLayoutParams(); bgn_top = (int) orlp.topMargin; bgn_lft = (int) orlp.leftMargin; // To prevent an initial jump of the magnifier, aposX and aPosY must // have the values from the magnifier frame if (aPosX == 0) aPosX = orgnlImageView.getX(); if (aPosY == 0) aPosY = orgnlImageView.getY(); break; case MotionEvent.ACTION_MOVE: pointerIndex = MotionEventCompat.getActionIndex(event); float crt_hrz = MotionEventCompat.getX(event, pointerIndex); float crt_vrt = MotionEventCompat.getY(event, pointerIndex); final float dx = crt_hrz - bgn_hrz; final float dy = crt_vrt - bgn_vrt; aPosX += dx; aPosY += dy; orgnlImageView.setX(aPosX); orgnlImageView.setY(aPosY); log_str = "Current Position: Horz = " + String.valueOf(crt_hrz) + "; Vert = " + String.valueOf(crt_vrt); Log.d("OnTouchListener", log_str); break; case MotionEvent.ACTION_UP: pointerIndex = MotionEventCompat.getActionIndex(event); end_hrz = (int) MotionEventCompat.getX(event, pointerIndex); end_vrt = (int) MotionEventCompat.getY(event, pointerIndex); } rel_anm_lo.invalidate(); return true; } }); sav_anm_btn = (Button) findViewById(R.id.sav_btn); sav_anm_btn.setOnClickListener(new View.OnClickListener() { public void onClick(View vw) { onClickFlg = 1; RelativeLayout rel_anm_lo = (RelativeLayout) findViewById(R.id.activity_anm_lo); rel_anm_lo.removeView(vw); Bitmap tnBmp = getWrtBmp("thumbnail", rel_anm_lo, 40); tnBmp.recycle(); int vw_nmbr = anmViews.size(); for (int vw_mbr = 1; vw_mbr < vw_nmbr; vw_mbr += 1) { anim_view = anmViews.get(vw_mbr); if (anim_view != null) { Animation crt_anm = anim_view.getAnimation(); if (crt_anm != null) crt_anm.cancel(); anim_view.setAnimation(null); rel_anm_lo.removeView(anim_view); // Garbage collect the bitmap Drawable drawable = anim_view.getDrawable(); if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap anim_bmp = bitmapDrawable.getBitmap(); anim_bmp.recycle(); } } } Bitmap orgnlImageBmp = getWrtBmp("bgimg", rel_anm_lo, 90); orgnlImageWdth = Integer.toString(orgnlImageBmp.getWidth()); orgnlImageHght = Integer.toString(orgnlImageBmp.getHeight()); anmViews.clear(); unbindDrawables(rel_anm_lo); ((RelativeLayout) rel_anm_lo).removeAllViews(); orgnlImageBmp.recycle(); crt_ctx = null; orgnlImageView = null; Intent intent = new Intent(AnimActivity.this, com.acceleratedio.pac_n_zoom.SaveAnmActivity.class); startActivity(intent); } }); progress = ProgressDialog.show(crt_ctx, "Loading the animation", "dialog message", true); GetRequest get_svg_img = new GetRequest(); get_svg_img.execute(""); }
From source file:com.linkbubble.ui.BubbleFlowView.java
protected void remove(final int index, boolean animateOff, boolean removeFromList, final OnRemovedListener onRemovedListener) { if (index < 0 || index >= mViews.size()) { return;/*from w w w . j a v a 2 s. c o m*/ } final View view = mViews.get(index); if (animateOff) { if (removeFromList == false) { throw new RuntimeException("removeFromList must be true if animating off"); } TranslateAnimation slideOffAnim = new TranslateAnimation(0, 0, 0, -mItemHeight); slideOffAnim.setDuration(Constant.BUBBLE_FLOW_ANIM_TIME); slideOffAnim.setFillAfter(true); slideOffAnim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mContent.removeView(view); // Cancel the current animation on the views so the offset no longer applies for (int i = 0; i < mViews.size(); i++) { View view = mViews.get(i); Animation viewAnimation = view.getAnimation(); if (viewAnimation != null) { viewAnimation.cancel(); view.setAnimation(null); } } updatePositions(); updateScales(getScrollX()); mSlideOffAnimationPlaying = false; if (onRemovedListener != null) { onRemovedListener.onRemoved(view); } } @Override public void onAnimationRepeat(Animation animation) { } }); invalidate(); // This fixes #284 - it's a hack, but it will do for now. view.startAnimation(slideOffAnim); mSlideOffAnimationPlaying = true; mViews.remove(view); int viewsSize = mViews.size(); if (index < viewsSize) { for (int i = index; i < viewsSize; i++) { final View viewToShift = mViews.get(i); TranslateAnimationEx slideAnim = new TranslateAnimationEx(0, -mItemWidth, 0, 0, new TranslateAnimationEx.TransformationListener() { @Override public void onApplyTransform(float interpolatedTime, Transformation t, float dx, float dy) { float centerX = getScrollX() + (mWidth / 2) - (mItemWidth / 2); updateScaleForView(viewToShift, centerX, viewToShift.getX() + dx); } }); slideAnim.setDuration(Constant.BUBBLE_FLOW_ANIM_TIME); slideAnim.setFillAfter(true); viewToShift.startAnimation(slideAnim); } } else if (viewsSize > 0) { for (int i = 0; i < index; i++) { final View viewToShift = mViews.get(i); TranslateAnimationEx slideAnim = new TranslateAnimationEx(0, mItemWidth, 0, 0, new TranslateAnimationEx.TransformationListener() { @Override public void onApplyTransform(float interpolatedTime, Transformation t, float dx, float dy) { float centerX = getScrollX() + (mWidth / 2) - (mItemWidth / 2); updateScaleForView(viewToShift, centerX, viewToShift.getX() + dx); } }); slideAnim.setDuration(Constant.BUBBLE_FLOW_ANIM_TIME); slideAnim.setFillAfter(true); viewToShift.startAnimation(slideAnim); } } } else { mContent.removeView(view); if (removeFromList) { mViews.remove(view); updatePositions(); updateScales(getScrollX()); mContent.invalidate(); } if (onRemovedListener != null) { onRemovedListener.onRemoved(view); } } }
From source file:com.spoiledmilk.ibikecph.map.MapActivity.java
private void translate(float deltaX, final boolean finalAnim) { if (leftMenu != null && leftMenu.getView() != null) { newX = posX + deltaX;/*from w w w.j av a 2s . c o m*/ if (slidden) { if (newX < -maxSlide) newX = -maxSlide; else if (newX > 0) newX = 0; } else { if (newX < 0) newX = 0; else if (newX > maxSlide) newX = maxSlide; } if (((int) newX) <= 0) { mapDisabledView.setVisibility(View.GONE); } final boolean newSlidden = slidden ? newX > -SLIDE_THRESHOLD : newX > SLIDE_THRESHOLD; if (finalAnim) { newX = (slidden == newSlidden) ? 0 : (slidden ? -maxSlide : maxSlide); } if (animation != null && animation.isInitialized()) { parentContainer.clearAnimation(); animation.cancel(); leftMenu.getView().invalidate(); } LOG.d("translate animation from posX " + posX + " to " + newX); animation = new TranslateAnimation(posX, newX, 0, 0); animation.setDuration(finalAnim ? 100 : 0); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (!finalAnim) { animation.setFillEnabled(true); animation.setFillAfter(true); } else { parentContainer.clearAnimation(); if (slidden == newSlidden) { if (!slidden) { leftContainer.setVisibility(View.GONE); mapDisabledView.setVisibility(View.GONE); leftMenu.getView().invalidate(); } else { mapDisabledView.setVisibility(View.VISIBLE); leftMenu.getView().invalidate(); } return; } slidden = newSlidden; int leftmargin = slidden ? maxSlide : 0; int rightMargin = slidden ? 0 : maxSlide; RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) parentContainer .getLayoutParams(); lp.setMargins(leftmargin, lp.topMargin, rightMargin, lp.bottomMargin); parentContainer.setLayoutParams(lp); if (leftmargin == 0) { leftContainer.setVisibility(View.GONE); mapDisabledView.setVisibility(View.GONE); leftMenu.getView().invalidate(); } posX = 0; Fragment fr = getSupportFragmentManager().findFragmentById(R.id.leftContainer); if (fr != null && fr instanceof EditFavoriteFragment) { ((EditFavoriteFragment) fr).hideKeyboard(); } else if (fr != null && fr instanceof AddFavoriteFragment) { ((AddFavoriteFragment) fr).hideKeyboard(); } } } }); posX = newX; parentContainer.startAnimation(animation); } }
From source file:com.android.incallui.CallCardFragment.java
private void changeCallStateLabel(CharSequence callStateLabel) { Log.v(this, "changeCallStateLabel : label = " + callStateLabel); if (!TextUtils.isEmpty(callStateLabel)) { mCallStateLabel.setText(callStateLabel); mCallStateLabel.setAlpha(1);//from www . j av a 2s . com mCallStateLabel.setVisibility(View.VISIBLE); } else { Animation callStateLabelAnimation = mCallStateLabel.getAnimation(); if (callStateLabelAnimation != null) { callStateLabelAnimation.cancel(); } mCallStateLabel.setText(null); mCallStateLabel.setAlpha(0); mCallStateLabel.setVisibility(View.GONE); } }
From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationActivity.java
void translate(float deltaX, final boolean finalAnim) { // mapFragment.mapView.setEnabled(false); float newX = posX + deltaX; if (slidden) { if (newX < -maxSlide) newX = -maxSlide;//w ww . j av a2 s. com else if (newX > 0) newX = 0; } else { if (newX < 0) newX = 0; else if (newX > maxSlide) newX = maxSlide; } if (((int) newX) <= 0) { mapDisabledView.setVisibility(View.GONE); } final boolean newSlidden = slidden ? newX > -SLIDE_THRESHOLD : newX > SLIDE_THRESHOLD; if (finalAnim) { newX = (slidden == newSlidden) ? 0 : (slidden ? -maxSlide : maxSlide); } if (animation != null && animation.isInitialized()) { animation.cancel(); parentContainer.clearAnimation(); leftContainer.invalidate(); } animation = new TranslateAnimation(posX, newX, 0, 0); animation.setDuration(finalAnim ? 100 : 0); animation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (!finalAnim) { animation.setFillEnabled(true); animation.setFillAfter(true); } else { parentContainer.clearAnimation(); if (slidden == newSlidden) { if (!slidden) { leftContainer.setVisibility(View.GONE); mapDisabledView.setVisibility(View.GONE); // mapFragment.mapView.setEnabled(true); // mapFragment.mapView.invalidate(); leftContainer.invalidate(); } else { leftContainer.setVisibility(View.VISIBLE); mapDisabledView.setVisibility(View.VISIBLE); leftContainer.invalidate(); } return; } slidden = newSlidden; int leftmargin = slidden ? maxSlide : 0; int rightMargin = slidden ? 0 : maxSlide; RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) parentContainer .getLayoutParams(); lp.setMargins(leftmargin, lp.topMargin, rightMargin, lp.bottomMargin); parentContainer.setLayoutParams(lp); if (leftmargin == 0) { leftContainer.setVisibility(View.GONE); mapDisabledView.setVisibility(View.GONE); // mapFragment.mapView.setEnabled(true); // mapFragment.mapView.invalidate(); leftContainer.invalidate(); } posX = 0; } } }); posX = newX; parentContainer.startAnimation(animation); }
From source file:org.appcelerator.titanium.view.TiUIView.java
/** * Animates the view if there are pending animations. */// www.ja va 2s . com public void animate() { if (nativeView == null) { return; } // Pre-honeycomb, if one animation clobbers another you get a problem whereby the background of the // animated view's parent (or the grandparent) bleeds through. It seems to improve if you cancel and clear // the older animation. So here we cancel and clear, then re-queue the desired animation. if (Build.VERSION.SDK_INT < TiC.API_LEVEL_HONEYCOMB) { Animation currentAnimation = nativeView.getAnimation(); if (currentAnimation != null && currentAnimation.hasStarted() && !currentAnimation.hasEnded()) { // Cancel existing animation and // re-queue desired animation. currentAnimation.cancel(); nativeView.clearAnimation(); proxy.handlePendingAnimation(true); return; } } TiAnimationBuilder builder = proxy.getPendingAnimation(); if (builder == null) { return; } proxy.clearAnimation(builder); AnimationSet as = builder.render(proxy, nativeView); // If a view is "visible" but not currently seen (such as because it's covered or // its position is currently set to be fully outside its parent's region), // then Android might not animate it immediately because by default it animates // "on first frame" and apparently "first frame" won't happen right away if the // view has no visible rectangle on screen. In that case invalidate its parent, which will // kick off the pending animation. boolean invalidateParent = false; ViewParent viewParent = nativeView.getParent(); if (this.visibility == View.VISIBLE && viewParent instanceof View) { int width = nativeView.getWidth(); int height = nativeView.getHeight(); if (width == 0 || height == 0) { // Could be animating from nothing to something invalidateParent = true; } else { Rect r = new Rect(0, 0, width, height); Point p = new Point(0, 0); invalidateParent = !(viewParent.getChildVisibleRect(nativeView, r, p)); } } Log.d(TAG, "starting animation: " + as, Log.DEBUG_MODE); nativeView.startAnimation(as); if (invalidateParent) { ((View) viewParent).postInvalidate(); } }