Skip to content

Commit 3ac6d50

Browse files
committed
Merge branch 'release/v1.2.0'
# Conflicts: # README.md
2 parents c67a18d + da9f0f2 commit 3ac6d50

File tree

13 files changed

+1002
-1127
lines changed

13 files changed

+1002
-1127
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Android SDK Build-tools 23.0.2
2121
## Usage
2222
##### Gradle
2323
dependencies {
24-
compile 'com.naver.android.helloyako:imagecropview:1.1.1'
24+
compile 'com.naver.android.helloyako:imagecropview:1.2.0'
2525
}
2626

2727
## Grid Option

app/src/main/java/com/naver/android/helloyako/imagecropsample/CropActivity.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import android.net.Uri;
2525
import android.os.Bundle;
2626
import android.os.Environment;
27-
import android.util.DisplayMetrics;
2827
import android.util.Log;
2928
import android.view.View;
3029
import android.widget.Toast;
3130

3231
import com.naver.android.helloyako.imagecrop.view.ImageCropView;
33-
import com.naver.android.helloyako.imagecrop.util.BitmapLoadUtils;
3432

3533
import java.io.File;
3634
import java.io.FileOutputStream;
@@ -63,16 +61,16 @@ public void onCreate(Bundle savedInstanceState) {
6361

6462
imageCropView.setImageFilePath(uri.toString());
6563

66-
imageCropView.setAspectRatio(1,1);
64+
imageCropView.setAspectRatio(1, 1);
6765

6866
findViewById(R.id.ratio11btn).setOnClickListener(new View.OnClickListener() {
6967
@Override
7068
public void onClick(View v) {
7169
Log.d(TAG, "click 1 : 1");
72-
if(isPossibleCrop(1,1)){
70+
if (isPossibleCrop(1, 1)) {
7371
imageCropView.setAspectRatio(1, 1);
7472
} else {
75-
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
73+
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
7674
}
7775
}
7876
});
@@ -81,10 +79,10 @@ public void onClick(View v) {
8179
@Override
8280
public void onClick(View v) {
8381
Log.d(TAG, "click 3 : 4");
84-
if(isPossibleCrop(3,4)){
82+
if (isPossibleCrop(3, 4)) {
8583
imageCropView.setAspectRatio(3, 4);
8684
} else {
87-
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
85+
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
8886
}
8987
}
9088
});
@@ -93,10 +91,10 @@ public void onClick(View v) {
9391
@Override
9492
public void onClick(View v) {
9593
Log.d(TAG, "click 4 : 3");
96-
if(isPossibleCrop(4,3)){
94+
if (isPossibleCrop(4, 3)) {
9795
imageCropView.setAspectRatio(4, 3);
9896
} else {
99-
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
97+
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
10098
}
10199
}
102100
});
@@ -105,10 +103,10 @@ public void onClick(View v) {
105103
@Override
106104
public void onClick(View v) {
107105
Log.d(TAG, "click 16 : 9");
108-
if(isPossibleCrop(16,9)){
106+
if (isPossibleCrop(16, 9)) {
109107
imageCropView.setAspectRatio(16, 9);
110108
} else {
111-
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
109+
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
112110
}
113111
}
114112
});
@@ -117,29 +115,37 @@ public void onClick(View v) {
117115
@Override
118116
public void onClick(View v) {
119117
Log.d(TAG, "click 9 : 16");
120-
if(isPossibleCrop(9,16)){
118+
if (isPossibleCrop(9, 16)) {
121119
imageCropView.setAspectRatio(9, 16);
122120
} else {
123-
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
121+
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
124122
}
125123
}
126124
});
127125

128126
findViewById(R.id.crop_btn).setOnClickListener(new View.OnClickListener() {
129127
@Override
130128
public void onClick(View v) {
131-
if(!imageCropView.isChangingScale()) {
129+
if (!imageCropView.isChangingScale()) {
132130
Bitmap b = imageCropView.getCroppedImage();
133-
bitmapConvertToFile(b);
131+
if (b != null) {
132+
bitmapConvertToFile(b);
133+
} else {
134+
Toast.makeText(CropActivity.this, R.string.fail_to_crop, Toast.LENGTH_SHORT).show();
135+
}
134136
}
135137
}
136138
});
137139
}
138140

139-
private boolean isPossibleCrop(int widthRatio, int heightRatio){
140-
int bitmapWidth = imageCropView.getViewBitmap().getWidth();
141-
int bitmapHeight = imageCropView.getViewBitmap().getHeight();
142-
if(bitmapWidth < widthRatio && bitmapHeight < heightRatio){
141+
private boolean isPossibleCrop(int widthRatio, int heightRatio) {
142+
Bitmap bitmap = imageCropView.getViewBitmap();
143+
if (bitmap == null) {
144+
return false;
145+
}
146+
int bitmapWidth = bitmap.getWidth();
147+
int bitmapHeight = bitmap.getHeight();
148+
if (bitmapWidth < widthRatio && bitmapHeight < heightRatio) {
143149
return false;
144150
} else {
145151
return true;
@@ -150,7 +156,7 @@ public File bitmapConvertToFile(Bitmap bitmap) {
150156
FileOutputStream fileOutputStream = null;
151157
File bitmapFile = null;
152158
try {
153-
File file = new File(Environment.getExternalStoragePublicDirectory("image_crop_sample"),"");
159+
File file = new File(Environment.getExternalStoragePublicDirectory("image_crop_sample"), "");
154160
if (!file.exists()) {
155161
file.mkdir();
156162
}
@@ -169,7 +175,7 @@ public void onScanCompleted(String path, Uri uri) {
169175
runOnUiThread(new Runnable() {
170176
@Override
171177
public void run() {
172-
Toast.makeText(CropActivity.this,"file saved",Toast.LENGTH_LONG).show();
178+
Toast.makeText(CropActivity.this, "file saved", Toast.LENGTH_LONG).show();
173179
}
174180
});
175181
}
@@ -190,15 +196,15 @@ public void run() {
190196
}
191197

192198
public void onClickSaveButton(View v) {
193-
positionInfo = imageCropView.getPositionInfo();
199+
imageCropView.saveState();
194200
View restoreButton = findViewById(R.id.restore_btn);
195201
if (!restoreButton.isEnabled()) {
196202
restoreButton.setEnabled(true);
197203
}
198204
}
199205

200206
public void onClickRestoreButton(View v) {
201-
imageCropView.applyPositionInfo(positionInfo);
207+
imageCropView.restoreState();
202208
}
203209

204210
}

app/src/main/java/com/naver/android/helloyako/imagecropsample/MainActivity.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
132132
switch (requestCode) {
133133
case ACTION_REQUEST_GALLERY:
134134
Uri uri = data.getData();
135-
String filePath = BitmapLoadUtils.getPathFromUri(this, uri);
135+
String filePath = getPathFromUri(uri);
136136
Uri filePathUri = Uri.parse(filePath);
137137
loadAsync(filePathUri);
138138
break;
@@ -268,4 +268,25 @@ protected void onCancelled() {
268268

269269
}
270270

271+
private String getPathFromUri(Uri uri) {
272+
if (uri == null) {
273+
return null;
274+
}
275+
Cursor cursor = null;
276+
try {
277+
String[] proj = {MediaStore.Images.Media.DATA};
278+
cursor = this.getContentResolver().query(uri, proj, null, null, null);
279+
if (cursor == null) {
280+
return null;
281+
}
282+
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
283+
cursor.moveToFirst();
284+
return cursor.getString(column_index);
285+
} finally {
286+
if (cursor != null) {
287+
cursor.close();
288+
}
289+
}
290+
}
291+
271292
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">ImageCropSample</string>
33
<string name="can_not_crop">Can not crop</string>
4+
<string name="fail_to_crop">Fail to crop</string>
45
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
8+
classpath 'com.android.tools.build:gradle:2.2.3'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
VERSION_NAME=1.1.1
2-
VERSION_CODE=7
1+
VERSION_NAME=1.2.0
2+
VERSION_CODE=8
33
GROUP=com.naver.android.helloyako
44

55
POM_DESCRIPTION=Android Image Crop View
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Apr 08 16:31:59 KST 2016
1+
#Sun Nov 27 12:45:11 KST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

imagecropview/src/main/java/com/naver/android/helloyako/imagecrop/model/CropInfo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ public CropInfo(float scale, float viewBitmapWidth, float viewImageTop, float vi
3131
}
3232

3333
public Bitmap getCroppedImage(String path) {
34-
int reqSize = 4000;
34+
return getCroppedImage(path, 4000);
35+
}
36+
37+
/**
38+
* @param reqSize for image sampling
39+
*
40+
*/
41+
public Bitmap getCroppedImage(String path, int reqSize) {
3542
Bitmap bitmap = BitmapLoadUtils.decode(path, reqSize, reqSize);
3643
return getCroppedImage(bitmap);
3744
}

imagecropview/src/main/java/com/naver/android/helloyako/imagecrop/util/BitmapLoadUtils.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717

1818
package com.naver.android.helloyako.imagecrop.util;
1919

20-
import android.content.Context;
21-
import android.database.Cursor;
2220
import android.graphics.Bitmap;
2321
import android.graphics.BitmapFactory;
2422
import android.graphics.Matrix;
2523
import android.media.ExifInterface;
26-
import android.net.Uri;
27-
import android.provider.MediaStore;
2824
import android.util.Log;
2925

3026
import java.io.IOException;
@@ -100,27 +96,6 @@ public static Bitmap rotate(Bitmap bitmap, int degrees) {
10096
}
10197

10298

103-
public static String getPathFromUri(Context context, Uri uri) {
104-
if (uri == null) {
105-
return null;
106-
}
107-
Cursor cursor = null;
108-
try {
109-
String[] proj = {MediaStore.Images.Media.DATA};
110-
cursor = context.getContentResolver().query(uri, proj, null, null, null);
111-
if (cursor == null) {
112-
return null;
113-
}
114-
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
115-
cursor.moveToFirst();
116-
return cursor.getString(column_index);
117-
} finally {
118-
if (cursor != null) {
119-
cursor.close();
120-
}
121-
}
122-
}
123-
12499
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight, boolean useImageView) {
125100
// Raw height and width of image
126101
final int height = options.outHeight;

imagecropview/src/main/java/com/naver/android/helloyako/imagecrop/util/GLUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import javax.microedition.khronos.egl.EGLContext;
88
import javax.microedition.khronos.egl.EGLDisplay;
99
import javax.microedition.khronos.egl.EGLSurface;
10-
import javax.microedition.khronos.opengles.GL10;
1110

1211
import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_SIZE;
1312
import static javax.microedition.khronos.egl.EGL10.EGL_BLUE_SIZE;

0 commit comments

Comments
 (0)