ANDROID – GESTURES L. Grewe. What and why  a great way to interact with applications on mobile devices.  With a touch screen, users can easily tap,

Slides:



Advertisements
Similar presentations
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Advertisements

CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
ASENT_MTTR.PPT Maintainability Predictions Last revised 8/11/2005.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Touch & Gestures.  MotionEvents  Touch Handling  Gestures.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Chapter 2 Querying a Database
BoardMaker Ver 6 Creating Interactive Activities for the Classroom.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Android Application Development 2013 PClassic Chris Murphy 1.
Adding Websites to a Folder  Putting sites into an already existing folder Putting sites into an already existing folder  Adding an image on the icon.
CS378 - Mobile Computing What's Next?. Fragments Added in Android 3.0, a release aimed at tablets A fragment is a portion of the UI in an Activity multiple.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
‘ {] Chapter 2 (HW01) Getting Started with Windows 7.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
Download Dropbox Download should start immediately Save download file:
Copyright 2007, Information Builders. Slide 1 WebFOCUS Maintain – Enhancing Objects with JavaScript Mark Derwin Information Builders Information Builders.
Basic Android Tutorial USF’s Association for Computing Machinery.
DUE Hello World on the Android Platform.
1 Mobile Computing Advanced Touching Copyright 2014 by Janson Industries Assg Part1Assg Part1 AssgPart2AssgPart2.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
CS378 - Mobile Computing More UI - Part 2. Special Menus Two special application menus – options menu – context menu Options menu replaced by action bar.
Go to your school’s web locker site school name.schoolweblockers.com) Your user name is the first letter of your first name, the first 4.
Android Boot Camp for Developers Using Java, 3E
User Interfaces: Part 1 (View Groups and Layouts).
Android – Fragments L. Grewe.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Mobile Programming Lecture 12 HierarchyViewer, Linkify, Gestures, and Version Control.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 11 Animation and TraceView.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
CS378 - Mobile Computing More UI - Part 2. Special Menus Two special application menus – options menu – context menu Options menu replaced by action bar.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Intoduction to Andriod studio Environment With a hello world program.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
CHAPTER 7 TouchGestures. Chapter objectives: To code the detection of and response to touch gestures. Patterns of common touches to create touch gestures.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Cosc 5/4730 Support design library. Support Design library Adds (API 9+) back support to a number of 5.0 lollipop widgets and material design pieces –
CS371m - Mobile Computing Gestures. Common Gestures 2.
Chapter 2: Simplify! The Android User Interface
Introduction to android
TUTORIAL ON MULTITOUCH AND SWIPE GESTURES
Android – Event Handling
Mobile Application Development BSCS-7 Lecture # 8
Creation of an Android App By Keith Lynn
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Mobile Computing With Android ACST 4550 Android Logs and Gestures
Program and Graphical User Interface Design
CS5103 Software Engineering
Cannon Game App Android How to Program
CS371m - Mobile Computing Gestures.
Android Developer Fundamentals V2
Fraedom Approvals Presentation
Interactive Graphics in Android
Mobile Programming Gestures in Android.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

ANDROID – GESTURES L. Grewe

What and why  a great way to interact with applications on mobile devices.  With a touch screen, users can easily tap, drag, fling, or slide to quickly perform actions in their favorite applications.  Android framework makes it's easy to recognize simple actions, like a swipe,  new gestures API in Android 1.6. lets developer recognize more complicated gestures.  package android.gesture, : store, load, draw, and recognize gestures. android.gesture

Creating a gestures library  Gestures Builder  application pre-installed on the emulator,  create a set of pre-defined gestures for your own application (rather than the standard set) Here is example with a few gestures already created Because store files in SD card: make sure to create an AVD with an SD card image to use Gestures Builder.

Defining your own Gestures  Gesture associated with a name  names do not have to be unique.  scan be very useful to have several gestures with the same name to increase the precision of the recognition.

Defining your own Gestures  GestureBuilder:  Every time you add or edit a gesture in the Gestures Builder, a file is generated on the emulator's SD card, /sdcard/gestures.  file contains the description of all the gestures  you will need to package it inside your application inside the resources directory, in /res/raw. move the generated /sdcard/gestures file to your /rese/raw folder in your project Android Studio (create raw directory) locate and right-click on the res folder (located under app) and select New -> Directory

How to move file  See outline for web page  FileExplorer tab (either Android Device Manager or DDMS in ecluspe view)  Go to /sdcard directory and copy the gesture file to your computer, for example on your desktop.  To copy the gesture file from the emulator, select it and click the “Pull a file from the device” button, marked with red in the screenshot below:  Don’t forget to create a new folder called raw in the res directory of your project and copy there the gesture file. Go to Android Device Manager to get to FileExporer

How to move file  For emulator called “emulator-5554” and puts it in the current directory of cmd prompt window  adb -s emulator-5554 pull /sdcard/gestures.  For a device and puts it in the current directory of cmd prompt window  adb -d pull /sdcard/gestures. Can do the following for command line

