List of usage examples for android.view View getTranslationX
@ViewDebug.ExportedProperty(category = "drawing") public float getTranslationX()
From source file:info.bartowski.easteregg.MLand.java
private void step(long t_ms, long dt_ms) { t = t_ms / 1000f; // seconds dt = dt_ms / 1000f;//from w ww.ja 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); } } if (mPlaying) { int livingPlayers = 0; for (i = 0; i < mPlayers.size(); i++) { final Player p = getPlayer(i); if (p.mAlive) { // 2. Check for altitude if (p.below(mHeight)) { if (DEBUG_IDDQD) { poke(i); unpoke(i); } else { L("player %d hit the floor", i); thump(i, 80); p.die(); } } // 3. Check for obstacles int maxPassedStem = 0; for (int j = mObstaclesInPlay.size(); j-- > 0;) { final Obstacle ob = mObstaclesInPlay.get(j); if (ob.intersects(p) && !DEBUG_IDDQD) { L("player hit an obstacle"); thump(i, 80); p.die(); } else if (ob.cleared(p)) { if (ob instanceof Stem) { maxPassedStem = Math.max(maxPassedStem, ((Stem) ob).id); } } } if (maxPassedStem > p.mScore) { p.addScore(1); } } if (p.mAlive) livingPlayers++; } if (livingPlayers == 0) { stop(); mTaps = 0; final int playerCount = mPlayers.size(); for (int pi = 0; pi < playerCount; pi++) { final Player p = mPlayers.get(pi); } } } // 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); mObstaclesInPlay.remove(v); } } 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; mCurrentPipeId++; final int obstacley = (int) (frand() * (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 (SHOW_TOUCHES || DEBUG_DRAW) invalidate(); }
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
/** * Add animators for animating out stale views * @param animationOutMode The animation mode to play for stale views *//* ww w . java 2s. c o m*/ private void addOutAnimatorsForStaleViews(List<Animator> animators, AnimationOut animationOutMode) { if (animationOutMode == AnimationOut.NONE) { return; } for (final View v : mViewsToAnimateOut) { // For each stale view to animate out, retrieve the animators for the view, then attach // the StaleViewAnimationEndListener which checks to see if the view should be recycled // at the end of the animation. final List<Animator> viewAnimators = new ArrayList<Animator>(); switch (animationOutMode) { case SLIDE: final LayoutParams lp = (LayoutParams) v.getLayoutParams(); // Bias towards sliding right, but depending on the column that this view // is laid out in, slide towards the nearest side edge. int endTranslation = (int) (v.getWidth() * 1.5); if (lp.column < (mColCount / 2)) { endTranslation = -endTranslation; } SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(), endTranslation); break; case COLLAPSE: SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v); break; case FLY_DOWN: SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight()); break; case FADE: SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */); break; default: throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode); } if (viewAnimators.size() > 0) { addStaleViewAnimationEndListener(v, viewAnimators); animators.addAll(viewAnimators); } } }
From source file:com.deepak.myclock.widget.sgv.StaggeredGridView.java
/** * Add animators for animating out stale views * @param animationOutMode The animation mode to play for stale views */// ww w. j a v a 2s . c o m private void addOutAnimatorsForStaleViews(List<Animator> animators, SgvAnimationHelper.AnimationOut animationOutMode) { if (animationOutMode == SgvAnimationHelper.AnimationOut.NONE) { return; } for (final View v : mViewsToAnimateOut) { // For each stale view to animate out, retrieve the animators for the view, then attach // the StaleViewAnimationEndListener which checks to see if the view should be recycled // at the end of the animation. final List<Animator> viewAnimators = new ArrayList<Animator>(); switch (animationOutMode) { case SLIDE: final LayoutParams lp = (LayoutParams) v.getLayoutParams(); // Bias towards sliding right, but depending on the column that this view // is laid out in, slide towards the nearest side edge. int endTranslation = (int) (v.getWidth() * 1.5); if (lp.column < (mColCount / 2)) { endTranslation = -endTranslation; } SgvAnimationHelper.addSlideOutAnimators(viewAnimators, v, (int) v.getTranslationX(), endTranslation); break; case COLLAPSE: SgvAnimationHelper.addCollapseOutAnimators(viewAnimators, v); break; case FLY_DOWN: SgvAnimationHelper.addFlyOutAnimators(viewAnimators, v, (int) v.getTranslationY(), getHeight()); break; case FADE: SgvAnimationHelper.addFadeAnimators(viewAnimators, v, v.getAlpha(), 0 /* end alpha */); break; default: throw new IllegalStateException("Unknown animationOutMode: " + animationOutMode); } if (viewAnimators.size() > 0) { addStaleViewAnimationEndListener(v, viewAnimators); animators.addAll(viewAnimators); } } }