头像

  1. public class Frag3Fragment extends BaseFragment<Frag3Presenter> implements Frag3Contract.View {
    
        @BindView(R.id.set_iamge)
        ImageView setIamge;
        @BindView(R.id.iv_img_setting)
        ImageView ivImgSetting;
        @BindView(R.id.ll_userIcon_setting)
        LinearLayout llUserIconSetting;
        @BindView(R.id.tv_userName_setting)
        TextView tvUserNameSetting;
        @BindView(R.id.ll_userName_setting)
        LinearLayout llUserNameSetting;
        @BindView(R.id.tv_nickName_setting)
        TextView tvNickNameSetting;
        @BindView(R.id.ll_nickName_setting)
        LinearLayout llNickNameSetting;
        @BindView(R.id.tv_gender_setting)
        TextView tvGenderSetting;
        @BindView(R.id.ll_gender_setting)
        LinearLayout llGenderSetting;
        @BindView(R.id.ll_userBirthday_setting)
        LinearLayout llUserBirthdaySetting;
        @BindView(R.id.ll_address_setting)
        LinearLayout llAddressSetting;
        @BindView(R.id.btn_cancel_setting)
        Button btnCancelSetting;
        Unbinder unbinder;
        private TextView camera;
        private TextView pick;
        private TextView cancel;
        private String path =Environment.getExternalStorageDirectory()+"/photo.png";
        private PopupWindow popupWindow;
    
        public static Frag3Fragment newInstance() {
            Frag3Fragment fragment = new Frag3Fragment();
            return fragment;
        }
    
        @Override
        public void setupFragmentComponent(@NonNull AppComponent appComponent) {
            DaggerFrag3Component //如找不到该类,请编译一下项目
                    .builder()
                    .appComponent(appComponent)
                    .frag3Module(new Frag3Module(this))
                    .build()
                    .inject(this);
        }
    
        @Override
        public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_frag3, container, false);
        }
    
        @Override
        public void initData(@Nullable Bundle savedInstanceState) {
            View inflate = View.inflate(getActivity(), R.layout.pop, null);
            popupWindow = new PopupWindow(inflate, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            popupWindow.setOutsideTouchable(true);
            camera = inflate.findViewById(R.id.tv_camera_popup);
            pick = inflate.findViewById(R.id.tv_pick_popup);
            cancel = inflate.findViewById(R.id.tv_cancel_popup);
    
    
    
            //相机
            camera.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(path)));
                    startActivityForResult(intent,888);
                    popupWindow.dismiss();
                }
            });
            //相册
            pick.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_PICK);
                    //设置图片格式
                    intent.setType("image/*");
                    startActivityForResult(intent,999);
                    popupWindow.dismiss();
    
                }
            });
    
            //取消
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popupWindow.dismiss();
                }
            });
        }
    
    
        @Override
        public void setData(@Nullable Object data) {
    
        }
    
        @Override
        public void showLoading() {
    
        }
    
        @Override
        public void hideLoading() {
    
        }
    
        @Override
        public void showMessage(@NonNull String message) {
            checkNotNull(message);
            ArmsUtils.snackbarText(message);
        }
    
        @Override
        public void launchActivity(@NonNull Intent intent) {
            checkNotNull(intent);
            ArmsUtils.startActivity(intent);
        }
    
        @Override
        public void killMyself() {
    
        }
    
        @Override
        public void responseMsg(Been been) {
            String msg = been.getMsg();
            Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            // TODO: inflate a fragment view
            View rootView = super.onCreateView(inflater, container, savedInstanceState);
            unbinder = ButterKnife.bind(this, rootView);
            return rootView;
        }
    
        @Override
        public void onDestroyView() {
            super.onDestroyView();
            unbinder.unbind();
        }
    
        @OnClick({R.id.ll_userIcon_setting, R.id.ll_userBirthday_setting})
        public void onViewClicked(View view) {
            switch (view.getId()) {
                case R.id.ll_userIcon_setting:
                    popupWindow.showAtLocation(llUserIconSetting,Gravity.BOTTOM,0,0);
                    break;
                case R.id.ll_userBirthday_setting:
                    break;
            }
        }
    
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode==999&&resultCode==getActivity().RESULT_OK){
                Uri uri = data.getData();
                crop(uri);
            }
            else if (requestCode==888&&resultCode==getActivity().RESULT_OK){
                Uri uri = Uri.fromFile(new File(path));
                crop(uri);
            }
            else if (requestCode==1000&&resultCode==getActivity().RESULT_OK){
                Bitmap  bitmap= data.getParcelableExtra("data");
                ivImgSetting.setImageBitmap(bitmap);
                File file = new File(getActivity().getFilesDir().getAbsolutePath());
                if (!file.exists()){
                    file.mkdirs();
                }
                //创建文件
                File file1 = new File(file, "photo.png");
                FileOutputStream fileOutputStream;
                try {
                    fileOutputStream = new FileOutputStream(file1);
                    bitmap.compress(Bitmap.CompressFormat.PNG,100,fileOutputStream);
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file1);
                Log.e("SettingActivity","file1"+file1);
                MultipartBody.Part file2 = MultipartBody.Part.createFormData("file", file1.getName(), requestBody);
                mPresenter.getData(file2);
            }
    
        }
    
        private void crop(Uri uri){
            Intent intent = new Intent("com.android.camera.action.CROP");
            intent.setDataAndType(uri,"image/*");
            intent.putExtra("crop",true);
            intent.putExtra("aspectX",1);
            intent.putExtra("aspectY",1);
            intent.putExtra("outputX",300);
            intent.putExtra("outputY",300);
            intent.putExtra("return-data",true);
            startActivityForResult(intent,1000);
    
        }
    }
    
  2. @Multipart
    @POST("file/upload")
    Observable<Been> uploadPhoto(@Query("uid") String uid, @Part MultipartBody.Part part);
  3. <LinearLayout
        android:background="#f00"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        >
        <ImageView
            android:id="@+id/set_iamge"
            android:layout_gravity="center_vertical"
            android:layout_width="35dp"
            android:layout_height="35dp" />
        <TextView
            android:layout_weight="1"
            android:layout_marginRight="35dp"
            android:text="个人中心"
            android:textSize="25dp"
            android:gravity="center"
            android:textColor="#fff"
            android:layout_width="0dp"
            android:layout_height="match_parent" />
    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/ll_userIcon_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="头像"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <ImageView
            android:id="@+id/iv_img_setting"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/user" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <LinearLayout
        android:id="@+id/ll_userName_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="用户名"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <TextView
            android:id="@+id/tv_userName_setting"
            android:text=""
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <LinearLayout
        android:id="@+id/ll_nickName_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="昵称"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <TextView
            android:id="@+id/tv_nickName_setting"
            android:text="善良"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <LinearLayout
        android:id="@+id/ll_gender_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="性别"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <TextView
            android:id="@+id/tv_gender_setting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <LinearLayout
        android:id="@+id/ll_userBirthday_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="出生日期"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <LinearLayout
        android:id="@+id/ll_address_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:gravity="center_vertical">
    
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:padding="10dp"
            android:text="地址管理"
            android:textColor="#000"
            android:textSize="20sp" />
    
        <ImageView
            android:layout_width="10dp"
            android:layout_height="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/rightjiantou" />
    </LinearLayout>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    
    <Button
        android:id="@+id/btn_cancel_setting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="30dp"
        android:background="#f00"
        android:gravity="center"
        android:text="注销登录"
        android:textColor="#fff"
        android:textSize="20dp" />
    
  4.  <TextView
            android:id="@+id/tv_camera_popup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#fff"
            android:gravity="center"
            android:padding="10dp"
            android:text="拍照"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="12dp"
            android:background="@android:color/darker_gray" />
    
        <TextView
            android:id="@+id/tv_pick_popup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#fff"
            android:gravity="center"
            android:padding="10dp"
            android:text="我的相册"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp" />
    
        <TextView
            android:id="@+id/tv_cancel_popup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:background="#fff"
            android:gravity="center"
            android:padding="10dp"
            android:text="取消"
            android:textColor="@color/colorPrimary"
            android:textSize="20sp" />
    </LinearLayout>
    
  5. @Override
    public Observable<Been> requestData(MultipartBody.Part data) {
        Apiserver apiserver = mRepositoryManager.obtainRetrofitService(Apiserver.class);
        Observable<Been> beenObservable = apiserver.uploadPhoto("2073", data);
        return beenObservable;
    }
  6. interface View extends IView {
       void responseMsg(Been been);
    }
    
    //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
    interface Model extends IModel {
      Observable<Been> requestData(MultipartBody.Part data);
    }
  7. 轮播
    @Override
    public void showData(UserBeen userbean) {
        List<UserBeen.DataBean.BannerBean> banner = userbean.getData().getBanner();
        ArrayList<String> img = new ArrayList<>();
        for (int i = 0; i < banner.size(); i++) {
            img.add(banner.get(i).getIcon());
        }
        fly.setImagesUrl(img);
    }
  8. implementation 'com.recker.flybanner:flybanner:1.3'
    implementation 'org.greenrobot:eventbus:3.1.1'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值