User Interaction Radan Ganchev Astea Solutions. Content Basic input events Gestures Drag and drop Sensors.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Object-Oriented Programming with Java The Java Event Model Lecture 5.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
Button click handlers Maarten Pennings. Introduction An activity has one or more views – view is also known as widget or control – examples include Button,
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
Object-Oriented Programming with Java Lecture 2 The Java Event Model.
1 Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources, Listener 10/9/2012 Y. Richard Yang.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Sensing. Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla)
Welcome to CIS 083 ! Events CIS 068.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
CS378 - Mobile Computing More UI - Part 2. Special Menus Two special application menus – options menu – context menu Options menu replaced by action bar.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Working in the Background Radan Ganchev Astea Solutions.
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
Omer Boyaci.  GUIs are event driven.  When the user interacts with a GUI component, the interaction—known as an event—drives the program to perform.
Mobile Programming Lecture 12 HierarchyViewer, Linkify, Gestures, and Version Control.
Copyright© Jeffrey Jongko, Ateneo de Manila University Editing ListAdapter Data part 2.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
Object Oriented Programming.  Interface  Event Handling.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
Handling View Events. Open the *MainActivity.java* which is the Activity that hosts the layout in "activity_main.xml". The setContentView method inside.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
Android View Stuff. TextViews Display text Display images???
Sensors in android. App being more applicable Keeping track of your heart beat while jogging. Pointing the phone camera towards the night sky to know.
Activities Димитър Н. Димитров Astea Solutions AD.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
CS378 - Mobile Computing More UI - Part 2. Special Menus Two special application menus – options menu – context menu Options menu replaced by action bar.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
Jaeki Song ISQS6337 JAVA Lecture 10 Applets. Jaeki Song ISQS6337 JAVA Applet Applets run within the Web browser environment –Applets bring dynamic interaction.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
CHAPTER 7 TouchGestures. Chapter objectives: To code the detection of and response to touch gestures. Patterns of common touches to create touch gestures.
The Doodlz app enables you to paint by dragging one or more fingers across the screen. The app provides options for setting the drawing color.
Building UI Components Димитър Н. Димитров Astea Solutions AD.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
CS371m - Mobile Computing Gestures. Common Gestures 2.
Vijay Kumar Kolagani Dr. Yingcai Xiao
TUTORIAL ON MULTITOUCH AND SWIPE GESTURES
Applets.
Android – Event Handling
Sensors, maps and fragments:
Vijay Kumar Kolagani Dr. Yingcai Xiao
Mobile Application Development BSCS-7 Lecture # 11
Programming in Java Event Handling
Android 16: Input Events Kirk Scott.
Mobile Computing With Android ACST 4550 Android Logs and Gestures
Chapter 2: GUI API Chapter 2.
Event Driven Programming
The mouse controls the movement of the pointer on your screen.
Introduction to Computing Using Java
Cannon Game App Android How to Program
Android Topics Custom ArrayAdapters
CS371m - Mobile Computing Gestures.
Event Driven Systems and Modeling
Android Developer Fundamentals V2
Mobile Programming Dr. Mohsin Ali Memon.
Mobile Programmming Dr. Mohsin Ali Memon.
Presentation transcript:

User Interaction Radan Ganchev Astea Solutions

Content Basic input events Gestures Drag and drop Sensors

Basic Input Events

Key events Track Touch events Other

Key Event Sources

Other event sources Touch events Trackball events

Other events Click ‣ Touch a clickable view ‣ Focus a view and press the action button ‣ Call view.performClick() Long click ‣ Same as click. It’s just... longer

Other events Focus change ‣ Use DPad to select another view ‣ Call view.requestFocus() Create context menu ‣ Long click a view which is registered for context menu

Handling events Register an event listener OnEventListener listener = new OnEventListener() { public void / boolean onEvent(...) {...} }; view.setOnEventListener(listener);

Handling events Register an event listener OnEventListener listener = new OnEventListener() { public void / boolean onEvent(...) {...} }; view.setOnEventListener(listener); Key Touch FocusChange CreateContextMenu Click LongClick

Handling events Register an event listener OnClickListener listener = new OnClickListener() { public void onClick(View view) {...} }; view.setOnClickListener(listener); Click listener example:

Handling events Extend View and override a method ‣ onKeyDown ‣ onKeyUp ‣ onTrackballEvent ‣ onTouchEvent ‣ onFocusChanged ‣ others...

The InputEvent object Holds the event parameters Comes in two flavors - KeyEvent and MotionEvent You receive it as an argument in your callback Some methods worth mentioning: ‣ getAction() ‣ getKeyCode() ‣ getX(), getY()

Event propagation Activity dispatch***Event

Event propagation Activity dispatch***Event Window dispatch DecorView Target View dispatch...

Event propagation Activity dispatch***Event Window dispatch DecorView Target View dispatch... bubble... bubble

Event propagation Activity dispatch***Event Window dispatch DecorView Target View dispatch... bubble... bubble View target =...; if (target.dispatchTouchEvent(...)) { return true ; } return onTouchEvent(...);

Gestures

What is a gesture? A series of touch events with pre-defined behavior Common gestures: FlingLong PressPinchScroll

Detecting Gestures The easy way: 1. Create a gesture listener - either implement OnGestureListener or extend SimpleOnGestureListener 2. Create a GestureDetector with your gesture listener 3. Pass all touch events of your view to the GestureDetector

Detecting Gestures The hard way: 1. Handle touch events for your view 2. Inspect the history of pointer movement and detect patterns - too messy for this lecture 3. Make sure no one steals your events - even messier... Involves methods like onInterceptTouchEvent and requestDisallowInterceptTouchEvent

Drag & Drop

Available since API level 11 (Android 3.0.x) Only works within a single application Allows users to move data (and other stuff) within your Activity layout

Drag & Drop Workflow Register OnDragListener s for each View you want to support drag & drop Call view.startDrag() whenever you decide, e.g. when view is long pressed Respond to the incoming drag events through your OnDragListener s

Drag & Drop Example

DRAG_STARTED startDrag()

Drag & Drop Example DRAG_STARTED DRAG_ENTERED startDrag()

Drag & Drop Example DRAG_STARTED DRAG_ENTERED DRAG_LOCATION DRAG_EXITED startDrag()

Drag & Drop Example DRAG_STARTED DRAG_ENTERED DRAG_LOCATION DRAG_EXITED DRAG_ENTERED startDrag()

Drag & Drop Example DRAG_STARTED DRAG_ENTERED DRAG_LOCATION DRAG_EXITED DRAG_ENTERED DRAG_LOCATION startDrag()

Drag & Drop Example DRAG_STARTED DRAG_ENTERED DRAG_LOCATION DRAG_EXITED DRAG_ENDED DRAG_ENTERED DRAG_LOCATION DROP DRAG_ENDED startDrag()

Sensors

Android currently supports 11 types of sensors: ‣ Accelerometer ‣ Gyroscope ‣ Magnetic field sensor ‣ Ambient temperature sensor, etc...

Using Sensors Sensors are accessed through the SensorManager system service The workflow is as follows: 1. Obtain a reference to the SensorManager 2. Check if the sensor you need is present 3. Register a listener to activate the sensor 4. Unregister the listener when you’re done!

Q & A Questions? Feedback section: ‣ Did you hear well? ‣ Was there anything you didn’t understand? ‣ What would you like changed in our next lecture?

Resources Input Events GestureDetector documentation Drag and Drop SensorManager documentation