圈子发布

public class AddCircleActivity extends BaseActivity {

@BindView(R.id.bo_text)
EditText boText;
@BindView(R.id.bo_image_list)
SimpleDraweeView image;
//    CirCleAdapter cirCleAdapter;
Bitmap bitmap;
@BindView(R.id.back)
ImageView back;
private int commodityId = 1;
private FabuQuanziBean fabuQuanziBean1;
private HashMap<String, String> hashMap;
private Persion persion;

@Override
protected void bindEvent() {

}

@Override
protected void initData() {

}

@Override
protected void initView() {
    ButterKnife.bind(this);
    persion = new Persion(this);

// cirCleAdapter = new CirCleAdapter();
// cirCleAdapter.setSign(1);
// cirCleAdapter.add(R.drawable.ic_launcher_background);
// boImageList.setLayoutManager(new GridLayoutManager(this,3));
// boImageList.setAdapter(cirCleAdapter);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String shuru = boText.getText().toString();
File file = BitMap.compressImage(bitmap);
RequestBody requestBody = RequestBody.create(MediaType.parse(“image/*”), file.getAbsoluteFile());
MultipartBody.Part image_part = MultipartBody.Part.createFormData(“image”, file.getName(), requestBody);

    hashMap = new HashMap<>();

    hashMap.put("commodityId", "" +commodityId);
    hashMap.put("content", "" + shuru);

// persion.getfabu(hashMap,file);
Observable getfabu = MyUtil.getutil().api.getfabu(hashMap, image_part);
getfabu.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer() {
@Override
public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(FabuQuanziBean fabuQuanziBean) {
                    fabuQuanziBean1 = fabuQuanziBean;
                    ToastData(fabuQuanziBean.getMessage()+"");
                }
            });
}
});

}

@Override
protected int bindLayout() {
    return R.layout.activity_add_circle;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // TODO: add setContentView(...) invocation
    ButterKnife.bind(this);
}

@OnClick(R.id.bo_image_list)
public void onViewClicked() {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("image/*");
    startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    //获取图片
    Uri data1 = data.getData();
    try {
        bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    image.setImageBitmap(bitmap);
}

public void getShow(FabuQuanziBean fabuQuanziBean) {
    String status = fabuQuanziBean.getStatus();
    if (status.equals("0000")){

        ToastData(fabuQuanziBean.getMessage());
    }
}

}

---------------------------BitMap---------------
public class BitMap {
//用来转换类型的 将Bitmap类型转换为Uri类型
public static File compressImage(Bitmap bitmap) {
ByteArrayOutputStream baos= new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
    int options = 100;
    while (baos.toByteArray().length / 1024 > 500) {  //循环判断如果压缩后图片是否大于500kb,大于继续压缩
        baos.reset();//重置baos即清空baos
        options -= 10;//每次都减少10
        bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
    }
    //以当前时间命名
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    Date date = new Date(System.currentTimeMillis());
    //图片名
    String filename = format.format(date);
    //存储到外存空间
    File file = new File(Environment.getExternalStorageDirectory(), filename + ".jpg");
    try {
        FileOutputStream fos = new FileOutputStream(file);
        try {
            fos.write(baos.toByteArray());
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return file;
}

}

----------------------------------Api
@Multipart
@POST(“circle/verify/v1/releaseCircle”)
Observable getfabu(@QueryMap HashMap<String, String> params, @Part MultipartBody.Part image);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值