Fix possible NPE in ActivityPicker.
Bug: 2325451. This change also improves the UI by returning an empty drawable of the appropriate size to make sure all labels line up correctly in the list.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.graphics.ColorFilter;
|
||||
import android.util.DisplayMetrics;
|
||||
import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
@@ -349,6 +350,11 @@ public class ActivityPicker extends AlertActivity implements
|
||||
int width = mIconWidth;
|
||||
int height = mIconHeight;
|
||||
|
||||
if (icon == null) {
|
||||
return new EmptyDrawable(width, height);
|
||||
}
|
||||
|
||||
try {
|
||||
if (icon instanceof PaintDrawable) {
|
||||
PaintDrawable painter = (PaintDrawable) icon;
|
||||
painter.setIntrinsicWidth(width);
|
||||
@@ -410,7 +416,58 @@ public class ActivityPicker extends AlertActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
icon = new EmptyDrawable(width, height);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
private static class EmptyDrawable extends Drawable {
|
||||
private final int mWidth;
|
||||
private final int mHeight;
|
||||
|
||||
EmptyDrawable(int width, int height) {
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user