Android Open Source - Save-the-Planet Drag Detector






From Project

Back to project page Save-the-Planet.

License

The source code is released under:

Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software ...

If you think the Android project Save-the-Planet 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.karolmajta.procprox;
//w  w  w .  java2s.co m
import java.util.ArrayList;

public class DragDetector {

  private ArrayList<Drag> drags;
  private ArrayList<IEventFilter<Drag>> filters;
  private boolean mousePressed;
  private float startX;
  private float startY;
  private float lastX;
  private float lastY;
  private int duration;
  
  public DragDetector() {
    drags = new ArrayList<Drag>();
    filters = new ArrayList<IEventFilter<Drag>>();
    mousePressed = false;
  }
  
  public boolean hasDrags() {
    if(drags.size() > 0) {
      return true;
    }else{
      return false;
    }
  }

  public ArrayList<Drag> getDrags() {
    return drags;
  }
  
  public void flush() {
    drags = new ArrayList<Drag>();
  }

  public void update(float mouseX, float mouseY, boolean mousePressed, int milis) {
    if(!this.mousePressed && mousePressed){
      this.mousePressed = true;
      startX = mouseX;
      startY = mouseY;
      duration = 0;
    }
    if(mousePressed){
      lastX = mouseX;
      lastY = mouseY;
      duration += milis;
    }
    if(this.mousePressed && !mousePressed){
      this.mousePressed = false;
      Drag d = new Drag
          (
              startX,
              startY,
              lastX,
              lastY,
              duration
          );
      boolean shouldAdd = true;
      for(IEventFilter<Drag> f : filters){
        if(f.filter(d)){
          shouldAdd = false;
          break;
        }
      }
      if(shouldAdd){
        drags.add(d);
      }
    }
  }

  public void addFilter(IEventFilter<Drag> filter) {
    filters.add(filter);
  }
}




Java Source Code List

com.karolmajta.procprox.DragDetector.java
com.karolmajta.procprox.Drag.java
com.karolmajta.procprox.FontManager.java
com.karolmajta.procprox.IEventFilter.java
com.karolmajta.procprox.TapDetector.java
com.karolmajta.procprox.Tap.java
com.karolmajta.procprox.excepiton.FontNotCreatedException.java
com.karolmajta.stp.LoadingScreenActivity.java
com.karolmajta.stp.MainMenuActivity.java
com.karolmajta.stp.exception.NoDeferredException.java
com.karolmajta.stp.exception.NoTasksInProgressQueueException.java
com.karolmajta.stp.exception.STPException.java
com.karolmajta.stp.exception.UnboundViewException.java
com.karolmajta.stp.models.ICanCollide.java
com.karolmajta.stp.models.IPConstants.java
com.karolmajta.stp.models.IProgress.java
com.karolmajta.stp.models.ITask.java
com.karolmajta.stp.models.ITickable.java
com.karolmajta.stp.models.MainMenuItemBall.java
com.karolmajta.stp.models.MainMenuObstacleBall.java
com.karolmajta.stp.models.ObstacleManager.java
com.karolmajta.stp.models.SyncProgress.java
com.karolmajta.stp.models.SyncTask.java
com.karolmajta.stp.models.Tickable.java
com.karolmajta.stp.models.Viewport.java
com.karolmajta.stp.views.FancyTextView.java
com.karolmajta.stp.views.IDrawable.java
com.karolmajta.stp.views.MainMenuItemBallDebugView.java
com.karolmajta.stp.views.MainMenuItemBallView.java
com.karolmajta.stp.views.MainMenuObstacleBallDebugView.java
com.karolmajta.stp.views.MainMenuObstacleBallView.java
com.karolmajta.stp.views.ObstacleManagerView.java
com.karolmajta.stp.views.ProgressDebugView.java
com.karolmajta.stp.views.ProgressView.java
com.karolmajta.stp.views.View.java