0

I'm having a double tap issue with my gesture overlay. When I press an item in the action bar, it also cause the gesture overly and tap listener to trigger. I don't want the single tap to go off when I use the action bar and press update or refresh or w/e i have up there?

activty_main.xml

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


 <android.gesture.GestureOverlayView
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:id="@+id/gestureOverlayView1"
         android:layout_width="match_parent"

         android:layout_height="match_parent" 
         tools:context=".MainActivity">



    <LinearLayout 
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dp" 
        android:layout_gravity="start">



    <TextView
        android:id="@+id/timerTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="5sp"
        android:text="@string/startTime"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/hanziTextView"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:ems="10"
        android:gravity="center"
        android:textSize="50sp" />

    <TextView
        android:id="@+id/instructionTextView"
        android:layout_width="574dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.05"
        android:textSize="40sp" />

</LinearLayout>

</android.gesture.GestureOverlayView>

   <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

   <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#666"
        android:dividerHeight="1dp"
        android:background="#333"
        android:paddingLeft="15sp"
        android:paddingRight="15sp"
        />

</android.support.v4.widget.DrawerLayout>

mainactivity.class oncreate

 detector=new GestureDetector(getBaseContext(), this);

        gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!gLibrary.load()) {
            finish();
       }  

        GestureOverlayView gOverlay = 
                (GestureOverlayView) findViewById(R.id.gestureOverlayView1);
            gOverlay.addOnGesturePerformedListener(this); 

           gOverlay.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE);
            gOverlay.setGestureColor(Color.TRANSPARENT);
            gOverlay.setUncertainGestureColor(Color.TRANSPARENT);

various listeners such as OnClickListener,OnLongClickListener, OnGesturePerformedListener, OnGestureListener

@Override
public boolean onDown(MotionEvent arg0) {

    return true;
}

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {


    boolean result = false;
    try {
        float diffY = e2.getY() - e1.getY();
        float diffX = e2.getX() - e1.getX();
        if (Math.abs(diffX) > Math.abs(diffY)) {
            if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                if (diffX > 0) {
                    onSwipeRight();
                } else {
                    onSwipeLeft();
                }
            }
        } else {
            if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                if (diffY > 0) {
                    onSwipeBottom();
                } else {
                    onSwipeTop();
                }
            }
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return result;
}


public void onSwipeRight() {
    Log.d(TAG, "right");

}


public void onSwipeLeft() {

    //Alot of stuff  

}

public void onSwipeTop() {
}

public void onSwipeBottom() {
    //Toast.makeText(this, "Pause", Toast.LENGTH_SHORT).show();

}
@Override
public void onLongPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public boolean dispatchTouchEvent(MotionEvent e)
{
    detector.onTouchEvent(e);

    return super.dispatchTouchEvent(e);
}

@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
        float arg3) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onShowPress(MotionEvent arg0) {
    // TODO Auto-generated method stub
    Log.i(LOGTAG, "testsing4");
    //Toast.makeText(getApplicationContext(), "Show Press gesture", 100).show();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    Log.i(LOGTAG, "testsing3");
    return detector.onTouchEvent(event);
}

@Override
public boolean onSingleTapUp(MotionEvent e) {

    //stuff
    return true;
}

public boolean onSingleTapConfirmed(MotionEvent e) { 

    //Toast.makeText(getApplicationContext(), "Single Tap Gesture", 100).show();
    Log.i(LOGTAG, "testsing1");
    return true; 
}

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        //stuff

    }
MAXGEN
  • 735
  • 1
  • 10
  • 21

1 Answers1

0

DoubleTap in android

Adding gestures for action bar is essentially the same.

Also, consider using long click instead. As Jems mentions, it is more natural of an input method, and it is easier to implement

Community
  • 1
  • 1
  • No I don't want gestures. The problem is I have icons and when I go to press those icons that are located in the action bar, it also triggers single tap. They both trigger and gives me both results which isn't good because user wanted only one action. Long click already using for something else and can't change the action. – MAXGEN Mar 12 '14 at 03:29
  • I am afraid I don't follow your description 100% – Sebastian Mocny Mar 12 '14 at 03:36
  • Consider http://stackoverflow.com/questions/5434258/using-a-gesture-overlay-view-in-android Also consider re sizing your layout so that the gesture detector isn't in the same area as the action bar. That or play with layering your button so the touch listener on the button handles the action, and then kills the event – Sebastian Mocny Mar 12 '14 at 03:38
  • http://www.androidsnippets.com/handle-touch-events-ontouchevent Here is a very simple explanation – Sebastian Mocny Mar 12 '14 at 03:39
  • I used onShowPress which isn't as senstive and it works pretty good. So again the action bar can contain menu icon items on the "BAR". Does that make sense? I have a textview that is located under teh actionbar and when I press singletap i have text that shows up but when I press the action bar to select one of the items, it also engages the single tap which isn't what i want. DOes that make sense? If not thank you for trying. – MAXGEN Mar 12 '14 at 03:39