Android Hacks - Hack21

  • Published on
    24-May-2015

  • View
    803

  • Download
    2

Embed Size (px)

DESCRIPTION

Android Hacks & ()http://www.oreilly.co.jp/books/9784873114569/

Transcript

  • 1. ANDROID HACKS #21 tsuruoka 09/19/11

2.

    • Android Hacks
    • http://www.oreilly.co.jp/books/9784873114569/

09/19/11 3.

  • Hack21
      • Fling

09/19/11 4. Hack21.

      • Fling

09/19/11 5. Hack21.

  • Motion
    • OnGestureListener
  • OnGestureListener
    • onDown
    • onFling
    • onLongPress
    • onScroll
    • onShowPress
      • onLongPress
    • onSingleTapUp

09/19/11 6. Hack21

  • Activity implements onGestureListener
    • GestureDetector gestureScanner
  • onCreate
    • gestureScanner = new GestureDetector(this)
  • Public boolean onTouchEvent(MotionEvent me)
  • return gestureScannner.onTouchEvent(me)

7. Hack21

  • onTouchEvent logcat
  • 02-11 17:04:11.792: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.792: DEBUG/mydbg(18605): onDown
  • 02-11 17:04:11.792: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.825: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.852: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.852: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:11.882: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.882: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:11.912: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:11.912: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:11.933: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:12.272: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:12.302: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:12.302: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:12.332: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:12.332: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:12.352: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:12.352: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:12.385: DEBUG/mydbg(18605): onTouchEvent
  • 02-11 17:04:12.385: DEBUG/mydbg(18605): onScroll
  • 02-11 17:04:12.385: DEBUG/mydbg(18605): onTouchEvent

8. Hack21

  • (Fling)
  • 02-11 17:45:47.852: DEBUG/mydbg(21436): onDown
  • 02-11 17:45:47.952: DEBUG/mydbg(21436): onShowPress
  • 02-11 17:45:48.242: DEBUG/mydbg(21436): onScroll
  • 02-11 17:45:48.432: DEBUG/mydbg(21436): onScroll
  • 02-11 17:45:48.442: DEBUG/mydbg(21436): onFling

9. Hack21

  • 02-11 17:47:02.322: DEBUG/mydbg(21436): onDown
  • 02-11 17:47:02.422: DEBUG/mydbg(21436): onShowPress
  • 02-11 17:47:02.652: DEBUG/mydbg(21436): onSingleTapUp
  • 02-11 17:47:05.542: DEBUG/mydbg(21436): onDown
  • 02-11 17:47:05.612: DEBUG/mydbg(21436): onSingleTapUp

10. Hack21

  • 02-11 17:10:14.032: DEBUG/mydbg(18916): onDown
  • 02-11 17:10:14.133: DEBUG/mydbg(18916): onShowPress
  • 02-11 17:10:14.632: DEBUG/mydbg(18916): onLongPress
  • onLongPress gesture
  • onScroll

11. Hack21

    • android-sdk-windowsplatformsandroid4samplesGestureBuilder
      • GestureBuilder gestures SD card
      • Res/raw/gestures
      • gestures

12. Hack21

  • tureBuilder

13. Hack21

  • View
    • Private GestureLibrary mLibrary
  • onCreate
    • mLibrary = GestureLibraries.fromRawResource(this,R.raw.gestures);
      • gestures
    • GestureOverlayview gestures = (GestureOverlayView)findViewById(R.id. XXX )
      • XXX GestureOverlayView id
    • Gestures.addOnGesturePerformedListener(this)

14. Hack21

  • public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
  • Log. d ("mydgb", "onGesturePerformed");
  • ArrayList predictions = mLibrary.recognize(gesture);
  • // We want at least one prediction
  • if (predictions.size() > 0) {
  • Prediction prediction = predictions.get(0);
  • // We want at least some confidence in the result
  • if (prediction.score > 1.0) {
  • // Show the spell
  • Toast. makeText (this, prediction.name, Toast. LENGTH_SHORT ).show();
  • }
  • }else{
  • Toast. makeText (this, "Such gesture isn't registered.", Toast. LENGTH_SHORT ).show();
  • }
  • }

15. Hack21

  • AndroidHacks