mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00

committed by
Nathan Walker

parent
dbaf203a59
commit
9b5d125f42
Binary file not shown.
@ -1060,12 +1060,11 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
|
|||||||
// view.layout(0, 0, width, height);
|
// view.layout(0, 0, width, height);
|
||||||
// view.draw(canvas);
|
// view.draw(canvas);
|
||||||
|
|
||||||
view.setDrawingCacheEnabled(true);
|
// view.setDrawingCacheEnabled(true);
|
||||||
const drawCache = view.getDrawingCache();
|
// const drawCache = view.getDrawingCache();
|
||||||
const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
|
// const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
|
||||||
view.setDrawingCacheEnabled(false);
|
// view.setDrawingCacheEnabled(false);
|
||||||
|
return org.nativescript.widgets.Utils.getBitmapFromView(view);
|
||||||
return bitmap;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,6 +633,7 @@ declare module org {
|
|||||||
export module widgets {
|
export module widgets {
|
||||||
export class Utils {
|
export class Utils {
|
||||||
public static class: java.lang.Class<org.nativescript.widgets.Utils>;
|
public static class: java.lang.Class<org.nativescript.widgets.Utils>;
|
||||||
|
public static getBitmapFromView(param0: globalAndroid.view.View): globalAndroid.graphics.Bitmap;
|
||||||
public static loadImageAsync(param0: globalAndroid.content.Context, param1: string, param2: string, param3: number, param4: number, param5: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
public static loadImageAsync(param0: globalAndroid.content.Context, param1: string, param2: string, param3: number, param4: number, param5: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
||||||
public static drawBoxShadow(param0: globalAndroid.view.View, param1: string): void;
|
public static drawBoxShadow(param0: globalAndroid.view.View, param1: string): void;
|
||||||
public static saveToFileAsync(param0: globalAndroid.graphics.Bitmap, param1: string, param2: string, param3: number, param4: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
public static saveToFileAsync(param0: globalAndroid.graphics.Bitmap, param1: string, param2: string, param3: number, param4: org.nativescript.widgets.Utils.AsyncImageCallback): void;
|
||||||
|
@ -33,9 +33,14 @@ import java.io.IOException;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static Drawable getDrawable(String uri, Context context){
|
public static Drawable getDrawable(String uri, Context context) {
|
||||||
int resId = 0;
|
int resId = 0;
|
||||||
int resPrefixLength = "res://".length();
|
int resPrefixLength = "res://".length();
|
||||||
|
|
||||||
@ -43,7 +48,7 @@ public class Utils {
|
|||||||
String resPath = uri.substring(resPrefixLength);
|
String resPath = uri.substring(resPrefixLength);
|
||||||
resId = context.getResources().getIdentifier(resPath, "drawable", context.getPackageName());
|
resId = context.getResources().getIdentifier(resPath, "drawable", context.getPackageName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resId > 0) {
|
if (resId > 0) {
|
||||||
return AppCompatResources.getDrawable(context, resId);
|
return AppCompatResources.getDrawable(context, resId);
|
||||||
} else {
|
} else {
|
||||||
@ -51,6 +56,42 @@ public class Utils {
|
|||||||
return null;
|
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) {
|
public static void drawBoxShadow(View view, String value) {
|
||||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user