List of usage examples for android.view.animation TranslateAnimation TranslateAnimation
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
From source file:com.kasungunathilaka.sarigama.ui.HomeActivity.java
private void showMiniPlayer(boolean show) { if (show) {/*from w w w . j a va 2 s .com*/ TranslateAnimation animate = new TranslateAnimation(0, 0, flMiniPlayer.getHeight(), 0); animate.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); flMiniPlayer.startAnimation(animate); flMiniPlayer.setVisibility(View.VISIBLE); } else { TranslateAnimation animate = new TranslateAnimation(0, 0, 0, flMiniPlayer.getHeight()); animate.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); flMiniPlayer.startAnimation(animate); flMiniPlayer.setVisibility(View.GONE); } flMiniPlayer.setVisibility(show ? View.VISIBLE : View.GONE); }
From source file:org.digitalcampus.oppia.activity.OppiaMobileActivity.java
private void animateScanMediaMessage() { TranslateAnimation anim = new TranslateAnimation(0, 0, -200, 0); anim.setDuration(900);//from w w w . jav a2s . co m messageContainer.startAnimation(anim); messageContainer.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); ValueAnimator animator = ValueAnimator.ofInt(initialCourseListPadding, messageContainer.getMeasuredHeight()); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { //@Override public void onAnimationUpdate(ValueAnimator valueAnimator) { courseList.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0); courseList.setSelectionAfterHeaderView(); } }); animator.setStartDelay(200); animator.setDuration(700); animator.start(); }
From source file:org.noorganization.instalist.view.activity.MainShoppingListView.java
private void slideDrawer(float _MoveFactor) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mFrameLayout.setTranslationX(_MoveFactor); } else {//from w w w.j av a2 s . c om TranslateAnimation anim = new TranslateAnimation(mLastDrawerTranslate, _MoveFactor, 0.0f, 0.0f); anim.setDuration(0); anim.setFillAfter(true); mFrameLayout.startAnimation(anim); mLastDrawerTranslate = _MoveFactor; } }
From source file:sjizl.com.FileUploadTest.java
public void do_animation_top(LinearLayout left_button) { float px = dipToPixels(getBaseContext(), -30); Animation animation1 = new TranslateAnimation(0, 0, -50, 0); animation1.setDuration(1000);//from ww w . ja v a 2 s .co m animation1.setFillEnabled(true); animation1.setFillAfter(true); left_button.startAnimation(animation1); }
From source file:org.creativecommons.thelist.misc.MainActivity.java
public void showSnackbar() { SnackbarManager.show(/* ww w. j ava 2 s . c o m*/ //also includes duration: SHORT, LONG, INDEFINITE Snackbar.with(mContext).text("Item deleted") //text to display .actionColor(getResources().getColor(R.color.colorSecondary)) .actionLabel("undo".toUpperCase()).actionListener(new ActionClickListener() { @Override public void onActionClicked(Snackbar snackbar) { /*NOTE: item does not need to be re-added here because it is only removed when the snackbar is actually dismissed*/ //What happens when item is swiped offscreen mItemList.add(0, mLastDismissedItem); //re-add item to users list in DB mCurrentUser.addItemToUserList(mLastDismissedItem.getItemID()); mFeedAdapter.notifyDataSetChanged(); mLayoutManager.scrollToPosition(0); mFab.show(); } }) //action buttons listener .eventListener(new EventListener() { Interpolator interpolator = new MaterialInterpolator(); @Override public void onShow(Snackbar snackbar) { TranslateAnimation tsa = new TranslateAnimation(0, 0, 0, -snackbar.getHeight()); tsa.setInterpolator(interpolator); tsa.setFillAfter(true); tsa.setFillEnabled(true); tsa.setDuration(300); mFab.startAnimation(tsa); } @Override public void onShowByReplace(Snackbar snackbar) { } @Override public void onShown(Snackbar snackbar) { } @Override public void onDismiss(Snackbar snackbar) { TranslateAnimation tsa2 = new TranslateAnimation(0, 0, -snackbar.getHeight(), 0); tsa2.setInterpolator(interpolator); tsa2.setFillAfter(true); tsa2.setFillEnabled(true); tsa2.setStartOffset(100); tsa2.setDuration(300); mFab.startAnimation(tsa2); } @Override public void onDismissByReplace(Snackbar snackbar) { } @Override public void onDismissed(Snackbar snackbar) { //TODO: QA //If no more items if (mItemList.isEmpty()) { mEmptyView.setVisibility(View.VISIBLE); } //If fab is hidden (bug fix?) if (!mFab.isVisible()) { mFab.show(); } } }) //event listener , MainActivity.this); }
From source file:com.wenwen.chatuidemo.activity.NewFragment.java
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { AnimationSet _AnimationSet = new AnimationSet(true); TranslateAnimation _TranslateAnimation; if (checkedId == R.id.btn1) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo1), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100);//from w w w .j av a 2s.co m mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(1); mRadioButton1.setTextColor(Color.RED); } else if (checkedId == R.id.btn2) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo2), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(2); } else if (checkedId == R.id.btn3) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo3), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(3); } else if (checkedId == R.id.btn4) { _TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo4), 0f, 0f); _AnimationSet.addAnimation(_TranslateAnimation); _AnimationSet.setFillBefore(false); _AnimationSet.setFillAfter(true); _AnimationSet.setDuration(100); mImageView.startAnimation(_AnimationSet); mViewPager.setCurrentItem(4); } mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft(); DebugLog.i("zj", "getCurrentCheckedRadioLeft=" + getCurrentCheckedRadioLeft()); DebugLog.i("zj", "getDimension=" + getResources().getDimension(R.dimen.rdo2)); mHorizontalScrollView.smoothScrollTo( (int) mCurrentCheckedRadioLeft - (int) getResources().getDimension(R.dimen.rdo2), 0); }
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;/*w ww . ja va2 s.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:org.mozilla.gecko.home.BrowserSearch.java
private void setSuggestionsEnabled(final boolean enabled) { // Clicking the yes/no buttons quickly can cause the click events be // queued before the listeners are removed above, so it's possible // setSuggestionsEnabled() can be called twice. mSuggestionsOptInPrompt // can be null if this happens (bug 828480). if (mSuggestionsOptInPrompt == null) { return;// w w w. j a va2 s . co m } // Make suggestions appear immediately after the user opts in ThreadUtils.postToBackgroundThread(new Runnable() { @Override public void run() { SuggestClient client = mSuggestClient; if (client != null) { client.query(mSearchTerm); } } }); // Pref observer in gecko will also set prompted = true PrefsHelper.setPref("browser.search.suggest.enabled", enabled); TranslateAnimation slideAnimation = new TranslateAnimation(0, mSuggestionsOptInPrompt.getWidth(), 0, 0); slideAnimation.setDuration(ANIMATION_DURATION); slideAnimation.setInterpolator(new AccelerateInterpolator()); slideAnimation.setFillAfter(true); final View prompt = mSuggestionsOptInPrompt.findViewById(R.id.prompt); TranslateAnimation shrinkAnimation = new TranslateAnimation(0, 0, 0, -1 * mSuggestionsOptInPrompt.getHeight()); shrinkAnimation.setDuration(ANIMATION_DURATION); shrinkAnimation.setFillAfter(true); shrinkAnimation.setStartOffset(slideAnimation.getDuration()); shrinkAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation a) { // Increase the height of the view so a gap isn't shown during animation mView.getLayoutParams().height = mView.getHeight() + mSuggestionsOptInPrompt.getHeight(); mView.requestLayout(); } @Override public void onAnimationRepeat(Animation a) { } @Override public void onAnimationEnd(Animation a) { // Removing the view immediately results in a NPE in // dispatchDraw(), possibly because this callback executes // before drawing is finished. Posting this as a Runnable fixes // the issue. mView.post(new Runnable() { @Override public void run() { mView.removeView(mSuggestionsOptInPrompt); mList.clearAnimation(); mSuggestionsOptInPrompt = null; if (enabled) { // Reset the view height mView.getLayoutParams().height = LayoutParams.MATCH_PARENT; mSuggestionsEnabled = enabled; mAnimateSuggestions = true; mAdapter.notifyDataSetChanged(); filterSuggestions(); } } }); } }); prompt.startAnimation(slideAnimation); mSuggestionsOptInPrompt.startAnimation(shrinkAnimation); mList.startAnimation(shrinkAnimation); }
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;/*www .jav a 2s . co m*/ } 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); } }
From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java
void animateGroupListItemsInternal(Map<MediaRouter.RouteInfo, Rect> previousRouteBoundMap, Map<MediaRouter.RouteInfo, BitmapDrawable> previousRouteBitmapMap) { if (mGroupMemberRoutesAdded == null || mGroupMemberRoutesRemoved == null) { return;/*from w w w. j a va2s . c o m*/ } 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); OverlayListView.OverlayObject object = null; if (mGroupMemberRoutesRemoved.contains(route)) { object = new OverlayListView.OverlayObject(bitmap, bounds).setAlphaAnimation(1.0f, 0.0f) .setDuration(mGroupListFadeOutDurationMs).setInterpolator(mInterpolator); } else { int deltaY = groupSizeDelta * mVolumeGroupListItemHeight; object = new OverlayListView.OverlayObject(bitmap, bounds).setTranslateYAnimation(deltaY) .setDuration(mGroupListAnimationDurationMs).setInterpolator(mInterpolator) .setAnimationEndListener(new OverlayListView.OverlayObject.OnAnimationEndListener() { @Override public void onAnimationEnd() { mGroupMemberRoutesAnimatingWithBitmap.remove(route); mVolumeGroupAdapter.notifyDataSetChanged(); } }); mGroupMemberRoutesAnimatingWithBitmap.add(route); } mVolumeGroupList.addOverlayObject(object); } }