3 Revize ebe150f018 ... 38c3355a00

Autor SHA1 Zpráva Datum
  e 38c3355a00 merg %!s(int64=6) %!d(string=před) roky
  e 96e7623f92 皮肤 %!s(int64=6) %!d(string=před) roky
  e a9cd8638f7 xiazai %!s(int64=6) %!d(string=před) roky

+ 8 - 0
app/src/main/java/com/kuxuan/moneynote/MyApplication.java

@@ -136,6 +136,14 @@ public class MyApplication extends Application {
136 136
     }
137 137
 
138 138
 
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
139 147
 //    @Override
140 148
 //    protected void attachBaseContext(Context base) {
141 149
 //        super.attachBaseContext(base);

+ 2 - 2
app/src/main/java/com/kuxuan/moneynote/common/Constant.java

@@ -108,8 +108,6 @@ public class Constant {
108 108
         //默认颜色
109 109
         public static final String COLOR_NORMAL = "fed953";
110 110
 
111
-        public static final String POSITION = "position";
112
-
113 111
         public static final String HOMEPICNAME = "HOME";
114 112
 
115 113
         public static final String MINE = "mine";
@@ -117,6 +115,8 @@ public class Constant {
117 115
         public static final String SKINICON = "skinicon";
118 116
 
119 117
 
118
+        public static final String CUTPIC = "cutpic";
119
+
120 120
     }
121 121
 
122 122
 

+ 41 - 0
app/src/main/java/com/kuxuan/moneynote/ui/activitys/MainActivity.java

@@ -1,8 +1,11 @@
1 1
 package com.kuxuan.moneynote.ui.activitys;
2 2
 
3
+import android.annotation.SuppressLint;
3 4
 import android.content.Intent;
4 5
 import android.os.Bundle;
5 6
 import android.support.v4.app.Fragment;
7
+import android.support.v4.app.FragmentManager;
8
+import android.util.Log;
6 9
 import android.view.KeyEvent;
7 10
 import android.widget.Toast;
8 11
 
@@ -37,6 +40,7 @@ import org.greenrobot.eventbus.Subscribe;
37 40
 import org.greenrobot.eventbus.ThreadMode;
38 41
 
39 42
 import java.util.ArrayList;
43
+import java.util.List;
40 44
 
41 45
 import butterknife.Bind;
42 46
 import io.reactivex.ObservableEmitter;
@@ -325,10 +329,47 @@ public class MainActivity extends BaseFragmentActivity {
325 329
     @Override
326 330
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
327 331
         super.onActivityResult(requestCode, resultCode, data);
332
+
333
+        FragmentManager fragmentManager=getSupportFragmentManager();
334
+        for(int indext=0;indext<fragmentManager.getFragments().size();indext++)
335
+        {
336
+            Fragment fragment=fragmentManager.getFragments().get(indext); //找到第一层Fragment
337
+            if(fragment==null)
338
+                Log.w("aaa", "Activity result no fragment exists for index: 0x"
339
+                        + Integer.toHexString(requestCode));
340
+            else
341
+                handleResult(fragment,requestCode,resultCode,data);
342
+        }
343
+
344
+
328 345
         /** attention to this below ,must add this**/
329 346
         UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
330 347
     }
331 348
 
349
+
350
+    /**
351
+     * 递归调用,对所有的子Fragment生效
352
+     * @param fragment
353
+     * @param requestCode
354
+     * @param resultCode
355
+     * @param data
356
+     */
357
+    private void handleResult(Fragment fragment,int requestCode,int resultCode,Intent data)
358
+    {
359
+        fragment.onActivityResult(requestCode, resultCode, data);//调用每个Fragment的onActivityResult
360
+        Log.e("sss", "MyBaseFragmentActivity");
361
+        List<Fragment> childFragment = fragment.getChildFragmentManager().getFragments(); //找到第二层Fragment
362
+        if(childFragment!=null)
363
+            for(Fragment f:childFragment)
364
+                if(f!=null)
365
+                {
366
+                    handleResult(f, requestCode, resultCode, data);
367
+                }
368
+        if(childFragment==null)
369
+            Log.e("sss", "MyBaseFragmentActivity1111");
370
+    }
371
+
372
+
332 373
     private long exitTime = 0;
333 374
 
334 375
     @Override

+ 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:

+ 128 - 7
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;
@@ -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
 

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

@@ -137,7 +137,7 @@ public class DetialModel implements DetialContract.DetialModel {
137 137
 
138 138
 
139 139
 
140
-        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin";
140
+        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin/";
141 141
 
142 142
         File file = new File(fileheader);
143 143
         if(!file.exists()){

+ 28 - 11
app/src/main/java/com/kuxuan/moneynote/ui/fragments/mine/MineFragment.java

@@ -216,12 +216,22 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
216 216
     public void initView() {
217 217
         EventBus.getDefault().register(this);
218 218
 
219
-        int position = (int) SPUtil.get(getContext(), Constant.Skin.CHECKED, -1);
220
-        if (position > -1) {
221
-            String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
222
-            File file = new File(fileheader + Constant.Skin.MINE + position + ".png");
223
-            GlideUtil.setImageWithNoCache(getContext(), file, iv_mineskin);
224
-        }
219
+         int position = (int) SPUtil.get(getContext(),Constant.Skin.CHECKED,-1);
220
+         if(position>-1){
221
+
222
+             String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin";
223
+
224
+             if(position==1000){
225
+                 String fileURl = (String) SPUtil.get(getContext(),Constant.Skin.CUTPIC,"");
226
+                 if(!fileURl.equals("")){
227
+                     GlideUtil.setImageWithNoCache(getContext(),new File(fileURl),iv_mineskin);
228
+                 }
229
+             }else {
230
+                 File file = new File(fileheader + Constant.Skin.HOMEPICNAME + position + ".png");
231
+                 GlideUtil.setImageWithNoCache(getContext(), file, iv_mineskin);
232
+             }
233
+
234
+         }
225 235
 
226 236
 
227 237
         cal = Calendar.getInstance();
@@ -442,11 +452,17 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
442 452
     ImageView iv_mineskin;
443 453
 
444 454
     @Subscribe(threadMode = ThreadMode.MAIN)
445
-    public void onMessageEvent5(SkinEvent skinBean) {
446
-
447
-        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath() + "/" + "skin";
448
-        File file = new File(fileheader + Constant.Skin.MINE + skinBean.getCode() + ".png");
449
-        GlideUtil.setImageWithNoCache(getContext(), file, iv_mineskin);
455
+    public void onMessageEvent5(SkinEvent skinBean){
456
+        String fileheader = MyApplication.getInstance().getApplicationContext().getFilesDir().getPath()+"/"+"skin/";
457
+        if(skinBean.getCode()==1000){
458
+            String fileURl = (String) SPUtil.get(getContext(),Constant.Skin.CUTPIC,"");
459
+            if(!fileURl.equals("")){
460
+                GlideUtil.setImageWithNoCache(getContext(),new File(fileURl),iv_mineskin);
461
+            }
462
+        }else {
463
+            File file = new File(fileheader + Constant.Skin.MINE+skinBean.getCode()+".png");
464
+            GlideUtil.setImageWithNoCache(getContext(),file,iv_mineskin);
465
+        }
450 466
 
451 467
     }
452 468
 
@@ -492,6 +508,7 @@ public class MineFragment extends MVPFragment<MinePresent, MineModel> implements
492 508
         }
493 509
 
494 510
         if (mineModel.getAvatar() == null && mineModel.getHeadimgurl() == null) {
511
+            return;
495 512
         } else {
496 513
             if (mineModel.getAvatar() == null) {
497 514
                 Glide.with(this).load(mineModel.getHeadimgurl())

+ 0 - 3
app/src/main/java/com/kuxuan/moneynote/ui/weight/NavigationLayout.java

@@ -1,7 +1,6 @@
1 1
 package com.kuxuan.moneynote.ui.weight;
2 2
 
3 3
 import android.content.Context;
4
-import android.graphics.Color;
5 4
 import android.graphics.drawable.ColorDrawable;
6 5
 import android.graphics.drawable.Drawable;
7 6
 import android.support.annotation.AttrRes;
@@ -15,10 +14,8 @@ import android.widget.ImageView;
15 14
 import android.widget.TextView;
16 15
 
17 16
 import com.kuxuan.moneynote.R;
18
-import com.kuxuan.moneynote.common.Constant;
19 17
 import com.kuxuan.moneynote.ui.activitys.home.DataGenerator;
20 18
 import com.kuxuan.moneynote.utils.DrawableUtil;
21
-import com.kuxuan.moneynote.utils.SPUtil;
22 19
 
23 20
 import de.hdodenhof.circleimageview.CircleImageView;
24 21
 

+ 13 - 0
app/src/main/java/com/kuxuan/moneynote/utils/FileUtil.java

@@ -0,0 +1,13 @@
1
+package com.kuxuan.moneynote.utils;
2
+
3
+/**
4
+ * Created by Allence on 2018/4/28 0028.
5
+ */
6
+
7
+public class FileUtil {
8
+
9
+
10
+
11
+
12
+
13
+}