Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
helloyako committed Feb 6, 2017
2 parents c67a18d + da9f0f2 commit 3ac6d50
Show file tree
Hide file tree
Showing 13 changed files with 1,002 additions and 1,127 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Android SDK Build-tools 23.0.2
## Usage
##### Gradle
dependencies {
compile 'com.naver.android.helloyako:imagecropview:1.1.1'
compile 'com.naver.android.helloyako:imagecropview:1.2.0'
}

## Grid Option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.naver.android.helloyako.imagecrop.view.ImageCropView;
import com.naver.android.helloyako.imagecrop.util.BitmapLoadUtils;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -63,16 +61,16 @@ public void onCreate(Bundle savedInstanceState) {

imageCropView.setImageFilePath(uri.toString());

imageCropView.setAspectRatio(1,1);
imageCropView.setAspectRatio(1, 1);

findViewById(R.id.ratio11btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "click 1 : 1");
if(isPossibleCrop(1,1)){
if (isPossibleCrop(1, 1)) {
imageCropView.setAspectRatio(1, 1);
} else {
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
}
}
});
Expand All @@ -81,10 +79,10 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
Log.d(TAG, "click 3 : 4");
if(isPossibleCrop(3,4)){
if (isPossibleCrop(3, 4)) {
imageCropView.setAspectRatio(3, 4);
} else {
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
}
}
});
Expand All @@ -93,10 +91,10 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
Log.d(TAG, "click 4 : 3");
if(isPossibleCrop(4,3)){
if (isPossibleCrop(4, 3)) {
imageCropView.setAspectRatio(4, 3);
} else {
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
}
}
});
Expand All @@ -105,10 +103,10 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
Log.d(TAG, "click 16 : 9");
if(isPossibleCrop(16,9)){
if (isPossibleCrop(16, 9)) {
imageCropView.setAspectRatio(16, 9);
} else {
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
}
}
});
Expand All @@ -117,29 +115,37 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
Log.d(TAG, "click 9 : 16");
if(isPossibleCrop(9,16)){
if (isPossibleCrop(9, 16)) {
imageCropView.setAspectRatio(9, 16);
} else {
Toast.makeText(CropActivity.this,R.string.can_not_crop,Toast.LENGTH_SHORT).show();
Toast.makeText(CropActivity.this, R.string.can_not_crop, Toast.LENGTH_SHORT).show();
}
}
});

findViewById(R.id.crop_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!imageCropView.isChangingScale()) {
if (!imageCropView.isChangingScale()) {
Bitmap b = imageCropView.getCroppedImage();
bitmapConvertToFile(b);
if (b != null) {
bitmapConvertToFile(b);
} else {
Toast.makeText(CropActivity.this, R.string.fail_to_crop, Toast.LENGTH_SHORT).show();
}
}
}
});
}

private boolean isPossibleCrop(int widthRatio, int heightRatio){
int bitmapWidth = imageCropView.getViewBitmap().getWidth();
int bitmapHeight = imageCropView.getViewBitmap().getHeight();
if(bitmapWidth < widthRatio && bitmapHeight < heightRatio){
private boolean isPossibleCrop(int widthRatio, int heightRatio) {
Bitmap bitmap = imageCropView.getViewBitmap();
if (bitmap == null) {
return false;
}
int bitmapWidth = bitmap.getWidth();
int bitmapHeight = bitmap.getHeight();
if (bitmapWidth < widthRatio && bitmapHeight < heightRatio) {
return false;
} else {
return true;
Expand All @@ -150,7 +156,7 @@ public File bitmapConvertToFile(Bitmap bitmap) {
FileOutputStream fileOutputStream = null;
File bitmapFile = null;
try {
File file = new File(Environment.getExternalStoragePublicDirectory("image_crop_sample"),"");
File file = new File(Environment.getExternalStoragePublicDirectory("image_crop_sample"), "");
if (!file.exists()) {
file.mkdir();
}
Expand All @@ -169,7 +175,7 @@ public void onScanCompleted(String path, Uri uri) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(CropActivity.this,"file saved",Toast.LENGTH_LONG).show();
Toast.makeText(CropActivity.this, "file saved", Toast.LENGTH_LONG).show();
}
});
}
Expand All @@ -190,15 +196,15 @@ public void run() {
}

public void onClickSaveButton(View v) {
positionInfo = imageCropView.getPositionInfo();
imageCropView.saveState();
View restoreButton = findViewById(R.id.restore_btn);
if (!restoreButton.isEnabled()) {
restoreButton.setEnabled(true);
}
}

public void onClickRestoreButton(View v) {
imageCropView.applyPositionInfo(positionInfo);
imageCropView.restoreState();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTION_REQUEST_GALLERY:
Uri uri = data.getData();
String filePath = BitmapLoadUtils.getPathFromUri(this, uri);
String filePath = getPathFromUri(uri);
Uri filePathUri = Uri.parse(filePath);
loadAsync(filePathUri);
break;
Expand Down Expand Up @@ -268,4 +268,25 @@ protected void onCancelled() {

}

private String getPathFromUri(Uri uri) {
if (uri == null) {
return null;
}
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = this.getContentResolver().query(uri, proj, null, null, null);
if (cursor == null) {
return null;
}
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">ImageCropSample</string>
<string name="can_not_crop">Can not crop</string>
<string name="fail_to_crop">Fail to crop</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.1.1
VERSION_CODE=7
VERSION_NAME=1.2.0
VERSION_CODE=8
GROUP=com.naver.android.helloyako

POM_DESCRIPTION=Android Image Crop View
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Apr 08 16:31:59 KST 2016
#Sun Nov 27 12:45:11 KST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public CropInfo(float scale, float viewBitmapWidth, float viewImageTop, float vi
}

public Bitmap getCroppedImage(String path) {
int reqSize = 4000;
return getCroppedImage(path, 4000);
}

/**
* @param reqSize for image sampling
*
*/
public Bitmap getCroppedImage(String path, int reqSize) {
Bitmap bitmap = BitmapLoadUtils.decode(path, reqSize, reqSize);
return getCroppedImage(bitmap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

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

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

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


public static String getPathFromUri(Context context, Uri uri) {
if (uri == null) {
return null;
}
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(uri, proj, null, null, null);
if (cursor == null) {
return null;
}
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight, boolean useImageView) {
// Raw height and width of image
final int height = options.outHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL10;

import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_SIZE;
import static javax.microedition.khronos.egl.EGL10.EGL_BLUE_SIZE;
Expand Down
Loading

0 comments on commit 3ac6d50

Please sign in to comment.