Android How To Program 3rd Edition By Deitel & Deitel – Test Bank A+

$35.00
Android How To Program 3rd Edition By Deitel & Deitel – Test Bank A+

Android How To Program 3rd Edition By Deitel & Deitel – Test Bank A+

$35.00
Android How To Program 3rd Edition By Deitel & Deitel – Test Bank A+

Chapter 6 Cannon Game App

  • Introduction

No questions.

  • Test-Driving the Cannon Game App

No questions.

  • Technologies Overview

No questions.

  • Using the Resource Folder res/raw

Q1. Media files (such as the sounds we used in the Cannon Game app), are placed in the app’s resource folder ________.

  1. res/media
  2. res/sounds
  3. res/raw
  4. res/multimedia

Answer: c. res/raw

  • Activity and Fragment Lifecycle Methods

Q1. Which of the following statements is false?

  1. When an Activity is shut down, its onDestroy method is called, which in turn calls the onDestroy methods of all the Fragments hosted by the Activity.
  2. We used the onDestroy method in the MainActivityFragment to release the CannonView’s sound resources.
  3. Method onDestroy is guaranteed to be called, so it can be used to release resources and to save critical data.
  4. The Android documentation recommends that you save data in methods onPause or onSaveInstanceState.

Answer: c. Method onDestroy is guaranteed to be called, so it can be used to release resources and to save critical data. Actually, method onDestroy is not guaranteed to be called, so it should be used only to release resources, not to save critical data.

  • Overriding View Method onTouchEvent

Q1. To process simple touch events in an app, override View method onTouchEvent, then use constants from class ________ (package android.view) to test which type of event occurred and process it accordingly.

  1. Event
  2. MotionEvent
  3. Motion
  4. View

Answer: b. MotionEvent

  • Adding Sound with SoundPool and AudioManager

Q1. An app’s sound effects are managed with a(n) ________ (package android.media), which can be used to load, play and unload sounds.

  1. Effects
  2. SoundPool
  3. EffectsPool
  4. SoundManager

Answer: SoundPool

Q2. Sounds are played using one of Android’s audio- ________ for alarms, music, notifications, phone rings, system sounds, phone calls and more.

  1. streams
  2. players
  3. tools
  4. None of the above

Answer: a. streams

Q3. The Android documentation recommends that games use the ________ to play sounds, because that stream’s volume can be controlled via the device’s volume buttons.

  1. phone audio stream
  2. alarm audio stream
  3. notifications audio stream
  4. music audio stream

Answer: d. music audio stream

Q4. Which of the following statements is false?

  1. You configure and create a SoundPool object using a SoundPool.Builder object.
  2. You use an AudioAttributes.Builder object to create an AudioAttributes object that will be associated with the SoundPool.
  3. AudioAttributes’s setGameAudio method is used to designate the audio as game audio.
  4. Activity’s setVolumeControlStream method allows the game’s volume to be controlled with the device’s volume buttons.

Answer: c. AudioAttributes’s setGameAudio method is used to designate the audio as game audio. Actually, AudioAttributes’s setUsage method is used to designate the audio as game audio.

  • Frame-by-Frame Animation with Threads, SurfaceView and SurfaceHolder

Q1. All updates to an app’s user interface must be performed in the GUI thread of execution, because GUI components are not ________.

  1. thread ready
  2. thread safe
  3. thread capable
  4. None of the above

Answer: b. thread safe

Q2. Games, often require complex logic that should be performed in separate threads of execution, and those threads often need to draw to the screen. For such cases, Android provides class ________—a subclass of View that provides a dedicated drawing area in which other threads can display graphics on the screen in a thread-safe manner.

  1. GameView
  2. ThreadView
  3. ThreadSafeView
  4. SurfaceView

Answer: d. SurfaceView

Q3. Each SurfaceView subclass should implement the interface ________, which contains methods that are called when the SurfaceView is created, changed (e.g., its size or orientation changes) or destroyed.

  1. SurfaceHolder.Callback
  2. SurfaceHolderCallback
  3. Surface.Callback
  4. SurfaceCallback

Answer: a. SurfaceHolder.Callback

  • Simple Collision Detection

Q1. Game-development frameworks typically provide sophisticated ________ collision-detection capabilities.

  1. pixel-based
  2. perfect
  3. pixel-perfect
  4. None of the above

Answer: c. pixel-perfect

  • Immersive Mode

