Example usage for android.view GestureDetector GestureDetector

List of usage examples for android.view GestureDetector GestureDetector

Introduction

In this page you can find the example usage for android.view GestureDetector GestureDetector.

Prototype

public GestureDetector(Context context, OnGestureListener listener) 

Source Link

Document

Creates a GestureDetector with the supplied listener.

Usage

From source file:SplashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    ImageView imageView = (ImageView) findViewById(R.id.splash_image);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    detector = new GestureDetector(this, new SplashListener());
}

From source file:Main.java

private static View.OnTouchListener generateOnTouchListener(Context context) {
    final GestureDetector detector = new GestureDetector(context,
            new GestureDetector.SimpleOnGestureListener() {
                @Override/* www  .j  a  v  a  2  s .  co m*/
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return true;
                }
            });
    return new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return detector.onTouchEvent(motionEvent);
        }
    };
}

From source file:DetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    detector = new GestureDetector(this, new GalleryGestureDetector());
    listener = new View.OnTouchListener() {

        @Override/*from  ww  w.j  av  a  2s .c om*/
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    };

    ImageIndex = 0;

    detailImage = (ImageView) findViewById(R.id.detail_image);
    detailImage.setOnTouchListener(listener);

    TextView detailName = (TextView) findViewById(R.id.detail_name);
    TextView detailDistance = (TextView) findViewById(R.id.detail_distance);
    TextView detailText = (TextView) findViewById(R.id.detail_text);
    detailText.setMovementMethod(new ScrollingMovementMethod());
    ImageView detailWebLink = (ImageView) findViewById(R.id.detail_web_link);

    int i = MainActivity.currentItem;
    Random n = new Random();
    int m = n.nextInt((600 - 20) + 1) + 20;
    setTitle(getString(R.string.app_name) + " - " + MainData.nameArray[i]);
    detailImage.setImageResource(MainData.detailImageArray[i]);
    detailName.setText(MainData.nameArray[i]);
    detailDistance.setText(String.valueOf(m) + " miles");
    detailText.setText(MainData.detailTextArray[i]);

    detailWebLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse(MainData.detailWebLink[MainActivity.currentItem]));
            startActivity(intent);
        }
    });
}

From source file:org.amahi.anywhere.view.ClickableViewPager.java

private void setup() {
    tapGestureDetector = new GestureDetector(getContext(), new TapGestureListener());
}

From source file:com.cdv.GalleryPager.VelocityViewPager.java

public VelocityViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    mGestureDetector = new GestureDetector(context, this);
}

From source file:cn.edu.zafu.easemob.CoverFlowLib.VelocityViewPager.java

public VelocityViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    setPageTransformer(false, new CoverFlowTransformer(context, attrs));
    mGestureDetector = new GestureDetector(context, this);
}

From source file:org.coursera.android.shift.ShiftIconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.shift_menu, container, false);

    mHead = layout.findViewById(R.id.head);
    final RelativeLayout.LayoutParams iconParams;
    iconParams = (RelativeLayout.LayoutParams) mHead.getLayoutParams();

    final GestureDetector gestureDetector = new GestureDetector(getActivity(), new SingleTapConfirm());

    mHead.setOnTouchListener(new View.OnTouchListener() {
        private int initialX;
        private int initialY;
        private float initialTouchX;
        private float initialTouchY;

        @Override//from  ww w .j av  a  2s. co  m
        public boolean onTouch(View v, MotionEvent event) {
            final int yLimit = layout.getMeasuredHeight() - mHead.getMeasuredHeight();
            final int xLimit = layout.getMeasuredWidth() - mHead.getMeasuredWidth();

            // single tap
            if (gestureDetector.onTouchEvent(event)) {
                mShiftLauncherView.showShiftMenu(getActivity());
                return true;
            }

            // drag icon
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                initialX = iconParams.leftMargin;
                initialY = iconParams.topMargin;
                initialTouchX = event.getRawX();
                initialTouchY = event.getRawY();
                return true;
            case MotionEvent.ACTION_CANCEL:
                return false;
            case MotionEvent.ACTION_UP:
                return true;
            case MotionEvent.ACTION_MOVE:
                int newX = initialX + (int) (event.getRawX() - initialTouchX);
                int newY = initialY + (int) (event.getRawY() - initialTouchY);

                iconParams.leftMargin = newX < 0 ? 0 : Math.min(newX, xLimit);
                iconParams.topMargin = newY < 0 ? 0 : Math.min(newY, yLimit);

                layout.updateViewLayout(mHead, iconParams);
                return true;
            }
            return false;
        }
    });
    return layout;
}

From source file:opensourceproject.kanjisteps.Practice_slides.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_practice_slides);

    gd = new GestureDetector(this, new MyGestureDetector());
    gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent e) {
            return gd.onTouchEvent(e);
        }/*from  w  ww.  ja  va2s.  c o m*/
    };

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        level_marker = extras.getString("INITIALIZE_LEVEL");
    }
    if (quizByLevelOnyomi() == 1 && quizByLevelMeaning() == 1) {
        resetButtons();

        //no review notice.
    }
}

From source file:com.kunze.androidlocaltodo.ProgrammaticViewPager.java

public ProgrammaticViewPager(Context context) {
    super(context);
    mEnabled = true;
    mSwipeDetector = new GestureDetector(getContext(), this);
}

From source file:org.peterbaldwin.vlcremote.fragment.NavigationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.navigation_fragment, root, false);
    Context context = view.getContext();
    GestureDetector.OnGestureListener listener = this;
    mGestureDetector = new GestureDetector(context, listener);
    view.findViewById(R.id.overlay).setOnTouchListener(this);
    return view;/* w  w w  .j  a v  a 2s.  c  om*/
}