[ 
https://issues.apache.org/jira/browse/CB-14047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16447317#comment-16447317
 ] 

ASF GitHub Bot commented on CB-14047:
-------------------------------------

macdonst closed pull request #319: CB-14047: (android) CameraLauncher: 
Replacing Repeated String literals with final variables
URL: https://github.com/apache/cordova-plugin-camera/pull/319
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index fbe8470e..03210828 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -87,6 +87,10 @@ Licensed to the Apache Software Foundation (ASF) under one
 
     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 @@ Licensed to the Apache Software Foundation (ASF) under one
     //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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Enhancement: Replacing Repeated String literals with final variables
> --------------------------------------------------------------------
>
>                 Key: CB-14047
>                 URL: https://issues.apache.org/jira/browse/CB-14047
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-plugin-camera
>    Affects Versions: cordova-android-7.0.0
>            Reporter: Hazem Saleh
>            Priority: Minor
>
> Replacing Repeated String literals with final variables.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to