Skip to content

Commit 8ff0d4e

Browse files
committed
Remove chinese text, examples of use square and aspect
1 parent d9994a5 commit 8ff0d4e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

example/src/main/java/com/soundcloud/android/crop/example/MainActivity.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.soundcloud.android.crop.example;
22

3-
import com.soundcloud.android.crop.Crop;
4-
53
import android.app.Activity;
64
import android.content.Intent;
75
import android.content.pm.PackageManager;
@@ -16,10 +14,13 @@
1614
import android.widget.ImageView;
1715
import android.widget.Toast;
1816

17+
import com.soundcloud.android.crop.Crop;
18+
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.text.SimpleDateFormat;
2222
import java.util.Date;
23+
import java.util.Locale;
2324

2425
public class MainActivity extends Activity {
2526

@@ -33,7 +34,6 @@ protected void onCreate(Bundle savedInstanceState) {
3334
resultView = (ImageView) findViewById(R.id.result_image);
3435
}
3536

36-
//处理6.0动态权限问题
3737
private void requestPermission() {
3838
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
3939
!= PackageManager.PERMISSION_GRANTED) {
@@ -53,9 +53,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
5353
}
5454

5555
private File imageFile;
56-
private void cropFromCamera(){
56+
57+
private void cropFromCamera() {
5758
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
58-
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
59+
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH).format(new Date());
5960
String fileName = timeStamp + "_";
6061
File fileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
6162
try {
@@ -74,7 +75,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
7475
resultView.setImageDrawable(null);
7576
Crop.pickImage(this);
7677
return true;
77-
}else if(item.getItemId() == R.id.action_select2){
78+
} else if (item.getItemId() == R.id.action_select2) {
7879
resultView.setImageDrawable(null);
7980
requestPermission();
8081
return true;
@@ -85,19 +86,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
8586
@Override
8687
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
8788
if ((requestCode == Crop.REQUEST_PICK || requestCode == REQUEST_PICK_CAMERA) && resultCode == RESULT_OK) {
88-
if(result != null)
89-
beginCrop(result.getData(),4,3);
89+
if (result != null)
90+
beginCrop(result.getData());
9091
else {
91-
beginCrop(Uri.fromFile(imageFile),4,3);
92+
beginCrop(Uri.fromFile(imageFile));
9293
}
9394
} else if (requestCode == Crop.REQUEST_CROP || requestCode == REQUEST_PICK_CAMERA) {
9495
handleCrop(resultCode, result);
9596
}
9697
}
9798

98-
private void beginCrop(Uri source,int width,int height) {
99+
private void beginCrop(Uri source) {
99100
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
100-
Crop.of(source, destination).withAspect(width,height).start(this);
101+
Crop.of(source, destination).start(this);
102+
// Crop.of(source, destination).asSquare().start(this);
103+
// Crop.of(source, destination).withAspect(4,3).start(this);
101104
}
102105

103106

lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.view.Window;
3535
import android.view.WindowManager;
3636

37-
import java.io.FileInputStream;
3837
import java.io.IOException;
3938
import java.io.InputStream;
4039
import java.io.OutputStream;
@@ -289,7 +288,7 @@ private void onSaveClicked() {
289288
}
290289
}
291290

292-
if(exifRotation != 0 && exifRotation % 90 == 0){
291+
if (exifRotation != 0 && exifRotation % 90 == 0) {
293292
int tmp = outWidth;
294293
outWidth = outHeight;
295294
outHeight = tmp;
@@ -389,10 +388,9 @@ private void saveOutput(Bitmap croppedImage) {
389388
OutputStream outputStream = null;
390389

391390
Bitmap destBitmap = croppedImage;
392-
if(exifRotation != 0){
391+
if (exifRotation != 0) {
393392
destBitmap = CropUtil.rotateImage(croppedImage, exifRotation);
394393
}
395-
FileInputStream inputStream = null;
396394
try {
397395
//save bitmap to file
398396
outputStream = getContentResolver().openOutputStream(saveUri);
@@ -403,11 +401,11 @@ private void saveOutput(Bitmap croppedImage) {
403401
}
404402
destBitmap.recycle();
405403
} catch (OutOfMemoryError error) {
406-
} catch (IOException e){
404+
Log.e("App is OOM: ", error);
405+
} catch (IOException e) {
407406
setResultException(e);
408407
Log.e("Cannot open file: " + saveUri, e);
409-
}finally {
410-
CropUtil.closeSilently(inputStream);
408+
} finally {
411409
CropUtil.closeSilently(outputStream);
412410
}
413411

0 commit comments

Comments
 (0)