MainActivity.java 37 KB
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
package com.hjx.personalcenter.activity;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.adapter.MianGridAdapter;
import com.hjx.personalcenter.adapter.VideoAdapter;
import com.hjx.personalcenter.customdialog.HeadDialog;
import com.hjx.personalcenter.customdialog.RecyclerViewSpaceItem;
import com.hjx.personalcenter.db.SaveParam;
import com.hjx.personalcenter.http.HttpCode;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.interfaces.DialogCallBack;
import com.hjx.personalcenter.model.DefautPublishInfo;
import com.hjx.personalcenter.model.PesonalInfo;
import com.hjx.personalcenter.model.SignInfo;
import com.hjx.personalcenter.model.VideoInfo;
import com.hjx.personalcenter.update.UpdateChecker;
import com.hjx.personalcenter.util.AlertUtils;
import com.hjx.personalcenter.util.BrithdayStar;
import com.hjx.personalcenter.util.CropUtils;
import com.hjx.personalcenter.util.DialogPermission;
import com.hjx.personalcenter.util.FileUtil;
import com.hjx.personalcenter.util.GetDevicesUtil;
import com.hjx.personalcenter.util.PermissionUtil;
import com.hjx.personalcenter.util.SharedPreferenceMark;
import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.callback.ConfigInput;
import com.mylhyl.circledialog.params.InputParams;
import com.mylhyl.circledialog.view.listener.OnInputClickListener;
import com.zaaach.toprightmenu.MenuItem;
import com.zaaach.toprightmenu.TopRightMenu;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, DialogCallBack.CallBackView {
    private ImageView iv_imformatioan, iv_setting, iv_sign, iv_sex,tv_edit_presoninfo;
    private TextView  tv_sign,
            tv_username, tv_username1, tv_mygad, tv_sex, tv_useinfo_adress, tv_useinfo_birthday,
            tv_useinfo_qq, tv_useinfo_school, tv_useinfo_gender, tv_yangji;
    private TextView linel_mycuoti, linel_mynote, linel_mycollege, linel_myclass,iv_look_card;
    private TopRightMenu mTopRightMenu;
    private LinearLayout view_novedeo;
    //水平滑动
    private RecyclerView mRecyclerView;
    private GridView mRecyclerViewpublish;
    private VideoAdapter RecyclerViewadapter;
    private MianGridAdapter RecyclerViewadapterpublish;
    private ArrayList<DefautPublishInfo.DataBean> defautPublishInfos = new ArrayList<>();

    private ArrayList<VideoInfo.DataBean> videoinfo = new ArrayList<>();
    private boolean showIcon = true;
    private boolean dimBg = true;
    private boolean needAnim = true;
    private static final int REQUEST_CODE_TAKE_PHOTO = 1;
    private static final int REQUEST_CODE_ALBUM = 2;
    private static final int REQUEST_CODE_CROUP_PHOTO = 3;
    SimpleDraweeView mSimpleDraweeView;
    private File file;
    private Uri uri;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case HttpCode.GETINFO:
                    PesonalInfo.DataBean cardinfoBean = (PesonalInfo.DataBean) msg.obj;
                    tv_username.setText(cardinfoBean.getNickName());
                    tv_username1.setText(cardinfoBean.getNickName());
                    tv_useinfo_adress.setText(cardinfoBean.getRegion().getRegionName());
                    tv_useinfo_birthday.setText(cardinfoBean.getBirthday());
                    tv_useinfo_qq.setText(cardinfoBean.getQq());
                    tv_useinfo_school.setText(cardinfoBean.getSchool().getSchoolName());
                    tv_useinfo_gender.setText(cardinfoBean.getGrade().getGradeName());
                    String sex = cardinfoBean.getGender();
                    if ("0".equals(sex)) {
                        tv_sex.setText("男");
                        iv_sex.setImageResource(R.mipmap.men);
                    } else {
                        tv_sex.setText("女");
                        iv_sex.setImageResource(R.mipmap.women);
                    }
                    mSimpleDraweeView.setImageURI(cardinfoBean.getPortrait());
                    //加载星座
                    BrithdayStar brithdayStar = new BrithdayStar();
                    if (cardinfoBean.getBirthday() ==null||"".equals(cardinfoBean.getBirthday())) {
                        tv_mygad.setText("");
                    } else {
                        String xiongzuo = brithdayStar.getConstellations(cardinfoBean.getBirthday());
                        tv_mygad.setText(xiongzuo);
                    }
                    //保存个人信息
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTUSERNAME,cardinfoBean.getNickName());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTGRADES,cardinfoBean.getGrade().getGradeName());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSCHOOL,cardinfoBean.getSchool().getSchoolName());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTCONSTELLATION,cardinfoBean.getBirthday());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTSEX,tv_sex.getText().toString());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTQQ,cardinfoBean.getQq());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTADRESS,cardinfoBean.getRegion().getRegionName());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ACCOUNTXINGZUO,cardinfoBean.getAddress());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.ADRESSID,cardinfoBean.getRegion().getRegionId());
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.PORTAIT,cardinfoBean.getPortrait());
                    String graderID = cardinfoBean.getGrade().getGradeId();
                    Log.e("test","nianji"+graderID);
                    try {
                        long auserID = Long.parseLong(graderID);
                        String ss =SaveParam.getInstance().getLoginParam(MainActivity.this, SaveParam.GRADENS);
                        if ((auserID<8)&&(ss ==null)){
                            Intent intentbroad = new Intent();
                            intentbroad.putExtra("info","小学");
                            //4、定义广播发送的action
                            intentbroad.setAction("com.ozing.launcher.SWITCH_GRADE");
                            //5、发送广播
                            sendBroadcast(intentbroad);
                            Log.i("---", "发送完了");
                        }
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }


                    SaveParam.getInstance().saveLoginParam(MainActivity.this, SaveParam.GRADENS, graderID);
                    String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId");
                    //账户类型
                    String accounts = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT);
                    String childID = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.CHILDSID);

                    try {
                        Object auserID;
                        int type;
                        int graderIDs = Integer.parseInt(graderID);
                        if ("2".equals(accounts)) {
                            type = Integer.parseInt(accounts);
                            auserID = childID;
                        } else {
                            type = Integer.parseInt(accounts);
                            auserID = Long.parseLong(userID);
                        }
                        //获取版本信息
                        //Log.e("test","nianji"+graderID+auserID+"sssss"+type);
                        HttpManager.getInstance().getpublishinfo(MainActivity.this, auserID, graderIDs, type, handler);

                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }

                    break;
                case HttpCode.SIGN:
                    SignInfo.DataBean dataBean = (SignInfo.DataBean) msg.obj;
                    if (dataBean.getSignature() == null) {
                        tv_sign.setText("你还未设置个性签名");
                    } else {
                        tv_sign.setText(dataBean.getSignature());
                    }

                    break;
                case HttpCode.PUBLISH_SUCESS:
                    defautPublishInfos.clear();
                    defautPublishInfos.addAll((List<DefautPublishInfo.DataBean>) msg.obj);
                    RecyclerViewadapterpublish.notifyDataSetChanged();
                    Gson gson = new Gson();
                    Log.e("test","(List<DefautPublishInfo.DataBean>) msg.obj"+ gson.toJson( msg.obj));
                    SaveParam.getInstance().saveLoginParam(MainActivity.this,SaveParam.VERSIONINTEFACE, gson.toJson( msg.obj));
                    break;
                case HttpCode.GETVIDIO_SUCESS:
                    videoinfo.clear();
                    if (((List<VideoInfo.DataBean>) msg.obj).size()==0) {
                        view_novedeo.setVisibility(View.VISIBLE);
                    } else {
                        view_novedeo.setVisibility(View.GONE);
                        videoinfo.addAll((List<VideoInfo.DataBean>) msg.obj);
                    }

                    RecyclerViewadapter.notifyDataSetChanged();
                    break;
                case HttpCode.SUCHCARDINFOONE:
                    JSONObject jsonObject;
                    String status;
                    try {
                        jsonObject = new JSONObject((String) msg.obj);
                        status = jsonObject.getString("status");
                        if (status.equals("1")) {
                            tv_yangji.setVisibility(View.GONE);
                            iv_look_card.setVisibility(View.VISIBLE);
                        } else if (status.equals("2001")) {
                            tv_yangji.setVisibility(View.GONE);
                            iv_look_card.setVisibility(View.VISIBLE);
                            AlertUtils.showToast(MainActivity.this, "您的机器还没有保卡信息,请重新登录");
                            SaveParam.getInstance().clearData(MainActivity.this);
                            Intent settingintent = new Intent();
                            settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class);
                            startActivity(settingintent);
                            overridePendingTransition(R.anim.rightin, R.anim.rightout);
                            finish();
                        } else if (status.equals("2002")) {
                            iv_look_card.setVisibility(View.GONE);
                            tv_yangji.setVisibility(View.VISIBLE);

                        } else {
                            AlertUtils.showToast(MainActivity.this, "服务器连接失败");
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_main);
        SysApplication.getInstance().addActivity(this);
        initView();
        initData();
        initLister();
        updateVersion();
    }

    //////版本更新
    private void updateVersion() {
        UpdateChecker updateChecker = new UpdateChecker(this);
        updateChecker.checkForUpdates();


    }

    private void initView() {
        iv_imformatioan = (ImageView) findViewById(R.id.iv_imformatioan);
        iv_look_card = (TextView) findViewById(R.id.iv_look_card);
        tv_edit_presoninfo = (ImageView) findViewById(R.id.tv_edit_presoninfo);
        iv_setting = (ImageView) findViewById(R.id.iv_setting);
        iv_sign = (ImageView) findViewById(R.id.iv_sign);
        tv_sign = (TextView) findViewById(R.id.tv_sign);
        //头像
        mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.iv_head);
        //初始化个人信息
        iv_sex = (ImageView) findViewById(R.id.iv_sex);
        tv_username = (TextView) findViewById(R.id.tv_username);
        tv_username1 = (TextView) findViewById(R.id.tv_username1);
        tv_mygad = (TextView) findViewById(R.id.tv_mygad);
        tv_sex = (TextView) findViewById(R.id.tv_sex);
        tv_useinfo_adress = (TextView) findViewById(R.id.tv_useinfo_adress);
        tv_useinfo_birthday = (TextView) findViewById(R.id.tv_useinfo_birthday);
        tv_useinfo_qq = (TextView) findViewById(R.id.tv_useinfo_qq);
        tv_useinfo_school = (TextView) findViewById(R.id.tv_useinfo_school);
        tv_useinfo_gender = (TextView) findViewById(R.id.tv_useinfo_gender);
        tv_yangji = (TextView) findViewById(R.id.tv_yangji);
        //跳转其他应用
        linel_mycuoti = (TextView) findViewById(R.id.linel_mycuoti);
        linel_mynote = (TextView) findViewById(R.id.linel_mynote);
        linel_mycollege = (TextView) findViewById(R.id.linel_mycollege);
        linel_myclass = (TextView) findViewById(R.id.linel_myclass);
        //
        mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal);
        mRecyclerViewpublish = (GridView) findViewById(R.id.id_recyclerview_pubish);
        view_novedeo = (LinearLayout) findViewById(R.id.view_novedeo);
    }


    private void initData() {
        file = new File(FileUtil.getCachePath(this), "user-avatar.jpg");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            uri = Uri.fromFile(file);
        } else {
            //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问)
            uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file);
        }
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

