GSR35MDP
GSR35MDP
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)
Projected Capacitance
• More accurate / multi-touch
• Sensing requires an “active” touch
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
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
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
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
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
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