List of usage examples for android.view View startAnimation
public void startAnimation(Animation animation)
From source file:org.uguess.android.sysinfo.ApplicationManager.java
void hideButtons() { if (rootView == null) { return;/*from w w w.j a va 2 s . c o m*/ } View v = rootView.findViewById(R.id.app_footer); if (v.getVisibility() != View.GONE) { v.setVisibility(View.GONE); v.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.footer_disappear)); } }
From source file:com.coco.draggablegridviewpager.DraggableGridViewPager.java
private void animateGap(int target) { for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); if (i == mLastDragged) { continue; }/*from ww w .j a v a 2 s .c om*/ int newPos = i; if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) { newPos--; } else if (target < mLastDragged && i >= target && i < mLastDragged) { newPos++; } int oldPos = i; if (newPositions.get(i) != -1) { oldPos = newPositions.get(i); } if (oldPos == newPos) { continue; } // animate DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos); final Rect oldRect = getRectByPosition(oldPos); final Rect newRect = getRectByPosition(newPos); oldRect.offset(-v.getLeft(), -v.getTop()); newRect.offset(-v.getLeft(), -v.getTop()); TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top, newRect.top); translate.setDuration(ANIMATION_DURATION); translate.setFillEnabled(true); translate.setFillAfter(true); v.clearAnimation(); v.startAnimation(translate); newPositions.set(i, newPos); } }
From source file:com.arta.lib.widget.crouton.Manager.java
/** * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}. * * @param crouton//ww w. j av a2 s . co m * The {@link Crouton} that should be added. */ private void addCroutonToView(final Crouton crouton) { // don't add if it is already showing if (crouton.isShowing()) { return; } final View croutonView = crouton.getView(); if (null == croutonView.getParent()) { ViewGroup.LayoutParams params = croutonView.getLayoutParams(); if (null == params) { params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } // display Crouton in ViewGroup is it has been supplied if (null != crouton.getViewGroup()) { // TODO implement add to last position feature (need to align with how this will be requested for activity) if (crouton.getViewGroup() instanceof FrameLayout) { crouton.getViewGroup().addView(croutonView, params); } else { crouton.getViewGroup().addView(croutonView, 0, params); } } else { Activity activity = crouton.getActivity(); if (null == activity || activity.isFinishing()) { return; } handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity); activity.addContentView(croutonView, params); } } croutonView.requestLayout(); // This is needed so the animation can use the measured with/height ViewTreeObserver observer = croutonView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @TargetApi(16) public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } croutonView.startAnimation(crouton.getInAnimation()); announceForAccessibilityCompat(crouton.getActivity(), crouton.getText()); if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) { sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration()); } } }); } }
From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java
/*** * ?//from ww w. j av a2 s . com * **/ private void animateDragged() { if (mLastDragged >= 0) { final View v = getChildAt(mLastDragged); final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); r.inset(-r.width() / 20, -r.height() / 20); v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY)); v.layout(r.left, r.top, r.right, r.bottom); AnimationSet animSet = new AnimationSet(true); ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2); scale.setDuration(ANIMATION_DURATION); AlphaAnimation alpha = new AlphaAnimation(1, .5f); alpha.setDuration(ANIMATION_DURATION); animSet.addAnimation(scale); animSet.addAnimation(alpha); animSet.setFillEnabled(true); animSet.setFillAfter(true); v.clearAnimation(); v.startAnimation(animSet); } }
From source file:com.example.androidannotationtesttwo.widget.crouton.Manager.java
/** * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity} * ./*from w ww .j av a2 s. c om*/ * * @param crouton The {@link Crouton} that should be added. */ private void addCroutonToView(final Crouton crouton) { // don't add if it is already showing if (crouton.isShowing()) { return; } final View croutonView = crouton.getView(); if (null == croutonView.getParent()) { ViewGroup.LayoutParams params = croutonView.getLayoutParams(); if (null == params) { params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } // display Crouton in ViewGroup is it has been supplied if (null != crouton.getViewGroup()) { // TODO implement add to last position feature (need to align // with how this will be requested for activity) if (crouton.getViewGroup() instanceof FrameLayout) { crouton.getViewGroup().addView(croutonView, params); } else { crouton.getViewGroup().addView(croutonView, 0, params); } } else { Activity activity = crouton.getActivity(); if (null == activity || activity.isFinishing()) { return; } handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity); activity.addContentView(croutonView, params); } } croutonView.requestLayout(); // This is needed so the animation can use // the measured with/height ViewTreeObserver observer = croutonView.getViewTreeObserver(); if (null != observer) { observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override @TargetApi(16) public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } croutonView.startAnimation(crouton.getInAnimation()); announceForAccessibilityCompat(crouton.getActivity(), crouton.getText()); if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) { sendMessageDelayed(crouton, Messages.REMOVE_CROUTON, crouton.getConfiguration().durationInMilliseconds + crouton.getInAnimation().getDuration()); } } }); } }
From source file:org.y20k.transistor.CollectionAdapter.java
@Override public void onBindViewHolder(final CollectionAdapterViewHolder holder, final int position) { Log.v(LOG_TAG + "debugCollectionView", "start onBindViewHolder , position=" + String.valueOf(position)); // final int position --> Do not treat position as fixed; only use immediately and call holder.getAdapterPosition() to look it up later // get station from position final Station station = mStationList.get(position); if (mTwoPane && mStationIDSelected == position) { holder.getListItemLayout().setSelected(true); } else {/* w w w . j a va 2 s.c o m*/ holder.getListItemLayout().setSelected(false); } String TitleOfBox = getTitleOfBox(station, position); if (TitleOfBox.isEmpty()) { holder.getLayoutCategoryView().setVisibility(View.GONE); } else { holder.getLayoutCategoryView().setVisibility(View.VISIBLE); holder.getTxtCategoryView().setText(TitleOfBox); } // set station image File stationImageFile = station.getStationImage(mActivity); if (stationImageFile != null && stationImageFile.exists()) { holder.getStationImageView().setImageURI(stationImageFile.toURI().toString());//.setImageBitmap(stationImageSmall); } else if (station.IMAGE_PATH != null && station.IMAGE_PATH != "") { holder.getStationImageView().setImageURI(station.IMAGE_PATH);//.setImageBitmap(stationImageSmall); } // set station Small image (to help cache image only if it's not already cached - this cache is Async) File stationSmallImageFile = station.getStationSmallImage(mActivity); stationSmallImageFile = null; //currently not needed // set station name holder.getStationNameView().setText(station.TITLE); holder.getRatingBarView().setRating(station.RATING); //change favorit button visibility ImageButton favView = holder.getFavoritButtonView(); changeVisibilityOfFavButton(favView, station.IS_FAVOURITE); favView.setTag(position); //on click favorit icon change the status then favView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // handle fav click int positoinHere = Integer.valueOf(v.getTag().toString()); Station stationHere = mStationList.get(positoinHere); animateFovoritVisual(mActivity, v, stationHere); } private void animateFovoritVisual(Context context, final View vFavButton, final Station stationHere) { Animation rotate; final int positionHere = Integer.valueOf(vFavButton.getTag().toString()); final int newStatus = (stationHere.IS_FAVOURITE == 0) ? 1 : 0; rotate = AnimationUtils.loadAnimation(context, R.anim.rotate_clockwise_slow); // attach listener for animation end rotate.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // send local broadcast Intent i = new Intent(); i.setAction(TransistorKeys.ACTION_COLLECTION_CHANGED); i.putExtra(TransistorKeys.EXTRA_COLLECTION_CHANGE, TransistorKeys.STATION_CHANGED_FAVORIT); i.putExtra(TransistorKeys.EXTRA_STATION_Position_ID, positionHere); i.putExtra(TransistorKeys.EXTRA_STATION, stationHere); i.putExtra(TransistorKeys.EXTRA_STATION_FAVORIT_VALUE, newStatus); LocalBroadcastManager.getInstance(mActivity.getApplication()).sendBroadcast(i); } @Override public void onAnimationRepeat(Animation animation) { } }); // start animation of button if (vFavButton != null) vFavButton.startAnimation(rotate); } }); //station description holder.getmStationDesciptionView().setText(station.DESCRIPTION); //shadow holder.getStationNameView().setShadowLayer(2, 1, 1, Color.BLACK); holder.getmStationDesciptionView().setShadowLayer(2, 1, 1, Color.BLACK); // set playback indicator - in phone view only FloatingActionButton fabPlayButton = holder.getFabPlayButton(); if (mPlayback && (station.getPlaybackState())) { if (SingletonProperties .getInstance().CurrentSelectedStation_Playback_Status == PlaybackStatus.LOADING) { holder.getPlaybackIndicator() .setBackgroundResource(R.drawable.ic_playback_indicator_small_loading_24dp); fabPlayButton.setImageResource(R.drawable.progress_loading); fabPlayButton.setTag(LOADING_STATUS); } else { holder.getPlaybackIndicator() .setBackgroundResource(R.drawable.ic_playback_indicator_small_started_24dp); fabPlayButton.setImageResource(R.drawable.smbl_stop); fabPlayButton.setTag(STOP_STATUS); } } else { //default fabPlayButton.setImageResource(R.drawable.smbl_play); fabPlayButton.setTag(PLAY_STATUS); } if (!mTwoPane && mPlayback && (station.getPlaybackState())) { // || getPositionOfCurrentPlayStation() == position holder.getPlaybackIndicator().setVisibility(View.VISIBLE); } else { holder.getPlaybackIndicator().setVisibility(View.GONE); } // attach three dots menu - in phone view only if (!mTwoPane) { holder.getStationMenuView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { StationContextMenu menu = new StationContextMenu(); menu.initialize(mActivity, view, station, position); menu.show(); } }); } else { holder.getStationMenuView().setVisibility(View.GONE); } fabPlayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mStationIDSelected = position; LogHelper.v(LOG_TAG, "Selected station (ID): " + mStationIDSelected); if (!mTwoPane) { // long click in phone mode handlePlayStopClick(position); } else { // long click in phone mode handlePlayStopClick(position); // click in tablet mode handleSingleClick(position, holder); notifyDataSetChanged(); } } }); // attach click listener holder.setClickListener(new CollectionAdapterViewHolder.ClickListener() { @Override public void onClick(View view, int pos, boolean isLongClick) { mStationIDSelected = pos; saveAppState(mActivity); LogHelper.v(LOG_TAG, "Selected station (ID): " + mStationIDSelected); if (isLongClick && !mTwoPane) { // long click in phone mode handlePlayStopClick(pos); } else if (!isLongClick && !mTwoPane) { // click in phone mode handleSingleClick(pos, holder); } else { // click in tablet mode handleSingleClick(pos, holder); notifyDataSetChanged(); //todo:tarek review why this line here } } }); }
From source file:com.android.hcframe.DraggableGridViewPager.java
private void animateGap(int target) { for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); if (i == mLastDragged) { continue; }// www . j a v a2 s . c o m int newPos = i; if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) { newPos--; } else if (target < mLastDragged && i >= target && i < mLastDragged) { newPos++; } int oldPos = i; if (newPositions.get(i) != -1) { oldPos = newPositions.get(i); } if (oldPos == newPos) { continue; } // animate HcLog.D("animateGap from=" + oldPos + ", to=" + newPos); final Rect oldRect = getRectByPosition(oldPos); final Rect newRect = getRectByPosition(newPos); oldRect.offset(-v.getLeft(), -v.getTop()); newRect.offset(-v.getLeft(), -v.getTop()); TranslateAnimation translate = new TranslateAnimation(oldRect.left, newRect.left, oldRect.top, newRect.top); translate.setDuration(ANIMATION_DURATION); translate.setFillEnabled(true); translate.setFillAfter(true); v.clearAnimation(); v.startAnimation(translate); newPositions.set(i, newPos); } }
From source file:org.telegram.ui.GalleryImageViewer.java
private void startViewAnimation(final View panel, boolean up) { Animation animation;/*from w ww . ja v a2 s. com*/ if (!up) { animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { panel.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation animation) { } }); animation.setDuration(400); } else { animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { panel.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); animation.setDuration(100); } panel.startAnimation(animation); }
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;/* www . j ava 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:android.support.v7.app.MediaRouteControllerDialog.java
private void animateGroupListItemsInternal(Map<MediaRouter.RouteInfo, Rect> previousRouteBoundMap, Map<MediaRouter.RouteInfo, BitmapDrawable> previousRouteBitmapMap) { if (mGroupMemberRoutesAdded == null || mGroupMemberRoutesRemoved == null) { return;//from w w w . java 2 s . com } int groupSizeDelta = mGroupMemberRoutesAdded.size() - mGroupMemberRoutesRemoved.size(); boolean listenerRegistered = false; Animation.AnimationListener listener = new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mVolumeGroupList.startAnimationAll(); mVolumeGroupList.postDelayed(mGroupListFadeInAnimation, mGroupListAnimationDurationMs); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }; // Animate visible items from previous positions to current positions except routes added // just before. Added routes will remain hidden until translate animation finishes. int first = mVolumeGroupList.getFirstVisiblePosition(); for (int i = 0; i < mVolumeGroupList.getChildCount(); ++i) { View view = mVolumeGroupList.getChildAt(i); int position = first + i; MediaRouter.RouteInfo route = mVolumeGroupAdapter.getItem(position); Rect previousBounds = previousRouteBoundMap.get(route); int currentTop = view.getTop(); int previousTop = previousBounds != null ? previousBounds.top : (currentTop + mVolumeGroupListItemHeight * groupSizeDelta); AnimationSet animSet = new AnimationSet(true); if (mGroupMemberRoutesAdded != null && mGroupMemberRoutesAdded.contains(route)) { previousTop = currentTop; Animation alphaAnim = new AlphaAnimation(0.0f, 0.0f); alphaAnim.setDuration(mGroupListFadeInDurationMs); animSet.addAnimation(alphaAnim); } Animation translationAnim = new TranslateAnimation(0, 0, previousTop - currentTop, 0); translationAnim.setDuration(mGroupListAnimationDurationMs); animSet.addAnimation(translationAnim); animSet.setFillAfter(true); animSet.setFillEnabled(true); animSet.setInterpolator(mInterpolator); if (!listenerRegistered) { listenerRegistered = true; animSet.setAnimationListener(listener); } view.clearAnimation(); view.startAnimation(animSet); previousRouteBoundMap.remove(route); previousRouteBitmapMap.remove(route); } // If a member route doesn't exist any longer, it can be either removed or moved out of the // ListView layout boundary. In this case, use the previously captured bitmaps for // animation. for (Map.Entry<MediaRouter.RouteInfo, BitmapDrawable> item : previousRouteBitmapMap.entrySet()) { final MediaRouter.RouteInfo route = item.getKey(); final BitmapDrawable bitmap = item.getValue(); final Rect bounds = previousRouteBoundMap.get(route); OverlayObject object = null; if (mGroupMemberRoutesRemoved.contains(route)) { object = new OverlayObject(bitmap, bounds).setAlphaAnimation(1.0f, 0.0f) .setDuration(mGroupListFadeOutDurationMs).setInterpolator(mInterpolator); } else { int deltaY = groupSizeDelta * mVolumeGroupListItemHeight; object = new OverlayObject(bitmap, bounds).setTranslateYAnimation(deltaY) .setDuration(mGroupListAnimationDurationMs).setInterpolator(mInterpolator) .setAnimationEndListener(new OverlayObject.OnAnimationEndListener() { @Override public void onAnimationEnd() { mGroupMemberRoutesAnimatingWithBitmap.remove(route); mVolumeGroupAdapter.notifyDataSetChanged(); } }); mGroupMemberRoutesAnimatingWithBitmap.add(route); } mVolumeGroupList.addOverlayObject(object); } }