Q1. Which of the next three statements is false?

  1. Full-screen immersive mode enables an app to take advantage of the entire screen.
  2. When an app is in immersive mode, the user can swipe down from the top of the screen to display the system bars temporarily.
  3. If the user does not interact with the system bars, they disappear after a few seconds.
  4. All of the above are true.

Answer: d. All of the above are true.

  • Building the GUI and Resource Files

No questions.

  • Creating the Project

Q1. Which of the next three statements is false?

  1. You can add a Fragment and its layout manually.
  2. You can design an app for only landscape orientation.
  3. To set the screen orientation to landscape, set android:-orientation to landscape.
  4. Each of the above is true.

Answer: c. To set the screen orientation to landscape, set android:-orientation to landscape. Actually, to set the screen orientation to landscape, set android:screen-Orientation to landscape.

  • Adjusting the Theme to Remove the App Title and App Bar

Q1. Game developers often use full-screen themes, such as

Theme.Material.Light.NoActionBar.Fullscreen

that display only the bottom system bar, which in landscape orientation appears at the screen’s ________.

  1. top
  2. bottom
  3. left edge
  4. right edge.

Answer: d. right edge

  • xml

No questions.

  • Colors

No questions.

  • Adding the Sounds to the App

No questions.

  • Adding Class MainActivityFragment

Q1. A Frame-Layout is designed to display one View, but can also be used to ________ views.

  1. stack
  2. nest
  3. position
  4. layer

Answers: d. layer.

  • Editing xml

No questions.

  • Adding the CannonView to xml

No questions.

  • Overview of This App’s Classes

No questions.

  • MainActivity Subclass of Activity

No questions.

  • MainActivityFragment Subclass of Fragment

Q1. There are seven sound streams identified by AudioManager constants. The music stream ________ is recommended for sound in games, because this stream’s volume can be controlled via the device’s buttons.

  1. AudioManager.STREAM
  2. AudioManager.MUSIC
  3. AudioManager.STREAM_MUSIC
  4. AudioManager.SYMPHONY

Answer: c. AudioManager.STREAM_MUSIC

  • Class GameElement

No questions.

  • Instance Variables and Constructor

No questions.

  • Methods update, draw, and playSound

No questions.

  • Blocker Subclass of GameElement

No questions.

  • Target Subclass of GameElement

No questions.

  • Cannon Class

No questions.

  • Instance Variables and Constructor

No questions.

  • Method align

No questions.

  • Method fireCannonball

No questions.

  • Method draw

No questions.

  • Methods getCannonball and removeCannonball

No questions.

  • Cannonball Subclass of GameElement

No questions.

  • Instance Variables and Constructor

No questions.

  • Methods getRadius, collidesWith, isOnScreen, and reverseVelocityX

No questions.

  • Method u pdate

No questions.

  • Method draw

Q1. Canvas’s ________ method draws a circle.

  1. drawOval
  2. drawEllipse
  3. drawCircle
  4. None of the above

Answer: c. drawCircle

  • CannonView Subclass of SurfaceView

No questions.

  • package and import Statements

No questions.

  • Instance Variables and Constants

No questions.

  • Constructor

Q1. When a View is inflated, its constructor is called with a Context and a(n) ________ as arguments.

  1. SetOfAttributes
  2. Attributes
  3. OptionsSet
  4. AttributeSet

Answer: d. AttributeSet

Q2. Pass ________ to an AudioAttributes.Builder object’s setUsage method to indicate that the audio is being used as game audio.

  1. AudioAttribute.USAGE_GAME
  2. AudioAttribute.GAME
  3. AudioAttribute.GAME_USAGE
  4. None of the above

Answer: a. AudioAttribute.USAGE_GAME

Q3. Which of the following statements is false?

  1. More complex games might play many sounds at the same time. SoundPool.Builder’s setMaxStreams method takes an argument that represents the maximum number of simultaneous sound streams that can play at once.
  2. A SparseIntArray maps integer keys to integer values. HashMap<Integer, Integer> is similar to—but more efficient than—a SparseIntArray for small numbers of key–value pairs.
  3. Each sound ID can be used to play a sound (and later to return its resources to the system).
  4. SoundPool method load receives three arguments—the application’s Context, a resource ID representing the sound file to load and the sound’s priority.

