List of usage examples for android.view.animation TranslateAnimation setFillBefore
public void setFillBefore(boolean fillBefore)
From source file:Main.java
public static void translateY(final View view, float fromY, float toY, long duration) { if (Build.VERSION.SDK_INT >= 12) { if (duration == 0) view.setTranslationY(toY);//from w w w .j av a2s .com else view.animate().translationY(toY).setDuration(duration).start(); } else { TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY); translate.setDuration(duration); translate.setFillEnabled(true); translate.setFillBefore(true); translate.setFillAfter(true); addAnimation(view, translate); } }
From source file:com.juick.android.ThreadFragment.java
private void resetMainMenuButton(boolean animate) { if (navMenu != null) { TranslateAnimation immediate = new TranslateAnimation(Animation.ABSOLUTE, animate ? initNavMenuTranslationX + 100 : initNavMenuTranslationX, Animation.ABSOLUTE, initNavMenuTranslationX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); immediate.setDuration(500);/* w w w. j av a2s .c om*/ immediate.setFillEnabled(true); immediate.setFillBefore(true); immediate.setFillAfter(true); navMenu.startAnimation(immediate); } //navMenu.startAnimation(immediate); }
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 w w .j a v a2 s . c om 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.juick.android.MessagesFragment.java
public void scrollToX(int scrollX, long duration) { currentScrollX = scrollX;// w w w. j a va 2s . 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); }