|
@@ -8,7 +8,9 @@ import android.graphics.Bitmap;
|
8
|
8
|
import android.graphics.Canvas;
|
9
|
9
|
import android.net.Uri;
|
10
|
10
|
import android.util.Base64;
|
|
11
|
+import android.view.TextureView;
|
11
|
12
|
import android.view.View;
|
|
13
|
+import android.view.ViewGroup;
|
12
|
14
|
import android.widget.ScrollView;
|
13
|
15
|
|
14
|
16
|
import com.facebook.react.bridge.Promise;
|
|
@@ -21,6 +23,8 @@ import java.io.File;
|
21
|
23
|
import java.io.FileOutputStream;
|
22
|
24
|
import java.io.IOException;
|
23
|
25
|
import java.io.OutputStream;
|
|
26
|
+import java.util.ArrayList;
|
|
27
|
+import java.util.List;
|
24
|
28
|
|
25
|
29
|
/**
|
26
|
30
|
* Snapshot utility class allow to screenshot a view.
|
|
@@ -116,6 +120,27 @@ public class ViewShot implements UIBlock {
|
116
|
120
|
}
|
117
|
121
|
}
|
118
|
122
|
|
|
123
|
+ private List<View> getAllChildren(View v) {
|
|
124
|
+
|
|
125
|
+ if (!(v instanceof ViewGroup)) {
|
|
126
|
+ ArrayList<View> viewArrayList = new ArrayList<View>();
|
|
127
|
+ viewArrayList.add(v);
|
|
128
|
+ return viewArrayList;
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ ArrayList<View> result = new ArrayList<View>();
|
|
132
|
+
|
|
133
|
+ ViewGroup viewGroup = (ViewGroup) v;
|
|
134
|
+ for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
|
135
|
+
|
|
136
|
+ View child = viewGroup.getChildAt(i);
|
|
137
|
+
|
|
138
|
+ //Do not add any parents, just add child elements
|
|
139
|
+ result.addAll(getAllChildren(child));
|
|
140
|
+ }
|
|
141
|
+ return result;
|
|
142
|
+ }
|
|
143
|
+
|
119
|
144
|
/**
|
120
|
145
|
* Screenshot a view and return the captured bitmap.
|
121
|
146
|
* @param view the view to capture
|
|
@@ -138,9 +163,21 @@ public class ViewShot implements UIBlock {
|
138
|
163
|
}
|
139
|
164
|
}
|
140
|
165
|
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
|
166
|
+ Bitmap childBitmapBuffer;
|
141
|
167
|
Canvas c = new Canvas(bitmap);
|
142
|
168
|
view.draw(c);
|
143
|
169
|
|
|
170
|
+ //after view is drawn, go through children
|
|
171
|
+ List<View> childrenList = getAllChildren(view);
|
|
172
|
+
|
|
173
|
+ for (View child : childrenList) {
|
|
174
|
+ if(child instanceof TextureView) {
|
|
175
|
+ ((TextureView) child).setOpaque(false);
|
|
176
|
+ childBitmapBuffer = ((TextureView) child).getBitmap(child.getWidth(), child.getHeight());
|
|
177
|
+ c.drawBitmap(childBitmapBuffer, child.getLeft() + ((ViewGroup)child.getParent()).getLeft() + child.getPaddingLeft(), child.getTop() + ((ViewGroup)child.getParent()).getTop() + child.getPaddingTop(), null);
|
|
178
|
+ }
|
|
179
|
+ }
|
|
180
|
+
|
144
|
181
|
if (width != null && height != null && (width != w || height != h)) {
|
145
|
182
|
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
|
146
|
183
|
}
|