Skip to content

Commit 5f54360

Browse files
committed
Merge branch 'release/v1.1.1'
2 parents 687b528 + 5bc9b0b commit 5f54360

File tree

11 files changed

+1305
-1207
lines changed

11 files changed

+1305
-1207
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.naver.android.helloyako.imagecropsample" >
44

5-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
65
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
76

87
<application

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

Lines changed: 94 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717

1818
package com.naver.android.helloyako.imagecropsample;
1919

20+
import android.Manifest;
2021
import android.app.Activity;
2122
import android.app.ProgressDialog;
2223
import android.content.DialogInterface;
2324
import android.content.Intent;
25+
import android.content.pm.PackageManager;
2426
import android.database.Cursor;
2527
import android.graphics.Bitmap;
2628
import android.graphics.drawable.BitmapDrawable;
2729
import android.graphics.drawable.Drawable;
2830
import android.net.Uri;
2931
import android.os.AsyncTask;
32+
import android.os.Build;
3033
import android.os.Bundle;
3134
import android.provider.MediaStore;
35+
import android.support.annotation.NonNull;
3236
import android.util.Log;
3337
import android.view.View;
3438
import android.widget.Button;
@@ -42,6 +46,7 @@ public class MainActivity extends Activity {
4246

4347
public static final String TAG = "MainActivity";
4448

49+
private static final int MAIN_ACTIVITY_REQUEST_STORAGE = RESULT_FIRST_USER;
4550
private static final int ACTION_REQUEST_GALLERY = 99;
4651

4752
Button mGalleryButton;
@@ -61,117 +66,140 @@ protected void onCreate(Bundle savedInstanceState) {
6166
imageWidth = 1000;
6267
imageHeight = 1000;
6368

64-
mGalleryButton = (Button) findViewById( R.id.button1 );
65-
mEditButton = (Button) findViewById( R.id.button2 );
66-
mImage = ( (ImageView) findViewById( R.id.image ) );
67-
mImageContainer = findViewById( R.id.image_container );
69+
mGalleryButton = (Button) findViewById(R.id.button1);
70+
mEditButton = (Button) findViewById(R.id.button2);
71+
mImage = ((ImageView) findViewById(R.id.image));
72+
mImageContainer = findViewById(R.id.image_container);
6873

69-
mGalleryButton.setOnClickListener( new View.OnClickListener() {
74+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
75+
if (getPackageManager().checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getPackageName()) == PackageManager.PERMISSION_GRANTED) {
76+
initClickListener();
77+
}
78+
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MAIN_ACTIVITY_REQUEST_STORAGE);
79+
} else {
80+
initClickListener();
81+
}
82+
}
83+
84+
@Override
85+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
86+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
87+
switch (requestCode) {
88+
case MAIN_ACTIVITY_REQUEST_STORAGE:
89+
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
90+
initClickListener();
91+
}
92+
break;
93+
}
94+
}
95+
96+
private void initClickListener() {
97+
mGalleryButton.setOnClickListener(new View.OnClickListener() {
7098

7199
@Override
72-
public void onClick( View v ) {
100+
public void onClick(View v) {
73101
pickFromGallery();
74102
}
75-
} );
103+
});
76104