Ans: b. A SparseIntArray maps integer keys to integer values. HashMap<Integer, Integer> is similar to—but more efficient than—a SparseIntArray for small numbers of key–value pairs. Actually, a SparseIntArray is similar to—but more efficient than—a HashMap<Integer, Integer> for small numbers of key–value pairs.

  • Overriding View Method onSizeChanged

Q1. Class View’s onSizeChanged method is called whenever the View’s size changes, including when the View is first added to the View hierarchy as the layout is inflated. The method receives the View’s new width and height and its old width and height. The first time this method is called, the old width and height are ________ and ________.

  1. 0, 0
  2. 0, 1
  3. 1, 0
  4. 1, 1

Answer: a. 0, 0

  • Methods getScreenWidth, getScreenHeight, and playSound

Q1. Methods getScreenWidth and getScreenHeight return the width and height of the screen, which are updated in the ________ method.

  1. onOrientationChanged
  2. onSizeChanged
  3. onConfigurationChanged
  4. None of the above

Answer: b. onSizeChanged

  • Method newGame

No questions.

  • Method updatePositions

Q1. You can terminate a Thread by calling its setRunning method with the argument ________.

  1. terminate
  2. true
  3. kill
  4. false

Answer: d. false

  • Method alignAndFireCannonball

No questions.

  • Method showGameOverDialog

Q1. A dialog must be displayed from the GUI thread. You call Activity method ________ to specify a Runnable that should execute in the GUI thread.

  1. runOnUiThread
  2. executeOnUIThread
  3. uiThread
  4. None of the above

Answer: a. runOnUiThread

  • Method drawGameElements

Q1. You can call Canvas’s drawRect method to clear the Canvas. The method receives the rectangle’s upper-left x-y coordinates, width and height, and the ________ object that specifies the drawing characteristics.

  1. Draw
  2. PaintSettings
  3. Paint
  4. DrawSettings

Answer: c. Paint

  • Method testForCollisions

No questions.

  • Methods stopGame and releaseResources

Q1. Class SoundPool’s ________ method gives the resources associated with a SoundPool back to the system.

  1. reset
  2. release
  3. reinitialize
  4. restore

Answer: b. release

  • Implementing the Callback Methods

Q1. Method ________ of interface SurfaceHolder.Callback is called when the SurfaceView’s size or orientation changes, and would typically be used to redisplay graphics based on those changes.

  1. surfaceSizeChanged
  2. surfaceOrientationChanged
  3. onSizeChanged
  4. surfaceChanged

Answer: d. surfaceChanged

Q2. Method surfaceCreated is called when the SurfaceView is created—e.g., ________.

  1. when the app first loads
  2. when the app resumes from the background
  3. Both of the above
  4. Neither of the above

Answer: c. Both of the above

  • Overriding View Method onTouchEvent

Q1. View method onTouchEvent determines when the user touches the screen. The MotionEvent parameter contains information about the event that occurred. If the user touched the screen, the parameter’s value is ________.

  1. MotionEvent.ACTION_DOWN
  2. MotionEvent.ACTION_TOUCH
  3. MotionEvent.ACTION_TAP
  4. MotionEvent.ACTION_DRAG

Answer: a. MotionEvent.ACTION_DOWN

  • CannonThread: Using a Thread to Create a Game Loop

Q1. To obtain the Canvas for drawing on the SurfaceView, call SurfaceHolder method ________.

  1. getCanvas
  2. createCanvas
  3. newCanvas
  4. lockCanvas

Answer: d. lockCanvas

Q2. Only one thread at a time can draw to a SurfaceView. To ensure this, you must first lock the SurfaceHolder by ________.

  1. calling lockSurfaceHolder
  2. specifying it as the expression in the parentheses of a synchronized block.
  3. calling getSurfaceHolderLock
  4. None of the above

Answer: b. specifying it as the expression in the parentheses of a synchronized block

  • Methods hideSystemBars and showSystemBars

Q1. Immersive mode is available in Android 4.4 (API level 19) and higher. You can check at runtime whether the device’s version is at least Android 4.4 (API level 19) by checking whether ________ is at least Build.VERSION_CODES_KITKAT.

  1. Build.VERSION_SDK
  2. Build.VERSION_SDK_INT
  3. Build.VERSION_INT
  4. Build.SDK_INT

Answer. b. Build.VERSION_SDK_INT

Chapter 7

