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.
Files changed (31) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG +10 -0
  3. data/lib/build/development/platform.rb +5 -1
  4. data/lib/build/development/web_server.rb +2 -0
  5. data/lib/commonAPI/coreapi/ext/shared/TimerImpl.cpp +10 -1
  6. data/lib/commonAPI/eventsource/ext/platform/android/ext_native.files +4 -4
  7. data/lib/commonAPI/eventsource/ext/shared/EventSource.h +2 -2
  8. data/lib/commonAPI/mediacapture/ext/camera.xml +16 -11
  9. data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraEclair.java +17 -6
  10. data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraObject.java +304 -294
  11. data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraRhoListener.java +528 -282
  12. data/lib/commonAPI/mediacapture/ext/platform/android/src/com/rho/camera/CameraSingletonObject.java +119 -94
  13. data/lib/commonAPI/mediacapture/ext/platform/wm/Mediacapture.vcproj +3 -3
  14. data/lib/commonAPI/mediacapture/ext/platform/wp8/src/Camera_impl.cs +63 -43
  15. data/lib/extensions/barcode-old/ext/barcode/platform/iphone/Rakefile +1 -1
  16. data/lib/framework/rhodes.rb +2 -2
  17. data/lib/framework/version.rb +2 -2
  18. data/lib/rhodes.rb +2 -2
  19. data/platform/android/Rhodes/jni/src/sslimpl.cpp +7 -2
  20. data/platform/android/Rhodes/src/com/rhomobile/rhodes/socket/SSLImpl.java +11 -4
  21. data/platform/android/build/android.rake +6 -0
  22. data/platform/iphone/Classes/SimpleMainView.m +8 -3
  23. data/platform/iphone/Classes/URLProtocol/CRhoURLProtocol.m +1 -1
  24. data/platform/shared/common/RhodesApp.cpp +4 -0
  25. data/platform/shared/common/RhodesApp.h +8 -0
  26. data/platform/shared/net/CURLNetRequest.cpp +4 -2
  27. data/platform/shared/net/HttpServer.cpp +2 -2
  28. data/platform/shared/ruby/ext/rho/rhoruby.c +1 -1
  29. data/res/generators/templates/iphone_project/Bremen7.xcodeproj/project.pbxproj +3 -0
  30. data/version +1 -1
  31. metadata +2 -2
