Android Open Source - Airplanes Tap Detector






From Project

Back to project page Airplanes.

License

The source code is released under:

GNU General Public License

If you think the Android project Airplanes 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 com.axnsan.airplanes.util;
//from  w w  w .jav  a2s.c  om
public class TapDetector implements Detector {
  /**Maximum slop(distance between down location and up location), in pixels**/
  public static final int SLOP = 20;
  /**Max delay between touch down and touch up, in seconds**/
  public static final float DELAY = 0.2f;
  
  private float delta = 0.f;
  private int x, y;
  private boolean waitingForUp = false;
  private TapListener listener = null;
  
  public TapDetector(TapListener lis) {
    listener = lis;
  }
  
  public void down(int x, int y) {
    waitingForUp = true;
    this.x = x; this.y = y;
    
    /* We set the initial duration to -1, and only set it to 0 and begin counting in the next frame.
       * This necessary to ensure we don't count the time before this frame.
       * We must do this because rendering only happens when waiting for input,
       * and as such frame delta can be very high if the last input was long ago.*/
    delta = -1.f;
  }
  
  public void up(int x, int y) {
    if (waitingForUp) {
      if (delta <= DELAY && Math.abs(this.x - x) < SLOP && Math.abs(this.y - y) < SLOP) {
        listener.tap(this.x, this.y);
      }
      waitingForUp = false;
    }
  }
  public boolean waiting() {
    return waitingForUp;
  }
  
  public void elapsed(float delta) {
    if (this.delta < 0.f) /*This step is necessary to ensure we don't count the time before the first tap*/
      this.delta = 0.f; 
    else {
      this.delta += delta;
      if (this.delta > DELAY) /*If we passed the max delay, stop waiting*/
        waitingForUp = false;
    }
  }
}




Java Source Code List

com.axnsan.airplanes.Airplanes.java
com.axnsan.airplanes.BaseGrid.java
com.axnsan.airplanes.GameConfiguration.java
com.axnsan.airplanes.GameState.java
com.axnsan.airplanes.GridRandomizer.java
com.axnsan.airplanes.Grid.java
com.axnsan.airplanes.GuardedScreen.java
com.axnsan.airplanes.HotseatMatchHandler.java
com.axnsan.airplanes.MainActivity.java
com.axnsan.airplanes.Main.java
com.axnsan.airplanes.MatchHandler.java
com.axnsan.airplanes.PlacementGrid.java
com.axnsan.airplanes.Plane.java
com.axnsan.airplanes.Player.java
com.axnsan.airplanes.PlayingGrid.java
com.axnsan.airplanes.online.ClientSocket.java
com.axnsan.airplanes.online.EventHandler.java
com.axnsan.airplanes.online.Game.java
com.axnsan.airplanes.online.LobbyScreen.java
com.axnsan.airplanes.online.LoginScreen.java
com.axnsan.airplanes.online.Message.java
com.axnsan.airplanes.online.Messages.java
com.axnsan.airplanes.online.OnlineGameScreen.java
com.axnsan.airplanes.online.OnlineMatchHandler.java
com.axnsan.airplanes.online.OnlineMenuScreen.java
com.axnsan.airplanes.online.OnlineSettingsScreen.java
com.axnsan.airplanes.online.SessionData.java
com.axnsan.airplanes.screens.BeginTurnScreen.java
com.axnsan.airplanes.screens.HotseatPlayersScreen.java
com.axnsan.airplanes.screens.HotseatScreen.java
com.axnsan.airplanes.screens.HotseatSettingsScreen.java
com.axnsan.airplanes.screens.HotseatStartScreen.java
com.axnsan.airplanes.screens.MainMenuScreen.java
com.axnsan.airplanes.screens.PlacementScreen.java
com.axnsan.airplanes.screens.PlayMenuScreen.java
com.axnsan.airplanes.screens.PracticeScreen.java
com.axnsan.airplanes.screens.PracticeSettingsScreen.java
com.axnsan.airplanes.screens.PracticeStartScreen.java
com.axnsan.airplanes.util.ActionManager.java
com.axnsan.airplanes.util.ActionResolver.java
com.axnsan.airplanes.util.BasicFontManager.java
com.axnsan.airplanes.util.Detector.java
com.axnsan.airplanes.util.DoubleTapDetector.java
com.axnsan.airplanes.util.DoubleTapListener.java
com.axnsan.airplanes.util.FontManagerInterface.java
com.axnsan.airplanes.util.FontManager.java
com.axnsan.airplanes.util.JavaXmlParser.java
com.axnsan.airplanes.util.Point2D.java
com.axnsan.airplanes.util.RandomizedQueue.java
com.axnsan.airplanes.util.StringManager.java
com.axnsan.airplanes.util.StringXmlParser.java
com.axnsan.airplanes.util.TTFFontManager.java
com.axnsan.airplanes.util.TapDetector.java
com.axnsan.airplanes.util.TapListener.java