Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Android How to Program Chapter 09 Solution Manual


 

Download  file with the answers

If you are not a member register here to download this file 


 

9 Doodlz App
Objec t ives
In this chapter you’ll:
■ Detect when the user touches
the screen, moves a finger
across the screen and
removes a finger from the
screen.
■ Process multiple screen
touches so the user can draw
with multiple fingers at once.
■ Use a SensorManager to
detect accelerometer motion
events to clear the screen
when the user shakes the
device.
■ Use an AtomicBoolean
object to allow multiple
threads to access a boolean
value in a thread-safe
manner.
■ Use a Paint object to
specify the color and width of
a line.
■ Use Path objects to store
each line’s data as the user
draws the lines and to draw
those lines with a Canvas.
■ Use a Toast to briefly
display a message on the
screen.
Self-Review Exercises 2
Self-Review Exercises
9.1 Fill in the blanks in each of the following statements:
a) Android 3.0’s look-and-feel is called the .

b) You use the SensorManager to register the sensor changes that your app should receive
and to specify the that will handle those sensor-change events.

c) A Path object (package android.graphics) represents a geometric path consisting of
line segments and .

d) We use the type of the touch event to determine whether the user has touched the
screen, or lifted a finger from the screen.

e) Use class SensorManager’s method to stop listening for accelerometer
events.

f) Override SensorEventListener method to process accelerometer events.

g) Use Dialog’s method to close a dialog.

h) When a View needs to be redrawn, it’s method is called.

i) MotionEvent’s method returns an int representing the MotionEvent
type, which you can use with constants from class MotionEvent to determine how to
handle each event.

j) The utility method is called when the user moves one or more fingers
across the screen.

k) Toast method receives as arguments the Context on which the Toast is
displayed, the message to display and the duration for which the Toast will be displayed.

9.2 State whether each of the following is true or false. If false, explain why.
a) (True/False) We use the standard SeekBar thumb in our apps, but you can customize it
by setting the SeekBar’s android:seekBar attribute to a drawable resource, such as an
image.

b) (True/False) You unregister the accelerometer event handler when the app is sent to the
foreground.

c) (True/False) Call the inherited View method validate to indicate that the View needs to
be redrawn.

3 Chapter 9 Doodlz App
d) (True/False) If the action is MotionEvent.ACTION_DOWN or Motion-
Event.ACTION_POINTER_DOWN, the user touched the screen with the same finger.

e) (True/False) Resetting the Path erases its corresponding painted line from the screen,
because those lines have already been drawn to the bitmap that’s displayed to the screen.

because those lines have already been drawn to the bitmap that’s displayed to the
screen.
Exercises
9.3 Fill in the blanks in each of the following statements:
a) Most Android devices have an that allows apps to detect movement.

b) A (package android.widget) displays a message for a short time, then disappears
from the screen.

c) The monitors the accelerometer to detect device movement.

d) SensorManager’s constant represents the acceleration due to gravity on
earth.

e) We register to receive accelerometer events using SensorManager’s registerListener
method, which receives three arguments: the SensorEventListener object that will respond
to the events, a Sensor representing the type of sensor data the app wishes to receive
and .

f) We pass true to Paint’s method to enable anti-aliasing which smooths the
edges of the lines.

g) Method sets paintLine’s stroke width to the specified number of pixels.

h) Android supports —that is, having multiple fingers touching the screen.

i) The utility method is called when the user lifts a finger from the screen.
The method receives the ID of the finger (lineID) for which the touch just ended as an
argument.

9.4 State whether each of the following is true or false. If false, explain why.
a) (True/False) In Android, sensor events are handled in the GUI thread.

b) (True/False) The alpha component specifies the Color’s transparency with 0 representing
completely transparent and 100 representing completely opaque.

Exercises 4
c) (True/False) For accelerometer events, the SensorEvent parameter values array contains
three elements representing the acceleration (in meter/second2) in the x (left/
right), y (up/down) and z (forward/backward) directions.

d) (True/False) Method onProgressChanged is called once when the user drags a SeekBar’s
thumb.

thumb.
e) (True/False) To get the finger’s unique ID that persists across MotionEvents until the
user removes that finger from the screen, we’ll use MotionEvent’s getID method, passing
the finger index as an argument.

f) (True/False) The system MotionEvent passed from onTouchEvent contains touch information
for multiple moves on the screen if they occur at the same time.

g) (True/False) Toast method setLocation specifies where the Toast will appear. The constant
Gravity.CENTER indicates that the Toast should be centered over the coordinates
specified by the method’s second and third arguments. Toast method show displays the
Toast.

h) (True/False) Use a ToastMessage to display a message that automatically disappears after
a short period of time.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!