List of usage examples for android.view.animation TranslateAnimation TranslateAnimation
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
From source file:Main.java
public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, float cycles, long durationMillis, final boolean isBanClick) { TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); translateAnimation.setDuration(durationMillis); if (cycles > 0.0) { translateAnimation.setInterpolator(new CycleInterpolator(cycles)); }/*from w ww . j a va 2 s.co m*/ translateAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { if (isBanClick) { view.setClickable(false); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (isBanClick) { view.setClickable(true); } } }); view.startAnimation(translateAnimation); }
From source file:net.sarangnamu.common.ui.widget.drawerlayout.ContentSlidingDrawerListener.java
@Override public void onDrawerSlide(View drawerView, float slideOffset) { // @see http://stackoverflow.com/questions/20057084/how-to-move-main-content-with-drawer-layout-left-side float moveFactor = (getListView().getWidth() * slideOffset); TranslateAnimation anim = new TranslateAnimation(lastTranslate, moveFactor, 0.0f, 0.0f); anim.setDuration(0);/* w w w. java 2 s . c o m*/ anim.setFillAfter(true); getContentFrame().startAnimation(anim); lastTranslate = moveFactor; }
From source file:com.devbrackets.android.exomedia.ui.animation.TopViewHideShowAnimation.java
public TopViewHideShowAnimation(View view, boolean toVisible, long duration) { super(false); this.toVisible = toVisible; this.animationView = view; //Creates the Alpha animation for the transition float startAlpha = toVisible ? 0 : 1; float endAlpha = toVisible ? 1 : 0; AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha); alphaAnimation.setDuration(duration); //Creates the Translate animation for the transition int startY = toVisible ? -view.getHeight() : 0; int endY = toVisible ? 0 : -view.getHeight(); TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY); translateAnimation//from ww w .j a v a2s .com .setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator()); translateAnimation.setDuration(duration); //Adds the animations to the set addAnimation(alphaAnimation); addAnimation(translateAnimation); setAnimationListener(new Listener()); }
From source file:com.enadein.carlogbook.db.CommonUtils.java
public static void runAnimation(int mlastPos, int pos, View view, float size) { if (UnitFacade.ANIM_LIST_ON) { float initialTranslation = (mlastPos <= pos) ? size : -size; Animation animationY = new TranslateAnimation(0, 0, initialTranslation, 0); animationY.setDuration(400);//from w w w. ja va 2s. com view.startAnimation(animationY); animationY = null; } }
From source file:com.devbrackets.android.exomedia.ui.animation.BottomViewHideShowAnimation.java
public BottomViewHideShowAnimation(View view, boolean toVisible, long duration) { super(false); this.toVisible = toVisible; this.animationView = view; //Creates the Alpha animation for the transition float startAlpha = toVisible ? 0 : 1; float endAlpha = toVisible ? 1 : 0; AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha); alphaAnimation.setDuration(duration); //Creates the Translate animation for the transition int startY = toVisible ? getHideShowDelta(view) : 0; int endY = toVisible ? 0 : getHideShowDelta(view); TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, startY, endY); translateAnimation/*from ww w.j a v a2s. c om*/ .setInterpolator(toVisible ? new LinearOutSlowInInterpolator() : new FastOutLinearInInterpolator()); translateAnimation.setDuration(duration); //Adds the animations to the set addAnimation(alphaAnimation); addAnimation(translateAnimation); setAnimationListener(new Listener()); }
From source file:com.dbeginc.dbweather.utils.animations.widgets.RainFallView.java
@Override protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { super.onSizeChanged(width, height, oldWidth, oldHeight); SecureRandom random = new SecureRandom(); Interpolator interpolator = new LinearInterpolator(); mRainFlakeCount = Math.max(width, height) / 20; coords = new int[mRainFlakeCount][]; drawables.clear();/*from w w w .j av a2 s. c o m*/ for (int i = 0; i < mRainFlakeCount; i++) { Animation animation = new TranslateAnimation(0, height / 10 - random.nextInt(height / 5), 0, height + 30); animation.setDuration(10 * height + random.nextInt(5 * height)); animation.setRepeatCount(-1); animation.initialize(10, 10, 10, 10); animation.setInterpolator(interpolator); coords[i] = new int[] { random.nextInt(width - 30), -30 }; drawables.add(new AnimateDrawable(mRainDrop, animation)); animation.setStartOffset(random.nextInt(20 * height)); animation.startNow(); int y; y = random.nextInt(2); if (y == 0) { drawables.add(new AnimateDrawable(mRainDrop, animation)); } else { drawables.add(new AnimateDrawable(mRainDrop)); } } }
From source file:com.dbeginc.dbweather.utils.animations.widgets.SnowFallView.java
@Override protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { super.onSizeChanged(width, height, oldWidth, oldHeight); Random random = new SecureRandom(); Interpolator interpolator = new LinearInterpolator(); snow_flake_count = Math.max(width, height) / 20; coords = new int[snow_flake_count][]; drawables.clear();// w w w . j a v a 2s. c om for (int i = 0; i < snow_flake_count; i++) { Animation animation = new TranslateAnimation(0, height / 10 - random.nextInt(height / 5), 0, height + 30); animation.setDuration(10 * height + random.nextInt(5 * height)); animation.setRepeatCount(-1); animation.initialize(10, 10, 10, 10); animation.setInterpolator(interpolator); coords[i] = new int[] { random.nextInt(width - 30), -30 }; drawables.add(new AnimateDrawable(snow_flake, animation)); animation.setStartOffset(random.nextInt(20 * height)); animation.startNow(); int y; y = random.nextInt(2); if (y == 0) { drawables.add(new AnimateDrawable(snow_flake, animation)); } else { drawables.add(new AnimateDrawable(snow_flake)); } } }
From source file:com.spoiledmilk.ibikecph.controls.SortableListView.java
@Override public boolean onTouchEvent(MotionEvent event) { mDetector.onTouchEvent(event);// w ww . ja v a2 s . com if ((getAdapter() != null && !(((FavoritesAdapter) getAdapter()).isEditMode)) || getAdapter() == null) { LOG.d("sortable list view super.onTouch"); return super.onTouchEvent(event); } this.adapter = (FavoritesAdapter) getAdapter(); if (event.getAction() == MotionEvent.ACTION_DOWN) { lastDistanceY = 0; views = new ArrayList<ViewData>(); for (int i = 0; i < getAdapter().getCount(); i++) { views.add(new ViewData(getChildAt(i), new TranslateAnimation(0, 0, 0, 0))); } posY = 0; movY = 0; touchY = event.getY(); View temp = getChildAt(0); temp.measure(0, 0); viewHeight = temp.getMeasuredHeight(); viewIndex = (int) (event.getY() / temp.getMeasuredHeight()) + fixedPositionOffset; indexToReorder = viewIndex; if (viewIndex < 0 || viewIndex > views.size() - 1) { mDetector.onTouchEvent(event); return true; } view = getChildAt(viewIndex); // - firstVisibleItem if (event.getX() < Util.dp2px(5) || event.getX() > Util.dp2px(85)) { // draging is enabled only when touching the left part of the view isDragStarted = false; } else { isDragStarted = true; } } if (view == null) { view = getChildAt(0); viewIndex = 0; } if (isDragStarted) { switch (event.getAction()) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: adapter.notifyDataSetChanged(); view.clearAnimation(); translate(view, 0, true); isDragStarted = false; if (adapter.getCount() > 1) adapter.reorder(0, 0, true); Iterator<ViewData> it = views.iterator(); while (it.hasNext()) { it.next().animation.cancel(); } if (animation != null) animation.cancel(); break; case MotionEvent.ACTION_DOWN: moveCount = 0; touchY = event.getY(); break; case MotionEvent.ACTION_MOVE: float newTouchY = event.getY(); float delta = newTouchY - touchY; indexToAnimate = (int) (event.getY() / viewHeight) + fixedPositionOffset; try { if (indexToReorder != indexToAnimate) { if (indexToAnimate >= 0 && indexToAnimate < adapter.getCount()) { int newY = delta > 0 ? views.get(indexToAnimate).lastY - viewHeight : views.get(indexToAnimate).lastY + viewHeight; ViewData animateView = views.get(indexToAnimate); if (animateView.animation != null && animateView.animation.isInitialized()) animateView.animation.cancel(); animateView.animation = new TranslateAnimation(0, 0, animateView.lastY, newY); animateView.lastY = newY; animateView.animation.setFillAfter(true); animateView.animation.setFillBefore(true); animateView.animation.setDuration(500); adapter.reorder(indexToAnimate + firstVisibleItem, indexToReorder + firstVisibleItem, false); animateView.view.clearAnimation(); animateView.view.startAnimation(animateView.animation); ViewData temp = animateView; views.set(indexToAnimate, views.get(indexToReorder)); views.set(indexToReorder, temp); indexToReorder = indexToAnimate; } } } catch (Exception e) { e.getLocalizedMessage(); } translate(view, delta, false); touchY = newTouchY; break; } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { final float newY = event.getY(); if ((movY == 0 && Math.abs(newY - touchY) > viewHeight) || Math.abs(newY - movY) > viewHeight) { movY = newY; } } return true; }
From source file:me.xiaopan.android.examples.activity.custom.SlideTabHostActivity.java
@Override public void onInitListener(Bundle savedInstanceState) { for (final Tab tab : tabList) { tab.getTitle().setOnClickListener(new OnClickListener() { @Override/*from w w w. java 2s . c o m*/ public void onClick(View v) { viewPager.setCurrentItem(Integer.valueOf(String.valueOf(tab.getIndex()))); } }); } viewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { //?tab?tab Tab lastTab = tabList.get(lastTabIndex); Tab currentTab = tabList.get(arg0); //??tab?tab lastTab.getTitle().setSelected(false); currentTab.getTitle().setSelected(true); //? TranslateAnimation translateAnimation = new TranslateAnimation(lastTab.getSlideBlock().getLeft(), currentTab.getSlideBlock().getLeft(), 0, 0); translateAnimation.setDuration(200); translateAnimation.setFillAfter(true); slideBlock.startAnimation(translateAnimation); //tab lastTabIndex = arg0; } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); }
From source file:com.flan.stock.view.TouTiaoPagerView.java
/** * ? ?/*from w w w. j a v a2 s . c o m*/ * @param position */ private void setCurrentTab(int position) { Animation animation = null; animation = new TranslateAnimation(tabImgWidth * currentTab, tabImgWidth * position, 0, 0); animation.setFillAfter(true);//True:??? animation.setDuration(300); //? img_tab.startAnimation(animation); currentTab = position; }