admin
2022-04-18 977c2717f0232905d511152327b347d25c991557
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
package com.weikou.beibeivideo.ui.login;
 
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import androidx.annotation.NonNull;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.lcjian.library.dialog.DialogUtil;
import com.lcjian.library.permission.PermissionHelper;
import com.lcjian.library.permission.PermissionInterface;
import com.lcjian.library.util.Environment;
import com.lcjian.library.util.SingleToast;
import com.lcjian.library.util.common.StringUtils;
import com.lcjian.library.util.glide.GlideCircleTransform;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.BeibeiVideoApplication;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.entity.vo.UserInfoVO;
import com.weikou.beibeivideo.ui.BaseActivity;
import com.weikou.beibeivideo.util.BeibeiConstant;
import com.weikou.beibeivideo.util.FileUtils;
import com.weikou.beibeivideo.util.UserUtil;
import com.weikou.beibeivideo.util.ui.TopStatusSettings;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Map;
 
/**
 * Created by weikou2015 on 2016/10/27.
 */
 
public class PersonInfoActivity extends BaseActivity implements View.OnClickListener, PermissionInterface {
 
    private String TAG = PersonInfoActivity.class.getSimpleName();
 
    private LinearLayout ll_portrait;
    private LinearLayout ll_nickName;
    private LinearLayout ll_birthday;
    private LinearLayout ll_sex;
    private LinearLayout ll_autograph;
 
    private ImageView iv_portrait;
    private TextView tv_nickName;
    private TextView tv_birthday;
    private TextView tv_sex;
    private TextView tv_autograph;
 
    private TextView tv_qq;
    private TextView tv_wx;
    private TextView tv_phone;
 
