The first problem was the Notification(..) constructor gets only resource id, not drawable. I need to display some small (dynamic) graphics in notification. Shortly before, I was able to implement custom View, just extended View class, and implemented onDraw() method. The view works perfectly (and i used it by full class name in xml layout file). I decided (by analogy), that i can build own Drawable class and declare it in xml file, but this not works. This is my drawable:
public class TestDrawable extends Drawable {
public TestDrawable() {
this.setBounds(0, 0, this.getIntrinsicWidth(), this.getIntrinsicHeight());
}
@Override
public int getIntrinsicWidth() {
return 36;
}
@Override
public int getIntrinsicHeight() {
return 36;
}
@Override
public void draw(Canvas canvas) {
Paint paint = new Paint();
paint.setStrokeWidth(2);
paint.setColor(Color.BLUE);
canvas.drawCircle(8, 8, 3, paint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@Override
public int getOpacity() {
return PixelFormat.OPAQUE;
}
}
I have checked a lot of variants of xml drawable files, constructors and combination of methods. But, draw() method even not called :(. I tested this drawable as an application icon. Other drawables, as shapes or images works as usual.
The view works perfectly (and i used it by full class name in xml layout file).
For your own activity, perhaps. You cannot use custom View
classes in any RemoteViews
circumstance.
I decided (by analogy), that i can build own Drawable class and declare it in xml file, but this not works.
Whether you can or cannot does not matter. An OS process displays the Notification
. The OS process does not have your custom Drawable
class. Hence, the OS process cannot use anything that depends upon your custom Drawable
class.
AFAIK, you cannot create new drawable resource types in general.