Skip to content

Commit

Permalink
Add validation on parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hkk595 committed Jan 30, 2018
1 parent 48d4025 commit e502c71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
2. Add the dependency in your module-level build.gradle
```groovy
dependencies {
compile 'com.github.hkk595:Resizer:v1.4'
compile 'com.github.hkk595:Resizer:v1.5'
}
```

Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/me/echodev/resizer/Resizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Resizer(Context context) {
* @return This Resizer instance, for chained settings.
*/
public Resizer setTargetLength(int targetLength) {
this.targetLength = targetLength;
this.targetLength = (targetLength < 0) ? 0 : targetLength;
return this;
}

Expand All @@ -53,7 +53,13 @@ public Resizer setTargetLength(int targetLength) {
* @return This Resizer instance, for chained settings.
*/
public Resizer setQuality(int quality) {
this.quality = quality;
if (quality < 0) {
this.quality = 0;
} else if (quality > 100) {
this.quality = 100;
} else {
this.quality = quality;
}
return this;
}

Expand All @@ -73,6 +79,8 @@ public Resizer setOutputFormat(String outputFormat) {
case "WEBP":
this.compressFormat = Bitmap.CompressFormat.WEBP;
break;
default:
break;
}
return this;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/me/echodev/resizer/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;

/**
* Created by K.K. Ho on 3/9/2017.
Expand All @@ -14,7 +15,7 @@ public class FileUtils {
public static String getOutputFilePath(Bitmap.CompressFormat compressFormat, String outputDirPath, String outputFilename, File sourceImage) {
String originalFileName = sourceImage.getName();
String targetFileName;
String targetFileExtension = "." + compressFormat.name().toLowerCase().replace("jpeg", "jpg");
String targetFileExtension = "." + compressFormat.name().toLowerCase(Locale.US).replace("jpeg", "jpg");

if (outputFilename == null) {
int extensionIndex = originalFileName.lastIndexOf('.');
Expand Down

0 comments on commit e502c71

Please sign in to comment.