Moving some abstract classes to interfaces, to better use java-8 features
Change-Id: I862af4931c95cbde052130d8b7d4ac3375db782f
This commit is contained in:
@@ -23,32 +23,30 @@ import android.os.Build;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
public class BitmapRenderer {
|
||||
/**
|
||||
* Interface representing a bitmap draw operation.
|
||||
*/
|
||||
public interface BitmapRenderer {
|
||||
|
||||
public static final boolean USE_HARDWARE_BITMAP = Utilities.ATLEAST_P;
|
||||
boolean USE_HARDWARE_BITMAP = Utilities.ATLEAST_P;
|
||||
|
||||
public static Bitmap createSoftwareBitmap(int width, int height, Renderer renderer) {
|
||||
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
renderer.draw(new Canvas(result));
|
||||
return result;
|
||||
}
|
||||
static Bitmap createSoftwareBitmap(int width, int height, BitmapRenderer renderer) {
|
||||
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
renderer.draw(new Canvas(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public static Bitmap createHardwareBitmap(int width, int height, Renderer renderer) {
|
||||
if (!USE_HARDWARE_BITMAP) {
|
||||
return createSoftwareBitmap(width, height, renderer);
|
||||
}
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
static Bitmap createHardwareBitmap(int width, int height, BitmapRenderer renderer) {
|
||||
if (!USE_HARDWARE_BITMAP) {
|
||||
return createSoftwareBitmap(width, height, renderer);
|
||||
}
|
||||
|
||||
Picture picture = new Picture();
|
||||
renderer.draw(picture.beginRecording(width, height));
|
||||
picture.endRecording();
|
||||
return Bitmap.createBitmap(picture);
|
||||
}
|
||||
Picture picture = new Picture();
|
||||
renderer.draw(picture.beginRecording(width, height));
|
||||
picture.endRecording();
|
||||
return Bitmap.createBitmap(picture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface representing a bitmap draw operation.
|
||||
*/
|
||||
public interface Renderer {
|
||||
void draw(Canvas out);
|
||||
}
|
||||
void draw(Canvas out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user