tauplatform 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/CHANGELOG +10 -0
- data/lib/build/development/platform.rb +5 -1
- data/lib/build/development/web_server.rb +2 -0
- data/lib/commonAPI/coreapi/ext/shared/TimerImpl.cpp +10 -1
- data/lib/commonAPI/eventsource/ext/platform/android/ext_native.files +4 -4
- data/lib/commonAPI/eventsource/ext/shared/EventSource.h +2 -2
- data/lib/commonAPI/mediacapture/ext/camera.xml +16 -11
- data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraEclair.java +17 -6
- data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraObject.java +304 -294
- data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraRhoListener.java +528 -282
- data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraSingletonObject.java +119 -94
- data/lib/commonAPI/mediacapture/ext/platform/wm/Mediacapture.vcproj +3 -3
- data/lib/commonAPI/mediacapture/ext/platform/wp8/src/Camera_impl.cs +63 -43
- data/lib/extensions/barcode-old/ext/barcode/platform/iphone/Rakefile +1 -1
- data/lib/framework/rhodes.rb +2 -2
- data/lib/framework/version.rb +2 -2
- data/lib/rhodes.rb +2 -2
- data/platform/android/Rhodes/jni/src/sslimpl.cpp +7 -2
- data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +11 -4
- data/platform/android/build/android.rake +6 -0
- data/platform/iphone/Classes/SimpleMainView.m +8 -3
- data/platform/iphone/Classes/URLProtocol/CRhoURLProtocol.m +1 -1
- data/platform/shared/common/RhodesApp.cpp +4 -0
- data/platform/shared/common/RhodesApp.h +8 -0
- data/platform/shared/net/CURLNetRequest.cpp +4 -2
- data/platform/shared/net/HttpServer.cpp +2 -2
- data/platform/shared/ruby/ext/rho/rhoruby.c +1 -1
- data/res/generators/templates/iphone_project/Bremen7.xcodeproj/project.pbxproj +3 -0
- data/version +1 -1
- metadata +2 -2
data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraRhoListener.java
CHANGED
@@ -3,6 +3,7 @@ package com.rho.camera;
|
|
3
3
|
import java.io.ByteArrayOutputStream;
|
4
4
|
import java.io.File;
|
5
5
|
import java.io.FileInputStream;
|
6
|
+
import java.io.OutputStream;
|
6
7
|
import java.io.FileNotFoundException;
|
7
8
|
import java.io.FileOutputStream;
|
8
9
|
import java.io.IOException;
|
@@ -37,7 +38,7 @@ import com.rhomobile.rhodes.util.Utils;
|
|
37
38
|
import com.rhomobile.rhodes.file.RhoFileApi;
|
38
39
|
|
39
40
|
public class CameraRhoListener extends AbstractRhoListener implements
|
40
|
-
|
41
|
+
IRhoListener {
|
41
42
|
|
42
43
|
private static final String TAG = CameraRhoListener.class.getSimpleName();
|
43
44
|
|
@@ -51,11 +52,24 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
51
52
|
private String imgPath = null;
|
52
53
|
private Bitmap mBitmap = null;
|
53
54
|
private String rename = null;
|
54
|
-
|
55
|
+
|
55
56
|
static CameraRhoListener getInstance() {
|
56
57
|
return sInstance;
|
57
58
|
}
|
58
59
|
|
60
|
+
|
61
|
+
private void cleanState() {
|
62
|
+
mActualPropertyMap = null;
|
63
|
+
picChoosen_imagewidth = 0;
|
64
|
+
picChoosen_imageheight = 0;
|
65
|
+
curUri = null;
|
66
|
+
storedUri = null;
|
67
|
+
resultMap=new HashMap<String,Object>();
|
68
|
+
imgPath = null;
|
69
|
+
mBitmap = null;
|
70
|
+
rename = null;
|
71
|
+
}
|
72
|
+
|
59
73
|
@Override
|
60
74
|
public void onCreateApplication(IRhoExtManager extManager) {
|
61
75
|
sInstance = this;
|
@@ -76,26 +90,36 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
76
90
|
Uri captureUri = null;
|
77
91
|
String targetPath = " ";
|
78
92
|
ByteArrayOutputStream stream = null;
|
93
|
+
Logger.T(TAG, "CameraRhoListener.onActivityResult() START");
|
94
|
+
Logger.T(TAG, "ActualProperties: ["+getActualPropertyMap()+"]");
|
95
|
+
Logger.T(TAG, "Properties: ["+propertyMap+"]");
|
96
|
+
|
79
97
|
try {
|
80
98
|
if (resultCode == Activity.RESULT_OK)
|
81
99
|
{
|
100
|
+
Logger.T(TAG, "resultCode == Activity.RESULT_OK");
|
82
101
|
getActualPropertyMap().put("default_camera_key_path", "");
|
83
102
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss");
|
84
103
|
rename = "IMG_"+ dateFormat.format(new Date(System.currentTimeMillis()))+".jpg";
|
85
104
|
if(propertyMap.containsKey("fileName")){
|
86
105
|
rename = propertyMap.get("fileName")+ ".jpg";
|
87
106
|
}
|
88
|
-
|
89
|
-
|
107
|
+
|
108
|
+
BitmapFactory.Options options_only_size = new BitmapFactory.Options();
|
109
|
+
options_only_size.inJustDecodeBounds = true;
|
110
|
+
|
111
|
+
String curPath = null;
|
112
|
+
String strCaptureUri = getActualPropertyMap().get("captureUri");
|
90
113
|
if (strCaptureUri != null)
|
91
114
|
{
|
92
115
|
captureUri = Uri.parse(getActualPropertyMap().get("captureUri"));
|
93
116
|
getActualPropertyMap().put("default_camera_key_path", "");
|
94
|
-
}
|
117
|
+
}
|
95
118
|
if (intent != null && intent.hasExtra(MediaStore.EXTRA_OUTPUT))
|
96
119
|
{
|
120
|
+
Logger.T(TAG, "intent != null && intent.hasExtra(MediaStore.EXTRA_OUTPUT)");
|
97
121
|
if(intent.hasExtra(MediaStore.EXTRA_OUTPUT)){
|
98
|
-
Logger.T(TAG, "Intent extras: "+ intent.getExtras().keySet());
|
122
|
+
Logger.T(TAG, "Intent extras: "+ intent.getExtras().keySet());
|
99
123
|
curUri = (Uri) intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
|
100
124
|
storedUri = curUri;
|
101
125
|
}
|
@@ -106,35 +130,46 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
106
130
|
try {
|
107
131
|
System.gc();
|
108
132
|
if (getActualPropertyMap().get("DeviceGallery_Key") == null){
|
109
|
-
|
133
|
+
BitmapFactory.decodeFile(curUri.getPath(), options_only_size);
|
134
|
+
if((getActualPropertyMap().get("outputFormat").equalsIgnoreCase("dataUri"))){
|
135
|
+
mBitmap = BitmapFactory.decodeFile(curUri.getPath());
|
136
|
+
}
|
137
|
+
|
110
138
|
}else{
|
111
139
|
imgPath = getFilePath(curUri);
|
112
|
-
|
140
|
+
BitmapFactory.decodeFile(imgPath, options_only_size);
|
141
|
+
if((getActualPropertyMap().get("outputFormat").equalsIgnoreCase("dataUri"))){
|
142
|
+
mBitmap = BitmapFactory.decodeFile(imgPath);
|
143
|
+
}
|
113
144
|
File f= new File(imgPath);
|
114
145
|
imgPath = copyImg(imgPath);
|
115
146
|
f.renameTo(new File(f.getParentFile(), rename));
|
116
147
|
String pathAfterRename = f.getParentFile().getAbsolutePath() +"/"+rename;
|
117
148
|
fixTheGalleryIssue(pathAfterRename);
|
118
|
-
// RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
119
|
-
|
149
|
+
// RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
150
|
+
// Uri.parse(curUri.getPath())));
|
120
151
|
getActualPropertyMap().put("default_camera_key_path", "default_camera_key_path_value");
|
121
152
|
}
|
122
|
-
|
153
|
+
|
123
154
|
} catch (OutOfMemoryError e1) {
|
124
155
|
e1.printStackTrace();
|
125
156
|
}
|
126
157
|
File file = null;
|
127
|
-
if (!getActualPropertyMap().containsKey("fileName") && getActualPropertyMap().get("ChoosePicture_Key") == null){
|
158
|
+
if (!getActualPropertyMap().containsKey("fileName") && getActualPropertyMap().get("ChoosePicture_Key") == null){
|
128
159
|
file= new File(curUri.getPath());
|
129
160
|
file.renameTo(new File(file.getParentFile(), rename));
|
130
161
|
String pathAfterRename = file.getParentFile().getAbsolutePath() +"/"+rename;
|
131
162
|
fixTheGalleryIssue(pathAfterRename);
|
132
|
-
// RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
133
|
-
|
163
|
+
// RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
164
|
+
// Uri.parse(curUri.getPath())));
|
134
165
|
}
|
135
|
-
picChoosen_imagewidth = mBitmap.getWidth();
|
136
|
-
picChoosen_imageheight = mBitmap.getHeight();
|
137
|
-
|
166
|
+
//picChoosen_imagewidth = mBitmap.getWidth();
|
167
|
+
//picChoosen_imageheight = mBitmap.getHeight();
|
168
|
+
picChoosen_imagewidth = options_only_size.outWidth;
|
169
|
+
picChoosen_imageheight = options_only_size.outHeight;
|
170
|
+
|
171
|
+
|
172
|
+
if((getActualPropertyMap().get("outputFormat").equalsIgnoreCase("dataUri"))){
|
138
173
|
stream = new ByteArrayOutputStream();
|
139
174
|
mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
140
175
|
byte[] byteArray = stream.toByteArray();
|
@@ -153,86 +188,226 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
153
188
|
byteArray = stream.toByteArray();
|
154
189
|
dataBuilder.append(Base64.encodeToString(byteArray, false));
|
155
190
|
}
|
156
|
-
getActualPropertyMap().put("curUri", dataBuilder.toString());
|
191
|
+
getActualPropertyMap().put("curUri", dataBuilder.toString());
|
157
192
|
curUri=Uri.parse(dataBuilder.toString());
|
193
|
+
mBitmap.recycle();
|
158
194
|
}
|
159
|
-
Logger.T(TAG, "Photo is captured: " + curUri);
|
160
|
-
mBitmap.recycle();
|
195
|
+
Logger.T(TAG, "Photo is captured: " + curUri);
|
196
|
+
//mBitmap.recycle();
|
161
197
|
}else if (captureUri != null )
|
162
|
-
{
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
198
|
+
{
|
199
|
+
Logger.T(TAG, "captureUri != null");
|
200
|
+
|
201
|
+
curUri = captureUri;
|
202
|
+
|
167
203
|
if (getActualPropertyMap().get("dataURI") == null) {
|
168
|
-
|
204
|
+
Logger.T(TAG, "getActualPropertyMap().get(dataURI) == null");
|
205
|
+
boolean fromGallery = false;
|
206
|
+
try {
|
207
|
+
imgPath = getFilePath(curUri);
|
208
|
+
}
|
209
|
+
catch (Exception e) {
|
210
|
+
e.printStackTrace();
|
211
|
+
}
|
212
|
+
Logger.T(TAG, "curUri ["+curUri+"]");
|
213
|
+
Logger.T(TAG, "imgPath ["+imgPath+"]");
|
214
|
+
//Utils.platformLog("################", "intent.getData() ["+intent.getData()+"]");
|
215
|
+
if (imgPath == null) {
|
216
|
+
try {
|
217
|
+
imgPath = getFilePath(intent.getData());
|
218
|
+
}
|
219
|
+
catch (Exception e) {
|
220
|
+
e.printStackTrace();
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
if (fromGallery) {
|
226
|
+
}
|
227
|
+
else {
|
169
228
|
File f= new File(imgPath);
|
170
229
|
imgPath = copyImg(imgPath);
|
171
230
|
getActualPropertyMap().put("default_camera_key_path", "default_camera_key_path_value");
|
172
231
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
173
232
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
picChoosen_imagewidth =
|
187
|
-
picChoosen_imageheight =
|
188
|
-
mBitmap.recycle();
|
233
|
+
try {
|
234
|
+
BitmapFactory.decodeStream(new FileInputStream(f), null, options_only_size);
|
235
|
+
if (!getActualPropertyMap().containsKey("fileName") && getActualPropertyMap().get("ChoosePicture_Key") == null){
|
236
|
+
f.renameTo(new File(f.getParentFile(), rename));
|
237
|
+
String pathAfterRename = f.getParentFile().getAbsolutePath() +"/"+rename;
|
238
|
+
fixTheGalleryIssue(pathAfterRename);
|
239
|
+
// RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
|
240
|
+
// Uri.parse(f.getAbsolutePath())));
|
241
|
+
}
|
242
|
+
} catch (FileNotFoundException e) {
|
243
|
+
e.printStackTrace();
|
244
|
+
}
|
245
|
+
picChoosen_imagewidth = options_only_size.outWidth;
|
246
|
+
picChoosen_imageheight = options_only_size.outHeight;
|
247
|
+
//mBitmap.recycle();
|
248
|
+
}
|
189
249
|
}
|
190
|
-
|
250
|
+
|
191
251
|
}
|
192
252
|
else
|
193
253
|
{
|
254
|
+
Logger.T(TAG, "else(2)");
|
194
255
|
curUri = intent.getData();
|
195
256
|
Logger.T(TAG, "Check intent data: " + curUri);
|
196
257
|
}
|
197
|
-
|
198
|
-
if (curUri
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
258
|
+
|
259
|
+
if (curUri == null) {
|
260
|
+
curUri = intent.getData();
|
261
|
+
}
|
262
|
+
|
263
|
+
if (curUri.getScheme().equals("file"))
|
264
|
+
{
|
265
|
+
Logger.T(TAG, "curUri.getScheme().equals(file)");
|
266
|
+
curPath = curUri.getPath();
|
267
|
+
Logger.T(TAG, "curPath["+curPath+"]");
|
268
|
+
String dataDir=RhodesActivity.safeGetInstance().getApplicationInfo().dataDir;
|
269
|
+
dataDir=dataDir+curPath.substring(curPath.lastIndexOf("/") );
|
270
|
+
|
271
|
+
if(getActualPropertyMap().get("fileName")==null)
|
272
|
+
{
|
273
|
+
getActualPropertyMap().put("fileName",dataDir);
|
274
|
+
}
|
275
|
+
if(getActualPropertyMap().get("fileName").contains(".jpg"))
|
276
|
+
targetPath = getActualPropertyMap().get("fileName");
|
277
|
+
else
|
278
|
+
targetPath = getActualPropertyMap().get("fileName")+".jpg";
|
279
|
+
File curFile = new File(curPath);
|
280
|
+
|
281
|
+
if (!curPath.equals(targetPath))
|
282
|
+
{
|
216
283
|
// Utils.copy(curPath, targetPath);
|
217
284
|
// curFile.delete();
|
218
|
-
|
219
|
-
|
285
|
+
Logger.T(TAG, "File copied to " + targetPath);
|
286
|
+
curUri = Uri.fromFile(new File(targetPath));
|
287
|
+
}
|
288
|
+
imgPath = copyImg(curPath);
|
289
|
+
curUri = Uri.parse(imgPath);
|
290
|
+
copyImgAsUserChoice(curPath);
|
291
|
+
|
292
|
+
Logger.T(TAG, "imgPath ["+imgPath+"]");
|
293
|
+
Logger.T(TAG, "curUri ["+curUri+"]");
|
294
|
+
Logger.T(TAG, "curPath ["+curPath+"]");
|
295
|
+
Logger.T(TAG, "targetPath["+targetPath+"]");
|
296
|
+
}
|
297
|
+
|
298
|
+
String useRealBitmapResize = getActualPropertyMap().get("useRealBitmapResize");
|
299
|
+
if ((useRealBitmapResize != null) && (Boolean.parseBoolean(useRealBitmapResize))) {
|
300
|
+
Logger.T(TAG, "$$$ real resize start $$$");
|
301
|
+
try {
|
302
|
+
// resize to preffered size
|
303
|
+
|
304
|
+
Logger.T(TAG, "imgPath ["+imgPath+"]");
|
305
|
+
Logger.T(TAG, "rename ["+rename+"]");
|
306
|
+
String bitmapPath = imgPath;
|
307
|
+
|
308
|
+
|
309
|
+
BitmapFactory.decodeFile(bitmapPath, options_only_size);
|
310
|
+
picChoosen_imagewidth = options_only_size.outWidth;
|
311
|
+
picChoosen_imageheight = options_only_size.outHeight;
|
312
|
+
|
313
|
+
int idesiredWidth = 0;
|
314
|
+
int idesiredHeight = 0;
|
315
|
+
if (getActualPropertyMap().get("desiredWidth") != null) {
|
316
|
+
idesiredWidth = Integer.valueOf(getActualPropertyMap().get("desiredWidth"));
|
317
|
+
}
|
318
|
+
if (getActualPropertyMap().get("desiredHeight") != null) {
|
319
|
+
idesiredHeight = Integer.valueOf(getActualPropertyMap().get("desiredHeight"));
|
220
320
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
321
|
+
Logger.T(TAG, " FILE ["+bitmapPath+"] orig["+picChoosen_imagewidth+"x"+picChoosen_imageheight+"] scaleto ["+idesiredHeight+"x"+idesiredHeight+"]");
|
322
|
+
if ((idesiredHeight > 0) && (idesiredWidth > 0)) {
|
323
|
+
// process resize
|
324
|
+
Logger.T(TAG, "Do SCALE orig["+picChoosen_imagewidth+"x"+picChoosen_imageheight+"] scaleto ["+idesiredHeight+"x"+idesiredHeight+"]");
|
325
|
+
|
326
|
+
|
327
|
+
float fcurWidth = picChoosen_imagewidth;
|
328
|
+
float fcurHeight = picChoosen_imageheight;
|
329
|
+
|
330
|
+
float desiredWidth = idesiredWidth;
|
331
|
+
float desiredHeight = idesiredHeight;
|
332
|
+
|
333
|
+
float kw = desiredWidth / fcurWidth;
|
334
|
+
float kh = desiredHeight / fcurHeight;
|
335
|
+
|
336
|
+
if (kw > 1.0) {
|
337
|
+
if (kh > kw) {
|
338
|
+
kw = kw/kh;
|
339
|
+
kh = 1.0f;
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
kh = kh/kw;
|
343
|
+
kw = 1.0f;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
else {
|
347
|
+
if (kh > 1.0) {
|
348
|
+
kw = kw/kh;
|
349
|
+
kh = 1.0f;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
float k = kw;
|
354
|
+
if (kw > kh) {
|
355
|
+
k = kh;
|
356
|
+
}
|
357
|
+
|
358
|
+
int newWidth = (int)(picChoosen_imagewidth*k);
|
359
|
+
int newHeight = (int)(picChoosen_imageheight*k);
|
360
|
+
|
361
|
+
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
|
362
|
+
bmOptions.inJustDecodeBounds = false;
|
363
|
+
bmOptions.inSampleSize = picChoosen_imagewidth / newWidth;
|
364
|
+
|
365
|
+
picChoosen_imagewidth = newWidth;
|
366
|
+
picChoosen_imageheight = newHeight;
|
367
|
+
|
368
|
+
|
369
|
+
Logger.T(TAG, "Load samle scale ["+bmOptions.inSampleSize+"]");
|
370
|
+
|
371
|
+
bmOptions.inPurgeable = true;
|
372
|
+
|
373
|
+
Bitmap bitmap = BitmapFactory.decodeFile(bitmapPath, bmOptions);
|
374
|
+
|
375
|
+
Bitmap scaledBitmap=Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
|
376
|
+
ByteArrayOutputStream bos=new ByteArrayOutputStream();
|
377
|
+
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 75, bos);
|
378
|
+
bitmap.recycle();
|
379
|
+
bitmap=null;
|
380
|
+
OutputStream out;
|
381
|
+
out = new FileOutputStream(bitmapPath+"_tmp");
|
382
|
+
bos.writeTo(out);
|
383
|
+
bos.flush();
|
384
|
+
|
385
|
+
File file= new File(bitmapPath+"_tmp");
|
386
|
+
File file_old = new File(bitmapPath);
|
387
|
+
file_old.delete();
|
388
|
+
file.renameTo(new File(bitmapPath));
|
389
|
+
fixTheGalleryIssue(bitmapPath);
|
390
|
+
|
391
|
+
|
392
|
+
}
|
393
|
+
} catch (Exception e) {
|
394
|
+
// TODO: handle exception
|
395
|
+
e.printStackTrace();
|
396
|
+
}
|
397
|
+
Logger.T(TAG, "$$$ resize finished $$$");
|
224
398
|
}
|
399
|
+
|
225
400
|
try{
|
226
401
|
DefaultCameraAsyncTask async = new DefaultCameraAsyncTask(mMethodResult, resultMap, intent, resultCode);
|
227
|
-
async.execute();
|
402
|
+
async.execute();
|
228
403
|
}
|
229
404
|
catch(Exception ex)
|
230
405
|
{
|
231
|
-
|
232
|
-
}
|
233
|
-
}
|
234
|
-
else if (resultCode == Activity.RESULT_CANCELED)
|
235
|
-
{
|
406
|
+
ex.printStackTrace();
|
407
|
+
}
|
408
|
+
}
|
409
|
+
else if (resultCode == Activity.RESULT_CANCELED)
|
410
|
+
{
|
236
411
|
getActualPropertyMap().put("default_camera_key_path", "");
|
237
412
|
DefaultCameraAsyncTask async = new DefaultCameraAsyncTask(mMethodResult, resultMap, intent,resultCode);
|
238
413
|
async.execute();
|
@@ -240,7 +415,7 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
240
415
|
mMethodResult.setError("Unknown error");
|
241
416
|
}
|
242
417
|
} catch (Throwable err) {
|
243
|
-
Logger.E(TAG, err);
|
418
|
+
Logger.E(TAG, err);
|
244
419
|
if (stream != null) {
|
245
420
|
try {
|
246
421
|
stream.reset();
|
@@ -251,28 +426,28 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
251
426
|
}
|
252
427
|
mMethodResult.setError(err.getMessage());
|
253
428
|
}
|
254
|
-
|
429
|
+
|
255
430
|
}
|
256
431
|
|
257
432
|
|
258
433
|
|
259
|
-
private void fixTheGalleryIssue(String absoluteRenamedPath )
|
434
|
+
private void fixTheGalleryIssue(String absoluteRenamedPath )
|
260
435
|
{
|
261
|
-
|
262
|
-
|
263
|
-
|
436
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
437
|
+
{
|
438
|
+
MediaScannerConnection.scanFile(RhodesActivity.getContext(), new String[] {absoluteRenamedPath }, null, new MediaScannerConnection.OnScanCompletedListener() {
|
264
439
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
440
|
+
public void onScanCompleted(String path, Uri uri)
|
441
|
+
{
|
442
|
+
}
|
443
|
+
});
|
269
444
|
|
270
|
-
|
271
|
-
|
272
|
-
|
445
|
+
}
|
446
|
+
else
|
447
|
+
{
|
273
448
|
RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
|
274
|
-
|
275
|
-
|
449
|
+
}
|
450
|
+
|
276
451
|
|
277
452
|
}
|
278
453
|
|
@@ -284,9 +459,9 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
284
459
|
void releaseMethodResult() {
|
285
460
|
mMethodResult = null;
|
286
461
|
resultMap.clear();
|
287
|
-
mActualPropertyMap.clear();
|
288
|
-
getActualPropertyMap().put("DeviceGallery_Key", "");
|
289
|
-
getActualPropertyMap().put("ChoosePicture_Key", "");
|
462
|
+
//mActualPropertyMap.clear();
|
463
|
+
//getActualPropertyMap().put("DeviceGallery_Key", "");
|
464
|
+
//getActualPropertyMap().put("ChoosePicture_Key", "");
|
290
465
|
}
|
291
466
|
|
292
467
|
void setActualPropertyMap(Map<String, String> propertyMap) {
|
@@ -296,264 +471,335 @@ public class CameraRhoListener extends AbstractRhoListener implements
|
|
296
471
|
Map<String, String> getActualPropertyMap() {
|
297
472
|
return mActualPropertyMap;
|
298
473
|
}
|
299
|
-
|
474
|
+
|
300
475
|
/**
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
476
|
+
* AsyncTask class to handle keydispatchingtimedout or ANR caused
|
477
|
+
* when OK or Cancel button of default camera in clicked
|
478
|
+
* @param IMethodResult Object to set the hash map properties
|
479
|
+
* @param HashMap to set properties of captured image to map
|
480
|
+
* @param Intent
|
481
|
+
* @param ResultCode to decide click is OK or Cancel
|
482
|
+
*/
|
308
483
|
public class DefaultCameraAsyncTask extends AsyncTask<Void, Void, Void>{
|
309
484
|
|
310
485
|
IMethodResult inMethodRes;
|
311
486
|
HashMap<String, Object> inResultMap = new HashMap<String,Object>();
|
312
487
|
Intent intent = new Intent();
|
313
488
|
int resCode;
|
314
|
-
|
489
|
+
|
315
490
|
public DefaultCameraAsyncTask(IMethodResult inMethodRes, HashMap<String, Object> inResultMap, Intent intent, int resCode){
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
491
|
+
this.inMethodRes = inMethodRes;
|
492
|
+
this.inResultMap = inResultMap;
|
493
|
+
this.intent = intent;
|
494
|
+
this.resCode = resCode;
|
495
|
+
}
|
496
|
+
|
322
497
|
@Override
|
323
498
|
protected Void doInBackground(Void... params) {
|
324
499
|
|
325
500
|
if(resCode == -1){
|
326
501
|
if (intent != null && intent.hasExtra("error")) {
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
}
|
332
|
-
else{
|
333
|
-
inResultMap.put("status","ok");
|
334
|
-
if(CameraSingletonObject.deprecated_choose_pic || CameraObject.deprecated_take_pic){
|
335
|
-
inResultMap.put("image_uri", "db/db-files/"+ curUri.toString().substring(curUri.toString().lastIndexOf("/")+1, curUri.toString().length()));
|
336
|
-
inResultMap.put("image_format", "jpg");
|
502
|
+
inResultMap.put("message", ""+intent.getStringExtra("error"));
|
503
|
+
if(intent.getStringExtra("error").contains("\\"))
|
504
|
+
inResultMap.put("message", "File path is invalid.");
|
505
|
+
inResultMap.put("status", "error");
|
337
506
|
}
|
338
507
|
else{
|
339
|
-
|
340
|
-
inResultMap.put("imageUri", imgPath);
|
341
|
-
inResultMap.put("imageFormat", "jpg");
|
342
|
-
}else{
|
343
|
-
inResultMap.put("imageUri", curUri.toString());
|
344
|
-
inResultMap.put("imageFormat", "jpg");
|
345
|
-
}
|
346
|
-
}
|
347
|
-
if(picChoosen_imagewidth > 0){
|
508
|
+
inResultMap.put("status","ok");
|
348
509
|
if(CameraSingletonObject.deprecated_choose_pic || CameraObject.deprecated_take_pic){
|
349
|
-
inResultMap.put("
|
350
|
-
inResultMap.put("
|
510
|
+
inResultMap.put("image_uri", "db/db-files/"+ curUri.toString().substring(curUri.toString().lastIndexOf("/")+1, curUri.toString().length()));
|
511
|
+
inResultMap.put("image_format", "jpg");
|
351
512
|
}
|
352
513
|
else{
|
353
|
-
|
354
|
-
|
514
|
+
if((getActualPropertyMap().get("default_camera_key_path") != null) && (getActualPropertyMap().get("default_camera_key_path") != "")){
|
515
|
+
inResultMap.put("imageUri", imgPath);
|
516
|
+
inResultMap.put("imageFormat", "jpg");
|
517
|
+
}else{
|
518
|
+
inResultMap.put("imageUri", curUri.toString());
|
519
|
+
inResultMap.put("imageFormat", "jpg");
|
520
|
+
}
|
355
521
|
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
522
|
+
if(picChoosen_imagewidth > 0){
|
523
|
+
if(CameraSingletonObject.deprecated_choose_pic || CameraObject.deprecated_take_pic){
|
524
|
+
inResultMap.put("image_width", "" + picChoosen_imagewidth);
|
525
|
+
inResultMap.put("image_height", "" + picChoosen_imageheight);
|
526
|
+
}
|
527
|
+
else{
|
528
|
+
inResultMap.put("imageWidth", "" + picChoosen_imagewidth);
|
529
|
+
inResultMap.put("imageHeight", "" + picChoosen_imageheight);
|
530
|
+
}
|
361
531
|
}
|
362
532
|
else{
|
363
|
-
|
364
|
-
|
533
|
+
if(CameraSingletonObject.deprecated_choose_pic || CameraObject.deprecated_take_pic){
|
534
|
+
inResultMap.put("image_width", "" + picChoosen_imagewidth);
|
535
|
+
inResultMap.put("image_height", "" + picChoosen_imageheight);
|
536
|
+
}
|
537
|
+
else{
|
538
|
+
inResultMap.put("imageWidth", "" + intent.getExtras().get("IMAGE_WIDTH"));
|
539
|
+
inResultMap.put("imageHeight", "" + intent.getExtras().get("IMAGE_HEIGHT"));
|
540
|
+
}
|
365
541
|
}
|
366
542
|
}
|
367
|
-
|
368
|
-
|
543
|
+
|
369
544
|
}else if(resCode == 0){
|
370
|
-
|
545
|
+
|
371
546
|
inResultMap.put("message", "User canceled operation.");
|
372
547
|
if (intent != null && intent.hasExtra("error")) {
|
373
548
|
inResultMap.put("message", ""+intent.getStringExtra("error"));
|
374
549
|
if(intent.getStringExtra("error").contains("\\"))
|
375
|
-
|
550
|
+
inResultMap.put("message", "File path is invalid.");
|
376
551
|
inResultMap.put("status", "error");
|
377
552
|
} else {
|
378
553
|
inResultMap.put("status", "cancel");
|
379
554
|
}
|
380
555
|
}
|
381
556
|
return null;
|
382
|
-
|
383
|
-
}
|
384
|
-
|
557
|
+
|
558
|
+
}
|
559
|
+
|
385
560
|
@Override
|
386
561
|
protected void onPostExecute(Void result) {
|
387
562
|
super.onPostExecute(result);
|
388
563
|
inMethodRes.set(inResultMap);
|
564
|
+
cleanState();
|
389
565
|
releaseMethodResult();
|
390
566
|
}
|
391
|
-
|
567
|
+
|
392
568
|
}
|
393
|
-
|
569
|
+
|
394
570
|
/*
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
571
|
+
* method to convert uri to file path
|
572
|
+
*
|
573
|
+
* @param Uri of file
|
574
|
+
* @returns String path of file
|
575
|
+
*
|
576
|
+
*/
|
401
577
|
private String getFilePath(Uri uri){
|
402
|
-
String
|
403
|
-
Cursor imageCursor = RhodesActivity.getContext().getContentResolver().query(
|
404
|
-
uri, null, null, null, null);
|
405
|
-
if(imageCursor.moveToFirst()){
|
406
|
-
mImgPath = imageCursor.getString(imageCursor
|
407
|
-
.getColumnIndex(MediaColumns.DATA));
|
408
|
-
imageCursor.close();
|
409
|
-
|
410
|
-
}
|
411
|
-
return mImgPath;
|
412
|
-
}
|
413
|
-
|
414
|
-
/**
|
415
|
-
* Copy image.
|
416
|
-
* Function to copy image from sd card to application root path
|
417
|
-
*
|
418
|
-
* @param photo
|
419
|
-
* the photo
|
420
|
-
* @return the string
|
421
|
-
*/
|
422
|
-
public String copyImg(String imgPath){
|
423
|
-
|
424
|
-
File oldFile = new File(imgPath);
|
425
|
-
|
426
|
-
int lastIndex = rename.lastIndexOf("/");
|
427
|
-
|
428
|
-
String file_name= rename.substring(lastIndex+1, rename.length());
|
429
|
-
|
430
|
-
File mediafile = new File(RhoFileApi.getDbFilesPath(), file_name);
|
431
|
-
|
432
|
-
//File mediafile = new File(RhoFileApi.getDbFilesPath(), rename);
|
433
|
-
FileInputStream finput= null;
|
434
|
-
FileOutputStream fout = null;
|
578
|
+
String resultPath = null;
|
435
579
|
try {
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
580
|
+
String mImgPath = null;
|
581
|
+
Cursor imageCursor = RhodesActivity.getContext().getContentResolver().query(
|
582
|
+
uri, null, null, null, null);
|
583
|
+
if(imageCursor.moveToFirst()){
|
584
|
+
mImgPath = imageCursor.getString(imageCursor
|
585
|
+
.getColumnIndex(MediaColumns.DATA));
|
586
|
+
imageCursor.close();
|
442
587
|
}
|
443
|
-
|
588
|
+
resultPath = mImgPath;
|
589
|
+
}
|
590
|
+
catch (Exception e) {
|
444
591
|
e.printStackTrace();
|
445
|
-
}
|
592
|
+
}
|
593
|
+
try {
|
594
|
+
if (resultPath == null) {
|
595
|
+
|
596
|
+
Uri selectedImage = uri;
|
597
|
+
String[] filePathColumn = { MediaStore.Images.Media.DATA };
|
598
|
+
|
599
|
+
Cursor cursor = RhodesActivity.getContext().getContentResolver().query(selectedImage,
|
600
|
+
filePathColumn, null, null, null);
|
601
|
+
cursor.moveToFirst();
|
602
|
+
|
603
|
+
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
604
|
+
resultPath = cursor.getString(columnIndex);
|
605
|
+
cursor.close();
|
606
|
+
|
607
|
+
}
|
608
|
+
}
|
609
|
+
catch (Exception e) {
|
446
610
|
e.printStackTrace();
|
447
|
-
}
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
611
|
+
}
|
612
|
+
return resultPath;
|
613
|
+
}
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
/**
|
619
|
+
* Copy image.
|
620
|
+
* Function to copy image from sd card to application root path
|
621
|
+
*
|
622
|
+
* @param photo
|
623
|
+
* the photo
|
624
|
+
* @return the string
|
625
|
+
*/
|
626
|
+
public String copyImg(String imgPath){
|
627
|
+
|
628
|
+
File oldFile = new File(imgPath);
|
629
|
+
|
630
|
+
int lastIndex = rename.lastIndexOf("/");
|
631
|
+
|
632
|
+
String file_name= rename.substring(lastIndex+1, rename.length());
|
633
|
+
|
634
|
+
File mediafile = new File(RhoFileApi.getDbFilesPath(), file_name);
|
635
|
+
|
636
|
+
//File mediafile = new File(RhoFileApi.getDbFilesPath(), rename);
|
637
|
+
FileInputStream finput= null;
|
638
|
+
FileOutputStream fout = null;
|
639
|
+
try {
|
640
|
+
finput = new FileInputStream(oldFile);
|
641
|
+
fout = new FileOutputStream(mediafile);
|
642
|
+
byte[] b = new byte[1024];
|
643
|
+
int read = 0;
|
644
|
+
while ((read = finput.read(b)) != -1) {
|
645
|
+
fout.write(b, 0, read);
|
646
|
+
}
|
647
|
+
} catch (FileNotFoundException e) {
|
648
|
+
e.printStackTrace();
|
649
|
+
} catch (IOException e) {
|
650
|
+
e.printStackTrace();
|
651
|
+
} finally {
|
652
|
+
if(finput != null){
|
653
|
+
try {
|
654
|
+
finput.close();
|
655
|
+
} catch (IOException e) {
|
656
|
+
e.printStackTrace();
|
454
657
|
}
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
658
|
+
}
|
659
|
+
|
660
|
+
if(fout != null){
|
661
|
+
try {
|
662
|
+
fout.close();
|
663
|
+
} catch (IOException e) {
|
664
|
+
e.printStackTrace();
|
462
665
|
}
|
463
666
|
}
|
464
|
-
|
465
|
-
return mediafile.getAbsolutePath();
|
466
667
|
}
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
668
|
+
|
669
|
+
return mediafile.getAbsolutePath();
|
670
|
+
}
|
671
|
+
|
672
|
+
|
673
|
+
public String copyImgToTarget(String srcPath, String dstPath) {
|
674
|
+
|
675
|
+
File oldFile = new File(srcPath);
|
676
|
+
File mediafile = new File(dstPath);
|
677
|
+
|
678
|
+
//File mediafile = new File(RhoFileApi.getDbFilesPath(), rename);
|
679
|
+
FileInputStream finput= null;
|
680
|
+
FileOutputStream fout = null;
|
681
|
+
try {
|
682
|
+
finput = new FileInputStream(oldFile);
|
683
|
+
fout = new FileOutputStream(mediafile);
|
684
|
+
byte[] b = new byte[1024];
|
685
|
+
int read = 0;
|
686
|
+
while ((read = finput.read(b)) != -1) {
|
687
|
+
fout.write(b, 0, read);
|
688
|
+
}
|
689
|
+
} catch (FileNotFoundException e) {
|
690
|
+
e.printStackTrace();
|
691
|
+
} catch (IOException e) {
|
692
|
+
e.printStackTrace();
|
693
|
+
} finally {
|
694
|
+
if(finput != null){
|
695
|
+
try {
|
696
|
+
finput.close();
|
697
|
+
} catch (IOException e) {
|
698
|
+
e.printStackTrace();
|
699
|
+
}
|
700
|
+
}
|
701
|
+
|
702
|
+
if(fout != null){
|
703
|
+
try {
|
704
|
+
fout.close();
|
705
|
+
} catch (IOException e) {
|
706
|
+
e.printStackTrace();
|
707
|
+
}
|
708
|
+
}
|
709
|
+
}
|
710
|
+
|
711
|
+
return mediafile.getAbsolutePath();
|
712
|
+
}
|
713
|
+
|
714
|
+
/**
|
715
|
+
* copyImgAsUserChoice image.
|
716
|
+
* Function to copy image from sd card to User specific path
|
717
|
+
* Provided in TestCam.html file.
|
718
|
+
* @param photo
|
719
|
+
* the photo
|
720
|
+
*
|
721
|
+
*/
|
722
|
+
public void copyImgAsUserChoice(String imgPath){
|
477
723
|
if(rename.contains("sdcard")){
|
478
|
-
|
724
|
+
|
479
725
|
Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
|
480
|
-
|
481
726
|
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
}
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
727
|
+
|
728
|
+
if(isSDPresent)
|
729
|
+
{
|
730
|
+
|
731
|
+
File oldFile = new File(imgPath);
|
732
|
+
|
733
|
+
int lastIndex = rename.lastIndexOf("/");
|
734
|
+
|
735
|
+
String subfolderName = rename.replaceAll("/sdcard", "");
|
736
|
+
String folderName = subfolderName.substring(subfolderName.indexOf("/")+1,subfolderName.lastIndexOf("/"));
|
737
|
+
|
738
|
+
String file_name= rename.substring(lastIndex+1, rename.length());
|
739
|
+
|
740
|
+
File directory = new File(Environment.getExternalStorageDirectory()+File.separator + folderName);
|
741
|
+
boolean flag = directory.mkdirs();
|
742
|
+
|
743
|
+
File mediafile = new File(directory +File.separator + file_name);
|
744
|
+
|
745
|
+
|
746
|
+
FileInputStream finput= null;
|
747
|
+
FileOutputStream fout = null;
|
748
|
+
try {
|
749
|
+
finput = new FileInputStream(oldFile);
|
750
|
+
fout = new FileOutputStream(mediafile);
|
751
|
+
byte[] b = new byte[1024];
|
752
|
+
int read = 0;
|
753
|
+
while ((read = finput.read(b)) != -1) {
|
754
|
+
fout.write(b, 0, read);
|
755
|
+
}
|
756
|
+
} catch (FileNotFoundException e) {
|
757
|
+
e.printStackTrace();
|
758
|
+
} catch (IOException e) {
|
759
|
+
e.printStackTrace();
|
760
|
+
} finally {
|
761
|
+
if(finput != null){
|
762
|
+
try {
|
763
|
+
finput.close();
|
764
|
+
|
765
|
+
} catch (IOException e) {
|
766
|
+
e.printStackTrace();
|
522
767
|
}
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
768
|
+
}
|
769
|
+
|
770
|
+
if(fout != null){
|
771
|
+
try {
|
772
|
+
fout.close();
|
773
|
+
} catch (IOException e) {
|
774
|
+
e.printStackTrace();
|
530
775
|
}
|
531
776
|
}
|
532
|
-
deleteImage();
|
533
777
|
}
|
534
|
-
|
535
|
-
|
778
|
+
deleteImage();
|
536
779
|
}
|
780
|
+
|
781
|
+
|
537
782
|
}
|
783
|
+
}
|
538
784
|
|
539
785
|
/**
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
786
|
+
* deleteImage image.
|
787
|
+
* Function for Deleting the Image from SD card.
|
788
|
+
* And maintain a copy of same Image at user specific Path
|
789
|
+
* @param nothing
|
790
|
+
*
|
791
|
+
*/
|
546
792
|
public void deleteImage(){
|
547
793
|
String storageLocation = null;
|
548
794
|
storageLocation = Environment.getExternalStorageDirectory().toString();
|
549
|
-
|
795
|
+
|
550
796
|
int lastIndex = rename.lastIndexOf("/");
|
551
797
|
String file_name= rename.substring(lastIndex+1, rename.length());
|
552
|
-
|
798
|
+
|
553
799
|
File file = new File(storageLocation + "/Pictures/"+file_name);
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
800
|
+
if(file.exists()){
|
801
|
+
file.delete();
|
802
|
+
}
|
803
|
+
}
|
804
|
+
|
559
805
|
}
|