Android Open Source - slider Tile Shifter






From Project

Back to project page slider.

License

The source code is released under:

Apache License

If you think the Android project slider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.devisnik.android.sliding.tile;
// w w  w .  ja  v  a 2s. co m
import android.os.Handler;
import android.os.SystemClock;
import de.devisnik.sliding.IPiece;
import de.devisnik.sliding.IShifterListener;
import de.devisnik.sliding.Point;
import de.devisnik.sliding.ShiftingEvent;
import de.devisnik.sliding.animation.AnimationRunner;
import de.devisnik.sliding.animation.MetaShiftable;
import de.devisnik.sliding.animation.ShiftAnimation;

public class TileShifter extends AnimationRunner {

  private static final int STEP_DURATION = 16;
  private final Handler itsHandler;
  private long itsStartTime;
  private final IShifterListener itsListener;
  private final MetaShiftable itsShiftable;
  private final TileStore itsTileStore;

  public static TileShifter create(final TileStore tileStore, final Handler handler, final int durationInMillis,
      final IShifterListener listener) {
    int steps = durationInMillis / STEP_DURATION;
    MetaShiftable metaShiftable = new MetaShiftable(steps);
    return new TileShifter(tileStore, metaShiftable, handler, steps, listener);
  }

  private TileShifter(final TileStore tileStore, final MetaShiftable shiftable, final Handler handler,
      final int steps, final IShifterListener listener) {
    super(new ShiftAnimation(shiftable, new Point(0, 0), steps));
    itsTileStore = tileStore;
    itsShiftable = shiftable;
    itsHandler = handler;
    itsListener = listener;
  }

  @Override
  protected void onStartShifting() {
    itsStartTime = SystemClock.uptimeMillis();
  }

  @Override
  protected void onDoneShifting() {
    if (itsListener != null)
      itsListener.doneShifting();
  }

  @Override
  protected void schedule(final Runnable runnable) {
    itsHandler.postAtTime(runnable, itsStartTime + itsAnimation.currentStep() * STEP_DURATION);
  }

  public TileShifter animate(final IPiece left, final IPiece right) {
    Point diff = Point.diff(left.getPosition(), right.getPosition());
    animate(left, diff);
    animate(right, Point.times(diff, -1));
    return this;
  }

  private void animate(final IPiece piece, final Point diff) {
    itsShiftable.addShifterFor(itsTileStore.get(piece), diff);
  }

  private void animate(final ShiftingEvent event) {
    itsShiftable.addShifterFor(itsTileStore.get(event.getPiece()),
        Point.diff(event.getNewPosition(), event.getOldPosition()));
  }

  public TileShifter animate(final ShiftingEvent[] events) {
    for (ShiftingEvent event : events) {
      animate(event);
    }
    return this;
  }
}




Java Source Code List

de.devisnik.android.sliding.ARandom.java
de.devisnik.android.sliding.FPSCounter.java
de.devisnik.android.sliding.FrameDrawer.java
de.devisnik.android.sliding.ISpeed.java
de.devisnik.android.sliding.ImageCache.java
de.devisnik.android.sliding.ImageFactory.java
de.devisnik.android.sliding.Logger.java
de.devisnik.android.sliding.OpenActivity.java
de.devisnik.android.sliding.OpenPreviewActivity.java
de.devisnik.android.sliding.PropertiesBuilder.java
de.devisnik.android.sliding.RenderHandler.java
de.devisnik.android.sliding.Replayer.java
de.devisnik.android.sliding.Settings.java
de.devisnik.android.sliding.SlidingPreferences.java
de.devisnik.android.sliding.SlidingWallpaper.java
de.devisnik.android.sliding.SpeedFactory.java
de.devisnik.android.sliding.SummaryUpdater.java
de.devisnik.android.sliding.tile.BitmapCachingPieceDrawer.java
de.devisnik.android.sliding.tile.CachingPieceDrawer.java
de.devisnik.android.sliding.tile.IPieceDrawer.java
de.devisnik.android.sliding.tile.ImagePieceDrawer.java
de.devisnik.android.sliding.tile.NumberPieceDrawer.java
de.devisnik.android.sliding.tile.PieceDrawerFactory.java
de.devisnik.android.sliding.tile.TileShifter.java
de.devisnik.android.sliding.tile.TileStore.java
de.devisnik.android.sliding.tile.Tile.java
de.devisnik.sliding.FrameFactory.java
de.devisnik.sliding.FrameScrambler.java
de.devisnik.sliding.FromHomeShiftingEvent.java
de.devisnik.sliding.IFrameListener.java
de.devisnik.sliding.IFrame.java
de.devisnik.sliding.IHole.java
de.devisnik.sliding.IMove.java
de.devisnik.sliding.IPiece.java
de.devisnik.sliding.IRandom.java
de.devisnik.sliding.IRobotFrame.java
de.devisnik.sliding.IShifterListener.java
de.devisnik.sliding.MoveFactory.java
de.devisnik.sliding.Point.java
de.devisnik.sliding.ShiftingEvent.java
de.devisnik.sliding.ToHomeShiftingEvent.java
de.devisnik.sliding.animation.AccelerateDecelerateInterpolator.java
de.devisnik.sliding.animation.AnimationRunner.java
de.devisnik.sliding.animation.Animation.java
de.devisnik.sliding.animation.IInterpolator.java
de.devisnik.sliding.animation.IMovement.java
de.devisnik.sliding.animation.IShiftable.java
de.devisnik.sliding.animation.LinearInterpolator.java
de.devisnik.sliding.animation.MetaShiftable.java
de.devisnik.sliding.animation.ShiftAnimation.java
de.devisnik.sliding.animation.Translation.java
de.devisnik.sliding.impl.Frame.java
de.devisnik.sliding.impl.Hole.java
de.devisnik.sliding.impl.Move.java
de.devisnik.sliding.impl.PieceIterator.java
de.devisnik.sliding.impl.Piece.java
de.devisnik.sliding.impl.RobotFrame.java
de.devisnik.sliding.impl.Scrambler.java