e 6 jaren geleden
bovenliggende
commit
a9cd8638f7

+ 0 - 1
app/src/main/java/com/kuxuan/moneynote/ui/activitys/person/PersonActivity.java

@@ -435,7 +435,6 @@ public class PersonActivity extends MVPFragmentActivity<PersonPresenter, PersonM
435 435
                             setImageToView(resultUri);
436 436
                         }
437 437
                         // 让刚才选择裁剪得到的图片显示在界面上
438
-
439 438
                     }
440 439
                     break;
441 440
                 case UCrop.RESULT_ERROR:

+ 105 - 1
app/src/main/java/com/kuxuan/moneynote/ui/fragments/details/DetialFragment.java

@@ -1,9 +1,13 @@
1 1
 package com.kuxuan.moneynote.ui.fragments.details;
2 2
 
3 3
 import android.content.Intent;
4
+import android.graphics.Bitmap;
5
+import android.graphics.BitmapFactory;
4 6
 import android.graphics.Color;
5 7
 import android.graphics.drawable.ColorDrawable;
8
+import android.net.Uri;
6 9
 import android.os.Bundle;
10
+import android.os.Environment;
7 11
 import android.os.Handler;
8 12
 import android.provider.Settings;
9 13
 import android.support.v7.widget.LinearLayoutManager;
@@ -43,6 +47,7 @@ import com.kuxuan.moneynote.ui.adapter.SkinAdapter;
43 47
 import com.kuxuan.moneynote.ui.weight.ScoreDialog;
44 48
 import com.kuxuan.moneynote.utils.DisplayUtil;
45 49
 import com.kuxuan.moneynote.utils.GlideUtil;
50
+import com.kuxuan.moneynote.utils.ImageUtil;
46 51
 import com.kuxuan.moneynote.utils.JavaFormatUtils;
47 52
 import com.kuxuan.moneynote.utils.NetWorkUtil;
48 53
 import com.kuxuan.moneynote.utils.SPUtil;
@@ -51,6 +56,7 @@ import com.kuxuan.moneynote.utils.TextSetUtil;
51 56
 import com.kuxuan.moneynote.utils.TimeUtlis;
52 57
 import com.kuxuan.moneynote.utils.UIHelper;
53 58
 import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
59
+import com.yalantis.ucrop.UCrop;
54 60
 
55 61
 import org.greenrobot.eventbus.EventBus;
56 62
 import org.greenrobot.eventbus.Subscribe;
@@ -61,6 +67,8 @@ import java.io.File;
61 67
 import butterknife.Bind;
62 68
 import butterknife.OnClick;
63 69
 
70
+import static android.app.Activity.RESULT_OK;
71
+
64 72
 /**
65 73
  * 首页-明细
66 74
  * Created by xieshengqi on 2017/10/19.
@@ -103,6 +111,7 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
103 111
     TextView allMoney_text;
104 112
     @Bind(R.id.fragment_detial_type_text)
105 113
     TextView type_text;
114
+    private static final int CHOOSE_PICTURE = 0;
106 115
 
107 116
     @Override
108 117
     public void initView() {
@@ -420,6 +429,89 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
420 429
 
421 430
     }
422 431
 
432
+    /**
433
+     * 裁剪图片方法实现
434
+     */
435
+    protected void startPhotoZoom(String dpath) {
436
+
437
+        UCrop.Options options = new UCrop.Options();
438
+        // 设置图片处理的格式JPEG
439
+        options.setCompressionFormat(Bitmap.CompressFormat.JPEG);
440
+        // 设置压缩后的图片精度
441
+        options.setCompressionQuality(96);
442
+
443
+        // 得到头像的缓存地址
444
+        File dPath = MyApplication.getPortraitTmpFile();
445
+
446
+        // 发起剪切
447
+        UCrop.of(Uri.fromFile(new File(dpath)), Uri.fromFile(dPath))
448
+                // 1比1比例
449
+                .withAspectRatio(8, 5)
450
+                // 返回最大的尺寸
451
+                .withMaxResultSize(560, 350)
452
+                // 相关参数
453
+                .withOptions(options)
454
+                .start(getActivity());
455
+    }
456
+
457
+
458
+    /**
459
+     * 保存裁剪之后的图片数据
460
+     */
461
+    protected void setImageToView(Uri uri) {
462
+        String mPortraitPath;
463
+        // 得到头像地址
464
+        mPortraitPath = uri.getPath();
465
+        BitmapFactory.Options options = new BitmapFactory.Options();
466
+        options.inSampleSize = 2;
467
+        Bitmap img = BitmapFactory.decodeFile(mPortraitPath, options);
468
+        uploadPic(img);
469
+    }
470
+
471
+    private void uploadPic(Bitmap bitmap) {
472
+        String imageFile = ImageUtil.savePhoto(bitmap, Environment
473
+                .getExternalStorageDirectory().getAbsolutePath(), String
474
+                .valueOf(System.currentTimeMillis()));
475
+
476
+        GlideUtil.setImageWithNoCache(getContext(),new File(imageFile),iv_banner);
477
+
478
+    }
479
+
480
+    @Override
481
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
482
+        super.onActivityResult(requestCode, resultCode, data);
483
+
484
+        if (resultCode == RESULT_OK) {
485
+            // 如果返回码是可以用的
486
+            switch (requestCode) {
487
+                case CHOOSE_PICTURE:
488
+                    // 开始对图片进行裁剪处理
489
+                    String url = ImageUtil.getPath(getContext(), data.getData());
490
+                    startPhotoZoom(url);
491
+
492
+                    break;
493
+                case UCrop.REQUEST_CROP:
494
+                    if (data != null) {
495
+                        final Uri resultUri = UCrop.getOutput(data);
496
+
497
+                        System.out.println("图片url" + resultUri);
498
+
499
+                        if (resultUri != null) {
500
+                            setImageToView(resultUri);
501
+                        }
502
+                        // 让刚才选择裁剪得到的图片显示在界面上
503
+                    }
504
+                    break;
505
+                case UCrop.RESULT_ERROR:
506
+                    break;
507
+                default:
508
+                    break;
509
+            }
510
+        }
511
+
512
+
513
+    }
514
+    ImageView iv_add;
423 515
     private void showPopWindow() {
424 516
 
425 517
 
@@ -440,6 +532,19 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
440 532
         popupWindow.showAtLocation(relativeLayout, Gravity.BOTTOM, 0, 0);
441 533
 
442 534
         final RecyclerView recyclerView = contentView.findViewById(R.id.recyclerview);
535
+
536
+        iv_add = contentView.findViewById(R.id.iv_add);
537
+
538
+        iv_add.setOnClickListener(new View.OnClickListener() {
539
+            @Override
540
+            public void onClick(View v) {
541
+                Intent openAlbumIntent = new Intent(
542
+                        Intent.ACTION_GET_CONTENT);
543
+                openAlbumIntent.setType("image/*");
544
+                startActivityForResult(openAlbumIntent, CHOOSE_PICTURE);
545
+            }
546
+        });
547
+
443 548
         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
444 549
         linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
445 550
         recyclerView.setLayoutManager(linearLayoutManager);
@@ -479,7 +584,6 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
479 584
                     String color1 = item.getColor();
480 585
                     color1 = "#"+color1.substring(2);
481 586
                     SPUtil.putAndApply(getContext(), Constant.Skin.COLOR_SELECT,color1 );
482
-
483 587
                     EventBus.getDefault().post(mskinBean);
484 588
                     setBanner(position);
485 589
                 }