Skip to content

Commit

Permalink
Add JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
hkk595 committed Jan 27, 2018
1 parent 494f008 commit 48d4025
Show file tree
Hide file tree
Showing 20 changed files with 2,711 additions and 9 deletions.
11 changes: 8 additions & 3 deletions 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.3'
compile 'com.github.hkk595:Resizer:v1.4'
}
```

Expand All @@ -27,6 +27,7 @@ File resizedImage = new Resizer(this)
.setTargetLength(1080)
.setQuality(80)
.setOutputFormat("JPEG")
.setOutputFilename("resized_image")
.setOutputDirPath(storagePath)
.setSourceImage(originalImage)
.getResizedFile();
Expand All @@ -38,7 +39,7 @@ Bitmap resizedImage = new Resizer(this)
.setSourceImage(originalImage)
.getResizedBitmap();
```
Note: You only need to specify the target length (in pixel) of the longer side of the image. Resizer will calculate the rest automatically.
Note: You only need to specify the target length (in pixel) of the longer side (or either side if it's a square) of the image. Resizer will calculate the rest automatically.

#### Using RxJava 2 with RxAndroid to get the resized image asynchronously
```java
Expand All @@ -47,6 +48,7 @@ new Resizer(this)
.setTargetLength(1080)
.setQuality(80)
.setOutputFormat("JPEG")
.setOutputFilename("resized_image")
.setOutputDirPath(storagePath)
.setSourceImage(originalImage)
.getResizedFileAsFlowable()
Expand Down Expand Up @@ -84,7 +86,9 @@ new Resizer(this)
}
});
```
Note: You don't need to declare the new image as final nor array if it is an instance variable of the class, instead of a local variable in a function.
Note: You don't need to declare the new image as final nor array if it's an instance variable of the class, instead of a local variable in a function.

#### Refer to the [JavaDoc](https://hkk595.github.io/Resizer) for more details.

#### Library specification
Minimum SDK: API 16
Expand All @@ -93,6 +97,7 @@ Note: You don't need to declare the new image as final nor array if it is an ins
targetLength: 1080
quality: 80
outputFormat: JPEG
outputFilename: same as the source file
outputDirPath: the external files directory of your app
Supported input formats:
Expand Down
67 changes: 61 additions & 6 deletions app/src/main/java/me/echodev/resizer/Resizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
* Created by K.K. Ho on 1/9/2017.
*/

/**
* An image resizing library for Android, which allows you to scale an image file to a smaller or bigger one while keeping the aspect ratio.
*/
public class Resizer {
private int targetLength, quality;
private Bitmap.CompressFormat compressFormat;
private String outputDirPath;
private String outputFilename;
private String outputDirPath, outputFilename;
private File sourceImage;

/**
* The constructor to initialize Resizer instance.
* @param context The global application context. You can get it by getApplicationContext().
*/
public Resizer(Context context) {
targetLength = 1080;
quality = 80;
Expand All @@ -31,16 +37,31 @@ public Resizer(Context context) {
outputFilename = null;
}

/**
* Set the target length of the image. You only need to specify the target length of the longer side (or either side if it's a square). Resizer will calculate the rest automatically.
* @param targetLength The target image length in pixel. The default value is 1080.
* @return This Resizer instance, for chained settings.
*/
public Resizer setTargetLength(int targetLength) {
this.targetLength = targetLength;
return this;
}

/**
* Set the image quality. The higher value, the better image quality but larger file size. PNG, which is a lossless format, will ignore the quality setting.
* @param quality The image quality value, ranges from 0 to 100. The default value is 80.
* @return This Resizer instance, for chained settings.
*/
public Resizer setQuality(int quality) {
this.quality = quality;
return this;
}

/**
* Set the image compression format by String.
* @param outputFormat The compression format. The default format is JPEG.
* @return This Resizer instance, for chained settings.
*/
public Resizer setOutputFormat(String outputFormat) {
switch (outputFormat) {
case "JPEG":
Expand All @@ -56,6 +77,11 @@ public Resizer setOutputFormat(String outputFormat) {
return this;
}

/**
* Set the image compression format by Bitmap.CompressFormat.
* @param compressFormat The compression format. The default format is JPEG.
* @return This Resizer instance, for chained settings.
*/
public Resizer setOutputFormat(Bitmap.CompressFormat compressFormat) {
if (compressFormat == null) {
throw new NullPointerException("compressFormat null");
Expand All @@ -65,11 +91,12 @@ public Resizer setOutputFormat(Bitmap.CompressFormat compressFormat) {
return this;
}

/** Set output file name.
* @param filename name of the output file, without file extension
* */
/**
* Set the output file name. If you don't set it, the output file will have the same name as the source file.
* @param filename The name of the output file, without file extension.
* @return This Resizer instance, for chained settings.
*/
public Resizer setOutputFilename(String filename) {

if (filename == null) {
throw new NullPointerException("filename null");
}
Expand All @@ -85,25 +112,49 @@ public Resizer setOutputFilename(String filename) {
return this;
}

/**
* Set the output directory path. If this is the same as where the source image locates, the source image can be overwritten.
* @param outputDirPath The path of the output directory. The default path is the external files directory of your app
* @return This Resizer instance, for chained settings.
*/
public Resizer setOutputDirPath(String outputDirPath) {
this.outputDirPath = outputDirPath;
return this;
}

/**
* Set the source image file.
* @param sourceImage The source image file to be resized.
* @return This Resizer instance, for chained settings.
*/
public Resizer setSourceImage(File sourceImage) {
this.sourceImage = sourceImage;
return this;
}

/**
* Get the resized image file.
* @return The resized image file.
* @throws IOException
*/
public File getResizedFile() throws IOException {
return ImageUtils.getScaledImage(targetLength, quality, compressFormat, outputDirPath, outputFilename,
sourceImage);
}

/**
* Get the resized image bitmap.
* @return The resized image bitmap.
* @throws IOException
*/
public Bitmap getResizedBitmap() throws IOException {
return ImageUtils.getScaledBitmap(targetLength, sourceImage);
}

/**
* Get the resized image file as RxJava Flowable.
* @return A Flowable that emits the resized image file or error.
*/
public Flowable<File> getResizedFileAsFlowable() {
return Flowable.defer(new Callable<Flowable<File>>() {
@Override
Expand All @@ -117,6 +168,10 @@ public Flowable<File> call() {
});
}

/**
* Get the resized image bitmap as RxJava Flowable.
* @return A Flowable that emits the resized image bitmap or error.
*/
public Flowable<Bitmap> getResizedBitmapAsFlowable() {
return Flowable.defer(new Callable<Flowable<Bitmap>>() {
@Override
Expand Down
19 changes: 19 additions & 0 deletions docs/allclasses-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="zh">
<head>
<!-- Generated by javadoc (1.8.0_152-release) on Sat Jan 27 10:34:02 HKT 2018 -->
<title>All Classes</title>
<meta name="date" content="2018-01-27">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="me/echodev/resizer/Resizer.html" title="class in me.echodev.resizer" target="classFrame">Resizer</a></li>
</ul>
</div>
</body>
</html>
19 changes: 19 additions & 0 deletions docs/allclasses-noframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="zh">
<head>
<!-- Generated by javadoc (1.8.0_152-release) on Sat Jan 27 10:34:02 HKT 2018 -->
<title>All Classes</title>
<meta name="date" content="2018-01-27">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 class="bar">All&nbsp;Classes</h1>
<div class="indexContainer">
<ul>
<li><a href="me/echodev/resizer/Resizer.html" title="class in me.echodev.resizer">Resizer</a></li>
</ul>
</div>
</body>
</html>
120 changes: 120 additions & 0 deletions docs/constant-values.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="zh">
<head>
<!-- Generated by javadoc (1.8.0_152-release) on Sat Jan 27 10:34:02 HKT 2018 -->
<title>Constant Field Values</title>
<meta name="date" content="2018-01-27">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Constant Field Values";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="me/echodev/resizer/package-summary.html">Package</a></li>
<li>Class</li>
<li><a href="overview-tree.html">Tree</a></li>
<li><a href="deprecated-list.html">Deprecated</a></li>
<li><a href="index-files/index-1.html">Index</a></li>
<li><a href="help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev</li>
<li>Next</li>
</ul>
<ul class="navList">
<li><a href="index.html?constant-values.html" target="_top">Frames</a></li>
<li><a href="constant-values.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h1 title="Constant Field Values" class="title">Constant Field Values</h1>
<h2 title="Contents">Contents</h2>
</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="me/echodev/resizer/package-summary.html">Package</a></li>
<li>Class</li>
<li><a href="overview-tree.html">Tree</a></li>
<li><a href="deprecated-list.html">Deprecated</a></li>
<li><a href="index-files/index-1.html">Index</a></li>
<li><a href="help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev</li>
<li>Next</li>
</ul>
<ul class="navList">
<li><a href="index.html?constant-values.html" target="_top">Frames</a></li>
<li><a href="constant-values.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>
Loading

0 comments on commit 48d4025

Please sign in to comment.