Fields Summary |
---|
private static final String | TAG |
public static final int | BITMAP_KEY_ARTWORKThe metadata key for the content artwork / album art. |
public static final int | RATING_KEY_BY_OTHERSThe metadata key for the content's average rating, not the user's rating.
The value associated with this key is a {@link Rating} instance. |
public static final int | RATING_KEY_BY_USERThe metadata key for the content's user rating.
The value associated with this key is a {@link Rating} instance.
This key can be flagged as "editable" (with {@link #addEditableKey(int)}) to enable
receiving user rating values through the
{@link android.media.RemoteControlClient.OnMetadataUpdateListener} interface. |
public static final int | KEY_EDITABLE_MASK |
protected long | mEditableKeys |
protected boolean | mMetadataChanged |
protected boolean | mApplied |
protected boolean | mArtworkChanged |
protected android.graphics.Bitmap | mEditorArtwork |
protected android.os.Bundle | mEditorMetadata |
protected MediaMetadata.Builder | mMetadataBuilder |
protected static final int | METADATA_TYPE_INVALID |
protected static final int | METADATA_TYPE_LONG |
protected static final int | METADATA_TYPE_STRING |
protected static final int | METADATA_TYPE_BITMAP |
protected static final int | METADATA_TYPE_RATING |
protected static final android.util.SparseIntArray | METADATA_KEYS_TYPE |
Methods Summary |
---|
public synchronized void | addEditableKey(int key)Flags the given key as being editable.
This should only be used by metadata publishers, such as {@link RemoteControlClient},
which will declare the metadata field as eligible to be updated, with new values
received through the {@link RemoteControlClient.OnMetadataUpdateListener} interface.
if (mApplied) {
Log.e(TAG, "Can't change editable keys of a previously applied MetadataEditor");
return;
}
// only one editable key at the moment, so we're not wasting memory on an array
// of editable keys to check the validity of the key, just hardcode the supported key.
if (key == RATING_KEY_BY_USER) {
mEditableKeys |= (KEY_EDITABLE_MASK & key);
mMetadataChanged = true;
} else {
Log.e(TAG, "Metadata key " + key + " cannot be edited");
}
|
public abstract void | apply()Applies all of the metadata changes that have been set since the MediaMetadataEditor instance
was created or since {@link #clear()} was called.
|
public synchronized void | clear()Clears all the pending metadata changes set since the MediaMetadataEditor instance was
created or since this method was last called.
Note that clearing the metadata doesn't reset the editable keys
(use {@link #removeEditableKeys()} instead).
if (mApplied) {
Log.e(TAG, "Can't clear a previously applied MediaMetadataEditor");
return;
}
mEditorMetadata.clear();
mEditorArtwork = null;
mMetadataBuilder = new MediaMetadata.Builder();
|
public synchronized android.graphics.Bitmap | getBitmap(int key, android.graphics.Bitmap defaultValue)Returns the {@link Bitmap} value for the key.
if (key != BITMAP_KEY_ARTWORK) {
throw(new IllegalArgumentException("Invalid type 'Bitmap' for key "+ key));
}
return (mEditorArtwork != null ? mEditorArtwork : defaultValue);
|
public synchronized int[] | getEditableKeys()Retrieves the keys flagged as editable.
// only one editable key supported here
if (mEditableKeys == RATING_KEY_BY_USER) {
int[] keys = { RATING_KEY_BY_USER };
return keys;
} else {
return null;
}
|
public synchronized long | getLong(int key, long defaultValue)Returns the long value for the key.
if (METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID) != METADATA_TYPE_LONG) {
throw(new IllegalArgumentException("Invalid type 'long' for key "+ key));
}
return mEditorMetadata.getLong(String.valueOf(key), defaultValue);
|
public synchronized java.lang.Object | getObject(int key, java.lang.Object defaultValue)Returns an object representation of the value for the key
switch (METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID)) {
case METADATA_TYPE_LONG:
if (mEditorMetadata.containsKey(String.valueOf(key))) {
return mEditorMetadata.getLong(String.valueOf(key));
} else {
return defaultValue;
}
case METADATA_TYPE_STRING:
if (mEditorMetadata.containsKey(String.valueOf(key))) {
return mEditorMetadata.getString(String.valueOf(key));
} else {
return defaultValue;
}
case METADATA_TYPE_RATING:
if (mEditorMetadata.containsKey(String.valueOf(key))) {
return mEditorMetadata.getParcelable(String.valueOf(key));
} else {
return defaultValue;
}
case METADATA_TYPE_BITMAP:
// only one key for Bitmap supported, value is not stored in mEditorMetadata Bundle
if (key == BITMAP_KEY_ARTWORK) {
return (mEditorArtwork != null ? mEditorArtwork : defaultValue);
} // else: fall through to invalid key handling
default:
throw(new IllegalArgumentException("Invalid key "+ key));
}
|
public synchronized java.lang.String | getString(int key, java.lang.String defaultValue)Returns the {@link String} value for the key.
if (METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID) != METADATA_TYPE_STRING) {
throw(new IllegalArgumentException("Invalid type 'String' for key "+ key));
}
return mEditorMetadata.getString(String.valueOf(key), defaultValue);
|
public synchronized android.media.MediaMetadataEditor | putBitmap(int key, android.graphics.Bitmap bitmap)Adds image.
if (mApplied) {
Log.e(TAG, "Can't edit a previously applied MediaMetadataEditor");
return this;
}
if (key != BITMAP_KEY_ARTWORK) {
throw(new IllegalArgumentException("Invalid type 'Bitmap' for key "+ key));
}
mEditorArtwork = bitmap;
mArtworkChanged = true;
return this;
|
public synchronized android.media.MediaMetadataEditor | putLong(int key, long value)Adds numerical information.
Note that none of the information added after {@link #apply()} has been called
will be available to consumers of metadata stored by the MediaMetadataEditor.
if (mApplied) {
Log.e(TAG, "Can't edit a previously applied MediaMetadataEditor");
return this;
}
if (METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID) != METADATA_TYPE_LONG) {
throw(new IllegalArgumentException("Invalid type 'long' for key "+ key));
}
mEditorMetadata.putLong(String.valueOf(key), value);
mMetadataChanged = true;
return this;
|
public synchronized android.media.MediaMetadataEditor | putObject(int key, java.lang.Object value)Adds information stored as an instance.
Note that none of the information added after {@link #apply()} has been called
will be available to consumers of metadata stored by the MediaMetadataEditor.
if (mApplied) {
Log.e(TAG, "Can't edit a previously applied MediaMetadataEditor");
return this;
}
switch(METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID)) {
case METADATA_TYPE_LONG:
if (value instanceof Long) {
return putLong(key, ((Long)value).longValue());
} else {
throw(new IllegalArgumentException("Not a non-null Long for key "+ key));
}
case METADATA_TYPE_STRING:
if ((value == null) || (value instanceof String)) {
return putString(key, (String) value);
} else {
throw(new IllegalArgumentException("Not a String for key "+ key));
}
case METADATA_TYPE_RATING:
mEditorMetadata.putParcelable(String.valueOf(key), (Parcelable)value);
mMetadataChanged = true;
break;
case METADATA_TYPE_BITMAP:
if ((value == null) || (value instanceof Bitmap)) {
return putBitmap(key, (Bitmap) value);
} else {
throw(new IllegalArgumentException("Not a Bitmap for key "+ key));
}
default:
throw(new IllegalArgumentException("Invalid key "+ key));
}
return this;
|
public synchronized android.media.MediaMetadataEditor | putString(int key, java.lang.String value)Adds textual information.
Note that none of the information added after {@link #apply()} has been called,
will be available to consumers of metadata stored by the MediaMetadataEditor.
if (mApplied) {
Log.e(TAG, "Can't edit a previously applied MediaMetadataEditor");
return this;
}
if (METADATA_KEYS_TYPE.get(key, METADATA_TYPE_INVALID) != METADATA_TYPE_STRING) {
throw(new IllegalArgumentException("Invalid type 'String' for key "+ key));
}
mEditorMetadata.putString(String.valueOf(key), value);
mMetadataChanged = true;
return this;
|
public synchronized void | removeEditableKeys()Causes all metadata fields to be read-only.
if (mApplied) {
Log.e(TAG, "Can't remove all editable keys of a previously applied MetadataEditor");
return;
}
if (mEditableKeys != 0) {
mEditableKeys = 0;
mMetadataChanged = true;
}
|