@@ -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
- IRhoListener {
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
- String curPath = null;
89
- String strCaptureUri = getActualPropertyMap().get("captureUri");
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
- mBitmap = BitmapFactory.decodeFile(curUri.getPath());
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
- mBitmap = BitmapFactory.decodeFile(imgPath);
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
- // Uri.parse(curUri.getPath())));
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
- // Uri.parse(curUri.getPath())));
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
- if((getActualPropertyMap().get("outputFormat").equalsIgnoreCase("dataUri"))){
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
- curUri = captureUri;
165
-
166
-
198
+ {
199
+ Logger.T(TAG, "captureUri != null");
200
+
201
+ curUri = captureUri;
202
+
167
203
  if (getActualPropertyMap().get("dataURI") == null) {
168
- imgPath = getFilePath(curUri);
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
- try {
175
- mBitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, options);
176
- if (!getActualPropertyMap().containsKey("fileName") && getActualPropertyMap().get("ChoosePicture_Key") == null){
177
- f.renameTo(new File(f.getParentFile(), rename));
178
- String pathAfterRename = f.getParentFile().getAbsolutePath() +"/"+rename;
179
- fixTheGalleryIssue(pathAfterRename);
180
- // RhodesActivity.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
181
- // Uri.parse(f.getAbsolutePath())));
182
- }
183
- } catch (FileNotFoundException e) {
184
- e.printStackTrace();
185
- }
186
- picChoosen_imagewidth = mBitmap.getWidth();
187
- picChoosen_imageheight = mBitmap.getHeight();
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.getScheme().equals("file"))
199
- {
200
- curPath = curUri.getPath();
201
- String dataDir=RhodesActivity.safeGetInstance().getApplicationInfo().dataDir;
202
- dataDir=dataDir+curPath.substring(curPath.lastIndexOf("/") );
203
-
204
- if(getActualPropertyMap().get("fileName")==null)
205
- {
206
- getActualPropertyMap().put("fileName",dataDir);
207
- }
208
- if(getActualPropertyMap().get("fileName").contains(".jpg"))
209
- targetPath = getActualPropertyMap().get("fileName");
210
- else
211
- targetPath = getActualPropertyMap().get("fileName")+".jpg";
212
- File curFile = new File(curPath);
213
-
214
- if (!curPath.equals(targetPath))
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
- Logger.T(TAG, "File copied to " + targetPath);
219
- curUri = Uri.fromFile(new File(targetPath));
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
- imgPath = copyImg(curPath);
222
- curUri = Uri.parse(imgPath);
223
- copyImgAsUserChoice(curPath);
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
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
262
- {
263
- MediaScannerConnection.scanFile(RhodesActivity.getContext(), new String[] {absoluteRenamedPath }, null, new MediaScannerConnection.OnScanCompletedListener() {
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
- public void onScanCompleted(String path, Uri uri)
266
- {
267
- }
268
- });
440
+ public void onScanCompleted(String path, Uri uri)
441
+ {
442
+ }
443
+ });
269
444
 
270
- }
271
- else
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
- * AsyncTask class to handle keydispatchingtimedout or ANR caused
302
- * when OK or Cancel button of default camera in clicked
303
- * @param IMethodResult Object to set the hash map properties
304
- * @param HashMap to set properties of captured image to map
305
- * @param Intent
306
- * @param ResultCode to decide click is OK or Cancel
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
- this.inMethodRes = inMethodRes;
317
- this.inResultMap = inResultMap;
318
- this.intent = intent;
319
- this.resCode = resCode;
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
- inResultMap.put("message", ""+intent.getStringExtra("error"));
328
- if(intent.getStringExtra("error").contains("\\"))
329
- inResultMap.put("message", "File path is invalid.");
330
- inResultMap.put("status", "error");
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
- if((getActualPropertyMap().get("default_camera_key_path") != null) && (getActualPropertyMap().get("default_camera_key_path") != "")){
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("image_width", "" + picChoosen_imagewidth);
350
- inResultMap.put("image_height", "" + picChoosen_imageheight);
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
- inResultMap.put("imageWidth", "" + picChoosen_imagewidth);
354
- inResultMap.put("imageHeight", "" + picChoosen_imageheight);
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
- else{
358
- if(CameraSingletonObject.deprecated_choose_pic || CameraObject.deprecated_take_pic){
359
- inResultMap.put("image_width", "" + picChoosen_imagewidth);
360
- inResultMap.put("image_height", "" + picChoosen_imageheight);
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
- inResultMap.put("imageWidth", "" + intent.getExtras().get("IMAGE_WIDTH"));
364
- inResultMap.put("imageHeight", "" + intent.getExtras().get("IMAGE_HEIGHT"));
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
- inResultMap.put("message", "File path is invalid.");
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
- * method to convert uri to file path
396
- *
397
- * @param Uri of file
398
- * @returns String path of file
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 mImgPath = null;
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
- finput = new FileInputStream(oldFile);
437
- fout = new FileOutputStream(mediafile);
438
- byte[] b = new byte[1024];
439
- int read = 0;
440
- while ((read = finput.read(b)) != -1) {
441
- fout.write(b, 0, read);
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
- } catch (FileNotFoundException e) {
588
+ resultPath = mImgPath;
589
+ }
590
+ catch (Exception e) {
444
591
  e.printStackTrace();
445
- } catch (IOException e) {
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
- } finally {
448
- if(finput != null){
449
- try {
450
- finput.close();
451
- } catch (IOException e) {
452
- e.printStackTrace();
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
- if(fout != null){
457
- try {
458
- fout.close();
459
- } catch (IOException e) {
460
- e.printStackTrace();
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
- * copyImgAsUserChoice image.
470
- * Function to copy image from sd card to User specific path
471
- * Provided in TestCam.html file.
472
- * @param photo
473
- * the photo
474
- *
475
- */
476
- public void copyImgAsUserChoice(String imgPath){
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
- if(isSDPresent)
483
- {
484
-
485
- File oldFile = new File(imgPath);
486
-
487
- int lastIndex = rename.lastIndexOf("/");
488
-
489
- String subfolderName = rename.replaceAll("/sdcard", "");
490
- String folderName = subfolderName.substring(subfolderName.indexOf("/")+1,subfolderName.lastIndexOf("/"));
491
-
492
- String file_name= rename.substring(lastIndex+1, rename.length());
493
-
494
- File directory = new File(Environment.getExternalStorageDirectory()+File.separator + folderName);
495
- boolean flag = directory.mkdirs();
496
-
497
- File mediafile = new File(directory +File.separator + file_name);
498
-
499
-
500
- FileInputStream finput= null;
501
- FileOutputStream fout = null;
502
- try {
503
- finput = new FileInputStream(oldFile);
504
- fout = new FileOutputStream(mediafile);
505
- byte[] b = new byte[1024];
506
- int read = 0;
507
- while ((read = finput.read(b)) != -1) {
508
- fout.write(b, 0, read);
509
- }
510
- } catch (FileNotFoundException e) {
511
- e.printStackTrace();
512
- } catch (IOException e) {
513
- e.printStackTrace();
514
- } finally {
515
- if(finput != null){
516
- try {
517
- finput.close();
518
-
519
- } catch (IOException e) {
520
- e.printStackTrace();
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
- if(fout != null){
525
- try {
526
- fout.close();
527
- } catch (IOException e) {
528
- e.printStackTrace();
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
- * deleteImage image.
541
- * Function for Deleting the Image from SD card.
542
- * And maintain a copy of same Image at user specific Path
543
- * @param nothing
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
- if(file.exists()){
555
- file.delete();
556
- }
557
- }
558
-
800
+ if(file.exists()){
801
+ file.delete();
802
+ }
803
+ }
804
+
559
805
  }