Download presentation
Presentation is loading. Please wait.
Published byBriana Lucas Modified over 9 years ago
1
Android How to Program Presented by Thomas Bucag, Rob Goodfellowe, Samantha Tomeï ©1992-2013 by Pearson Education, Inc. All Rights Reserved.
2
Objectives Demo of the app/GUI design Technology Overview UML Diagrams BitmapFactory TransitionDrawable MediaPlayer Intents
3
©1992-2013 by Pearson Education, Inc. All Rights Reserved.
8
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
9
Class Overview Diagrams Generated by ObjectAid UML Explorer for Eclipse http://www.objectaid.com
10
Slideshow Class Diagrams Generated by ObjectAid UML Explorer for Eclipse http://www.objectaid.com
11
Slideshow Editor Class Class SlideshowEditor is-a ListActivity (List View) is-an Activity Diagrams Generated by ObjectAid UML Explorer for Eclipse http://www.objectaid.com Load BitmapFactory
12
Class SlideshowInfo, SlideshowPlayer SlideshowInfo is used by Slideshow Stores data for a single slideshow Diagrams Generated by ObjectAid UML Explorer for Eclipse http://www.objectaid.com
13
TransitionDrawable Class PictureTaker, MediaItem Diagrams Generated by ObjectAid UML Explorer for Eclipse http://www.objectaid.com
14
Bitmap Factory Used to create bitmap objects Used in this app to load from the device for use as thumbnails Package: android.graphics Extends: java.lang.Object.android.graphics.BitmapFactory Nested 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 1 Decode 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
15
TransitionDrawable extends LayerDrawable implements Drawable.Callback Hierarchy java.lang.Object android.graphics.drawable.Drawable android.graphics.drawable.LayerDrawable android.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 element. Each Drawable in the transition is defined in a nested. For more information, see the guide to Drawable Resources. Source: android.developer.com retrieved 30 July 2012
16
TransitionDrawable Public 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
17
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
18
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
19
©1992-2013 by Pearson Education, Inc. All Rights Reserved.
44
Is a ListActivity Is an Activity
45
©1992-2013 by Pearson Education, Inc. All Rights Reserved.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.