Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings.

Similar presentations

Presentation on theme: "Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings."— Presentation transcript:

1 Mobile Computing Lecture#13

2 Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings  Widget Implementation Live Wallpaper  Components  Example

3 Widgets  Introduced in Android 1.5  Displays an application's most important or timely information at a glance, on a user's Home screen  The standard Android system image includes several examples of widgets, including widgets for Analog Clock, Music, Google search etc  Users can display a widget on phone’s home screen by: 1. Touching & holding an empty area of the Home screen 2. Selecting Widgets from the menu, and then selecting the widget they want 3

4 Home Screen with Widgets 4

5 Creating App Widget App Widgets are implemented as IntentReceivers. They use RemoteViews to update a view hierarchy hosted within another application process; in most cases that host process is the home screen. To create a widget for your application you need to create three components:  A layout resource that defines the UI for the widget  An XML definition file that describes the metadata associated with the widget  An Intent Receiver that defines and controls the widget 5

6 Supported Widget Views and Layouts Available Layouts  Frame Layout  Linear Layout  Relative Layout Supported Views  Analog Clock  Button  Chronometer  ImageButton  ImageView  ProgressBar  TextView 6

7 Layouts/Views Not Supported  All Custom Views  Descendents of the allowed Views  EditText 7

8 App Widget XML Layout Resource 8

9 Defining Widget Settings Widget definition resources are stored as XML in the res/xml folder of your project. The appwidget-provider tag lets you describe the widget metadata that defines the size, layout, and update rate for your widget using the following attributes:  initialLayout The layout resource to use in constructing the widget’s user interface  minWidth / minHeight Respectively, the minimum width and minimum height of the widget, as described in the previous section  label The title used by your widget in the widget-picker 9

10 Defining Widget Settings  updatePeriodMillis The minimum period between widget updates in milliseconds Android will wake the device to update your widget at this rate, so you should specify at least an hour. Ideally your widget shouldn’t use this update technique more than once or twice daily.  configure You can optionally specify a fully qualified Activity to be launched when your widget is added to the home screen. This Activity can be used to specify widget settings and user preferences. Using a configuration Activity will be discussed later. 10

11 Widget Settings 11

12 Widget Implementation Widgets are implemented as Intent Receivers with Intent Filters that catch broadcast Intents, which request widget updates using the appWidget.ACTION_APPWIDGET_UPDATE, DELETED, ENABLED, and DISABLED actions. You can create your widget by extending the intentReceiver class directly and interpreting those broadcast Intents by overriding the onReceive method. The AppWidgetProvider class provides a simplified alternative by encapsulating the Intent processing and presenting you with event handlers for the update, delete, enable, and disable events. 12

13 Widget Implementation 13

14 Widget Implementation  The AppWidgetProvider class extends BroadcastReceiver as a convenience class to handle the App Widget broadcasts.  The AppWidgetProvider receives only the event broadcasts that are relevant to the App Widget, such as when the App Widget is updated, deleted, enabled, and disabled.  When these broadcast events occur, the AppWidgetProvider receives the following method calls: i. onUpdate() ii. onDeleted() iii. onEnabled() iv. onDisabled() v. onReceive() 14

15 Widget Manifest Node 15

16 Remote Views & App Widget Manager  RemoteViews class is used to describe and manipulate a View hierarchy that’s hosted within another application process  This lets you change a property, or run a method, on a View running as part of another application. For example, the Views within App Widgets are hosted within a separate process (generally the home screen), so Remote Views can be used to modify the widget UI from the Intent Receiver running within your application.  AppWidgetManager is used to update App Widgets and provide details related to them. 16

17 Remote Views & App Widget Manager  Using Remote Views with the App Widget Manager, you can modify the appearance of the Views supported by the App Widget framework. Among other things, you can change the visibility, text, or image values, and add click listeners 17

18 onUpdate() Handler 18

19 Configuration Activity  If you would like the user to configure settings when he or she adds a new App Widget, you can create an App Widget configuration Activity.  This Activity will be automatically launched by the App Widget host and allows the user to configure available settings for the App Widget at create-time, such as the App Widget color, size, update period or other functionality settings.Activity  The configuration Activity should be declared as a normal Activity in the Android manifest file. However, it will be launched by the App Widget host with the ACTION_APPWIDGET_CONFIGURE action, so the Activity needs to accept this Intent. For example: ACTION_APPWIDGET_CONFIGURE 19

20 Configuration Activity … 20

21 Live Wallpaper  It is a new way to add an application component to the home screen  Introduced in Android 2.1 (API level 7)  Live Wallpaper lets you create dynamic, interactive home- screen backgrounds, providing you with an exciting new alternative for displaying information to your users directly on the home screen. 21

22 Creating Live Wallpaper To create a new Live Wallpaper you need three components: 1. A Live Wallpaper XML resource 2. A Wallpaper Service implementation 3. A Wallpaper Engine implementation (returned through the Wallpaper Service) 22

23 Live Wallpaper (XML Resource) 23  Stored in res/xml folder  Resource defines author’s name, description, thumbnail image etc  Can also define settingsActivity tag to specify configuration activity for wallpaper

24 Wallpaper Service  Extend the WallpaperService class to create a wrapper Service that instantiates a Wallpaper Service Engine class  All the drawing and interaction for Live Wallpaper is handled in the Wallpaper Service Engine class  Override the onCreateEngine() handler to return a new instance of your custom Wallpaper Service Engine 24

25 Wallpaper Service 25

26 Live Wallpaper (Manifest Entry)  One must add his/her Live Wallpaper Service to application’s manifest using the tag  It must also include an Intent Filter to listen for the android.service.wallpaper.WallpaperService action  tag must also use node that specifies the android.service.wallpaper as the name attribute, and associates it with the resource file described in the (xml resource) using a resource attribute  Your Live Wallpaper Service must also require the android.permission.BIND_WALLPAPER permission using the android.permission attribute 26

27 Live Wallpaper (Manifest Entry) 27

28 Wallpaper Engine 28

29 Wallpaper Engine … 29

30 Wallpaper Example (Configuration) 30

31 Live Wallpaper (animating) 31

32 Audio Playing  Android includes a comprehensive Media Player to simplify the playback of audio and video  Android 2.1 (API level 7) supports the following multimedia formats for playback as part of the base framework. Note that some devices may support playback of additional file formats: i. AAC LC/LTP ii. HE-AACv1 (AAC+) iii. HE-AACv2 (Enhanced AAC+) iv. AMR-NB v. AMR-WB vi. MP3 vi. MIDI vii. Ogg Vorbis viii. PCM / WAVE 32

33 Multimedia Systems  Multimedia playback in Android is handled by the MediaPlayer class  Media can be stored in application resources, local files, Content Providers, or streamed from a network URL  In each case, the file format and type of multimedia being played is abstracted from you as a developer 33

34 Playing Media  In the most simplistic terms, transitions through the state machine can be described as follows:  Initialize the Media Player with media to play  Prepare the Media Player for playback  Start the playback  Pause or stop the playback prior to its completing  Release Resources (Playback complete) 34

35 Media Player Usage 35

36 Play Audio 36 Important functions::: player.pause(); player.release(); player.start(); player.isPlaying();

37 Notifications  The status bar across the top of the device screen shows pending notifications for the user to read at a convenient time  In general, because an activity mostly interacts with the user, services are more likely to utilize this feature  As a rule, notifications should be concise and minimal for the best user experience 37

38 Notification Declaration 38

39 NotificationBar Expansion 39

40 Notifying Event 40

Download ppt "Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings."

Similar presentations

Ads by Google