0% found this document useful (0 votes)
10 views11 pages

GSR35MDP

Notes on Mobiles device programming for level 300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

GSR35MDP

Notes on Mobiles device programming for level 300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

lOMoARcPSD|51022864

Sample/practice exam January 2017, answers

Mobile Device Programming (University of Nottingham)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Bles Sings ([email protected])
lOMoARcPSD|51022864

Describe how you would make use of all four of the major Android components in
the software design of the application, detailing the tasks that you might expect the
user to perform, the function of each component, and how the components are
related and make use of one another.

Activity
Provide UI element to control the application (e.g. start tracking).
Communicate / inform Service to start or stop when user clicked (touched) the button.
Receive broadcast, display the info onto UI allow the user to keep track.
Allow user to view the past record by retrieving data stored in the SQLite database through
content provider.
Service
Use the location API built-in to use the GPS of the phone.
When service is started, get location info such as coordinates (longitude and latitude) and
distance.
When the service is stop, store the distance, date and duration info into the phone storage
through Content Provider.
Broadcast Receiver
The info obtained in the service can be pass to activity through broadcast receiver by
broadcasting locally (only this app can get).
Content Provider
Allow the app to store data in the form of database (SQLite)

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Capacitive Touch Screen


• Screen is covered in a capacitive material
Capacitance = ability to store electric charge (Works through glass)
• Human beings act as small capacitors
• Apply a small voltage to generate an electrostatic field
- Touching with a finger creates a dynamic capacitor
• Measure effective capacitance at each corner of the screen
-The larger the change, the closer to the corner the touch is
-Combine measurements from all corners = location of the touch

Projected Capacitance
• More accurate / multi-touch
• Sensing requires an “active” touch

Touch relies on finger contact with the display


• Make the button
bigger
• Haptic or lasting visual feedback
• Best use of space (e.g. full screen width button)
• Break tasks into small & discrete Activities
Designing for Multiple Screens
• Use "wrap_content" and "match_parent"
• Use RelativeLayout
Provide alternative bitmaps for different screen resolutions (put in res/drawable-xhdpi;
drawable-hdpi; drawable-mdpi; drawable-ldpi)

A gesture is a series of touch events that occur over a period of time

• Handle a sequence of events


– TouchBegin
– TouchMoved
– TouchEnded

Two ways to get touch events:


-Register a new OnTouchListener with a view, (with setOnTouchListener(…))
-Implement onTouchEvent() in a View

MotionEvent encapsulates info of:


1. Touch events
a. Touch begins (ACTION_DOWN)
b. Finger move (ACTION_MOVE)
c. Touch ends (ACTION_UP)
2. X,Y coordinates of touch, pressure, size and orientation
3. Additional info for multitouch  pointer id, action index

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Action Down
• A gesture starts when a finger is pressed
• A MotionEvent is generated for this ACTION_DOWN
• Can find the action by calling getAction()
• This can also have the identifier of the ‘pointer’ so use getActionMasked() instead
(for multi-touch).
ActionMove
• As the finger moves, a series of
ACTION_MOVE events will be sent
• Can find the new position using getX() and getY() (return floats)
Action Up
• A gesture ends in three ways:
-ACTION_UP event (i.e. last finger has been taken off the display)
-ACTION_CANCEL event (e.g. phone rings)
-ACTION_OUTSIDE event if the finger moves outside the relevant view
Single Touch
• A touch gesture is formed by
– A single ACTION_DOWN
– Zero or more ACTION_MOVE
– An ACTION_UP to finish
• Single-touch interactions
– Positions are tracked to move an object
– Use movement velocity for a swipe / fling
Dragging / Scrolling
• Store the original x, y touch location from ACTION_DOWN
• Calculate changes from stored value and value returned from ACTION_MOVE
or ACTION_UP
• Adding the coordinate changes to the original object location
Swipe / Fling
• Rather than moving the object, calculate the velocity and direction
• On ACTION_UP, continue to move the object with that velocity
• Gives the user an obvious visual feedback of “flinging” UI elements across the
screen

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Multi-touch
• Very similar to single touch
• Same sequence of events as before with a few more events (e.g.
ACTION_POINTER_DOWN and ACTION_POINTER_UP)
• Index: position within an array in a MotionEvent
• ID: Unique for each pointer to allow tracking individual pointer across the entire
gesture
• Number of pointers can change as fingers are lifted or placed, so does the indices of the
pointers.
Pinch to Zoom
• Obtain the IDs of the two pointers
• Obtain the location of each pointer
• Calculate and store the distance between the two pointers
• The ratio of new distance to the old one gives the zoom ratio
• Rescale the object using the ratio

