mirror of
https://gitee.com/shuto/cordova-imagePicker.git
synced 2026-05-23 00:05:03 +08:00
Added the ability to return errors in resizeImagesTask, so that failed attempts to import will call return as errors, differently than cancelling. Also some whitespace fixing.
This commit is contained in:
@@ -17,53 +17,56 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class ImagePicker extends CordovaPlugin {
|
||||
public static String TAG = "ImagePicker";
|
||||
|
||||
private CallbackContext callbackContext;
|
||||
private JSONObject params;
|
||||
|
||||
public static String TAG = "ImagePicker";
|
||||
|
||||
private CallbackContext callbackContext;
|
||||
private JSONObject params;
|
||||
|
||||
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
||||
this.callbackContext = callbackContext;
|
||||
this.params = args.getJSONObject(0);
|
||||
this.callbackContext = callbackContext;
|
||||
this.params = args.getJSONObject(0);
|
||||
if (action.equals("getPictures")) {
|
||||
Intent intent = new Intent(cordova.getActivity(), MultiImageChooserActivity.class);
|
||||
int max = 20;
|
||||
int desiredWidth = 0;
|
||||
int desiredHeight = 0;
|
||||
int quality = 100;
|
||||
int desiredHeight = 0;
|
||||
int quality = 100;
|
||||
if (this.params.has("maximumImagesCount")) {
|
||||
max = this.params.getInt("maximumImagesCount");
|
||||
max = this.params.getInt("maximumImagesCount");
|
||||
}
|
||||
if (this.params.has("width")) {
|
||||
desiredWidth = this.params.getInt("width");
|
||||
desiredWidth = this.params.getInt("width");
|
||||
}
|
||||
if (this.params.has("height")) {
|
||||
desiredWidth = this.params.getInt("height");
|
||||
desiredWidth = this.params.getInt("height");
|
||||
}
|
||||
if (this.params.has("quality")) {
|
||||
quality = this.params.getInt("quality");
|
||||
}
|
||||
quality = this.params.getInt("quality");
|
||||
}
|
||||
intent.putExtra("MAX_IMAGES", max);
|
||||
intent.putExtra("WIDTH", desiredWidth);
|
||||
intent.putExtra("HEIGHT", desiredHeight);
|
||||
intent.putExtra("QUALITY", quality);
|
||||
if (this.cordova != null) {
|
||||
this.cordova.startActivityForResult((CordovaPlugin) this, intent, 0);
|
||||
}
|
||||
if (this.cordova != null) {
|
||||
this.cordova.startActivityForResult((CordovaPlugin) this, intent, 0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
ArrayList<String> fileNames = data.getStringArrayListExtra("MULTIPLEFILENAMES");
|
||||
JSONArray res = new JSONArray(fileNames);
|
||||
this.callbackContext.success(res);
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
JSONArray res = new JSONArray();
|
||||
this.callbackContext.success(res);
|
||||
} else {
|
||||
this.callbackContext.error("No images selected");
|
||||
}
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
ArrayList<String> fileNames = data.getStringArrayListExtra("MULTIPLEFILENAMES");
|
||||
JSONArray res = new JSONArray(fileNames);
|
||||
this.callbackContext.success(res);
|
||||
} else if (resultCode == Activity.RESULT_CANCELED && data != null) {
|
||||
String error = data.getStringExtra("ERRORMESSAGE");
|
||||
this.callbackContext.error("An error occurred loading one of the selected images");
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
JSONArray res = new JSONArray();
|
||||
this.callbackContext.success(res);
|
||||
} else {
|
||||
this.callbackContext.error("No images selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user