    private TextView tv_bind_qq;
    private TextView tv_bind_wx;
    private TextView tv_bind_phone;
 
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_person_info);
        TopStatusSettings.setStatusViewAndDeepColor(this);
        ll_portrait = (LinearLayout) findViewById(R.id.ll_portrait_select);
        ll_nickName = (LinearLayout) findViewById(R.id.ll_nickName);
        ll_birthday = (LinearLayout) findViewById(R.id.ll_birthday);
        ll_sex = (LinearLayout) findViewById(R.id.ll_sex);
        ll_autograph = (LinearLayout) findViewById(R.id.ll_autograph);
        iv_portrait = (ImageView) findViewById(R.id.iv_portrai_select);
        tv_nickName = (TextView) findViewById(R.id.tv_nickName);
        tv_birthday = (TextView) findViewById(R.id.tv_birthday);
        tv_sex = (TextView) findViewById(R.id.tv_sex);
        tv_autograph = (TextView) findViewById(R.id.tv_autograph);
 
        tv_qq = findViewById(R.id.tv_qq);
        tv_wx = findViewById(R.id.tv_wx);
        tv_phone = findViewById(R.id.tv_phone);
 
        tv_bind_qq = findViewById(R.id.tv_bind_qq);
        tv_bind_wx = findViewById(R.id.tv_bind_wx);
        tv_bind_phone = findViewById(R.id.tv_bind_phone);
        TextView tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
        tv_top_bar_middle.setText("个人资料");
 
        ll_portrait.setOnClickListener(this);
        ll_nickName.setOnClickListener(this);
        ll_birthday.setOnClickListener(this);
        ll_sex.setOnClickListener(this);
        ll_autograph.setOnClickListener(this);
        findViewById(R.id.tv_top_bar_left).setOnClickListener(this);
        tv_bind_qq.setOnClickListener(this);
        tv_bind_wx.setOnClickListener(this);
        tv_bind_phone.setOnClickListener(this);
        mPermissionsChecker = new PermissionHelper(this, this);//权限
    }
 
    private String sign = "";
 
    private void getPersonInfo() {
        SharedPreferences sp = getSharedPreferences("user", Context.MODE_PRIVATE);
        String loginUid = sp.getString("LoginUid", "");
        String uid = sp.getString("uid", "");
        BeibeiVideoAPI.getPersonInfo(this, uid, loginUid, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optBoolean("IsPost")) {
                    JSONObject data = jsonObject.optJSONObject("Data");
                    UserInfoVO userInfoVO = new Gson().fromJson(data.toString(), UserInfoVO.class);
                    setData(userInfoVO);
                }
            }
        });
    }
 
    private void setData(UserInfoVO userInfoVO) {
        Glide.with(PersonInfoActivity.this).load(BeibeiConstant.addPreFix(userInfoVO.getPortrait())).
                placeholder(R.drawable.ic_portrait_default).error(R.drawable.ic_portrait_default).transform(new GlideCircleTransform(getApplicationContext())).into(iv_portrait);
        if (!StringUtils.isEmpty(userInfoVO.getNickName())) {
            tv_nickName.setText(userInfoVO.getNickName());
            tv_nickName.setTextColor(Color.GRAY);
        } else {
            tv_nickName.setText("未填写");
            tv_nickName.setTextColor(Color.GRAY);
        }
 
 
        if (!StringUtils.isEmpty(userInfoVO.getBirthday())) {
            tv_birthday.setText(userInfoVO.getBirthday());
            tv_birthday.setTextColor(Color.GRAY);
        } else {
            tv_birthday.setText("未填写");
            tv_birthday.setTextColor(Color.GRAY);
        }
 
        if (!StringUtils.isEmpty(userInfoVO.getSex())) {
            tv_sex.setText(Integer.parseInt(userInfoVO.getSex()) == 0 ? "女" : "男");
            tv_sex.setTextColor(Color.GRAY);
        } else {
            tv_sex.setText("未填写");
            tv_sex.setTextColor(Color.GRAY);
        }
 
        sign = userInfoVO.getSign();
 
        if (!StringUtils.isEmpty(userInfoVO.getSign())) {
            tv_autograph.setText(userInfoVO.getSign());
            tv_autograph.setTextColor(Color.GRAY);
        } else {
            tv_autograph.setText("未填写");
            tv_autograph.setTextColor(Color.GRAY);
        }
 
 
        if (!StringUtils.isEmpty(userInfoVO.getQqOpenId())) {
            tv_qq.setText(userInfoVO.getQqNickName());
            tv_bind_qq.setVisibility(View.GONE);
            tv_qq.setVisibility(View.VISIBLE);
        } else {
            tv_bind_qq.setVisibility(View.VISIBLE);
            tv_qq.setVisibility(View.GONE);
        }
 
 
        if (!StringUtils.isEmpty(userInfoVO.getWxUnionId())) {
            tv_wx.setText(userInfoVO.getWxName());
            tv_bind_wx.setVisibility(View.GONE);
            tv_wx.setVisibility(View.VISIBLE);
        } else {
            tv_bind_wx.setVisibility(View.VISIBLE);
            tv_wx.setVisibility(View.GONE);
        }
 
 
        if (!StringUtils.isEmpty(userInfoVO.getPhone())) {
            tv_phone.setText(userInfoVO.getPhone());
            tv_bind_phone.setVisibility(View.GONE);
            tv_phone.setVisibility(View.VISIBLE);
        } else {
            tv_bind_phone.setVisibility(View.VISIBLE);
            tv_phone.setVisibility(View.GONE);
        }
 
 
    }
 
 
    /**
     * 权限请求码
     *
     * @return
     */
    @Override
    public int getPermissionsRequestCode() {
        return 1001;
    }
 
    /**
     * 请求权限
     *
     * @return
     */
    @Override
    public String[] getPermissions() {
        return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
    }
 
    /**
     * 权限请求成功
     */
    @Override
    public void requestPermissionsSuccess() {
        ll_portrait.performClick();
    }
 
    /**
     * 权限请求失败
     */
    @Override
    public void requestPermissionsFail() {
//        Toast.makeText(this, "你以拒绝权限", Toast.LENGTH_SHORT).show();
    }
 
    /**
     * 请求权限结果
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (mPermissionsChecker.requestPermissionsResult(requestCode, permissions, grantResults)) {
            //权限请求结果,并已经处理了该回调
            return;
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
 
 
    String imgBase64 = "";
 
    private Uri uriClipUri;//剪裁图片路径
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
 
        //图库
        if (resultCode == RESULT_OK && resultCode != RESULT_CANCELED && requestCode == 1001 && data != null) {//相册
            Uri selectedImage = data.getData();
            startPhotoZoom(selectedImage);//系统剪裁
        } else if (resultCode == RESULT_OK && requestCode == 1002 && data != null) {//剪裁完成
            if (uriClipUri != null) {
                //图库
                Photo_crop crop = new Photo_crop();//初始化 图片压缩
                File f = new File(uriClipUri.getPath());//获取图片
                if (crop.compressPhto(f, false)) {//压缩并保存成功
                    Uri uri = Uri.parse("file://" + "/" + android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + "avatar.png");
                    f = new File(uri.getPath());
                    imgBase64 = bitmapToBase64(f);
                    iv_portrait.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(PersonInfoActivity.this).load(uriClipUri).transform(new GlideCircleTransform(PersonInfoActivity.this)).into(iv_portrait);
                        }
                    }, 200);
                    //上传
                    updatePersonInfo(null, null, null, imgBase64, null);
                }
            }
        }
    }
 
    /**
     * 获取相册图片
     *
     * @param uri
     */
    public void startPhotoZoom(Uri uri) {
        File storageDir = new File(android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/");
        if (!storageDir.exists()) {//没有文件夹则创建
            storageDir.mkdir();
        }
        //com.android.camera.action.CROP,这个action是调用系统自带的图片裁切功能
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");//裁剪的图片uri和图片类型
        intent.putExtra("crop", "true");//设置允许裁剪,如果不设置,就会跳过裁剪的过程,还可以设置putExtra("crop", "circle")
        if (Build.MANUFACTURER.equals("HUAWEI")) { //华为特殊处理 不然会显示圆
            intent.putExtra("aspectX", 9998);
            intent.putExtra("aspectY", 9999);
        } else {
            intent.putExtra("aspectX", 1);//裁剪框的 X 方向的比例,需要为整数
            intent.putExtra("aspectY", 1);//裁剪框的 Y 方向的比例,需要为整数
        }
        intent.putExtra("outputX", 250);//返回数据的时候的X像素大小。
        intent.putExtra("outputY", 250);//返回数据的时候的Y像素大小。
        //裁剪时是否保留图片的比例,这里的比例是1:1
        intent.putExtra("scale", true);
        //是否是圆形裁剪区域,设置了也不一定有效
        intent.putExtra("circleCrop", false);
 
        //uritempFile为Uri类变量,实例化uritempFile
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //如果是7.0的相册
            //设置裁剪的图片地址Uri
            uriClipUri = Uri.parse("file://" + "/" + android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + System.currentTimeMillis() + "_clip.jpg");
        } else {
            uriClipUri = Uri.parse("file://" + "/" + android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + System.currentTimeMillis() + "_clip.jpg");
        }
        //Android 对Intent中所包含数据的大小是有限制的,一般不能超过 1M,否则会使用缩略图 ,所以我们要指定输出裁剪的图片路径
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uriClipUri);
        intent.putExtra("return-data", false);//是否将数据保留在Bitmap中返回
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出格式,一般设为Bitmap格式及图片类型
        intent.putExtra("noFaceDetection", false);//人脸识别功能
        startActivityForResult(intent, 1002);//裁剪完成的标识
    }
 
    private String bitmapToBase64(File file) {
        String base64 = null;
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            byte[] bytes = new byte[in.available()];
            int length = in.read(bytes);
            base64 = Base64.encodeToString(bytes, 0, length, Base64.DEFAULT);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return base64;
 
    }
 
    private String saveBitmapTofile(Bitmap bm) {
        String name = "img.png";
        File fDir = new File(Environment.getExternalStorageDirectory() + "");
        if (!fDir.exists()) {
            fDir.mkdir();
        }
        File picFile = new File(fDir, name);
        try {
            FileOutputStream out = new FileOutputStream(picFile);
            bm.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return picFile.getPath();
    }
 
    @SuppressLint("SdCardPath")
 
    private int imgWidth = 400;
 
    private int imgHeight = 400;
 
    private int maxSize = 300;
 
    /*
     * 压缩图片
     */
    private Bitmap compressImage(Bitmap image) {
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
        int options = 100;
        while (baos.toByteArray().length / 1024 > maxSize) { // 循环判断如果压缩后图片是否大于100kb,大于继续压缩
            baos.reset();// 重置baos即清空baos
            image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中
            options -= 10;// 每次都减少10
        }
        ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中
        Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片
        return bitmap;
    }
 
    private PermissionHelper mPermissionsChecker; // 权限检测器 检测是否有储存卡写入读取权限
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_top_bar_left:
                finish();
                break;
            case R.id.ll_portrait_select:
                if (mPermissionsChecker.lacksPermissions(getPermissions())) {//检测是否有写入的权限
                    mPermissionsChecker.showNormalDialog();
                } else {
                    Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    try {
                        startActivityForResult(picture, 1001);
                    } catch (ActivityNotFoundException exception) {
                        Toast.makeText(this, "no activity", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.ll_nickName:
                getNickName();
                break;
            case R.id.ll_birthday:
                getDate();
                break;
            case R.id.ll_sex:
                getSex();
                break;
            case R.id.ll_autograph://个性签名
                getAutograph();
                break;
 
            case R.id.tv_bind_qq:
                //绑定QQ
            {
                if (LoginActivity.isQQClientAvailable(getApplicationContext())) {
                    // qq登录逻辑处理 点击登录后需要暂时锁定返回键和返回功能 不然会报错
                    UMShareAPI.get(getApplicationContext()).getPlatformInfo(PersonInfoActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() {
 
                        @Override
                        public void onStart(SHARE_MEDIA share_media) {
                            DialogUtil.show(loadingDialog);
                        }
 
                        @Override
                        public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
                            Log.d(TAG, "onComplete");
                            DialogUtil.dismiss(loadingDialog);
                            String nickName = map.get("name");
                            String openid = map.get("openid");
                            String portrait = map.get("iconurl");
                            String sex = map.get("gender");
                            String province = map.get("province");
                            String city = map.get("city");
                            if (StringUtils.isEmpty(openid)) {
                                return;
                            }
 
                            BeibeiVideoAPI.bindQQ(PersonInfoActivity.this, UserUtil.getLoginUid(getApplicationContext()), nickName, portrait, openid, new BasicTextHttpResponseHandler() {
                                @Override
                                public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                                    if (jsonObject.optBoolean("IsPost")) {
                                        Toast.makeText(PersonInfoActivity.this, "QQ绑定成功", Toast.LENGTH_SHORT).show();
                                        getPersonInfo();
                                    } else {
                                        Toast.makeText(PersonInfoActivity.this, jsonObject.optString("Error"), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                        }
 
                        @Override
                        public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
                            throwable.printStackTrace();
                            Log.d(TAG, "onError");
                            DialogUtil.dismiss(loadingDialog);
 
                            Toast.makeText(PersonInfoActivity.this, "QQ授权出错,请稍后再试", Toast.LENGTH_SHORT).show();
                        }
 
                        @Override
                        public void onCancel(SHARE_MEDIA share_media, int i) {
                            Log.d(TAG, "onCancel");
                            DialogUtil.dismiss(loadingDialog);
                        }
                    });
                } else {
                    Toast.makeText(this, "QQ不可用,请查询手机是否安装QQ...", Toast.LENGTH_LONG).show();
                }
            }
            break;
            case R.id.tv_bind_wx: {
                if (LoginActivity.isWXClientAvailable(getApplicationContext())) {
                    SendAuth.Req req = new SendAuth.Req();
                    req.scope = "snsapi_userinfo";
                    req.state = "bind";
                    BeibeiVideoApplication.application.mWxApi.sendReq(req);
                } else {
                    Toast.makeText(this, "微信不可用,请查询手机是否安装微信...", Toast.LENGTH_LONG).show();
                }
            }
            break;
            case R.id.tv_bind_phone: {
                Intent intent = new Intent(this, PhoneLoginActivity.class);
                intent.putExtra("login", false);
                startActivity(intent);
            }
            break;
        }
    }
 
 
    private void updatePersonInfo(String sex, String birthday,
                                  String personSign, String portrait, String nickName) {
        SharedPreferences sp = getSharedPreferences("user", Context.MODE_PRIVATE);
        String uid = UserUtil.getUid(this);
        String loginUid = UserUtil.getLoginUid(this);
        BeibeiVideoAPI.upLoadPersonInfo(this, uid, loginUid, sex, birthday,
                personSign, portrait, nickName, new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onStart() {
                        super.onStart();
                        if (portrait != null)
                            DialogUtil.show(loadingDialog);
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        DialogUtil.dismiss(loadingDialog);
                    }
 
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optBoolean("IsPost")) {
                            SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE);
                            SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putString("name", nickName);
                            editor.commit();
                        }
                    }
                });
    }
 
    private int mSex = 0;
 
    private void getSex() {
        if (isFinishing())
            return;
        final String sex[] = new String[]{"女", "男"};
        new AlertDialog.Builder(this).setTitle("性别选择").setSingleChoiceItems(
                sex, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mSex = which;
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.i("mResult", "which的值为:" + which);
                        tv_sex.setText(sex[mSex]);
                        updatePersonInfo(mSex + "", null, null, null, null);
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
    }
 
    private void getAutograph() {
        View v = LayoutInflater.from(this).inflate(R.layout.item_edit_dialog, null);
        TextView tv_title = (TextView) v.findViewById(R.id.tv_dialog_title);
        tv_title.setText("个性签名");
        tv_title.setVisibility(View.GONE);
        final EditText et_msg = (EditText) v.findViewById(R.id.et_dialog_message);
        TextView tv_cancel = (TextView) v.findViewById(R.id.tv_cancel);
        TextView tv_confirm = (TextView) v.findViewById(R.id.tv_confirm);
 
        if (isFinishing())
            return;
        final AlertDialog alertDialog = new AlertDialog.Builder(PersonInfoActivity.this).setTitle("个性签名").setView(v).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String str = et_msg.getText().toString();
                if (StringUtils.isEmpty(str)) {
                    SingleToast.showToast(PersonInfoActivity.this, "个性签名不能为空");
                    return;
                } else {
                    tv_autograph.setText(str);
                    updatePersonInfo(null, null, str, null, null);
                    dialog.dismiss();
                }
            }
        }).create();
        alertDialog.show();
        et_msg.setText(sign);
        et_msg.setSelection(et_msg.getText().length());
    }
 
    private void getNickName() {
        final EditText et_msg = new EditText(this);
        et_msg.setBackground(null);
        if (isFinishing())
            return;
        if (tv_nickName.getText() != null) {
            et_msg.setText(tv_nickName.getText() + "");
            et_msg.setSelection(tv_nickName.getText().length());
        }
        AlertDialog alertDialog = new AlertDialog.Builder(PersonInfoActivity.this).setView(et_msg).setTitle("昵称修改")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String str = et_msg.getText().toString();
                        if (StringUtils.isEmpty(str)) {
                            SingleToast.showToast(PersonInfoActivity.this, "昵称不能为空");
                        } else {
                            tv_nickName.setText(str);
                            updatePersonInfo(null, null, null, null, str);
                            dialog.dismiss();
                        }
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create();
        alertDialog.show();
    }
 
    /**
     * 获取生日
     */
    String date = "";
 
    private void getDate() {
        View view = LayoutInflater.from(this).inflate(R.layout.item_datepicker, null);
        if (isFinishing())
            return;
        final AlertDialog alertDialog = new AlertDialog.Builder(PersonInfoActivity.this).setView(view).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                tv_birthday.setText(date);
                updatePersonInfo(null, date, null, null, null);
                dialog.dismiss();
            }
        }).setTitle("生日选择").create();
        alertDialog.show();
        DatePicker datePicker = (DatePicker) view.findViewById(R.id.datePicker);
        TextView tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
        final TextView tv_confirm = (TextView) view.findViewById(R.id.tv_confirm);
 
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        date = year + "/" + monthOfYear + "/" + dayOfMonth;
        datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                date = year + "/" + (monthOfYear + 1) + "/" + dayOfMonth;
            }
        });
 
    }
 
    @Override
    public void onResume() {
        super.onResume();
        getPersonInfo();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        String filePath = android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/";
        if (new File(filePath).exists()) {
            FileUtils.deleteDirectory(filePath);
        }
    }
 
    class Photo_crop {
        /**
         * 获取相册图片
         *
         * @param uri
         */
        public Uri startPhotoZoom(Uri uri, Context mContext) {
            Uri uriClipUri = null;
            //com.android.camera.action.CROP,这个action是调用系统自带的图片裁切功能
            Intent intent = new Intent("com.android.camera.action.CROP");
            intent.setDataAndType(uri, "image/*");//裁剪的图片uri和图片类型
            intent.putExtra("crop", "true");//设置允许裁剪,如果不设置,就会跳过裁剪的过程,还可以设置putExtra("crop", "circle")
            if (Build.MANUFACTURER.equals("HUAWEI")) { //华为特殊处理 不然会显示圆
                intent.putExtra("aspectX", 9998);
                intent.putExtra("aspectY", 9999);
            } else {
                intent.putExtra("aspectX", 1);//裁剪框的 X 方向的比例,需要为整数
                intent.putExtra("aspectY", 1);//裁剪框的 Y 方向的比例,需要为整数
            }
            intent.putExtra("outputX", 600);//返回数据的时候的X像素大小。
            intent.putExtra("outputY", 600);//返回数据的时候的Y像素大小。
            //裁剪时是否保留图片的比例,这里的比例是1:1
            intent.putExtra("scale", true);
            //是否是圆形裁剪区域true,设置了也不一定有效
            intent.putExtra("circleCrop", false);
            //uritempFile为Uri类变量,实例化uritempFile
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                //如果是7.0的相册
                //设置裁剪的图片地址Uri
                uriClipUri = Uri.parse("file://" + "/" + android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + "clip.jpg");
            } else {
                uriClipUri = Uri.parse("file://" + "/" + android.os.Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + "clip.jpg");
            }
            Log.e("uriClipUri=====", "" + uriClipUri);
            //Android 对Intent中所包含数据的大小是有限制的,一般不能超过 1M,否则会使用缩略图 ,所以我们要指定输出裁剪的图片路径
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uriClipUri);
            intent.putExtra("return-data", false);//是否将数据保留在Bitmap中返回
            intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出格式,一般设为Bitmap格式及图片类型
            intent.putExtra("noFaceDetection", false);//人脸识别功能
            ((Activity) mContext).startActivityForResult(intent, 1002);//裁剪完成的标识
            return uriClipUri;
        }
 
        /**
         * 图片压缩的方法(只是内存减少,避免oom,图片本身在disk盘体积不变)
         * 显示的Bitmap占用的内存少一点,还是需要去设置加载的像素长度和宽度(变成缩略图)
         *
         * @param mFile
         * @param crop  是否剪裁圆形图片 true 是 false 否
         * @return
         */
        public boolean compressPhto(File mFile, boolean crop) {
//        BitmapFactory这个类就提供了多个解析方法(decodeResource、decodeStream、decodeFile等)用于创建Bitmap。
//        比如如果图片来源于网络,就可以使用decodeStream方法;
//        如果是sd卡里面的图片,就可以选择decodeFile方法;
//        如果是资源文件里面的图片,就可以使用decodeResource方法等
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true; // 获取当前图片的边界大小
            //BitmapFactory.decodeResource(getResources(), R.drawable.bg, options);
            BitmapFactory.decodeFile(mFile.getAbsolutePath(), options);
            int outHeight = options.outHeight; //获取图片本身的高像素
            int outWidth = options.outWidth;//获取图片本身的宽的像素
            String outMimeType = options.outMimeType;
            options.inJustDecodeBounds = false;
            //inSampleSize的作用就是可以把图片的长短缩小inSampleSize倍,所占内存缩小inSampleSize的平方
            //对于inSampleSize值的大小有要求,最好是整数且2的倍数
            options.inSampleSize = caculateSampleSize(options, 500, 500);
            //etPath()得到的是构造file的时候的路径。getAbsolutePath()得到的是全路径
            String path = mFile.getPath();
            String absPath = mFile.getAbsolutePath();
            Bitmap bitmap = BitmapFactory.decodeFile(absPath, options);
            try {
                return saveBitmap(bitmap, "avatar.png", crop);//保存成功
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
//        ivUserPhoto.setImageBitmap(bitmap);
//        //尺寸压缩结果
//        ivSize.setImageBitmap(bitmap);
        }
 
        /**
         * 计算出所需要压缩的大小
         *
         * @param options
         * @param reqWidth  希望的图片宽大小
         * @param reqHeight 希望的图片高大小
         * @return
         */
        private int caculateSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
            int sampleSize = 1;
            int picWidth = options.outWidth;
            int picHeight = options.outHeight;
            if (picWidth > reqWidth || picHeight > reqHeight) {
                int halfPicWidth = picWidth / 2;
                int halfPicHeight = picHeight / 2;
                while (halfPicWidth / sampleSize > reqWidth || halfPicHeight / sampleSize > reqHeight) {
                    sampleSize *= 2;
                }
            }
            return sampleSize;
        }
 
 
        /**
         * 保存文件,
         *
         * @param bitmap
         * @param bitName 文件名
         * @param crop
         * @return
         * @throws IOException
         */
        private boolean saveBitmap(Bitmap bitmap, String bitName, boolean crop) throws IOException {
            boolean save = false;
            File storageDir = new File(Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/");
            if (!storageDir.exists()) {//没有文件夹则创建
                storageDir.mkdir();
            }
            String fileName;
            File file;
            fileName = Environment.getExternalStorageDirectory().getPath() + "/YSDQImg/" + bitName;
            file = new File(fileName);
            if (bitmap != null) {
                if (file.exists()) {
                    file.delete();
                }
                FileOutputStream out;
 
                out = new FileOutputStream(file);
                // 格式为 JPEG,照相机拍出的图片为JPEG格式的,PNG格式的不能显示在相册中
                if (bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)) {
                    out.flush();
                    out.close();
                }
                save = true;//保存成功
            }
            return save;
        }
    }
 
}