77-
mEditButton.setOnClickListener( new View.OnClickListener() {
105+
mEditButton.setOnClickListener(new View.OnClickListener() {
78106

79107
@Override
80-
public void onClick( View v ) {
81-
if ( mImageUri != null ) {
108+
public void onClick(View v) {
109+
if (mImageUri != null) {
82110
startCrop(mImageUri);
83111
}
84112
}
85-
} );
113+
});
86114

87-
mImageContainer.setOnClickListener( new View.OnClickListener() {
115+
mImageContainer.setOnClickListener(new View.OnClickListener() {
88116

89117
@Override
90-
public void onClick( View v ) {
118+
public void onClick(View v) {
91119
findViewById(R.id.touch_me).setVisibility(View.GONE);
92120
Uri uri = pickRandomImage();
93-
if ( uri != null ) {
121+
if (uri != null) {
94122
Log.d(TAG, "image uri: " + uri);
95-
loadAsync( uri );
123+
loadAsync(uri);
96124
}
97125
}
98-
} );
126+
});
99127
}
100128

101129
@Override
102130
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
103-
if ( resultCode == RESULT_OK ) {
131+
if (resultCode == RESULT_OK) {
104132
switch (requestCode) {
105133
case ACTION_REQUEST_GALLERY:
106134
Uri uri = data.getData();
107135
String filePath = BitmapLoadUtils.getPathFromUri(this, uri);
108136
Uri filePathUri = Uri.parse(filePath);
109-
loadAsync( filePathUri );
137+
loadAsync(filePathUri);
110138
break;
111139
}
112140
}
113141
}
114142

115143
private void pickFromGallery() {
116-
Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
117-
intent.setType( "image/*" );
144+
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
145+
intent.setType("image/*");
118146

119-
Intent chooser = Intent.createChooser( intent, "Choose a Picture" );
120-
startActivityForResult( chooser, ACTION_REQUEST_GALLERY );
147+
Intent chooser = Intent.createChooser(intent, "Choose a Picture");
148+
startActivityForResult(chooser, ACTION_REQUEST_GALLERY);
121149
}
122150

123-
private void startCrop(Uri imageUri){
124-
Intent intent = new Intent(MainActivity.this,CropActivity.class);
151+
private void startCrop(Uri imageUri) {
152+
Intent intent = new Intent(MainActivity.this, CropActivity.class);
125153
intent.setData(imageUri);
126154
startActivity(intent);
127155
}
128156

129-
private boolean setImageURI( final Uri uri, final Bitmap bitmap ) {
157+
private boolean setImageURI(final Uri uri, final Bitmap bitmap) {
130158

131-
Log.d( TAG, "image size: " + bitmap.getWidth() + "x" + bitmap.getHeight() );
132-
mImage.setImageBitmap( bitmap );
133-
mImage.setBackgroundDrawable( null );
159+
Log.d(TAG, "image size: " + bitmap.getWidth() + "x" + bitmap.getHeight());
160+
mImage.setImageBitmap(bitmap);
161+
mImage.setBackgroundDrawable(null);
134162

135-
mEditButton.setEnabled( true );
163+
mEditButton.setEnabled(true);
136164
mImageUri = uri;
137165

138166
return true;
139167
}
140168

141169
private Uri pickRandomImage() {
142-
Cursor c = getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA },
143-
MediaStore.Images.ImageColumns.SIZE + ">?", new String[] { "90000" }, null );
170+
Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA},
171+
MediaStore.Images.ImageColumns.SIZE + ">?", new String[]{"90000"}, null);
144172
Uri uri = null;
145173

146-
if ( c != null ) {
174+
if (c != null) {
147175
int total = c.getCount();
148-
int position = (int) ( Math.random() * total );
149-
Log.d( TAG, "pickRandomImage. total images: " + total + ", position: " + position );
150-
if ( total > 0 ) {
151-
if ( c.moveToPosition( position ) ) {
176+
int position = (int) (Math.random() * total);
177+
Log.d(TAG, "pickRandomImage. total images: " + total + ", position: " + position);
178+
if (total > 0) {
179+
if (c.moveToPosition(position)) {
152180
String data = c.getString(c.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
153-
uri = Uri.parse( data );
154-
Log.d( TAG, uri.toString() );
181+
uri = Uri.parse(data);
182+
Log.d(TAG, uri.toString());
155183
}
156184
}
157185
c.close();
158186
}
159187
return uri;
160188
}
161189

162-
private void loadAsync( final Uri uri ) {
163-
Log.i( TAG, "loadAsync: " + uri );
190+
private void loadAsync(final Uri uri) {
191+
Log.i(TAG, "loadAsync: " + uri);
164192

165193
Drawable toRecycle = mImage.getDrawable();
166-
if ( toRecycle != null && toRecycle instanceof BitmapDrawable) {
167-
if ( ( (BitmapDrawable) mImage.getDrawable() ).getBitmap() != null )
168-
( (BitmapDrawable) mImage.getDrawable() ).getBitmap().recycle();
194+
if (toRecycle != null && toRecycle instanceof BitmapDrawable) {
195+
if (((BitmapDrawable) mImage.getDrawable()).getBitmap() != null)
196+
((BitmapDrawable) mImage.getDrawable()).getBitmap().recycle();
169197
}
170-
mImage.setImageDrawable( null );
198+
mImage.setImageDrawable(null);
171199
mImageUri = null;
172200

173201
DownloadAsync task = new DownloadAsync();
174-
task.execute( uri );
202+
task.execute(uri);
175203
}
176204

177205
class DownloadAsync extends AsyncTask<Uri, Void, Bitmap> implements DialogInterface.OnCancelListener {
@@ -183,61 +211,61 @@ class DownloadAsync extends AsyncTask<Uri, Void, Bitmap> implements DialogInterf
183211
protected void onPreExecute() {
184212
super.onPreExecute();
185213

186-
mProgress = new ProgressDialog( MainActivity.this );
187-
mProgress.setIndeterminate( true );
188-
mProgress.setCancelable( true );
189-
mProgress.setMessage( "Loading image..." );
190-
mProgress.setOnCancelListener( this );
214+
mProgress = new ProgressDialog(MainActivity.this);
215+
mProgress.setIndeterminate(true);
216+
mProgress.setCancelable(true);
217+
mProgress.setMessage("Loading image...");
218+
mProgress.setOnCancelListener(this);
191219
mProgress.show();
192220
}
193221

194222
@Override
195-
protected Bitmap doInBackground( Uri... params ) {
223+
protected Bitmap doInBackground(Uri... params) {
196224
mUri = params[0];
197225

198226
Bitmap bitmap = null;
199227

200-
while ( mImageContainer.getWidth() < 1 ) {
228+
while (mImageContainer.getWidth() < 1) {
201229
try {
202-
Thread.sleep( 1 );
203-
} catch ( InterruptedException e ) {
230+
Thread.sleep(1);
231+
} catch (InterruptedException e) {
204232
e.printStackTrace();
205233
}
206234
}
207235

208236
final int w = mImageContainer.getWidth();
209-
Log.d( TAG, "width: " + w );
210-
bitmap = BitmapLoadUtils.decode(mUri.toString(), imageWidth, imageHeight,true);
237+
Log.d(TAG, "width: " + w);
238+
bitmap = BitmapLoadUtils.decode(mUri.toString(), imageWidth, imageHeight, true);
211239
return bitmap;
212240
}
213241

214242
@Override
215-
protected void onPostExecute( Bitmap result ) {
216-
super.onPostExecute( result );
243+
protected void onPostExecute(Bitmap result) {
244+
super.onPostExecute(result);
217245

218-
if ( mProgress.getWindow() != null ) {
246+
if (mProgress.getWindow() != null) {
219247
mProgress.dismiss();
220248
}
221249

222-
if ( result != null ) {
223-
setImageURI( mUri, result );
250+
if (result != null) {
251+
setImageURI(mUri, result);
224252
} else {
225253
Toast.makeText(MainActivity.this, "Failed to load image " + mUri, Toast.LENGTH_SHORT).show();
226254
}
227255
}
228256

229257
@Override
230-
public void onCancel( DialogInterface dialog ) {
231-
Log.i( TAG, "onProgressCancel" );
232-
this.cancel( true );
258+
public void onCancel(DialogInterface dialog) {
259+
Log.i(TAG, "onProgressCancel");
260+
this.cancel(true);
233261
}
234262

235263
@Override
236264
protected void onCancelled() {
237265
super.onCancelled();
238-
Log.i( TAG, "onCancelled" );
266+
Log.i(TAG, "onCancelled");
239267
}
240268

241269
}
242-
270+
243271
}

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.0.0'
8+
classpath 'com.android.tools.build:gradle:2.1.0'
99

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

gradle.properties

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

55
POM_DESCRIPTION=Android Image Crop View
@@ -13,6 +13,6 @@ POM_LICENCE_DIST=repo
1313
POM_DEVELOPER_ID=helloyako
1414
POM_DEVELOPER_NAME=Ohkyun Kim
1515

16-
ANDROID_BUILD_TARGET_SDK_VERSION=21
17-
ANDROID_BUILD_TOOLS_VERSION=21.1.2
18-
ANDROID_BUILD_SDK_VERSION=21
16+
ANDROID_BUILD_TARGET_SDK_VERSION=23
17+
ANDROID_BUILD_TOOLS_VERSION=23.0.2
18+
ANDROID_BUILD_SDK_VERSION=23

imagecropview/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ android {
3434
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3535
}
3636
}
37+
lintOptions {
38+
abortOnError false
39+
}
3740
}
3841

3942
repositories {

0 commit comments

Comments
 (0)