CB-14047: (android) CameraLauncher: Replacing Repeated String literals with final variables (#319)
This commit is contained in:
parent
d9d80e40c1
commit
5ec121bf98
@ -87,6 +87,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
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 JPEG_EXTENSION = ".jpg";
|
||||||
|
private static final String PNG_EXTENSION = ".png";
|
||||||
|
private static final String PNG_MIME_TYPE = "image/png";
|
||||||
|
private static final String JPEG_MIME_TYPE = "image/jpeg";
|
||||||
private static final String GET_PICTURE = "Get Picture";
|
private static final String GET_PICTURE = "Get Picture";
|
||||||
private static final String GET_VIDEO = "Get Video";
|
private static final String GET_VIDEO = "Get Video";
|
||||||
private static final String GET_All = "Get All";
|
private static final String GET_All = "Get All";
|
||||||
@ -100,6 +104,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
//Where did this come from?
|
//Where did this come from?
|
||||||
private static final int CROP_CAMERA = 100;
|
private static final int CROP_CAMERA = 100;
|
||||||
|
|
||||||
|
private static final String TIME_FORMAT = "yyyyMMdd_HHmmss";
|
||||||
|
|
||||||
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
|
||||||
@ -341,9 +347,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encodingType == JPEG) {
|
if (encodingType == JPEG) {
|
||||||
fileName = fileName + ".jpg";
|
fileName = fileName + JPEG_EXTENSION;
|
||||||
} else if (encodingType == PNG) {
|
} else if (encodingType == PNG) {
|
||||||
fileName = fileName + ".png";
|
fileName = fileName + PNG_EXTENSION;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
|
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
|
||||||
}
|
}
|
||||||
@ -599,8 +605,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getPicturesPath() {
|
private String getPicturesPath() {
|
||||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
|
||||||
String imageFileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
|
String imageFileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? JPEG_EXTENSION : PNG_EXTENSION);
|
||||||
File storageDir = Environment.getExternalStoragePublicDirectory(
|
File storageDir = Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES);
|
Environment.DIRECTORY_PICTURES);
|
||||||
storageDir.mkdirs();
|
storageDir.mkdirs();
|
||||||
@ -621,8 +627,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
* @return String String value of mime type or empty string if mime type is not supported
|
* @return String String value of mime type or empty string if mime type is not supported
|
||||||
*/
|
*/
|
||||||
private String getMimetypeForFormat(int outputFormat) {
|
private String getMimetypeForFormat(int outputFormat) {
|
||||||
if (outputFormat == PNG) return "image/png";
|
if (outputFormat == PNG) return PNG_MIME_TYPE;
|
||||||
if (outputFormat == JPEG) return "image/jpeg";
|
if (outputFormat == JPEG) return JPEG_MIME_TYPE;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,7 +642,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
realPath.substring(realPath.lastIndexOf('/') + 1) :
|
realPath.substring(realPath.lastIndexOf('/') + 1) :
|
||||||
"modified." + (this.encodingType == JPEG ? "jpg" : "png");
|
"modified." + (this.encodingType == JPEG ? "jpg" : "png");
|
||||||
|
|
||||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
|
||||||
//String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
|
//String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
|
||||||
String modifiedPath = getTempDirectoryPath() + "/" + fileName;
|
String modifiedPath = getTempDirectoryPath() + "/" + fileName;
|
||||||
|
|
||||||
@ -704,7 +710,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
this.callbackContext.success(uriString);
|
this.callbackContext.success(uriString);
|
||||||
} else {
|
} else {
|
||||||
// If we don't have a valid image so quit.
|
// If we don't have a valid image so quit.
|
||||||
if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
|
if (!(JPEG_MIME_TYPE.equalsIgnoreCase(mimeType) || PNG_MIME_TYPE.equalsIgnoreCase(mimeType))) {
|
||||||
LOG.d(LOG_TAG, "I either have a null image path or bitmap");
|
LOG.d(LOG_TAG, "I either have a null image path or bitmap");
|
||||||
this.failPicture("Unable to retrieve path to picture!");
|
this.failPicture("Unable to retrieve path to picture!");
|
||||||
return;
|
return;
|
||||||
@ -912,7 +918,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
*/
|
*/
|
||||||
private Uri getUriFromMediaStore() {
|
private Uri getUriFromMediaStore() {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
|
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
|
||||||
Uri uri;
|
Uri uri;
|
||||||
try {
|
try {
|
||||||
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||||
@ -975,14 +981,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
InputStream fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
|
InputStream fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
|
||||||
if (fileStream != null) {
|
if (fileStream != null) {
|
||||||
// Generate a temporary file
|
// Generate a temporary file
|
||||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
|
||||||
String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
|
String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? JPEG_EXTENSION : PNG_EXTENSION);
|
||||||
localFile = new File(getTempDirectoryPath() + fileName);
|
localFile = new File(getTempDirectoryPath() + fileName);
|
||||||
galleryUri = Uri.fromFile(localFile);
|
galleryUri = Uri.fromFile(localFile);
|
||||||
writeUncompressedImage(fileStream, galleryUri);
|
writeUncompressedImage(fileStream, galleryUri);
|
||||||
try {
|
try {
|
||||||
String mimeType = FileHelper.getMimeType(imageUrl.toString(), cordova);
|
String mimeType = FileHelper.getMimeType(imageUrl.toString(), cordova);
|
||||||
if ("image/jpeg".equalsIgnoreCase(mimeType)) {
|
if (JPEG_MIME_TYPE.equalsIgnoreCase(mimeType)) {
|
||||||
// ExifInterface doesn't like the file:// prefix
|
// ExifInterface doesn't like the file:// prefix
|
||||||
String filePath = galleryUri.toString().replace("file://", "");
|
String filePath = galleryUri.toString().replace("file://", "");
|
||||||
// read exifData of source
|
// read exifData of source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user