I've found the following code and I want to see a background image instead of a static color. I don't know how to fix the getResources
error.
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.text.format.Time;
import hu.rycus.watchface.commons.NonAmbientBackground;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
public class Background extends NonAmbientBackground {
private Bitmap bitmap;
private Bitmap sBbitmap;
@Override
protected void onSizeSet(final int width, final int height, final boolean round) {
super.onSizeSet(width, height, round);
paint.setColor(0xFF0000AA);
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
canvas.drawRect(0, 0, width, height, paint);
}
@Override
protected void onDrawBackground(final Canvas canvas, final Time time) {
canvas.drawBitmap(bitmap, 0, 0, paint);
}
I've tried to change the code in protected void onSizeSet
to:
Resources resources = Background.this.getResources();
int imgResId;
imgResId = R.drawable.wood;
Drawable backgroundDrawable = resources.getDrawable(imgResId);
bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
canvas.drawBitmap(bitmap, 0, 0, null);
But then I get an error because it can't find the getResources
.
edit: I've found something here: getResources does not work / undefined Java And if I use this in my code just under the imports then it give's no error.
What do I need to change after Resources resources = ?
Because now it says: Expected class or package.