//        LinearLayoutManager linearLayoutManagerpublish = new LinearLayoutManager(this);
//        linearLayoutManagerpublish.setOrientation(LinearLayoutManager.HORIZONTAL);

        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.addItemDecoration(new RecyclerViewSpaceItem(10));

//        mRecyclerViewpublish.setLayoutManager(linearLayoutManagerpublish);
//        mRecyclerViewpublish.addItemDecoration(new RecyclerViewSpaceItem(10));

        //设置视频适配器
        RecyclerViewadapter = new VideoAdapter(this, videoinfo);
        RecyclerViewadapterpublish = new MianGridAdapter(defautPublishInfos,this);

        //版本信息适配器
        mRecyclerView.setAdapter(RecyclerViewadapter);
        mRecyclerViewpublish.setAdapter(RecyclerViewadapterpublish);

        //判断保卡信息是否为样机
        String yangji = SaveParam.getInstance().getLoginParam(this, SaveParam.YANGJI);
        String deviceNumber = GetDevicesUtil.getDevicesInfo(MainActivity.this).getDeviceNumber();
        if ("1".equals(yangji)) {
            iv_look_card.setVisibility(View.GONE);
            tv_yangji.setVisibility(View.VISIBLE);
        } else {
            HttpManager.getInstance().getcardinfo1(this, deviceNumber, handler);

        }
        String userID = SaveParam.getInstance().getLoginParam(this, "userId");
        //获取个性签名
        String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT);
        String childsID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID);

        try {
            long auserID = 1;
            long id = Long.parseLong(userID);
            long childssID = Long.parseLong(childsID);

            int typeaccount1 = Integer.parseInt(typeaccount);
            if (typeaccount1==2){
                auserID =childssID;
            }else {
                auserID =id;
            }

                HttpManager.getInstance().getsignatures(MainActivity.this, auserID, typeaccount1, handler);

        } catch (NumberFormatException e) {
            e.printStackTrace();
        }


    }

    private void initLister() {
        iv_imformatioan.setOnClickListener(this);
        iv_look_card.setOnClickListener(this);
        tv_edit_presoninfo.setOnClickListener(this);
        iv_setting.setOnClickListener(this);
        iv_sign.setOnClickListener(this);
        mSimpleDraweeView.setOnClickListener(this);
        linel_mycuoti.setOnClickListener(this);
        linel_mynote.setOnClickListener(this);
        linel_mycollege.setOnClickListener(this);
        linel_myclass.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_imformatioan:
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, FeedBackActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.rightin, R.anim.rightout);
                break;
            case R.id.iv_look_card:
                Intent lookintent = new Intent();
                lookintent.setClass(MainActivity.this, ElectronicCardLookInfoActivity.class);
                startActivity(lookintent);
                overridePendingTransition(R.anim.rightin, R.anim.rightout);
                break;
            case R.id.tv_edit_presoninfo:
                Intent editintent = new Intent();
                editintent.setClass(MainActivity.this, ChangePresonalInfoActivity.class);
                startActivity(editintent);
                overridePendingTransition(R.anim.rightin, R.anim.rightout);
                break;
            case R.id.iv_head:
                HeadDialog.getInstance(this).show(getSupportFragmentManager(), "HeadDialog");
                break;
            case R.id.iv_setting:
                mTopRightMenu = new TopRightMenu(MainActivity.this);
                List<MenuItem> menuItems = new ArrayList<>();
                menuItems.add(new MenuItem(R.mipmap.blank, "切换账户"));
                menuItems.add(new MenuItem(R.mipmap.blank, "账户管理"));
                mTopRightMenu
                        .setHeight(150)     //默认高度480
                        .setWidth(320)      //默认宽度wrap_content
                        .showIcon(showIcon)     //显示菜单图标,默认为true
                        .dimBackground(dimBg)           //背景变暗,默认为true
                        .needAnimationStyle(needAnim)   //显示动画,默认为true
                        .setAnimationStyle(R.style.TRM_ANIM_STYLE)  //默认为R.style.TRM_ANIM_STYLE
                        .setOnMenuItemClickListener(new TopRightMenu.OnMenuItemClickListener() {
                            @Override
                            public void onMenuItemClick(int position) {
                                switch (position) {
                                    case 0:
                                        new CircleDialog.Builder(MainActivity.this)
                                                .setCanceledOnTouchOutside(false)
                                                .setWidth(0.4f)
                                                .setCancelable(false)
                                                .setText("您确定要退出,更换其他账号登录吗?")
                                                .setNegative("取消", null)
                                                .setPositive("确定", new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {
                                                        String graderID = SaveParam.getInstance().getLoginParam(MainActivity.this, SaveParam.GRADENS);
                                                        int graderIDs = Integer.parseInt(graderID);
                                                        if (graderIDs<8){
                                                            Intent intentbroad = new Intent();
                                                            intentbroad.putExtra("info","小学");
                                                            //4、定义广播发送的action
                                                            intentbroad.setAction("com.ozing.launcher.SWITCH_GRADE");
                                                            //5、发送广播
                                                            sendBroadcast(intentbroad);
                                                            Log.i("---", "发送完了");
                                                        }
                                                        //清除数据
                                                        SaveParam.getInstance().clearData(MainActivity.this);
                                                        Intent settingintent = new Intent();
                                                        settingintent.setClass(MainActivity.this, LoginAndRegisterActivity.class);
                                                        startActivity(settingintent);
                                                        overridePendingTransition(R.anim.rightin, R.anim.rightout);
                                                        finish();
                                                    }
                                                })
                                                .show();
                                        break;
                                    case 1:
                                        Intent accontMintent = new Intent();
                                        accontMintent.setClass(MainActivity.this, AccountManagementActivity.class);
                                        startActivity(accontMintent);
                                        overridePendingTransition(R.anim.rightin, R.anim.rightout);
                                        break;
                                }
                            }
                        })
                        .addMenuList(menuItems)
                        .showAsDropDown(iv_setting, -250, 0);
                break;
            case R.id.iv_sign:
                new CircleDialog.Builder(this)
                        .setCanceledOnTouchOutside(false)
                        .setCancelable(true)
                        .setTitle("个性签名")
                        .setInputHint("请输入个性签名")
                        .setWidth(0.5f)
                        .configInput(new ConfigInput() {
                            @Override
                            public void onConfig(InputParams params) {
//                                params.inputBackgroundResourceId = R.drawable.bg_input;
                            }
                        })
                        .setNegative("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                RecyclerViewadapterpublish.notifyDataSetChanged();
                            }
                        })
                        .setPositiveInput("确定", new OnInputClickListener() {
                            @Override
                            public void onClick(String text, View v) {
                                if (text.equals("")) {
                                    AlertUtils.showToast(MainActivity.this, "请输入个性签名");
                                } else {
                                    try {
                                        String typeaccount = SaveParam.getInstance().getCustomizeParam(MainActivity.this, SaveParam.ACCOUNT);
                                        String userID = SaveParam.getInstance().getLoginParam(MainActivity.this, "userId");
                                        long auserID = Long.parseLong(userID);
                                        int typeaccount1 = Integer.parseInt(typeaccount);
                                        HttpManager.getInstance().changsignature(MainActivity.this, auserID, typeaccount1, text);
                                        RecyclerViewadapterpublish.notifyDataSetChanged();
                                    } catch (NumberFormatException e) {
                                        e.printStackTrace();
                                    }

                                    tv_sign.setText(text);
                                }

                            }
                        })
                        .show();
                break;
            case R.id.linel_mycuoti:
//                Intent intentbroad = new Intent();
//                //intentbroad.putExtra("info","小学");
//                //4、定义广播发送的action
//                intentbroad.setAction("com.ozing.launcher.SWITCH_GRADE");
//                //5、发送广播
//                sendBroadcast(intentbroad);
//                Log.i("---", "发送完了");
                break;
            case R.id.linel_mynote:
//                Intent intentbroad1 = new Intent();
//                //intentbroad1.putExtra("info","中学");
//                //4、定义广播发送的action
//                intentbroad1.setAction("com.ozing.launcher.SWITCH_GRADE");
//                //5、发送广播
//                sendBroadcast(intentbroad1);
//                Log.i("---", "发送完了");
                break;
            case R.id.linel_mycollege:
                AlertUtils.showToast(this, "我的收藏 ");
                break;
            case R.id.linel_myclass:
                AlertUtils.showToast(this, "我的班级 ");
                break;
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        String userID = SaveParam.getInstance().getLoginParam(this, "userId");
        //账户类型
        String accounts = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT);
        try {
            int graderID;
            long auserID = Long.parseLong(userID);
            int typeaccount1 = Integer.parseInt(accounts);
            //获取最近播放视频
             HttpManager.getInstance().getstuyvidioinfo(this, auserID, handler);
            //获取个人信息
            HttpManager.getInstance().getpresonalinfo(MainActivity.this, auserID, typeaccount1, handler);


        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

    }

    //回调头像监听
    @Override
    public void heard(Context context, View v, int headpitiaon) {
        String picUrl = "";
        String userID;
        String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT);
        if ("2".equals(typeaccount)) {
            userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID);
        } else {
            userID = SaveParam.getInstance().getLoginParam(this, "userId");
        }
        switch (v.getId()) {
            //选择默认图片
            case R.id.oktakephone:
                if (headpitiaon == 1) {
                    mSimpleDraweeView.setImageDrawable(null);
                    mSimpleDraweeView.setImageResource(R.mipmap.default_avatar1);
                    picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/61e8d8cf-651f-49c9-beb2-ff1387af390a.png";
                    try {
                        HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                } else if (headpitiaon == 2) {
                    mSimpleDraweeView.setImageDrawable(null);
                    mSimpleDraweeView.setImageResource(R.mipmap.default_avatar2);
                    picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/8480ff7b-42f1-4d64-b848-c8f4f3afd385.png";
                    try {
                        HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                } else if (headpitiaon == 3) {
                    mSimpleDraweeView.setImageDrawable(null);
                    mSimpleDraweeView.setImageResource(R.mipmap.default_avatar3);
                    picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/184112f4-bfe0-4db8-bc1e-6212755b241c.png";
                    try {
                        HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                } else if (headpitiaon == 4) {
                    mSimpleDraweeView.setImageDrawable(null);
                    mSimpleDraweeView.setImageResource(R.mipmap.default_avatar4);
                    picUrl = "http://hjxprodbucket.oss.aliyuncs.com/static/upload/boss_api/announcement/2017-08-29/e31c9e11-9276-4bf4-a162-b66272fdc351.png";
                    try {
                        HttpManager.getInstance().headerdeft(this, userID, typeaccount, picUrl);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                } else {
                    mSimpleDraweeView.setImageDrawable(null);
                    mSimpleDraweeView.setImageResource(R.mipmap.header_default);
                    ;
                }

                break;
            case R.id.canceltakephone:

                break;
            //拍摄和相册
            case R.id.take_pic:
                if (PermissionUtil.hasCameraPermission(MainActivity.this)) {
                    uploadAvatarFromPhotoRequest();
                }
                break;
            case R.id.xiangce:
                uploadAvatarFromAlbumRequest();
                break;

        }

    }
    //照相
    private void uploadAvatarFromPhotoRequest() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);
    }

    //选择图库
    private void uploadAvatarFromAlbumRequest() {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM);
    }

    //回掉
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != -1) {
            return;
        }
        if (requestCode == REQUEST_CODE_ALBUM && data != null) {
            Uri newUri;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
                newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData()));
            } else {
                newUri = data.getData();
            }
            if (newUri != null) {
                startPhotoZoom(newUri);
            } else {
                Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show();
            }
        } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) {
            //startPhotoZoom(uri);
            uploadAvatarFromPhoto();
        } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) {
            uploadAvatarFromPhoto();
        }
    }

    private void uploadAvatarFromPhoto() {
        compressAndUploadAvatar(file.getPath());

    }

    private void compressAndUploadAvatar(String fileSrc) {


        //上传到服务器

        final File cover = FileUtil.getSmallBitmap(this, fileSrc);
        String mimeType = "image/*";
        //requestBody = RequestBody.create(MediaType.parse(mimeType), file);
        //String fileName = cover.getName();
        String userID;
        String typeaccount = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT);
        if ("2".equals(typeaccount)) {
            userID = SaveParam.getInstance().getCustomizeParam(this, SaveParam.CHILDSID);
        } else {
            userID = SaveParam.getInstance().getLoginParam(this, "userId");
        }

        //上传头像

        try {
            HttpManager.getInstance().header(this, userID, typeaccount, fileSrc);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources());
        GenericDraweeHierarchy hierarchy = builder
                .setDesiredAspectRatio(1f)
                .setFailureImage(R.mipmap.header_default)
                //圆形头像
                .setRoundingParams(RoundingParams.asCircle())
                .build();

        //加载本地图片
        Uri uri = Uri.fromFile(cover);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setOldController(mSimpleDraweeView.getController())
                .setUri(uri)
                .build();
        mSimpleDraweeView.setHierarchy(hierarchy);
        mSimpleDraweeView.setController(controller);

    }

    public void startPhotoZoom(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
        intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
        intent.putExtra("aspectY", 1);// x:y=1:1
//        intent.putExtra("outputX", 400);//图片输出大小
//        intent.putExtra("outputY", 400);
        intent.putExtra("output", Uri.fromFile(file));
        intent.putExtra("outputFormat", "JPEG");// 返回格式
        startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {

            case PermissionUtil.REQUEST_SHOWCAMERA:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission Granted
                    uploadAvatarFromPhotoRequest();

                } else {
                    if (!SharedPreferenceMark.getHasShowCamera()) {
                        SharedPreferenceMark.setHasShowCamera(true);
                        new DialogPermission(this, "关闭摄像头权限影响扫描功能");

                    } else {
                        Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT)
                                .show();
                    }
                }
                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }



    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次退出程序",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                SysApplication.getInstance().finishActivity(MainActivity.this);
            }
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }
}