daily pastebin goal
69%
SHARE
TWEET

gestures

a guest Nov 14th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.teacher.mygesture
  2.  
  3. import android.support.v7.app.AppCompatActivity
  4. import android.os.Bundle
  5. import android.support.v4.view.GestureDetectorCompat
  6. import android.view.GestureDetector
  7. import android.view.MotionEvent
  8. import android.widget.Toast
  9. import kotlinx.android.synthetic.main.activity_main.*
  10.  
  11. class MainActivity : AppCompatActivity(),GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener {
  12.  
  13.  
  14.     var gDetector: GestureDetectorCompat? = null
  15.  
  16.     override fun onCreate(savedInstanceState: Bundle?) {
  17.         super.onCreate(savedInstanceState)
  18.         setContentView(R.layout.activity_main)
  19.         this.gDetector = GestureDetectorCompat(this,this)
  20.         gDetector?.setOnDoubleTapListener(this)
  21.  
  22.     }
  23.  
  24.     override fun onTouchEvent(event: MotionEvent?): Boolean {
  25.         this.gDetector?.onTouchEvent(event)
  26.         return super.onTouchEvent(event)
  27.     }
  28.  
  29.     override fun onDown(e: MotionEvent?): Boolean {
  30.  
  31.         return true
  32.     }
  33.  
  34.     override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {
  35.         gestureStatusText.text = "On Fling"
  36.         return true
  37.     }
  38.  
  39.     override fun onLongPress(e: MotionEvent?) {
  40.        Toast.makeText(this,"Please kill Ostrov",Toast.LENGTH_SHORT).show()
  41.     }
  42.  
  43.  
  44.     override fun onShowPress(e: MotionEvent?) {
  45.         gestureStatusText.text = "on show press"
  46.     }
  47.  
  48.     override fun onSingleTapUp(e: MotionEvent?): Boolean {
  49.         Toast.makeText(this,"Roy the Faigale", Toast.LENGTH_SHORT).show()
  50.         return true
  51.     }
  52.  
  53.     override fun onDoubleTap(e: MotionEvent?): Boolean {
  54.         gestureStatusText.text = "on double tap"
  55.         return true
  56.     }
  57.  
  58.     override fun onDoubleTapEvent(e: MotionEvent?): Boolean {
  59.         gestureStatusText.text = "on double tap"
  60.         return true
  61.     }
  62.  
  63.     override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
  64.         gestureStatusText.text = "on single tap confirmed"
  65.         return true
  66.     }
  67.  
  68.     override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
  69.         gestureStatusText.text = "on scroll"
  70.         return true
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top