Android Open Source - Flippy-Radio Activity Swipe Detector






From Project

Back to project page Flippy-Radio.

License

The source code is released under:

Apache License

If you think the Android project Flippy-Radio 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.bitflippersanonymous.flippy.util;
/*from  w  w  w.j a  va 2 s. c om*/
import android.view.MotionEvent;
import android.view.View;

abstract public class ActivitySwipeDetector implements View.OnTouchListener {

  static final String logTag = "ActivitySwipeDetector";
  static final int MIN_DISTANCE = 100;
  private float downX, downY, upX, upY;
  enum Type {
    LeftToRight,
    RightToLeft,
    TopToBottom,
    BottomToTop
  };

  abstract public boolean onSwipe(Type type, View view);
  
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      switch(event.getAction()){
          case MotionEvent.ACTION_DOWN: {
              downX = event.getX();
              downY = event.getY();
              return true;
          }
          case MotionEvent.ACTION_UP: {
              upX = event.getX();
              upY = event.getY();

              float deltaX = downX - upX;
              float deltaY = downY - upY;

              // swipe horizontal?
              if(Math.abs(deltaX) > MIN_DISTANCE){
                  // left or right
                  if(deltaX < 0) { return onSwipe(Type.LeftToRight, v); }
                  if(deltaX > 0) { return onSwipe(Type.RightToLeft, v); }
              }

              // swipe vertical?
              if(Math.abs(deltaY) > MIN_DISTANCE){
                  // top or down
                  if(deltaY < 0) { return onSwipe(Type.TopToBottom, v); }
                  if(deltaY > 0) { return onSwipe(Type.BottomToTop, v); }
              }
              return true;
          }
      }
      return false;
  }
  
}




Java Source Code List

.PlsAdapter.java
com.bitflippersanonymous.flippy.activity.FlippyAboutActivity.java
com.bitflippersanonymous.flippy.activity.FlippyBaseActivity.java
com.bitflippersanonymous.flippy.activity.FlippyBrowseActivity.java
com.bitflippersanonymous.flippy.activity.FlippyInfoActivity.java
com.bitflippersanonymous.flippy.activity.FlippyMainActivity.java
com.bitflippersanonymous.flippy.activity.FlippyQueueActivity.java
com.bitflippersanonymous.flippy.activity.FlippySearchActivity.java
com.bitflippersanonymous.flippy.activity.FlippySettingsActivity.java
com.bitflippersanonymous.flippy.db.FlippyDatabaseAdapter.java
com.bitflippersanonymous.flippy.db.FlippyDatabaseHelper.java
com.bitflippersanonymous.flippy.domain.EntryView.java
com.bitflippersanonymous.flippy.domain.PlsDbAdapter.java
com.bitflippersanonymous.flippy.domain.PlsEntry.java
com.bitflippersanonymous.flippy.domain.PodcastParser.java
com.bitflippersanonymous.flippy.domain.SimpleCursorLoader.java
com.bitflippersanonymous.flippy.service.FlippyPlayerService.java
com.bitflippersanonymous.flippy.util.ActivitySwipeDetector.java
com.bitflippersanonymous.flippy.util.Util.java