Android Open Source - android-tools Gesture Helper






From Project

Back to project page android-tools.

License

The source code is released under:

MIT License

If you think the Android project android-tools 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 net.comfreeze.lib.views;
//from ww w .j a  v a  2  s .c o m
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

/**
 * @author james
 * @version %I%
 * @package ComFreeze Android Tools
 * @serial 8/9/13
 */
public class GestureHelper implements View.OnTouchListener, GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
    public static final String TAG = GestureHelper.class.getSimpleName();
    private GestureDetector detector;
    private GestureHelperActionListener listener;
    private View view;

    public GestureHelper(Context context, GestureHelperActionListener listener) {
        this.detector = new GestureDetector(context, this);
        this.listener = listener;
    }

    public boolean onTouchEvent(View v, MotionEvent ev) {
        this.view = v;
        return detector.onTouchEvent(ev);
    }

    public boolean onTouch(View v, MotionEvent ev) {
        return onTouchEvent(v, ev);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        if (null != listener)
            return listener.onAction(ACTION.SINGLE_TAP, view, e);
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent e) {
        if (null != listener)
            return listener.onAction(ACTION.DOUBLE_TAP, view, e);
        return false;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        if (null != listener)
            return listener.onAction(ACTION.DOUBLE_TAP_EVENT, view, e);
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        if (null != listener)
            return listener.onAction(ACTION.DOWN, view, e);
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        if (null != listener)
            listener.onAction(ACTION.SHOW_PRESS, view, e);
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        if (null != listener)
            return listener.onAction(ACTION.SINGLE_TAP_UP, view, e);
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        if (null != listener)
            return listener.onAction(ACTION.SCROLL, view, e1, e2, distanceX, distanceY);
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        if (null != listener)
            listener.onAction(ACTION.LONG_PRESS, view, e);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (null != listener)
            listener.onAction(ACTION.FLING, view, e1, e2, velocityX, velocityY);
        return false;
    }

    public static enum ACTION {
        SINGLE_TAP, DOUBLE_TAP, DOUBLE_TAP_EVENT, DOWN, LONG_PRESS, SHOW_PRESS, SINGLE_TAP_UP, SCROLL, FLING
    }

    public interface GestureHelperActionListener {
        public boolean onAction(ACTION action, View v, MotionEvent e);

        public boolean onAction(ACTION action, View v, MotionEvent e1, MotionEvent e2, float v1, float v2);
    }
}




Java Source Code List

net.comfreeze.lib.BundleBuilder.java
net.comfreeze.lib.CFZApplication.java
net.comfreeze.lib.ContentValueBuilder.java
net.comfreeze.lib.FragmentMap.java
net.comfreeze.lib.adapter.HeaderListAdapter.java
net.comfreeze.lib.adapter.IHeaderListAdapter.java
net.comfreeze.lib.adapter.SeparatedListAdapter.java
net.comfreeze.lib.api.BaseAPI.java
net.comfreeze.lib.api.RestAPI.java
net.comfreeze.lib.api.XMLAPI.java
net.comfreeze.lib.api.helper.CursorHelper.java
net.comfreeze.lib.api.helper.JSONHelper.java
net.comfreeze.lib.api.helper.ModelHelper.java
net.comfreeze.lib.api.xml.WordpressAPI.java
net.comfreeze.lib.audio.SoundManager.java
net.comfreeze.lib.db.DatabaseHelper.java
net.comfreeze.lib.db.DatabaseTable.java
net.comfreeze.lib.db.helper.HelperCursor.java
net.comfreeze.lib.db.model.CFZModel.java
net.comfreeze.lib.db.model.FieldColumnMap.java
net.comfreeze.lib.fragments.CFZListFragment.java
net.comfreeze.lib.provider.CFZSimpleProvider.java
net.comfreeze.lib.service.CFZService.java
net.comfreeze.lib.ui.SupportFragmentActivity.java
net.comfreeze.lib.ui.dialog.CFZDialogProgress.java
net.comfreeze.lib.ui.fragment.CFZFragmentBase.java
net.comfreeze.lib.views.BiScrollView.java
net.comfreeze.lib.views.CFZViewHelper.java
net.comfreeze.lib.views.FlowLayout.java
net.comfreeze.lib.views.GestureHelper.java
net.comfreeze.lib.views.HeaderListView.java
net.comfreeze.lib.views.ResizingView.java
net.comfreeze.lib.views.ViewCollection.java
net.comfreeze.lib.views.ViewUtils.java
net.comfreeze.lib.xml.XMLParser.java
net.comfreeze.lib.xml.wordpress.FeedXmlParser.java