Post on 28-Dec-2015
Slideshow AppAndroid How to Program
Presented by Thomas Bucag, RobGoodfellowe, Samantha Tomeï
©1992-2013 by Pearson Education, Inc. All Rights Reserved.
Objectives Demo of the app/GUI design Technology Overview UML Diagrams BitmapFactory TransitionDrawable MediaPlayer Intents
Overview
Launching Intents that use built-in content providers Specifying the GUI for an AlertDialog Customizing the Layout for a ListActivity Launch an Intent that returns a result ArrayAdapter for a ListView View-Holder Pattern Notifying a ListView when its data source changes Adding data to a GUI component for use in an event
handler Playing Music with a MediaPlayer Loading Images with BitmapFactory Cross fading between images with TransitionDrawable and BitmapDrawable
Technology Overview
Slideshow Editor ClassClass SlideshowEditor is-a ListActivity (List View) is-an Activity
Diagrams Generated by ObjectAid UML Explorer for Eclipsehttp://www.objectaid.com
Load BitmapFactory
Class SlideshowInfo, SlideshowPlayer
SlideshowInfo is used by SlideshowStores data for a single slideshow
Diagrams Generated by ObjectAid UML Explorer for Eclipsehttp://www.objectaid.com
TransitionDrawableClass PictureTaker, MediaItem
Diagrams Generated by ObjectAid UML Explorer for Eclipsehttp://www.objectaid.com
Bitmap FactoryUsed to create bitmap objectsUsed in this app to load from the device for use as thumbnailsPackage: android.graphicsExtends: java.lang.Object.android.graphics.BitmapFactoryNested Class: BitmapFactory.Options• Used in this case to configure the bitmaps, and downsample the images to save
memory• Helps prevent out of memory errors common with bitmaps
Public Constructor: BitmapFactory()Public Methods: public static BitmapdecodeFile(String pathName)
Since: API Level 1Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.Parameters:pathName - complete path name for the file to be decoded.Returns the resulting decoded bitmap, or null if it could not be decoded.
BitmapFactory.Options() - Create a default Options object, which if left unchanged will give the same result from the decoder as if null were passed.
Source: android.developer.com retrieved 30 July 2012
TransitionDrawableextends LayerDrawableimplements Drawable.CallbackHierarchyjava.lang.Objectandroid.graphics.drawable.Drawableandroid.graphics.drawable.LayerDrawableandroid.graphics.drawable.TransitionDrawable
• An extension of LayerDrawables that is intended to cross-fade between the first and second layer. To start the transition, call startTransition(int). To display just the first layer, call resetTransition().
• It can be defined in an XML file with the <transition> element. Each Drawable in the transition is defined in a nested <item>. For more information, see the guide to Drawable Resources.
Source: android.developer.com retrieved 30 July 2012
TransitionDrawablePublic Constructor:• TransitionDrawable(Drawable[] layers)• Create a new transition drawable with the specified list of layers (at least 2). Public Methods:• draw(Canvas canvas): Draw in its bounds (set via setBounds) respecting optional
effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).• setCrossFadeEnabled(boolean enabled): Enables or disables the cross fade of the
drawables.• isCrossFadeEnabled(): Indicates whether the cross fade is enabled for this transition.• startTransition(int durationMillis): Begin the second layer on top of the first layer. XML Attributes• android:top, :left, :right, :bottom - coordinate of the layer’s side.• android:drawable - Drawable used to render the layer.• android:id - Identifier of the layer. This can be used to retrieve the layer from a
drawbable container.
Source: android.developer.com retrieved 30 July 2012
Ability to play music and videos within an application Import android.media.MediaPlayer MediaPlayer vs SoundPool Methods associated with MediaPlayer
◦ MediaPlayer //create new object◦ setDataSource //obtain file location◦ Prepare //prepares player◦ seekTo //passes a time◦ start //starts media player◦ pause //pauses playback◦ reset //resets media player◦ release //releases resources◦ setLooping //loop playback
Developer.android.com/reference/android/media/MediaPlayer.html
MediaPlayer
Launching Intents that use built-in content providers Specify the MIME type of data
◦ Activity that shows specified type of data (Fig. 12.4a)◦ Activity-chooser dialog to select Activity to use (Fig. 12.5)
Launch an Intent that returns a result startActivity to launch Activity associated with each Intent
◦ Favorite Twitter Searches app returns from Browser◦ Address Book app automatically returns to main Activity
startActivityForResult ◦ Refresh the Slideshow Activity’s ListView after the user edits a slideshow◦ Refresh the SlideshowEditor Activity’s ListView after the user adds a new
image to the slideshow◦ Get the location of an image of music track the user added to a
slideshow
Intents