Loading the gestures library  load it inside your application. Assuming the name of the file is R.raw.spells (res/raw/spells.xml) mLibrary = GestureLibraries.fromRawResource(this,R.raw.spells); if (!mLibrary.load()) { finish(); } NOTE: here the gestures file is called spells.xml

Recognizing gestures  add a GestureOverlayView to your XML layout: A simple drawing board on which user can draw gestures. can alter properties: color, width of the stroke used to draw gestures,  i.e. res/layout/main.xml contains NOTE: you must use android.gesture.GestureOverlayView --- its fully qualified name.

Register Listener for User Drawing on GestureOverlayView  Commonly used listener is GestureOverlayView.OnGesturePerformedListener  Typically do in onCreate of Activity, here the Activity is the listener GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures); gestures.addOnGesturePerformedListener(this);

Listener Code -- class implementing GestureOverlayView.OnGesturePerformedListener RECOGNIZE  get sent gesture in the onGesturePerformed method:  call GestureLibrary.recognize(gesture) to get a list of Prediction instances,  each with a name - the same name you entered in the Gestures Builder –  each with a score.  list is sorted by descending scores;  higher the score more likely the associated gesture is the one the user intended to draw

Listener Code -- class implementing GestureOverlayView.OnGesturePerformedListener RECOGNIZE public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { //this call asks to recognize the gesture against loaded gesture library ArrayList predictions = mLibrary.recognize(gesture); // We want at least one prediction if (predictions.size() > 0) { Prediction prediction = predictions.get(0); //get the 1st prediction auto generated for you by Android // 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(); } } } NOTE: 1st prediction is taken into account only if it's score > 1.0 NOE: Scores < 1.0 are typically poor matches.

Gestures overlay  GestureOverlayView was used as a normal view  OR it can also be used as an overlay on top of other views. This can be useful to recognize gestures in a game or just anywhere in the UI of an application.  Example: GesturesListDemo, we'll create an overlay on top of a list of contacts. XML Layout -- scroll orientation of view underneath is vertical thus, any horizontal drawing know right away gesture

GestureListDemo  gestures view is an overlay on top of a regular ListView. PROPERTIES  gestureStrokeType: indicates whether we want to recognize gestures made of a single stroke or multiple strokes. Since one of our gestures is the "+" symbol, we need multiple strokes  eventsInterceptionEnabled: when set to true, this property tells the overlay to steal the events from its children as soon as it knows the user is really drawing a gesture. This is useful when there's a scrollable view under the overlay, to avoid scrolling the underlying child as the user draws his gesture  orientation: indicates the scroll orientation of the views underneath. In this case the list scrolls vertically, which means that any horizontal gestures (like action_delete) can immediately be recognized as a gesture. Gestures that start with a vertical stroke must contain at least one horizontal component to be recognized. In other words, a simple vertical line cannot be recognized as a gesture since it would conflict with the list's scrolling.

GestureListDemo  The code used to load and set up the gestures library and overlay is exactly the same as before public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { ArrayList predictions = mLibrary.recognize(gesture); if (predictions.size() > 0 && predictions.get(0).score > 1.0) { String action = predictions.get(0).name; //get the name of the predicted gesture if ("action_add".equals(action)) { Toast.makeText(this, "Adding a contact", Toast.LENGTH_SHORT).show(); } else if ("action_delete".equals(action)) { Toast.makeText(this, "Removing a contact", Toast.LENGTH_SHORT).show(); } else if ("action_refresh".equals(action)) { Toast.makeText(this, "Reloading contacts", Toast.LENGTH_SHORT).show(); } } } Names of Gestures: “action_add” “action_delete” “action_refresh”

You can Also recognize standard Gestures without setting them up Example, screen shot where did a swipe from left to right ---- called a "Fling“ public class Gesture_SwipeCoded2 extends Activity implements OnGestureListener { private LinearLayout main; private TextView viewA; private GestureDetector public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureScanner = new GestureDetector(this); main = new LinearLayout(this); main.setBackgroundColor(Color.GRAY); main.setLayoutParams(new LinearLayout.LayoutParams(320,480)); viewA = new TextView(this); viewA.setBackgroundColor(Color.YELLOW); viewA.setTextColor(Color.BLACK); viewA.setTextSize(16); viewA.setLayoutParams(new LinearLayout.LayoutParams(320,80)); main.addView(viewA); setContentView(main); }

public boolean onTouchEvent(MotionEvent me) { return gestureScanner.onTouchEvent(me); public boolean onDown(MotionEvent e) { viewA.setText("-" + "DOWN" + "-"); return true; public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { viewA.setText("-" + "FLING" + "-"); return true; }

public void onLongPress(MotionEvent e) { viewA.setText("-" + "LONG PRESS" + "-"); public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { viewA.setText("-" + "SCROLL" + "-"); return true; public void onShowPress(MotionEvent e) { viewA.setText("-" + "SHOW PRESS" + "-"); public boolean onSingleTapUp(MotionEvent e) { viewA.setText("-" + "SINGLE TAP UP" + "-"); return true; } }