List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:org.runbuddy.tomahawk.views.AlbumArtViewPager.java
public void setOnGestureListener(GestureDetector.SimpleOnGestureListener listener) { mGestureDetector = new GestureDetector(getContext(), listener); }
From source file:com.conecuh.bluetoothjoystick.BasicGestureDetectFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View gestureView = getActivity().findViewById(R.id.fullscreen_content); gestureView.setClickable(true);/*from w ww. j a v a 2 s .c om*/ gestureView.setFocusable(true); // BEGIN_INCLUDE(init_detector) // First create the GestureListener that will include all our callbacks. // Then create the GestureDetector, which takes that listener as an argument. GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener(); final GestureDetector gd = new GestureDetector(getActivity(), gestureListener); /* For the view where gestures will occur, create an onTouchListener that sends * all motion events to the gesture detector. When the gesture detector * actually detects an event, it will use the callbacks you created in the * SimpleOnGestureListener to alert your application. */ touchProcessor = new SerialTouchProcessor(); gestureView.setOnTouchListener(touchProcessor); Log.i("TAG", "SerialTouchProcessor Created"); // gestureView.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View view, MotionEvent motionEvent) { // gd.onTouchEvent(motionEvent); // return false; // } // }); // END_INCLUDE(init_detector) }
From source file:com.example.android.basicgesturedetect.BasicGestureDetectFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View gestureView = getActivity().findViewById(R.id.sample_output); gestureView.setClickable(true);/*w w w.ja va 2 s . c om*/ gestureView.setFocusable(true); // BEGIN_INCLUDE(init_detector) // First create the GestureListener that will include all our callbacks. // Then create the GestureDetector, which takes that listener as an argument. GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener(); final GestureDetector gd = new GestureDetector(getActivity(), gestureListener); /* For the view where gestures will occur, create an onTouchListener that sends * all motion events to the gesture detector. When the gesture detector * actually detects an event, it will use the callbacks you created in the * SimpleOnGestureListener to alert your application. */ gestureView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { gd.onTouchEvent(motionEvent); return false; } }); // END_INCLUDE(init_detector) }
From source file:com.kunze.androidlocaltodo.ProgrammaticViewPager.java
public ProgrammaticViewPager(Context context, AttributeSet attrs) { super(context, attrs); mEnabled = true;/*from w w w .j a v a2 s .com*/ mSwipeDetector = new GestureDetector(getContext(), this); }
From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.Tabs.Inputs.Input_GestureFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.input_gesture_fragment, container, false); ButterKnife.inject(this, view); actionPad.setClickable(true);/* w ww.j a v a 2s . c o m*/ actionPad.setFocusable(true); GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener(gestureContent, getActivity()); final GestureDetector gd = new GestureDetector(getActivity(), gestureListener); actionPad.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { gd.onTouchEvent(motionEvent); return false; } }); return view; }
From source file:com.google.android.apps.santatracker.dasherdancer.NoSwipeViewPager.java
public void setGestureDetectorListeners(Context context, OnGestureListener listener, OnScaleGestureListener scaleListener) { mGestureDetector = new GestureDetector(context, listener); mScaleGestureDetector = new ScaleGestureDetector(context, scaleListener); }
From source file:com.dfws.idea.ClosePcActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main); this.closePcButton = (Button) this.findViewById(R.id.close_pc_button); this.wakeupPcButton = (Button) this.findViewById(R.id.wakeup_pc_button); this.viewSourceButton = (Button) this.findViewById(R.id.view_source_button); this.initBind(); gestureDetector = new GestureDetector(this, onGestureListener); Log.i("life", "onCreate"); }
From source file:co.bytera.twodimensionalviewpager.fragment.TwoDimensionalViewPagerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_layout, container, false); viewPager = (ViewPager) v.findViewById(R.id.viewPager); /*/* w ww . ja v a2s . c o m*/ * To detect the gesture (UP/DOWN/LEFT/RIGHT) */ final GestureDetector gesture = new GestureDetector(getActivity(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final int SWIPE_MIN_DISTANCE = 120; final int SWIPE_MAX_OFF_PATH = 250; final int SWIPE_THRESHOLD_VELOCITY = 200; try { if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { /* * finger motion is UP side. page is moving to next row */ adapter.nextRow(); adapter.notifyDataSetChanged(); } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { /* * finger motion is DOWN side. page is moving to previous row */ adapter.previousRow(); adapter.notifyDataSetChanged(); } else if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { /* * more action can be done here */ } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { /* * more action can be done here */ } } catch (Exception e) { e.printStackTrace(); } return super.onFling(e1, e2, velocityX, velocityY); } }); /* * set on touch listener to the viewPager */ viewPager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gesture.onTouchEvent(event); } }); return v; }
From source file:org.deviceconnect.android.deviceplugin.host.activity.TouchProfileActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.touch_main); // Get Application class instance. mApp = (HostDeviceApplication) this.getApplication(); // Get serviceId. Intent intent = getIntent();/*from ww w .java 2 s.c om*/ mServiceId = intent.getStringExtra(DConnectMessage.EXTRA_SERVICE_ID); // Create GestureDetector instance. mGestureDetector = new GestureDetector(this, mSimpleOnGestureListener); // onclicklistener register. Button button = (Button) findViewById(R.id.button_touch_close); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { finish(); } }); }
From source file:com.sckftr.android.app.view.HackyViewPager.java
public HackyViewPager(Context context, AttributeSet attrs) { super(context, attrs); GestureDetector.SimpleOnGestureListener singleTapListener = new GestureDetector.SimpleOnGestureListener() { // @Override public boolean onSingleTapUp(MotionEvent e) { // AppConst.Log.d(null, "hacky pager gd on tap up"); ///*from ww w. j a v a 2 s. c o m*/ // return super.onSingleTapUp(e); // } // // @Override public boolean onSingleTapConfirmed(MotionEvent e) { // // // AppConst.Log.d(null, "hacky pager gd on tap conf"); // // if (listener != null) listener.onSingleTap(HackyViewPager.this); // // return super.onSingleTapConfirmed(e); // } //strange, but works as single tap @Override public void onLongPress(MotionEvent e) { //AppConst.Log.d(null, "hacky pager gd on long press"); if (listener != null) { listener.onSingleTap(HackyViewPager.this); //AppConst.Log.d(null, "listener triggered"); } super.onLongPress(e); } }; gestureDetector = new GestureDetector(getContext(), singleTapListener); }