|
@@ -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;
|
|
@@ -45,6 +49,7 @@ import com.kuxuan.moneynote.ui.adapter.SkinAdapter;
|
45
|
49
|
import com.kuxuan.moneynote.ui.weight.ScoreDialog;
|
46
|
50
|
import com.kuxuan.moneynote.utils.DisplayUtil;
|
47
|
51
|
import com.kuxuan.moneynote.utils.GlideUtil;
|
|
52
|
+import com.kuxuan.moneynote.utils.ImageUtil;
|
48
|
53
|
import com.kuxuan.moneynote.utils.JavaFormatUtils;
|
49
|
54
|
import com.kuxuan.moneynote.utils.NetWorkUtil;
|
50
|
55
|
import com.kuxuan.moneynote.utils.SPUtil;
|
|
@@ -53,6 +58,7 @@ import com.kuxuan.moneynote.utils.TextSetUtil;
|
53
|
58
|
import com.kuxuan.moneynote.utils.TimeUtlis;
|
54
|
59
|
import com.kuxuan.moneynote.utils.UIHelper;
|
55
|
60
|
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
|
|
61
|
+import com.yalantis.ucrop.UCrop;
|
56
|
62
|
|
57
|
63
|
import org.greenrobot.eventbus.EventBus;
|
58
|
64
|
import org.greenrobot.eventbus.Subscribe;
|
|
@@ -63,6 +69,8 @@ import java.io.File;
|
63
|
69
|
import butterknife.Bind;
|
64
|
70
|
import butterknife.OnClick;
|
65
|
71
|
|
|
72
|
+import static android.app.Activity.RESULT_OK;
|
|
73
|
+
|
66
|
74
|
/**
|
67
|
75
|
* 首页-明细
|
68
|
76
|
* Created by xieshengqi on 2017/10/19.
|
|
@@ -98,25 +106,36 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
98
|
106
|
LinearLayout nologin_layout;
|
99
|
107
|
@Bind(R.id.nologinornet_textView)
|
100
|
108
|
TextView nol_text;
|
101
|
|
-
|
|
109
|
+ private static final int CHOOSE_PICTURE = 0;
|
102
|
110
|
@Bind(R.id.score_imageview)
|
103
|
111
|
ImageView score_img;
|
104
|
112
|
@Bind(R.id.fragment_detial_allMoney)
|
105
|
113
|
TextView allMoney_text;
|
106
|
114
|
@Bind(R.id.fragment_detial_type_text)
|
107
|
115
|
TextView type_text;
|
108
|
|
-
|
|
116
|
+ String fileheader;
|
109
|
117
|
@Override
|
110
|
118
|
public void initView() {
|
111
|
119
|
EventBus.getDefault().register(this);
|
112
|
120
|
handler = new Handler();
|
113
|
|
-
|
|
121
|
+ fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin/";
|
114
|
122
|
int position = (int) SPUtil.get(getContext(), Constant.Skin.CHECKED, -1);
|
115
|
123
|
|
116
|
124
|
if (position > -1) {
|
117
|
|
- String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
|
118
|
|
- File file = new File(fileheader + Constant.Skin.HOMEPICNAME + position + ".png");
|
119
|
|
- GlideUtil.setImageWithNoCache(getContext(), file, iv_banner);
|
|
125
|
+
|
|
126
|
+ if(position==1000){
|
|
127
|
+
|
|
128
|
+ String fileURl = (String) SPUtil.get(getContext(),Constant.Skin.CUTPIC,"");
|
|
129
|
+ if(!fileURl.equals("")){
|
|
130
|
+ GlideUtil.setImageWithNoCache(getContext(),new File(fileURl),iv_banner);
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ }else {
|
|
134
|
+
|
|
135
|
+ File file = new File(fileheader + Constant.Skin.HOMEPICNAME + position + ".png");
|
|
136
|
+ GlideUtil.setImageWithNoCache(getContext(), file, iv_banner);
|
|
137
|
+ }
|
|
138
|
+
|
120
|
139
|
}
|
121
|
140
|
|
122
|
141
|
|
|
@@ -352,6 +371,7 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
352
|
371
|
}
|
353
|
372
|
|
354
|
373
|
|
|
374
|
+
|
355
|
375
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
356
|
376
|
public void onMessageEvent(RefreshEvent event) {
|
357
|
377
|
mPresenter.getDataLists(mPresenter.getCurrentYear() + "", mPresenter.getCurrentMonth() + "");
|
|
@@ -372,6 +392,7 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
372
|
392
|
BaseQuickAdapter adapter;
|
373
|
393
|
|
374
|
394
|
|
|
395
|
+
|
375
|
396
|
@OnClick(R.id.iv_skinicon)
|
376
|
397
|
public void click() {
|
377
|
398
|
|
|
@@ -392,6 +413,8 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
392
|
413
|
Handler handler;
|
393
|
414
|
|
394
|
415
|
|
|
416
|
+
|
|
417
|
+
|
395
|
418
|
@Override
|
396
|
419
|
public void showDownLoad(RES res, int size, int position, final View background, final ProgressBar progressBar, final int current) {
|
397
|
420
|
|
|
@@ -420,6 +443,92 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
420
|
443
|
|
421
|
444
|
}
|
422
|
445
|
|
|
446
|
+ /**
|
|
447
|
+ * 裁剪图片方法实现
|
|
448
|
+ */
|
|
449
|
+ protected void startPhotoZoom(String dpath) {
|
|
450
|
+
|
|
451
|
+ UCrop.Options options = new UCrop.Options();
|
|
452
|
+ // 设置图片处理的格式JPEG
|
|
453
|
+ options.setCompressionFormat(Bitmap.CompressFormat.PNG);
|
|
454
|
+ // 设置压缩后的图片精度
|
|
455
|
+ options.setCompressionQuality(96);
|
|
456
|
+
|
|
457
|
+ // 得到头像的缓存地址
|
|
458
|
+ File dPath = MyApplication.getPortraitTmpFile();
|
|
459
|
+
|
|
460
|
+ // 发起剪切
|
|
461
|
+ UCrop.of(Uri.fromFile(new File(dpath)), Uri.fromFile(dPath))
|
|
462
|
+ .withAspectRatio(8, 5)
|
|
463
|
+ // 返回最大的尺寸
|
|
464
|
+ .withMaxResultSize(1000, 625)
|
|
465
|
+ // 相关参数
|
|
466
|
+ .withOptions(options)
|
|
467
|
+ .start(getActivity());
|
|
468
|
+ }
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+ /**
|
|
472
|
+ * 保存裁剪之后的图片数据
|
|
473
|
+ */
|
|
474
|
+ protected void setImageToView(Uri uri) {
|
|
475
|
+ String mPortraitPath;
|
|
476
|
+ mPortraitPath = uri.getPath();
|
|
477
|
+ BitmapFactory.Options options = new BitmapFactory.Options();
|
|
478
|
+ options.inSampleSize = 2;
|
|
479
|
+ Bitmap img = BitmapFactory.decodeFile(mPortraitPath, options);
|
|
480
|
+ uploadPic(img);
|
|
481
|
+ }
|
|
482
|
+
|
|
483
|
+ private void uploadPic(Bitmap bitmap) {
|
|
484
|
+ String imageFile = ImageUtil.savePhoto(bitmap, Environment
|
|
485
|
+ .getExternalStorageDirectory().getAbsolutePath(), String
|
|
486
|
+ .valueOf(System.currentTimeMillis()));
|
|
487
|
+
|
|
488
|
+ GlideUtil.setImageWithNoCache(getContext(),new File(imageFile),iv_banner);
|
|
489
|
+ SPUtil.putAndApply(getContext(),Constant.Skin.CHECKED,1000);
|
|
490
|
+// String mVideoPath = fileheader + Constant.Skin.CUTPIC+1000+".png";
|
|
491
|
+
|
|
492
|
+ SPUtil.putAndApply(getContext(),Constant.Skin.CUTPIC,imageFile);
|
|
493
|
+ SkinEvent skinEvent = new SkinEvent(1000);
|
|
494
|
+ EventBus.getDefault().post(skinEvent);
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ @Override
|
|
498
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
499
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
500
|
+
|
|
501
|
+ if (resultCode == RESULT_OK) {
|
|
502
|
+ // 如果返回码是可以用的
|
|
503
|
+ switch (requestCode) {
|
|
504
|
+ case CHOOSE_PICTURE:
|
|
505
|
+ // 开始对图片进行裁剪处理
|
|
506
|
+ String url = ImageUtil.getPath(getContext(), data.getData());
|
|
507
|
+ startPhotoZoom(url);
|
|
508
|
+
|
|
509
|
+ break;
|
|
510
|
+ case UCrop.REQUEST_CROP:
|
|
511
|
+ if (data != null) {
|
|
512
|
+ final Uri resultUri = UCrop.getOutput(data);
|
|
513
|
+
|
|
514
|
+ System.out.println("图片url" + resultUri);
|
|
515
|
+
|
|
516
|
+ if (resultUri != null) {
|
|
517
|
+ setImageToView(resultUri);
|
|
518
|
+ }
|
|
519
|
+ // 让刚才选择裁剪得到的图片显示在界面上
|
|
520
|
+ }
|
|
521
|
+ break;
|
|
522
|
+ case UCrop.RESULT_ERROR:
|
|
523
|
+ break;
|
|
524
|
+ default:
|
|
525
|
+ break;
|
|
526
|
+ }
|
|
527
|
+ }
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+ }
|
|
531
|
+ ImageView iv_add;
|
423
|
532
|
private void showPopWindow() {
|
424
|
533
|
|
425
|
534
|
|
|
@@ -440,6 +549,19 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
440
|
549
|
popupWindow.showAtLocation(relativeLayout, Gravity.BOTTOM, 0, 0);
|
441
|
550
|
|
442
|
551
|
final RecyclerView recyclerView = contentView.findViewById(R.id.recyclerview);
|
|
552
|
+
|
|
553
|
+ iv_add = contentView.findViewById(R.id.iv_add);
|
|
554
|
+
|
|
555
|
+ iv_add.setOnClickListener(new View.OnClickListener() {
|
|
556
|
+ @Override
|
|
557
|
+ public void onClick(View v) {
|
|
558
|
+ Intent openAlbumIntent = new Intent(
|
|
559
|
+ Intent.ACTION_GET_CONTENT);
|
|
560
|
+ openAlbumIntent.setType("image/*");
|
|
561
|
+ startActivityForResult(openAlbumIntent, CHOOSE_PICTURE);
|
|
562
|
+ }
|
|
563
|
+ });
|
|
564
|
+
|
443
|
565
|
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
444
|
566
|
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
445
|
567
|
recyclerView.setLayoutManager(linearLayoutManager);
|
|
@@ -521,7 +643,6 @@ public class DetialFragment extends MVPFragment<DetialPresent, DetialModel> impl
|
521
|
643
|
|
522
|
644
|
private void setBanner(int position) {
|
523
|
645
|
|
524
|
|
- String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
|
525
|
646
|
File file = new File(fileheader + Constant.Skin.HOMEPICNAME + position + ".png");
|
526
|
647
|
GlideUtil.setImageWithNoCache(getContext(), file, iv_banner);
|
527
|
648
|
|