Return to Video

Working with Muzei

  • 0:02 - 0:06
    So we've worked with notifications and
    more recently with widgets.
  • 0:06 - 0:09
    Both are good examples of API's
    provided by the Android system
  • 0:09 - 0:13
    that let your app extend beyond the full
    screen activity we started with.
  • 0:13 - 0:16
    However, this isn't limited
    to just the system.
  • 0:17 - 0:21
    Apps can also provide API's you
    can integrate into your app to
  • 0:21 - 0:22
    further extend your app.
  • 0:24 - 0:28
    A little research shows that this is
    exactly how Muzei does its magic.
  • 0:28 - 0:32
    It extends the live wallpaper
    API provided by Android.
  • 0:32 - 0:37
    Gives us an easy API where we only worry
    about sending Muzei new wallpapers.
  • 0:37 - 0:41
    And it does all the work actually
    displaying them to the user,
  • 0:41 - 0:45
    controlling things like how bright or
    blurred the picture should be,
  • 0:45 - 0:48
    fixing those issues with readability,
    we mentioned before.
  • 0:48 - 0:53
    And even mirroring the wallpaper over to
    Android Wear devices if the user wants.
  • 0:53 - 0:54
    So how do we do it?
  • 0:54 - 0:56
    First, we'll add a gradle dependency.
  • 0:56 - 1:00
    Then a manifest entry for
    our MuzeiArtSource.
  • 1:00 - 1:02
    MuzeiArtSource is an intent service,
  • 1:02 - 1:05
    which Muzei will connect
    to get our wallpapers.
  • 1:05 - 1:09
    The intent filter is how Muzei knows
    it can connect to our service.
  • 1:09 - 1:11
    We'll also include a special icon,
  • 1:11 - 1:16
    description and even a color to
    help make sunshine feel at home.
  • 1:16 - 1:20
    So what happens when a user selects
    our app for their wallpapers.
  • 1:20 - 1:24
    First, we get a call back in our
    Muzei Art Source of on Enabled.
  • 1:24 - 1:27
    Then on Subscriber Added.
  • 1:27 - 1:29
    Then comes the most important one,
    on Update.
  • 1:29 - 1:34
    This is where we will publish our
    wallpaper making it available to Muzei.
  • 1:34 - 1:37
    Similarly, upon selecting
    a different app,
  • 1:37 - 1:42
    we'll get an on Subscriber Removed,
    and on Disabled callback.
  • 1:42 - 1:45
    So what would our on Update look like?
  • 1:45 - 1:48
    We'll do a simple query to
    get the current weather.
  • 1:48 - 1:52
    Use a new Utility method
    getImageURLForWeatherCondition
  • 1:52 - 1:58
    to get the appropriate wallpaper URL and
    then build up an Artwork object.
  • 1:58 - 2:00
    In our case we'll include the imageUrl.
  • 2:00 - 2:04
    We'll use a description of the weather
    as the title or main piece of content.
  • 2:04 - 2:08
    And then we'll use
    the locationQuery as the byline.
  • 2:08 - 2:10
    Our secondary line of text.
  • 2:10 - 2:13
    Muzei offers the ability
    to open more details.
  • 2:13 - 2:16
    Loading the main activity of
    sunshine seems like a good way of
  • 2:16 - 2:17
    seeing more details to me.
  • 2:18 - 2:21
    We'll pass that artwork
    through to publishArtwork.
  • 2:21 - 2:25
    Like magic, we'll see Muzei
    handle all the image loading,
  • 2:25 - 2:30
    live wallpaper code and other work to
    get our imagery on the user's wallpaper.
  • 2:30 - 2:31
    Neat.
  • 2:31 - 2:35
    While we have the option of using
    Muzei's scheduleUpdate method,
  • 2:35 - 2:37
    we can use the same
    approach as our Widget, and
  • 2:37 - 2:40
    use our data changed action
    to trigger an update.
  • 2:40 - 2:44
    That way, whenever the data changes,
    we'll update the wallpaper as well.
  • 2:44 - 2:47
    In this case, though,
    we're triggering a service.
  • 2:47 - 2:51
    So we'll add a start service call,
    to our sync adapter.
  • 2:51 - 2:55
    Then, our onHandleIntent,
    can include a special check for
  • 2:55 - 2:56
    the data updated action.
  • 2:56 - 2:59
    And if we're enabled, and
    the user who has selected us as their
  • 2:59 - 3:02
    background source,
    we can call our own update method.
Title:
Working with Muzei
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD855 - Android Fundamentals 2
Duration:
03:03

English subtitles

Revisions Compare revisions