Skip to content
Permalink
Browse files
CB-14047: (android) CameraLauncher: Replacing Repeated String literal…
…s with final variables (#319)
  • Loading branch information
hazems authored and macdonst committed Apr 22, 2018
1 parent d9d80e4 commit 5ec121bf981374973833061ab466ce41573ab6e7
Showing 1 changed file with 18 additions and 12 deletions.
@@ -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 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_VIDEO = "Get Video";
private static final String GET_All = "Get All";
@@ -100,6 +104,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
//Where did this come from?
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 targetWidth; // desired width of the image
private int targetHeight; // desired height of the image
@@ -341,9 +347,9 @@ private File createCaptureFile(int encodingType, String fileName) {
}

if (encodingType == JPEG) {
fileName = fileName + ".jpg";
fileName = fileName + JPEG_EXTENSION;
} else if (encodingType == PNG) {
fileName = fileName + ".png";
fileName = fileName + PNG_EXTENSION;
} else {
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
}
@@ -599,8 +605,8 @@ else if (destType == FILE_URI || destType == NATIVE_URI) {
}

private String getPicturesPath() {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
String imageFileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? JPEG_EXTENSION : PNG_EXTENSION);
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
storageDir.mkdirs();
@@ -621,8 +627,8 @@ private void refreshGallery(Uri contentUri) {
* @return String String value of mime type or empty string if mime type is not supported
*/
private String getMimetypeForFormat(int outputFormat) {
if (outputFormat == PNG) return "image/png";
if (outputFormat == JPEG) return "image/jpeg";
if (outputFormat == PNG) return PNG_MIME_TYPE;
if (outputFormat == JPEG) return JPEG_MIME_TYPE;
return "";
}

@@ -636,7 +642,7 @@ private String outputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
realPath.substring(realPath.lastIndexOf('/') + 1) :
"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 modifiedPath = getTempDirectoryPath() + "/" + fileName;

@@ -704,7 +710,7 @@ private void processResultFromGallery(int destType, Intent intent) {
this.callbackContext.success(uriString);
} else {
// 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");
this.failPicture("Unable to retrieve path to picture!");
return;
@@ -912,7 +918,7 @@ private void writeUncompressedImage(Uri src, Uri dest) throws FileNotFoundExcept
*/
private Uri getUriFromMediaStore() {
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;
try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
@@ -975,14 +981,14 @@ private Bitmap getScaledAndRotatedBitmap(String imageUrl) throws IOException {
InputStream fileStream = FileHelper.getInputStreamFromUriString(imageUrl, cordova);
if (fileStream != null) {
// Generate a temporary file
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? JPEG_EXTENSION : PNG_EXTENSION);
localFile = new File(getTempDirectoryPath() + fileName);
galleryUri = Uri.fromFile(localFile);
writeUncompressedImage(fileStream, galleryUri);
try {
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
String filePath = galleryUri.toString().replace("file://", "");
// read exifData of source

0 comments on commit 5ec121b

Please sign in to comment.