List of usage examples for android.view View getTranslationX
@ViewDebug.ExportedProperty(category = "drawing") public float getTranslationX()
From source file:com.hippo.drawerlayout.DrawerLayout.java
public static boolean isViewUnder(@Nullable View view, int x, int y) { if (view == null) { return false; } else {//w w w . j av a 2 s. co m float translationX = 0.0f; float translationY = 0.0f; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { translationX = view.getTranslationX(); translationY = view.getTranslationY(); } return x >= view.getLeft() + translationX && x < view.getRight() + translationX && y >= view.getTop() + translationY && y < view.getBottom() + translationY; } }
From source file:com.vaguehope.onosendai.widget.SidebarLayout.java
protected void animateSidebar(final boolean gotoOpen) { final View host = getHostView(); if (host.getAnimation() != null) return;/*from ww w .j a v a2 s. co m*/ final float deltaX; final Animation animation; if (gotoOpen) { deltaX = host.getTranslationX() > 0 ? -host.getTranslationX() : -this.sidebarWidth; animation = new TranslateAnimation(0, deltaX, 0, 0); animation.setAnimationListener(this.openListener); } else { deltaX = this.sidebarWidth - host.getTranslationX(); animation = new TranslateAnimation(0, deltaX, 0, 0); animation.setAnimationListener(this.closeListener); } animation.setDuration((long) (SLIDE_DURATION * (Math.abs(deltaX) / this.sidebarWidth))); animation.setFillAfter(true); animation.setFillEnabled(true); host.startAnimation(animation); }
From source file:com.mad.splitlist.util.DividerItemDecoration.java
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { final int offset = (int) (mPaint.getStrokeWidth() / DIVIDE_OFFSET); for (int i = 0; i < parent.getChildCount(); i++) { final View view = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); final int position = params.getViewAdapterPosition(); // Draw separator using paint. if (position < state.getItemCount()) { // apply alpha to support animations mPaint.setAlpha((int) (view.getAlpha() * mAlpha)); float positionY = view.getBottom() + offset + view.getTranslationY(); // do the drawing c.drawLine(view.getLeft() + view.getTranslationX(), positionY, view.getRight() + view.getTranslationX(), positionY, mPaint); }/*from ww w.j a va 2 s .co m*/ } }
From source file:com.appsimobile.appsii.Appsi.java
float updateDimColor(View scrollView, boolean left) { if (scrollView != null) { int mTargetWidth = scrollView.getWidth(); float factor; int scroll = (int) -scrollView.getTranslationX(); float openedPercentage; if (left) { scroll = (int) (scroll + (0 * getResources().getDisplayMetrics().density)); factor = scroll / (float) mTargetWidth; openedPercentage = 1 - factor; } else {/*from w w w . jav a 2s .c om*/ scroll = (int) (scroll - (0 * getResources().getDisplayMetrics().density)); factor = (mTargetWidth - scroll) / (float) mTargetWidth; openedPercentage = 1 - (factor - 1); } mPopupLayer.setDimLayerAlpha(1); return openedPercentage; } return 0; }
From source file:com.comcast.freeflow.core.FreeFlowContainer.java
/** * Returns the actual frame for a view as its on stage. The FreeFlowItem's * frame object always represents the position it wants to be in but actual * frame may be different based on animation etc. * /*from w w w .j av a 2 s. com*/ * @param freeflowItem * The freeflowItem to get the <code>Frame</code> for * @return The Frame for the freeflowItem or null if that view doesn't exist */ public Rect getActualFrame(final FreeFlowItem freeflowItem) { View v = freeflowItem.view; if (v == null) { return null; } Rect of = new Rect(); of.left = (int) (v.getLeft() + v.getTranslationX()); of.top = (int) (v.getTop() + v.getTranslationY()); of.right = (int) (v.getRight() + v.getTranslationX()); of.bottom = (int) (v.getBottom() + v.getTranslationY()); return of; }
From source file:info.bartowski.easteregg.LLand.java
private void step(long t_ms, long dt_ms) { t = t_ms / 1000f; // seconds dt = dt_ms / 1000f;//www . j a v a 2 s .c o m if (DEBUG) { t *= DEBUG_SPEED_MULTIPLIER; dt *= DEBUG_SPEED_MULTIPLIER; } // 1. Move all objects and update bounds final int N = getChildCount(); int i = 0; for (; i < N; i++) { final View v = getChildAt(i); if (v instanceof GameView) { ((GameView) v).step(t_ms, dt_ms, t, dt); } } // 2. Check for altitude if (mPlaying && mDroid.below(mHeight)) { if (DEBUG_IDDQD) { poke(); } else { L("player hit the floor"); stop(); } } // 3. Check for obstacles boolean passedBarrier = false; for (int j = mObstaclesInPlay.size(); j-- > 0;) { final Obstacle ob = mObstaclesInPlay.get(j); if (mPlaying && ob.intersects(mDroid) && !DEBUG_IDDQD) { L("player hit an obstacle"); stop(); } else if (ob.cleared(mDroid)) { if (ob instanceof Stem) passedBarrier = true; mObstaclesInPlay.remove(j); } } if (mPlaying && passedBarrier) { addScore(1); } // 4. Handle edge of screen // Walk backwards to make sure removal is safe while (i-- > 0) { final View v = getChildAt(i); if (v instanceof Obstacle) { if (v.getTranslationX() + v.getWidth() < 0) { removeViewAt(i); } } else if (v instanceof Scenery) { final Scenery s = (Scenery) v; if (v.getTranslationX() + s.w < 0) { v.setTranslationX(getWidth()); } } } // 3. Time for more obstacles! if (mPlaying && (t - mLastPipeTime) > PARAMS.OBSTACLE_PERIOD) { mLastPipeTime = t; final int obstacley = (int) (Math.random() * (mHeight - 2 * PARAMS.OBSTACLE_MIN - PARAMS.OBSTACLE_GAP)) + PARAMS.OBSTACLE_MIN; final int inset = (PARAMS.OBSTACLE_WIDTH - PARAMS.OBSTACLE_STEM_WIDTH) / 2; final int yinset = PARAMS.OBSTACLE_WIDTH / 2; final int d1 = irand(0, 250); final Obstacle s1 = new Stem(getContext(), obstacley - yinset, false); addView(s1, new LayoutParams(PARAMS.OBSTACLE_STEM_WIDTH, (int) s1.h, Gravity.TOP | Gravity.LEFT)); s1.setTranslationX(mWidth + inset); s1.setTranslationY(-s1.h - yinset); ViewCompat.setTranslationZ(s1, PARAMS.OBSTACLE_Z * 0.75f); s1.animate().translationY(0).setStartDelay(d1).setDuration(250); mObstaclesInPlay.add(s1); final Obstacle p1 = new Pop(getContext(), PARAMS.OBSTACLE_WIDTH); addView(p1, new LayoutParams(PARAMS.OBSTACLE_WIDTH, PARAMS.OBSTACLE_WIDTH, Gravity.TOP | Gravity.LEFT)); p1.setTranslationX(mWidth); p1.setTranslationY(-PARAMS.OBSTACLE_WIDTH); ViewCompat.setTranslationZ(p1, PARAMS.OBSTACLE_Z); p1.setScaleX(0.25f); p1.setScaleY(0.25f); p1.animate().translationY(s1.h - inset).scaleX(1f).scaleY(1f).setStartDelay(d1).setDuration(250); mObstaclesInPlay.add(p1); final int d2 = irand(0, 250); final Obstacle s2 = new Stem(getContext(), mHeight - obstacley - PARAMS.OBSTACLE_GAP - yinset, true); addView(s2, new LayoutParams(PARAMS.OBSTACLE_STEM_WIDTH, (int) s2.h, Gravity.TOP | Gravity.LEFT)); s2.setTranslationX(mWidth + inset); s2.setTranslationY(mHeight + yinset); ViewCompat.setTranslationZ(s2, PARAMS.OBSTACLE_Z * 0.75f); s2.animate().translationY(mHeight - s2.h).setStartDelay(d2).setDuration(400); mObstaclesInPlay.add(s2); final Obstacle p2 = new Pop(getContext(), PARAMS.OBSTACLE_WIDTH); addView(p2, new LayoutParams(PARAMS.OBSTACLE_WIDTH, PARAMS.OBSTACLE_WIDTH, Gravity.TOP | Gravity.LEFT)); p2.setTranslationX(mWidth); p2.setTranslationY(mHeight); ViewCompat.setTranslationZ(p2, PARAMS.OBSTACLE_Z); p2.setScaleX(0.25f); p2.setScaleY(0.25f); p2.animate().translationY(mHeight - s2.h - yinset).scaleX(1f).scaleY(1f).setStartDelay(d2) .setDuration(400); mObstaclesInPlay.add(p2); } if (DEBUG_DRAW) invalidate(); }
From source file:cc.flydev.launcher.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;//from ww w .j a va 2 s .c o m } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:saftyos.android.launcher3.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;/* w w w . j a v a 2s . c o m*/ } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:com.n2hsu.launcher.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to // actually be // called and we expect the animation to be a continuation of the fling, // we have/*from www. j ava 2 s.com*/ // to account for the time that has elapsed since the fling finished. // And since // we don't have a startDelay, we will always get call to update when we // call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime; } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:com.minoon.stackviewpagersample.StackViewPager.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false). * @param dx Delta scrolled in pixels/* w w w. j a v a 2 s .c om*/ * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; // [Changed] // final int scrollX = v.getScrollX(); final int scrollX = (int) v.getTranslationX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollHorizontally(v, -dx); }