android:gravity="center_horizontal"
android:id="@+id/keyguard_transport_control">
- <!-- FrameLayout used as scrim to show between album art and buttons -->
- <FrameLayout
+ <!-- Use ImageView for its cropping features; otherwise could be android:background -->
+ <ImageView
+ android:id="@+id/albumart"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:foreground="@drawable/ic_lockscreen_player_background"
- android:contentDescription="@string/keygaurd_accessibility_media_controls">
- <!-- Use ImageView for its cropping features; otherwise could be android:background -->
- <ImageView
- android:id="@+id/albumart"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="fill"
- android:scaleType="centerCrop"
- android:adjustViewBounds="false"
- />
- </FrameLayout>
+ android:layout_gravity="fill"
+ android:scaleType="centerCrop"
+ android:adjustViewBounds="false"
+ android:contentDescription="@string/keygaurd_accessibility_media_controls" />
+
<LinearLayout
android:orientation="vertical"
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
case MSG_SET_ARTWORK:
if (mClientGeneration == msg.arg1) {
- if (mMetadata.bitmap != null) {
- mMetadata.bitmap.recycle();
- }
mMetadata.bitmap = (Bitmap) msg.obj;
- mAlbumArt.setImageBitmap(mMetadata.bitmap);
+ KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(
+ mMetadata.bitmap);
}
break;
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh) {
if (mAttached) {
- int dim = Math.min(512, Math.max(w, h));
+ final DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
+ int dim = Math.max(dm.widthPixels, dm.heightPixels);
if (DEBUG) Log.v(TAG, "TCV uses bitmap size=" + dim);
mAudioManager.remoteControlDisplayUsesBitmapSize(mIRCD, dim, dim);
}
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
- mAlbumArt.setImageBitmap(mMetadata.bitmap);
+ KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(
+ mMetadata.bitmap);
final int flags = mTransportControlFlags;
setVisibilityBasedOnFlag(mBtnPrev, flags, RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS);
setVisibilityBasedOnFlag(mBtnNext, flags, RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
package com.android.keyguard;
+import android.app.PendingIntent;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
import com.android.internal.policy.IKeyguardShowCallback;
import com.android.internal.widget.LockPatternUtils;
private boolean mScreenOn = false;
private LockPatternUtils mLockPatternUtils;
+ private KeyguardUpdateMonitorCallback mBackgroundChanger = new KeyguardUpdateMonitorCallback() {
+ @Override
+ public void onSetBackground(Bitmap bmp) {
+ mKeyguardHost.setCustomBackground(bmp != null ?
+ new BitmapDrawable(mContext.getResources(), bmp) : null);
+ }
+ };
+
public interface ShowListener {
void onShown(IBinder windowToken);
};
class ViewManagerHost extends FrameLayout {
private static final int BACKGROUND_COLOR = 0x70000000;
+ private Drawable mCustomBackground;
+
// This is a faster way to draw the background on devices without hardware acceleration
private final Drawable mBackgroundDrawable = new Drawable() {
@Override
public void draw(Canvas canvas) {
- canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
+ if (mCustomBackground != null) {
+ final Rect bounds = mCustomBackground.getBounds();
+ final int vWidth = getWidth();
+ final int vHeight = getHeight();
+
+ final int restore = canvas.save();
+ canvas.translate(-(bounds.width() - vWidth) / 2,
+ -(bounds.height() - vHeight) / 2);
+ mCustomBackground.draw(canvas);
+ canvas.restoreToCount(restore);
+ } else {
+ canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC);
+ }
}
@Override
setBackground(mBackgroundDrawable);
}
+ public void setCustomBackground(Drawable d) {
+ mCustomBackground = d;
+ if (d != null) {
+ d.setColorFilter(BACKGROUND_COLOR, PorterDuff.Mode.SRC_OVER);
+ }
+ computeCustomBackgroundBounds();
+ invalidate();
+ }
+
+ private void computeCustomBackgroundBounds() {
+ if (mCustomBackground == null) return; // Nothing to do
+ if (!isLaidOut()) return; // We'll do this later
+
+ final int bgWidth = mCustomBackground.getIntrinsicWidth();
+ final int bgHeight = mCustomBackground.getIntrinsicHeight();
+ final int vWidth = getWidth();
+ final int vHeight = getHeight();
+
+ final float bgAspect = (float) bgWidth / bgHeight;
+ final float vAspect = (float) vWidth / vHeight;
+
+ if (bgAspect > vAspect) {
+ mCustomBackground.setBounds(0, 0, (int) (vHeight * bgAspect), vHeight);
+ } else {
+ mCustomBackground.setBounds(0, 0, vWidth, (int) (vWidth / bgAspect));
+ }
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ computeCustomBackgroundBounds();
+ }
+
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
lp.setTitle("Keyguard");
mWindowLayoutParams = lp;
mViewManager.addView(mKeyguardHost, lp);
+
+ KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mBackgroundChanger);
}
if (force || mKeyguardView == null) {
+ mKeyguardHost.setCustomBackground(null);
mKeyguardHost.removeAllViews();
inflateKeyguardView(options);
mKeyguardView.requestFocus();
public void run() {
synchronized (KeyguardViewManager.this) {
lastView.cleanUp();
+ // Let go of any large bitmaps.
+ mKeyguardHost.setCustomBackground(null);
mKeyguardHost.removeView(lastView);
}
}