mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
committed by
Nathan Walker
parent
dbaf203a59
commit
9b5d125f42
@@ -33,9 +33,14 @@ import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public class Utils {
|
||||
public static Drawable getDrawable(String uri, Context context){
|
||||
public static Drawable getDrawable(String uri, Context context) {
|
||||
int resId = 0;
|
||||
int resPrefixLength = "res://".length();
|
||||
|
||||
@@ -43,7 +48,7 @@ public class Utils {
|
||||
String resPath = uri.substring(resPrefixLength);
|
||||
resId = context.getResources().getIdentifier(resPath, "drawable", context.getPackageName());
|
||||
}
|
||||
|
||||
|
||||
if (resId > 0) {
|
||||
return AppCompatResources.getDrawable(context, resId);
|
||||
} else {
|
||||
@@ -51,6 +56,42 @@ public class Utils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap drawBitmap(View view) {
|
||||
int width = view.getWidth();
|
||||
int height = view.getHeight();
|
||||
Bitmap bitmap;
|
||||
if (view.getAlpha() < 1F) {
|
||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
} else {
|
||||
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
|
||||
}
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
if (!ViewCompat.isLaidOut(view)) {
|
||||
view.layout(0, 0, width, height);
|
||||
}
|
||||
view.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromView(View view) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
return drawBitmap(view);
|
||||
} else {
|
||||
|
||||
view.setDrawingCacheEnabled(true);
|
||||
Bitmap drawCache = view.getDrawingCache();
|
||||
Bitmap bitmap = Bitmap.createBitmap(drawCache);
|
||||
view.setDrawingCacheEnabled(false);
|
||||
|
||||
if (bitmap == null) {
|
||||
bitmap = drawBitmap(view);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBoxShadow(View view, String value) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user