Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Computing With Android ACST 4550 Android Logs and Gestures

Similar presentations


Presentation on theme: "Mobile Computing With Android ACST 4550 Android Logs and Gestures"— Presentation transcript:

1 Mobile Computing With Android ACST 4550 Android Logs and Gestures

2 Logs When your Android App is running on a connected device or an emulator you can capture real-time log messages in the LogCat (for Log Catalog) window. The messages are itemized in the LogCat window by Log Level, TimeStamp, Process ID, Task ID, Application Name (if not generated by the OS), Tag String and Text Message String. The messages are color-coded in the LogCat window like so:

3 Logs There are 5 standard Levels of Logs being generated continuously by the runtime environment, each with their own color. And for your own debugging purposes you can generate your own Logs with your own Tag strings and Message strings with the following commands: Debug – Blue – Command: Log.d(TagString, MessageString); Error Logs – Red – Command: Log.e(TagString, MessageString); Info Logs – Green – Command: Log.i(TagString, MessageString); Verbose Logs – Black – Command: Log.v(TagString, MessageString); Warning Logs – Orange – Command: Log.w(TagString, MessageString);

4 The Android Gesture Listener
The Android is an operating system for a touch screen device, and as such, it allows for a range of various types of touch events. The following is description of four of the types of touch events that are available (there are others as well): Touch or Tap: The user taps the screen once Double Tap: The user taps the screen twice Long press: The user touches the screen and holds their finger in position Fling: The user touches the screen and quickly flicks their finger across the screen in the direction they’d like to move. Because these events are connected to the screen, the listener for these events (the “Gesture Listener”) is part of the View class and not the Activity class, where normal Controller code should be.

5 The SimpleOnGestureListener
The easiest “Gesture Listener” or “Gesture Detector” to use is called the SimpleOnGestureListener. It can be invoked inside of the onTouchEvent() handler inside of a view. To respond to a gesture you use one of the following methods: public boolean onDown(MotionEvent e) Notified when a tap occurs with the down MotionEvent that triggered it. public void onLongPress(MotionEvent e) Notified when a long press occurs with the initial on down MotionEvent that trigged it. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) Notified of a fling event with the on down MotionEvent and matching up MotionEvent. public boolean onSingleTapUp(MotionEvent e) Notified when a tap occurs with the up MotionEvent that triggered it. public boolean onSingleTapConfirmed(MotionEvent e) Notified when a single-tap occurs. public boolean onDoubleTap(MotionEvent e) Notified when a double-tap occurs.

6 The SimpleOnGestureListener
The SimpleOnGestureListener class has no method bodies for the Gesture Listener methods (like an Adapter class) so you inherit from it and then override the method handlers you want to use: private class GestureListener extends SimpleOnGestureListener { @Override public boolean onDown(MotionEvent e) { // your handler code goes here return true; } public void onLongPress(MotionEvent e) { The above example just uses the onDown() and onLongPress() methods, but you could use any of the others as well.

7 The SimpleOnGestureListener
You don’t need to use all the SimpleOnGestureListener methods but if you want to use any of them, then you must include the onDown() method and it must return true, because the other methods aren’t activated until that method returns true. In the previous example, you’d first declare a GestureDectector: private GestureDetector gestureDetector; Then instantiate it in your constructor with your Listener like so: gestureDetector = new GestureDetector(context, new GestureListener()); Then you call your handlers from the onTouchEvent() like so: public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); }

8 The SimpleOnGestureListener
You might decide to only use the onDown() method handler if you just care about a single touch on the screen. But if you are interested in Double Taps and Single Taps, then you will need to use the onSingleTapConfirmed() method to verify that a Single Tap is not just the first part of a Double Tap. All of the method handlers are passed a MotionEvent object, which includes numerous details about the touch event that triggered that method being called, such as the location of the touch, the time the event started, how long it took, and even how much pressure was applied, among other things.

9 The SimpleOnGestureListener
In this first example, the onDown() method is used to simply start and stop the waving animation of the Snowman, and in this case we don’t care about Double Taps. Example #1: SnowmanOneGestureView.java The second example handles four gestures, including Single Tap and Double Tap, so onDown() is not directly used, but it still must return true. The four gestures being supported are: Single Tap: Start or Stop the waving Double Tap: Does nothing Long press: Randomly change the color of the Snowman Fling: Make the Snowman white again. Example #2: SnowmanFourGesturesView.java


Download ppt "Mobile Computing With Android ACST 4550 Android Logs and Gestures"

Similar presentations


Ads by Google