Two-finger rotation
• Obtain the IDs of the two pointers
• Use the vertical and horizontal location difference to calculate the initial
angle
• Obtain the new locations of the two pointers to derive the new angle
• Object (e.g. photos) can be rotated using the angle difference

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Differences between touch-based interaction vs mouse-driven interface. Effect on design.


Touch-based has relatively low precision as compared to mouse-driven. The surface of finger is
larger than mouse cursor, which might cause mistouched on UI element that is not intended.
The impact is the size of the UI element is now designed bigger.
Number of points. Android application support more control than mouse driven. Touch based
allow more points to control (Android device support 2 points or more up to 256 points). The
impact, allow the app to have more gesture control providing extra functionalities, such as pinch
to zoom and 2 finger rotation.

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

UI design, spacing between UI must be big enough to avoid unintended mistouched. Else, hard
for user to work accurately
Size is fixed in relative to display. -> use relative layout
Use “wrap_content” and “match_parent”
Use portrait and landscape
Break tasks into small & discrete activities
Capacitive touch screen vs Resistive touch screen

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Activity Lifecycle
1. Active
a. In the foreground
2. Paused
a. Still visible, but not top
3. Stopped
a. Obscured by another activity
If paused or stopped, the system can drop the Activity from memory
• Stopped activities are suspended in memory
o Consume no processing resources
• Inactive activities are destroyed if memory is required
o Oldest first

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Activity Lifecycle Callback Methods


• onCreate() – called when the activity is first created.
• onRestart() – Called when the activity is about to restart after having previously been stopped by
the runtime system.
• onStart()
– Always called immediately after the call to the onCreate() or onRestart() methods
– indicates to the activity that it is about to become visible to the user.
– followed by a call to onResume() if the activity moves to the top of the activity stack,
or onStop() if it is
pushed down the stack by another activity.
• onResume() – Indicates that the activity is now at the top of the activity stack and is the activity
with which the user is currently interacting.
• onPause()
– Indicates that a previous activity is about to become the foreground activity.
– followed by a call to either the onResume() or onStop() method depending on
whether the activity moves
back to the foreground or becomes invisible to the user.
• onStop()
– The activity is now no longer visible to the user.
– followed by a call to onRestart() if the activity moves to the foreground again, or
onDestroy() if the activity is
being terminated.
• onDestroy() – The activity is about to be destroyed, either
– because the activity has completed its tasks and has called the finish() method
– because the runtime is terminating it either to release memory
– due to a configuration change (such as the orientation of the device changing).
– note that a call will not always be made to onDestroy() when an activity is terminated.

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

Android Processes
1. Processes host apps
a. Apps are made up of components
b. Process can be in one of the 5 states at any given time:
i. Foreground Process  (Highest Priority)
ii. Visible Process
iii. Service Process
iv. Background Process
v. Empty Process  (Lowest Priority)

2. Foreground Process
a. Last to be terminated by system
b. Criteria:
i. Hosts an activity which the user is currently interacting
ii. Hosts a service connected to the activity which the user is
interacting
iii. Hosts a Service that has indicated, via a call to startForeground(),
that termination would be disruptive to the user experience
iv. Hosts a Service executing either its onCreate(), onResume() or
onStart() callbacks

Downloaded by Bles Sings ([email protected])


lOMoARcPSD|51022864

v. Hosts a Broadcast Receiver that is currently executing its


onReceive() method
3. Visible Process
a. A process containing an activity that is visible but is not the activity
with which the user is interacting
i. Partial screen or dialog in the foreground
ii. Hosts a service that is bound to a visible or foreground activity
4. Service Process
a. Processes that contain a Service that has already been started and is
currently executing
5. Background Process
a. A process that contains 1 or more activities that are not currently visible to
the user, and does not host a Service that qualifies for Service Process
status.
b. Terminated when additional memory needs to be freed for higher priority
processes
6. Empty Process
a. Empty processes no longer contain any active applications and are held in
memory ready to serve as hosts for newly launched apps
b. First to be killed to free up resources

Intent intent = new Intent(this, HelloService.class);


startService(intent);

Stopping a service
A started service must manage its own lifecycle. That is, the system does not stop or destroy the
service unless it must recover system memory and the service continues to run
after onStartCommand() returns. The service must stop itself by calling stopSelf(), or another
component can stop it by calling stopService().

Once requested to stop with stopSelf() or stopService(), the system destroys the service as soon
as possible

Downloaded by Bles Sings ([email protected])

You might also like