Doodlz App

  • Introduction
  1. With Android’s ________ you can draw on the entire screen—the device’s system bars and action bar toggle between displayed and hidden when you tap the screen.

Ans: immersive mode

  1. An ARGB color contains ________ (transparency), ________, ________ and ________ componnts.

Ans: alpha, red, green, blue

  • Technologies Overview
  • Using SensorManager to Listen for Accelerometer Events
  1. Most Android devices have a(n) ________ that allows apps to detect movement.

Ans: accelerometer

  • Custom DialogFragments
  1. (True/False) AlertDialogs are often created using anonymous inner classes that extend DialogFragment and display only text and buttons. AlertDialogs may also contain custom Views.

Ans: True

  1. The first Fragment lifecycle method called when a Fragment is attached to a parent Activity is ________.

Ans: onAttach

  1. The last Fragment lifecycle method called when a Fragment is about to be detached from a parent Activity is ________.

Ans: onDetach

  • Drawing with Canvas and Bitmap
  1. (True/False) You can associate a Canvas with a Bitmap, then use the Canvas to draw on the Bitmap, which can then be displayed on the screen. A Bitmap can also be saved into a file.

Ans: True.

  • Processing Multiple Touch Events and Storing Lines in Paths
  1. (True/False) You process touch events by overriding the View method onTouchEvent.

Ans: False. Actually, you override the View method onTouchEvent.

  1. You use the type of a ________ to determine whether the user has touched the screen, dragged across the screen or lifted a finger from the screen.

Ans: touch event

  • Android 4.4 Immersive Mode
  1. Android’s full-screen immersive mode enables an app to take advantage of the entire screen, but still allows the user to access the ________ when necessary.

Ans: system bars

  • GestureDetector and SimpleOnGestureListener
  1. (True/False) A GestureDetector allows an app to react to user interactions such as flings, single taps, double taps, long presses and scrolls by implementing the methods of interfaces GestureDetector.OnGestureListener and Gesture-Detector.On-Double-Tap-Listener interfaces.

Ans: True.

  • Saving the Drawing to the Device’s Gallery
  1. The default location in which photos taken with the device are stored is the device’s ________.

Ans: gallery

  1. The ________ manages media files (images, audio and video) stored on a device.

Ans: MediaStore

  • Android 4.4 Printing and the Android Support Library’s PrintHelper Class
  1. Class ________ provides a user interface for selecting a printer, has a method for determining whether a given device supports printing and provides a method for printing a Bitmap.

Ans: PrintHelper

  1. The Android Support Library is a set of libraries that are commonly used to provide new Android features for use in older Android versions.

Ans: True.

  • Building the App’s GUI and Resource Files

No questions

  • MainActivity Class
  1. What does the following code do?

