mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:42:51 +08:00
Adding video select to getPicture to line up with iOS
This commit is contained in:
parent
f271e2e0fa
commit
67393c516e
@ -49,6 +49,24 @@ Camera.EncodingType = {
|
|||||||
};
|
};
|
||||||
Camera.prototype.EncodingType = Camera.EncodingType;
|
Camera.prototype.EncodingType = Camera.EncodingType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of pictures to select from. Only applicable when
|
||||||
|
* PictureSourceType is PHOTOLIBRARY or SAVEDPHOTOALBUM
|
||||||
|
*
|
||||||
|
* Example: navigator.camera.getPicture(success, fail,
|
||||||
|
* { quality: 80,
|
||||||
|
* destinationType: Camera.DestinationType.DATA_URL,
|
||||||
|
* sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
|
||||||
|
* mediaType: Camera.MediaType.PICTURE})
|
||||||
|
*/
|
||||||
|
Camera.MediaType = {
|
||||||
|
PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
|
||||||
|
VIDEO: 1, // allow selection of video only, ONLY RETURNS URL
|
||||||
|
ALLMEDIA : 2 // allow selection from all media types
|
||||||
|
};
|
||||||
|
Camera.prototype.MediaType = Camera.MediaType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Source to getPicture from.
|
* Source to getPicture from.
|
||||||
*
|
*
|
||||||
@ -111,6 +129,10 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
|||||||
if (typeof options.encodingType == "number") {
|
if (typeof options.encodingType == "number") {
|
||||||
encodingType = this.options.encodingType;
|
encodingType = this.options.encodingType;
|
||||||
}
|
}
|
||||||
|
var mediaType = Camera.MediaType.PICTURE;
|
||||||
|
if (typeof options.mediaType == "number") {
|
||||||
|
mediaType = this.options.mediaType;
|
||||||
|
}
|
||||||
|
|
||||||
var targetWidth = -1;
|
var targetWidth = -1;
|
||||||
if (typeof options.targetWidth == "number") {
|
if (typeof options.targetWidth == "number") {
|
||||||
@ -132,7 +154,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
|
PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, mediaType]);
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
|
@ -43,15 +43,25 @@ public class CameraLauncher extends Plugin {
|
|||||||
private static final int CAMERA = 1; // Take picture from camera
|
private static final int CAMERA = 1; // Take picture from camera
|
||||||
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android)
|
private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android)
|
||||||
|
|
||||||
|
private static final int PICTURE = 0; // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
|
||||||
|
private static final int VIDEO = 1; // allow selection of video only, ONLY RETURNS URL
|
||||||
|
private static final int ALLMEDIA = 2; // allow selection from all media types
|
||||||
|
|
||||||
private static final int JPEG = 0; // Take a picture of type JPEG
|
private static final int JPEG = 0; // Take a picture of type JPEG
|
||||||
private static final int PNG = 1; // Take a picture of type PNG
|
private static final int PNG = 1; // Take a picture of type PNG
|
||||||
|
private static final String GET_PICTURE = "Get Picture";
|
||||||
|
private static final String GET_VIDEO = "Get Video";
|
||||||
|
private static final String GET_All = "Get All";
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "CameraLauncher";
|
||||||
|
|
||||||
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
private int targetWidth; // desired width of the image
|
private int targetWidth; // desired width of the image
|
||||||
private int targetHeight; // desired height of the image
|
private int targetHeight; // desired height of the image
|
||||||
private Uri imageUri;
|
private Uri imageUri; // Uri of captured image
|
||||||
private int encodingType;
|
private int encodingType; // Type of encoding to use
|
||||||
// Uri of captured image
|
private int mediaType; // What type of media to retrieve
|
||||||
|
|
||||||
public String callbackId;
|
public String callbackId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +106,10 @@ public class CameraLauncher extends Plugin {
|
|||||||
if (args.length() > 5) {
|
if (args.length() > 5) {
|
||||||
this.encodingType = args.getInt(5);
|
this.encodingType = args.getInt(5);
|
||||||
}
|
}
|
||||||
|
this.mediaType = PICTURE;
|
||||||
|
if (args.length() > 6) {
|
||||||
|
this.mediaType = args.getInt(6);
|
||||||
|
}
|
||||||
if (srcType == CAMERA) {
|
if (srcType == CAMERA) {
|
||||||
this.takePicture(args.getInt(0), destType, encodingType);
|
this.takePicture(args.getInt(0), destType, encodingType);
|
||||||
}
|
}
|
||||||
@ -174,11 +188,25 @@ public class CameraLauncher extends Plugin {
|
|||||||
this.mQuality = quality;
|
this.mQuality = quality;
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
|
String title = GET_PICTURE;
|
||||||
|
if (this.mediaType == PICTURE) {
|
||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
|
}
|
||||||
|
else if (this.mediaType == VIDEO) {
|
||||||
|
intent.setType("video/*");
|
||||||
|
title = GET_VIDEO;
|
||||||
|
}
|
||||||
|
else if (this.mediaType == ALLMEDIA) {
|
||||||
|
// I wanted to make the type 'image/*, video/*' but this does not work on all versions
|
||||||
|
// of android so I had to go with the wildcard search.
|
||||||
|
intent.setType("*/*");
|
||||||
|
title = GET_All;
|
||||||
|
}
|
||||||
|
|
||||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent,
|
this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent,
|
||||||
new String("Get Picture")), (srcType+1)*16 + returnType + 1);
|
new String(title)), (srcType+1)*16 + returnType + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,6 +355,13 @@ public class CameraLauncher extends Plugin {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
Uri uri = intent.getData();
|
Uri uri = intent.getData();
|
||||||
android.content.ContentResolver resolver = this.ctx.getContentResolver();
|
android.content.ContentResolver resolver = this.ctx.getContentResolver();
|
||||||
|
|
||||||
|
// If you ask for video or all media type you will automatically get back a file URI
|
||||||
|
// and there will be no attempt to resize any returned data
|
||||||
|
if (this.mediaType != PICTURE) {
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
// If sending base64 image back
|
// If sending base64 image back
|
||||||
if (destType == DATA_URL) {
|
if (destType == DATA_URL) {
|
||||||
try {
|
try {
|
||||||
@ -345,7 +380,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
// If sending filename back
|
// If sending filename back
|
||||||
else if (destType == FILE_URI) {
|
else if (destType == FILE_URI) {
|
||||||
// Do we need to scale the returned file
|
// Do we need to scale the returned file
|
||||||
if (this.targetHeight != 0 && this.targetWidth != 0) {
|
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
||||||
try {
|
try {
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||||
bitmap = scaleBitmap(bitmap);
|
bitmap = scaleBitmap(bitmap);
|
||||||
@ -370,6 +405,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
this.failPicture("Selection cancelled.");
|
this.failPicture("Selection cancelled.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user