platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java in rhodes-3.4.2 vs platform/android/Rhodes/src/com/rhomobile/rhodes/camera/Camera.java in rhodes-3.5.1.12
- old
+ new
@@ -25,15 +25,12 @@
*------------------------------------------------------------------------*/
package com.rhomobile.rhodes.camera;
import java.io.File;
-import java.util.Iterator;
-import java.util.List;
import android.content.Intent;
-import android.hardware.Camera.Size;
import android.os.Build;
import com.rhomobile.rhodes.Capabilities;
import com.rhomobile.rhodes.Logger;
import com.rhomobile.rhodes.RhodesActivity;
@@ -44,11 +41,11 @@
public class Camera {
private static final String TAG = "Camera";
- public static final String INTENT_EXTRA_PREFIX = RhodesService.INTENT_EXTRA_PREFIX + "camera.";
+ public static final String INTENT_EXTRA_PREFIX = RhodesService.INTENT_EXTRA_PREFIX + ".camera.";
private static int mMainCamera_max_Width = 0;
private static int mMainCamera_max_Height = 0;
private static int mFrontCamera_max_Width = 0;
private static int mFrontCamera_max_Height = 0;
@@ -131,33 +128,37 @@
klass = c;
settings = new CameraSettings(settingsObj);
}
public void run() {
- init();
- RhodesActivity ra = RhodesActivity.getInstance();
- Intent intent = new Intent(ra, klass);
- intent.putExtra(INTENT_EXTRA_PREFIX + "callback", url);
- intent.putExtra(INTENT_EXTRA_PREFIX + "settings", settings);
- ra.startActivity(intent);
+ try {
+ init();
+ RhodesActivity ra = RhodesActivity.safeGetInstance();
+ Intent intent = new Intent(ra, klass);
+ intent.putExtra(INTENT_EXTRA_PREFIX + "callback", url);
+ intent.putExtra(INTENT_EXTRA_PREFIX + "settings", settings);
+ ra.startActivity(intent);
+ } catch (Exception e) {
+ Logger.E(TAG, e);
+ }
}
};
public static void takePicture(String url, Object params_obj) {
try {
Runnable runnable = Capabilities.CAMERA_ENABLED ? new Picture(url, ImageCapture.class, params_obj) :
new CameraDisabled(url);
- PerformOnUiThread.exec(runnable, false);
+ PerformOnUiThread.exec(runnable);
}
catch (Exception e) {
reportFail("takePicture", e);
}
}
public static void choosePicture(String url) {
try {
- PerformOnUiThread.exec(new Picture(url, FileList.class, null), false);
+ PerformOnUiThread.exec(new Picture(url, FileList.class, null));
}
catch (Exception e) {
reportFail("choosePicture", e);
}
}
@@ -168,12 +169,29 @@
if (idx != -1)
fp = fp.substring(idx + 1);
execute_callback(callbackUrl, fp, "", fp.length() == 0, w, h, format);
}
+
+ public static void doCancelCallback(String callbackUrl) {
+ execute_callback(callbackUrl, null, null, true, 0, 0, null);
+
+ }
+ public static void doErrorCallback(String callbackUrl, String errorMsg) {
+ execute_callback(callbackUrl, null, errorMsg, false, 0, 0, null);
+
+ }
+
+
public static void execute_callback(String callbackUrl, String filePath, String error, boolean cancelled, int w, int h, String format) {
+ if (callbackUrl == null) {
+ return;
+ }
+ if (callbackUrl.length() <= 0) {
+ return;
+ }
StringBuffer body = new StringBuffer();
body.append("&rho_callback=1");
if (cancelled || ((error != null) && (error.length() > 0))) {
if (cancelled) {
body.append("&status=cancel&message=User canceled operation.");
@@ -211,10 +229,10 @@
}
}
}
}
catch (Exception e) {
- Logger.E(TAG, e.getMessage());
+ Logger.E(TAG, e);
}
if (camera == null) {
int[] res = {0,0};