com.google.android.apps.muzei.api
Class MuzeiContract.Artwork

java.lang.Object
  extended by com.google.android.apps.muzei.api.MuzeiContract.Artwork
All Implemented Interfaces:
BaseColumns
Enclosing class:
MuzeiContract

public static final class MuzeiContract.Artwork
extends Object
implements BaseColumns

Constants and helper methods for the Artwork table, providing access to the current artwork.

The Artwork table contains at most a single row with the details of the most recent artwork. It also provides direct access to the cached image already downloaded by Muzei, ensuring that you do not need to do additional networks requests or have internet access when retrieving the latest artwork.

Working with the Artwork table

There's only one URI you need to care about: CONTENT_URI.

Querying this URI will return either zero rows (in cases where the user has never activated Muzei before) or one row containing all of the details needed to create an Artwork object. The helper method getCurrentArtwork(Context) does exactly this work for you, although you can certainly query the CONTENT_URI directly and either use the columns directly or use Artwork.fromCursor(Cursor) to parse the Cursor for you.

If instead you use ContentResolver.openInputStream(Uri) on the CONTENT_URI, you'll get an InputStream for the cached image Bitmap. This can then be passed to BitmapFactory.decodeStream(InputStream) or similar methods to retrieve the Bitmap itself. The helper method getCurrentArtworkBitmap(Context) does this operation, although note that this may return a very large Bitmap so following the Displaying Bitmaps Efficiently training advice is highly suggested.

Listening for changes

Just like any ContentProvider, listening for changes can be done by implementing a ContentObserver on CONTENT_URI or by using any of the helper classes such as CursorLoader to listen for updates.

However, if you want to receive updates while in the background and do not want to maintain a constantly running ContentObserver, you can instead listen for the ACTION_ARTWORK_CHANGED broadcast, sent out immediately after an update is made:

 <receiver android:name=".ExampleArtworkUpdateReceiver">
     <intent-filter>
         <action android:name="com.google.android.apps.muzei.ACTION_ARTWORK_CHANGED" />
     </intent-filter>
 </receiver>
No data is sent alongside the broadcast, but this can be used to kick off an IntentService to retrieve the latest artwork or start other processing.

Examples

For complete examples of using this class, see example-contract-widget and example-watchface.


Field Summary
static String ACTION_ARTWORK_CHANGED
          Intent action that will be broadcast when the artwork is changed.
static String COLUMN_NAME_BYLINE
          Column name for the artwork's byline (such as author and date).
static String COLUMN_NAME_IMAGE_URI
          Column name of the artwork image URI.
static String COLUMN_NAME_TITLE
          Column name for the artwork's title.
static String COLUMN_NAME_TOKEN
          Column name for the artwork's opaque application-specific identifier.
static String COLUMN_NAME_VIEW_INTENT
          Column name for the artwork's view Intent, encoded via Intent.toUri(Intent.URI_INTENT_SCHEME) and can be decoded via Intent.parseUri(viewIntent, Intent.URI_INTENT_SCHEME)
static String CONTENT_TYPE
          The MIME type of CONTENT_URI providing artwork.
static Uri CONTENT_URI
          The content:// style URL for this table.
static String TABLE_NAME
          The table name offered by this provider.
 
Fields inherited from interface android.provider.BaseColumns
_COUNT, _ID
 
Method Summary
static Artwork getCurrentArtwork(Context context)
          Returns the current Muzei Artwork
static Bitmap getCurrentArtworkBitmap(Context context)
          Naively gets the current artwork image without any subsampling or optimization for output size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_ARTWORK_CHANGED

public static final String ACTION_ARTWORK_CHANGED
Intent action that will be broadcast when the artwork is changed. This happens immediately after the ContentProvider is updated with data and should be considered the signal that you can retrieve the new artwork.

See Also:
Constant Field Values

COLUMN_NAME_BYLINE

public static final String COLUMN_NAME_BYLINE
Column name for the artwork's byline (such as author and date).

Type: TEXT

See Also:
Constant Field Values

COLUMN_NAME_IMAGE_URI

public static final String COLUMN_NAME_IMAGE_URI
Column name of the artwork image URI. In almost all cases you should use ContentResolver.openInputStream(CONTENT_URI) to retrieve the already downloaded artwork.

Type: TEXT (URI)

See Also:
Constant Field Values

COLUMN_NAME_TITLE

public static final String COLUMN_NAME_TITLE
Column name for the artwork's title.

Type: TEXT

See Also:
Constant Field Values

COLUMN_NAME_TOKEN

public static final String COLUMN_NAME_TOKEN
Column name for the artwork's opaque application-specific identifier.

Type: TEXT

See Also:
Constant Field Values

COLUMN_NAME_VIEW_INTENT

public static final String COLUMN_NAME_VIEW_INTENT
Column name for the artwork's view Intent, encoded via Intent.toUri(Intent.URI_INTENT_SCHEME) and can be decoded via Intent.parseUri(viewIntent, Intent.URI_INTENT_SCHEME)

Type: TEXT (Intent encoded URI)

See Also:
Constant Field Values

CONTENT_TYPE

public static final String CONTENT_TYPE
The MIME type of CONTENT_URI providing artwork.

See Also:
Constant Field Values

CONTENT_URI

public static final Uri CONTENT_URI
The content:// style URL for this table. This is the main entry point for queries and for opening an InputStream to the current artwork's image.


TABLE_NAME

public static final String TABLE_NAME
The table name offered by this provider.

See Also:
Constant Field Values
Method Detail

getCurrentArtwork

public static Artwork getCurrentArtwork(Context context)
Returns the current Muzei Artwork

Parameters:
context - Context to retrieve a ContentResolver
Returns:
the current Artwork or null if one could not be found

getCurrentArtworkBitmap

public static Bitmap getCurrentArtworkBitmap(Context context)
                                      throws FileNotFoundException
Naively gets the current artwork image without any subsampling or optimization for output size

Note that this may return a very large Bitmap so following the Displaying Bitmaps Efficiently training is highly recommended.

Parameters:
context - Context to retrieve a ContentResolver
Returns:
A Bitmap of the current artwork or null if the image could not be decoded
Throws:
FileNotFoundException - If no cached artwork image was found