11package com .soundcloud .android .crop .example ;
22
3- import com .soundcloud .android .crop .Crop ;
4-
53import android .app .Activity ;
64import android .content .Intent ;
75import android .content .pm .PackageManager ;
1614import android .widget .ImageView ;
1715import android .widget .Toast ;
1816
17+ import com .soundcloud .android .crop .Crop ;
18+
1919import java .io .File ;
2020import java .io .IOException ;
2121import java .text .SimpleDateFormat ;
2222import java .util .Date ;
23+ import java .util .Locale ;
2324
2425public 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
0 commit comments