List of usage examples for android.view.animation TranslateAnimation setDuration
public void setDuration(long durationMillis)
From source file:com.coco.draggablegridviewpager.DraggableGridViewPager.java
private void animateGap(int target) { for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i);//from w w w . jav a2 s. co m if (i == mLastDragged) { continue; } 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.adityarathi.muo.ui.activities.NowPlayingActivity.java
/** * Slides in the controls bar from the bottom along with a * slight rotation.// www. ja v a2 s. c o m */ private void animateInControlsBar() { android.view.animation.TranslateAnimation slideUp = new android.view.animation.TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 2.0f, Animation.RELATIVE_TO_SELF, 0.0f); slideUp.setDuration(300); slideUp.setInterpolator(new DecelerateInterpolator(2.0f)); slideUp.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mControlsLayoutHeaderParent.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mControlsLayoutHeaderParent.startAnimation(slideUp); }
From source file:com.juick.android.ThreadFragment.java
private void openNavigationMenu(float currentTranslation) { try {/*from w ww.j av a2s.c o m*/ navigationMenuShown = true; for (final FlyingItem item : flyingItems) { item.setVisibility(View.VISIBLE); item.ani = new TranslateAnimation(Animation.ABSOLUTE, 300, Animation.ABSOLUTE, item.designedX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, item.designedY); item.ani.setInterpolator(new OvershootInterpolator(2)); item.ani.setDuration(500); item.ani.setFillAfter(true); item.ani.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { // this code is very ugly because it's all android 2.3 animations. item.widget.getHitRect(item.originalHitRect); item.widget.clearAnimation(); item.widget.layout(item.originalHitRect.left + (int) item.widget.initialTranslationX, item.originalHitRect.top + (int) item.widget.initialTranslationY, item.originalHitRect.right + (int) item.widget.initialTranslationX, item.originalHitRect.bottom + (int) item.widget.initialTranslationY); item.widget.disableReposition = true; } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); item.widget.startAnimation(item.ani); } TranslateAnimation aniOut = new TranslateAnimation(Animation.ABSOLUTE, currentTranslation, Animation.ABSOLUTE, -1.2f * getActivity().getWindowManager().getDefaultDisplay().getWidth(), Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); aniOut.setInterpolator(new DecelerateInterpolator(1)); aniOut.setDuration(700); aniOut.setFillAfter(true); navMenu.startAnimation(aniOut); getListView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } catch (Throwable e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:com.android.hcframe.DraggableGridViewPager.java
private void animateGap(int target) { for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i);// w w w . j av a 2 s .c o m if (i == mLastDragged) { continue; } 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:com.juick.android.ThreadFragment.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public boolean onTouch(View view, MotionEvent event) { if (parent.onListTouchEvent(view, event)) return true; if (parent.isFinishing()) return true; if (mScaleDetector != null) { try {//from w ww . jav a2s . c o m mScaleDetector.onTouchEvent(event); } catch (Exception e) { // shit happens there inside } } try { MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); event.getPointerCoords(0, pc); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (navMenu != null && navMenu.getVisibility() == View.VISIBLE) { int[] listViewLocation = new int[2]; int[] imageLocation = new int[2]; getListView().getLocationOnScreen(listViewLocation); navMenu.getLocationOnScreen(imageLocation); imageLocation[0] += navMenu.initialTranslationX; float touchX = pc.x + listViewLocation[0] - imageLocation[0]; float touchY = pc.y + listViewLocation[1] - imageLocation[1]; System.out.println("TOUCH: ACTION_DOWN: x=" + pc.x + " y=" + pc.y); if (touchX > -20 && touchX < navMenu.getWidth() && touchY > 0 && touchY < navMenu.getHeight() * 1.5) { // extra Y pixels due to picture not balanced touchOriginX = pc.x; touchOriginY = pc.y; System.out.println("TOUCH: OK TOUCH NAVMENU"); return true; } } break; case MotionEvent.ACTION_UP: if (!ignoreMove && !isNavigationMenuShown()) resetMainMenuButton(false); if (touchOriginX > 0 || ignoreMove) { touchOriginX = -1; ignoreMove = false; return true; } break; case MotionEvent.ACTION_MOVE: if (ignoreMove || navMenu == null) return true; event.getPointerCoords(0, pc); double travelledDistance = Math .sqrt(Math.pow(touchOriginX - pc.x, 2) + Math.pow(touchOriginY - pc.y, 2)); boolean inZone = false; if (!isNavigationMenuShown()) { if (touchOriginX >= 0) { // detect angle where finger moves if (travelledDistance < 10) { // grace period inZone = true; } else { float dx = Math.abs(touchOriginX - pc.x); float dy = Math.abs(touchOriginY - pc.y); if (dx > dy) { // movement in 45 degree zone if (touchOriginX > pc.x) { // towards left inZone = true; double neededDistance = 1.5 / 2.54 * getResources().getDisplayMetrics().xdpi; if (travelledDistance > neededDistance) { // moved 1.5 centimeters System.out.println("TOUCH: OPEN MENU"); ignoreMove = true; openNavigationMenu(pc.x - touchOriginX + initNavMenuTranslationX); touchOriginX = -1; } } } else { System.out.println("TOUCH: LEAVING ZONE: dx=" + dx + " dy=" + dy); } } if (inZone && !ignoreMove) { TranslateAnimation immediate = new TranslateAnimation(Animation.ABSOLUTE, pc.x - touchOriginX + initNavMenuTranslationX, Animation.ABSOLUTE, pc.x - touchOriginX + initNavMenuTranslationX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); immediate.setDuration(5); immediate.setFillAfter(true); immediate.setFillBefore(true); immediate.setFillEnabled(true); navMenu.startAnimation(immediate); } } if (!inZone) { resetMainMenuButton(false); if (touchOriginX >= 0) { System.out.println("TOUCH: ACTION_MOVE: x=" + pc.x + " y=" + pc.y); System.out.println("TOUCH: LEFT ZONE"); touchOriginX = -1; } } if (inZone) { return true; } if (doOnClick != null || ignoreMove) { return true; } } break; } } catch (NoClassDefFoundError err) { // so be it. } return false; }
From source file:com.xander.panel.PanelController.java
private Animation createPanelAnimation(int animType) { int type = TranslateAnimation.RELATIVE_TO_SELF; TranslateAnimation an = null; if (ANIM_TYPE_SHOW == animType) { if (Gravity.TOP == mGravity) { an = new TranslateAnimation(type, 0, type, 0, type, -1, type, 0); } else if (Gravity.BOTTOM == mGravity) { an = new TranslateAnimation(type, 0, type, 0, type, 1, type, 0); }/* www. ja v a 2 s.c om*/ } else { if (Gravity.TOP == mGravity) { an = new TranslateAnimation(type, 0, type, 0, type, 0, type, -1); } else if (Gravity.BOTTOM == mGravity) { an = new TranslateAnimation(type, 0, type, 0, type, 0, type, 1); } } an.setDuration(DURATION_TRANSLATE); an.setFillAfter(true); return an; }
From source file:com.icloud.listenbook.base.view.DraggableGridViewPager.java
/** * /*w w w.ja v a2 s . c om*/ * */ private void animateGap(int target) { for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); // if (i == mLastDragged) { continue; } // ?? 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.juick.android.MessagesFragment.java
public void scrollToX(int scrollX, long duration) { currentScrollX = scrollX;// ww w. jav a 2 s .c o m final View frag = getActivity().findViewById(R.id.messagesfragment); TranslateAnimation ta = new TranslateAnimation(lastToXDelta != null ? lastToXDelta : 0, -scrollX, 0, 0); lastToXDelta = -scrollX; ta.setFillEnabled(true); ta.setDuration(duration); ta.setFillAfter(true); ta.setFillBefore(true); if (parent instanceof MainActivity) { final View navPanel = parent.findViewById(R.id.navigation_panel); navPanel.setVisibility(View.VISIBLE); } if (duration > 2) { ta.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { if (mScrollState == SCROLL_STATE_SETTLING) { setScrollState(SCROLL_STATE_IDLE); frag.clearAnimation(); } } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); } frag.startAnimation(ta); }
From source file:com.juick.android.MainActivity.java
public void openNavigationMenu(boolean animate) { if (isNavigationMenuShown()) return;//from w w w . j a v a 2 s. c o m navigationMenuShown = true; final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel); navigationPanel.setVisibility(View.VISIBLE); final View frag = (ViewGroup) findViewById(R.id.messagesfragment); if (animate) { AnimationSet set = new AnimationSet(true); TranslateAnimation translate = new TranslateAnimation(0, navigationPanel.getWidth(), 0, 0); translate.setFillAfter(false); translate.setFillEnabled(true); translate.setDuration(400); set.addAnimation(translate); set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { frag.clearAnimation(); layoutNavigationPane(); } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); frag.startAnimation(set); } else { layoutNavigationPane(); } }
From source file:com.juick.android.MainActivity.java
public void closeNavigationMenu(boolean animate, boolean immediate) { if (!isNavigationMenuShown()) return;// w w w . ja v a 2s . co m final ViewGroup navigationPanel = (ViewGroup) findViewById(R.id.navigation_panel); final View frag = findViewById(R.id.messagesfragment); final DragSortListView navigationList = (DragSortListView) findViewById(R.id.navigation_list); if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } if (animate) { final AnimationSet set = new AnimationSet(true); TranslateAnimation translate = new TranslateAnimation(0, -navigationPanel.getWidth(), 0, 0); translate.setFillAfter(false); translate.setFillEnabled(true); translate.setDuration(400); set.addAnimation(translate); set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { navigationMenuShown = false; frag.clearAnimation(); layoutNavigationPane(); //navigationPanel.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); handler.postDelayed(new Runnable() { @Override public void run() { frag.startAnimation(set); getActivity().findViewById(R.id.layout_container).invalidate(); } }, immediate ? 1 : 200); // to smooth the slide } else { navigationMenuShown = false; layoutNavigationPane(); } }