Android Open Source - Airplanes Double 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;
// ww w . j  av a2s .  com
public class DoubleTapDetector implements Detector {
  /**Maximum slop(distance between taps) in pixels**/
  public static final int SLOP = 30;
  /**Max delay between taps in seconds**/
  public static final float DELAY = 0.5f;
  
  private float delta = 0.f;
  private int x, y;
  private boolean waitingFor2ndTap = false;
  private DoubleTapListener listener = null;
  
  public DoubleTapDetector(DoubleTapListener lis) {
    listener = lis;
  }
  
  public void tap(int x, int y) {
    if (waitingFor2ndTap) {
      if (delta <= DELAY && Math.abs(this.x - x) < SLOP && Math.abs(this.y - y) < SLOP) {
        listener.doubleTap(this.x, this.y);
      }
      waitingFor2ndTap = false;
    }
    else {
      waitingFor2ndTap = 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 boolean waiting() {
    return waitingFor2ndTap;
  }
  
  public void elapsed(float delta) {
    if (this.delta < 0.f) 
      this.delta = 0.f; 
    else {
      this.delta += delta;
      if (this.delta > DELAY) /*If we passed the max delay, stop waiting*/
        waitingFor2ndTap = 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