Merge "Scale bitmaps in metadata sent to the system" into lmp-mr1-dev
This commit is contained in:
@ -1942,4 +1942,8 @@
|
|||||||
<string-array translatable="false" name="config_sms_convert_destination_number_support">
|
<string-array translatable="false" name="config_sms_convert_destination_number_support">
|
||||||
<item>false</item>
|
<item>false</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- The maximum bitmap size that can be written to a MediaMetadata object. This value
|
||||||
|
is the max width/height allowed in dips.-->
|
||||||
|
<dimen name="config_mediaMetadataBitmapMaxSize">320dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1810,6 +1810,8 @@
|
|||||||
<java-symbol type="color" name="notification_progress_background_color" />
|
<java-symbol type="color" name="notification_progress_background_color" />
|
||||||
<java-symbol type="id" name="media_actions" />
|
<java-symbol type="id" name="media_actions" />
|
||||||
|
|
||||||
|
<java-symbol type="dimen" name="config_mediaMetadataBitmapMaxSize" />
|
||||||
|
|
||||||
<!-- From SystemUI -->
|
<!-- From SystemUI -->
|
||||||
<java-symbol type="anim" name="push_down_in" />
|
<java-symbol type="anim" name="push_down_in" />
|
||||||
<java-symbol type="anim" name="push_down_out" />
|
<java-symbol type="anim" name="push_down_out" />
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
package android.media;
|
package android.media;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.content.ContentProviderClient;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@ -25,16 +23,14 @@ import android.media.browse.MediaBrowser;
|
|||||||
import android.media.session.MediaController;
|
import android.media.session.MediaController;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CancellationSignal;
|
|
||||||
import android.os.OperationCanceledException;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Size;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -568,6 +564,29 @@ public final class MediaMetadata implements Parcelable {
|
|||||||
mBundle = new Bundle(source.mBundle);
|
mBundle = new Bundle(source.mBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Builder using a {@link MediaMetadata} instance to set
|
||||||
|
* initial values, but replace bitmaps with a scaled down copy if they
|
||||||
|
* are larger than maxBitmapSize.
|
||||||
|
*
|
||||||
|
* @param source The original metadata to copy.
|
||||||
|
* @param maxBitmapSize The maximum height/width for bitmaps contained
|
||||||
|
* in the metadata.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public Builder(MediaMetadata source, int maxBitmapSize) {
|
||||||
|
this(source);
|
||||||
|
for (String key : mBundle.keySet()) {
|
||||||
|
Object value = mBundle.get(key);
|
||||||
|
if (value != null && value instanceof Bitmap) {
|
||||||
|
Bitmap bmp = (Bitmap) value;
|
||||||
|
if (bmp.getHeight() > maxBitmapSize || bmp.getWidth() > maxBitmapSize) {
|
||||||
|
putBitmap(key, scaleBitmap(bmp, maxBitmapSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put a CharSequence value into the metadata. Custom keys may be used,
|
* Put a CharSequence value into the metadata. Custom keys may be used,
|
||||||
* but if the METADATA_KEYs defined in this class are used they may only
|
* but if the METADATA_KEYs defined in this class are used they may only
|
||||||
@ -707,6 +726,10 @@ public final class MediaMetadata implements Parcelable {
|
|||||||
* <li>{@link #METADATA_KEY_ALBUM_ART}</li>
|
* <li>{@link #METADATA_KEY_ALBUM_ART}</li>
|
||||||
* <li>{@link #METADATA_KEY_DISPLAY_ICON}</li>
|
* <li>{@link #METADATA_KEY_DISPLAY_ICON}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
* <p>
|
||||||
|
* Large bitmaps may be scaled down by the system. To pass full
|
||||||
|
* resolution images {@link Uri Uris} should be used with
|
||||||
|
* {@link #putString}.
|
||||||
*
|
*
|
||||||
* @param key The key for referencing this value
|
* @param key The key for referencing this value
|
||||||
* @param value The Bitmap to store
|
* @param value The Bitmap to store
|
||||||
@ -731,5 +754,15 @@ public final class MediaMetadata implements Parcelable {
|
|||||||
public MediaMetadata build() {
|
public MediaMetadata build() {
|
||||||
return new MediaMetadata(mBundle);
|
return new MediaMetadata(mBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bitmap scaleBitmap(Bitmap bmp, int maxSize) {
|
||||||
|
float maxSizeF = maxSize;
|
||||||
|
float widthScale = maxSizeF / bmp.getWidth();
|
||||||
|
float heightScale = maxSizeF / bmp.getHeight();
|
||||||
|
float scale = Math.min(widthScale, heightScale);
|
||||||
|
int height = (int) (bmp.getHeight() * scale);
|
||||||
|
int width = (int) (bmp.getWidth() * scale);
|
||||||
|
return Bitmap.createScaledBitmap(bmp, width, height, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ public final class MediaSession {
|
|||||||
public @interface SessionFlags { }
|
public @interface SessionFlags { }
|
||||||
|
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
private final int mMaxBitmapSize;
|
||||||
|
|
||||||
private final MediaSession.Token mSessionToken;
|
private final MediaSession.Token mSessionToken;
|
||||||
private final MediaController mController;
|
private final MediaController mController;
|
||||||
@ -147,6 +148,8 @@ public final class MediaSession {
|
|||||||
if (TextUtils.isEmpty(tag)) {
|
if (TextUtils.isEmpty(tag)) {
|
||||||
throw new IllegalArgumentException("tag cannot be null or empty");
|
throw new IllegalArgumentException("tag cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
mMaxBitmapSize = context.getResources().getDimensionPixelSize(
|
||||||
|
com.android.internal.R.dimen.config_mediaMetadataBitmapMaxSize);
|
||||||
mCbStub = new CallbackStub(this);
|
mCbStub = new CallbackStub(this);
|
||||||
MediaSessionManager manager = (MediaSessionManager) context
|
MediaSessionManager manager = (MediaSessionManager) context
|
||||||
.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
||||||
@ -409,6 +412,7 @@ public final class MediaSession {
|
|||||||
* @param metadata The new metadata
|
* @param metadata The new metadata
|
||||||
*/
|
*/
|
||||||
public void setMetadata(@Nullable MediaMetadata metadata) {
|
public void setMetadata(@Nullable MediaMetadata metadata) {
|
||||||
|
metadata = (new MediaMetadata.Builder(metadata, mMaxBitmapSize)).build();
|
||||||
try {
|
try {
|
||||||
mBinder.setMetadata(metadata);
|
mBinder.setMetadata(metadata);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
Reference in New Issue
Block a user