if (screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Ans: If this app is running on an extra large device, we set the orientation to landscape; otherwise, we set it to portrait.

  • DoodleFragment Class
  1. (True/False) One problem with using a shake event is that even unintentional small movements always result in events.

Ans: False. You can set a threshold to ensure that movements less than this amount are not interpreted as shakes.

  1. (True/False) Like an Activity, a Fragment can place items in the app’s action bar and options menu. To do so, the Fragment must call its setHasOptionsMenu method with the argument true.

Ans: True.

  1. SensorManager’s GRAVITY_EARTH constant represents ________.

Ans: the acceleration due to gravity on earth

  1. You register to receive accelerometer events using SensorManager’s registerListener method. One of its arguments is the rate at which sensor events should be delivered to the app. Why would you specify SENSOR_DELAY_NORMAL to receive sensor events at the default rate, instead of choosing a faster rate?

Ans: Because although a faster rate can be used to get more accurate data, it would be more CPU and battery intensive.

  1. We override SensorEventListener method ________ to process accelerometer events.

Ans: onSensorChanged

  1. Why would you provide an empty body for a method?

Ans: Because the method is required by an interface.

  1. It’s important to handle sensor events quickly or to copy the event data because ________.

Ans: the array of sensor values is reused for each sensor event.

  1. (True/False) When the user selects a menu item, Fragment method onOptionsItemSelected responds to the selection.

Ans: True.

  1. When processing a menu selection you use the MenuItem’s ________ method to get the resource ID of the selected menu item, then take appropriate actions based on the selection.

Ans: getItemID

  • DoodleView Class
  1. Why would you pass true to Paint’s setAntiAlias method?

Ans: To enable anti-aliasing, which smoothes the edges of lines.

  1. (True/False) You set a line’s width using Paint’s setLineWidth method.

Ans: False. You use Paint’s setStrokeWidth method to do this.

  1. Why would you call Paint’s setStrokeCap method with Paint.Cap.ROUND?

Ans: To round the ends of lines.

  1. Which of the following statements is false?
  2. Bitmap’s staticcreateBitmap method creates a Bitmap of the specified width and height.
  3. The last argument to createBitmap is the Bitmap’s encoding, which specifies how each pixel in the Bitmap is stored. The constant Bitmap.Config.ARGB_8888 indicates that each pixel’s color has a default value of 8 for the alpha, red, green and blue components.
  4. A Canvas is used to draw shapes directly to a Bitmap.
  5. You can use Bitmap’s eraseColor method to fill the Bitmap with white pixels.

Ans: b. The last argument to createBitmap is the Bitmap’s encoding, which specifies how each pixel in the Bitmap is stored. The constant Bitmap.Config.ARGB_8888 indicates that each pixel’s color has a default value of 8 for the alpha, red, green and blue components. Actually, the constant indicates that each pixel’s color is represented by a 4-byte ARGB value.

  1. Why would you call the inherited View method invalidate?

Ans: To indicate that the View needs to be redrawn.

  1. When a View needs to be redrawn, its onDraw method is called. The first argument is the Bitmap to draw, the next two arguments are the x-y coordinates where the upper-left corner of the Bitmap should be placed on the View and the last argument is the ________ object that specifies the drawing characteristics.

Ans: Paint

  1. SimpleOn-Gesture-Listener is an ________ class that implements interfaces OnGestureListener and OnDoubleTap-Listener.

Ans: adapter

  1. Which of the following statements is false?
  2. Method onTouchEvent is called when the View receives a touch event.
  3. Android supports multitouch—that is, having multiple fingers touching the screen.
  4. The user must maintain the same number of fingers touching the screen for the duration of the multitouch event.
  5. Each finger—known as a pointer—has a unique ID that identifies it across touch events.

Ans: c. The user must maintain the same number of fingers touching the screen for the duration of the multitouch event. Actually, at any time, the user can touch the screen with more fingers or remove fingers from the screen.

  1. Which of the following statements is false?
  2. Motion-Event’s getActionMasked method returns an int representing the MotionEvent type, which you can use with constants from class MotionEvent to determine how to handle each event.
  3. Motion-Event’s getActionIndex method returns an integer index representing which finger caused the event. This index is the finger’s unique ID.
  4. To get the finger’s unique ID that persists across MotionEvents until the user removes that finger from the screen, we’ll use Motion-Event’s getPointerID method, passing the finger index as an argument.
  5. If the action is MotionEvent.ACTION_DOWN or MotionEvent.ACTION_POINTER_DOWN, the user touched the screen with a new finger.

Ans: b. Motion-Event’s getActionIndex method returns an integer index representing which finger caused the event. Actually, this index is not the finger’s unique ID—it’s simply the index at which that finger’s information is located in this MotionEvent object.

  1. Call Path’s ________ method to set the Path’s starting coordinates and specify the new Point’s x and y values.

Ans: moveTo

  1. (True/False) The system MotionEvent passed from onTouchEvent contains touch information for multiple moves on the screen if they occur at the same time. MotionEvent method getPointerCount returns the number of touches the Motion-Event describes.

Ans: True.

  1. (True/False) Store the image in the device’s Gallery by calling class MediaStore.Images.Media’s insertImage method. Method insertImage returns a String representing the image’s location on the device, or null if the image could not be saved.

Ans: True.

  1. PrintHelper method printBitmap displays Android’s print dialog, which allows the user to choose whether to save the image as a ________ on the device or to print the image to an available printer.

Ans: PDF document

  • ColorDialogFragment Class
  1. Color’s static methods alpha-, red, green and blue extract the ARGB values from the color, and SeekBar’s ________ method positions the thumbs.

Ans: setProgress

  1. When the ColorDialogFragment is added to a parent Activity, method ________ is called.

Ans: onAttach

  1. Method onProgressChanged is called when the position of a SeekBar’s ________ changes.

Ans: thumb

  • LineWidthDialogFragment Class

No questions

  • EraseImageDialogFragment Class
+
-
Only 0 units of this product remain

You might also be interested in