Exemplo n.º 1
0
  /**
   * 默认先上传本地图片,之后才显示出来 sendImageMessage @Title: sendImageMessage
   *
   * @param @param localPath
   * @return void
   * @throws
   */
  private void sendImageMessage(final String local) {
    if (layout_more.getVisibility() == View.VISIBLE) {
      layout_more.setVisibility(View.GONE);
      layout_add.setVisibility(View.GONE);
      layout_emo.setVisibility(View.GONE);
    }
    BmobProFile.getInstance(this)
        .getLocalThumbnail(
            local,
            1,
            new LocalThumbnailListener() {
              @Override
              public void onSuccess(String s) {
                sentImage(s);
              }

              @Override
              public void onError(int i, String s) {
                sentImage(local);
              }
            });
  }
Exemplo n.º 2
0
  /**
   * 上传用户头像
   *
   * @param filePath
   */
  private void uploadFile(String filePath) {

    showProgressDialog();
    BTPFileResponse response =
        BmobProFile.getInstance(this)
            .upload(
                filePath,
                new UploadListener() {

                  @Override
                  public void onSuccess(String fileName, String url, BmobFile bmobFile) {
                    dismissProgressDialog();
                    String URL =
                        BmobProFile.getInstance(MineInfoEditActivity.this)
                            .signURL(fileName, url, BmobConfig.BMOB_ACCESS_KEY, 0, null);
                    bmobFile.setUrl(URL);
                    curUser.setPicUser(bmobFile);
                    refreshUserIcon();
                    ToastUtils.showToast("文件已上传成功:" + fileName);
                    Log.d(TAG, "filename: " + fileName + " url: " + url);
                  }

                  @Override
                  public void onProgress(int ratio) {
                    // TODO Auto-generated method stub
                    Log.d(TAG, "MainActivity -onProgress :" + ratio);
                  }

                  @Override
                  public void onError(int statuscode, String errormsg) {
                    // TODO Auto-generated method stub
                    dismissProgressDialog();
                    ToastUtils.showToast("上传出错:" + errormsg);
                  }
                });
  }
  /** @Description: 发布 */
  private void send() {
    dialog.show();
    secondHandInfo.setTitle(title);
    secondHandInfo.setType(type);
    secondHandInfo.setPrice(price);
    secondHandInfo.setDescribe(describe);
    if ("可议价".equals(bargain)) {
      secondHandInfo.setBargain(true);
    } else if ("不可议价".equals(bargain)) {
      secondHandInfo.setBargain(false);
    }
    secondHandInfo.setQq(qq);
    secondHandInfo.setPhone(phone);
    secondHandInfo.setUsername(GlobalParams.userInfo.getUsername()); // 发布人信息
    secondHandInfo.setUser(GlobalParams.userInfo);
    // 要上传的图片文件路径
    List<String> filePathList = new ArrayList<String>();
    for (ImageItem item : picList) {
      if ("".equals(item.getImagePath()) || null == item.getImagePath() || !item.getIsLocalPic()) {

      } else {
        filePathList.add(item.getImagePath());
      }
    }
    // List转换成数组
    String[] filePaths = (String[]) filePathList.toArray(new String[0]);
    if (null == filePaths || 1 > filePaths.length) {
      secondHandInfo.setPicFileList(picFileList);
      if (isNew) {
        secondHandInfo.save(
            this,
            new SaveListener() {

              @Override
              public void onSuccess() { // 新增发布成功
                LogcatUtils.i("新增闲置物品成功");
                dialog.dismiss();
                setResult(CommonConstant.RESULTCODE_ADD_SECOND_HAND_OK);
                finish();
              }

              @Override
              public void onFailure(int code, String message) { // 发布失败
                LogcatUtils.e("新增闲置物品失败:" + code + " " + message);
                dialog.dismiss();
                switch (code) {
                  case 9010:
                    { // 网络超时
                      ToastUtils.showToast("网络超时,请检查您的手机网络~");
                      break;
                    }
                  case 9016:
                    { // 无网络连接,请检查您的手机网络
                      ToastUtils.showToast("无网络连接,请检查您的手机网络~");
                      break;
                    }
                  default:
                    {
                      ToastUtils.showToast("新增闲置物品失败,请重试~");
                      break;
                    }
                }
              }
            });
      } else {
        secondHandInfo.update(
            this,
            new UpdateListener() {

              @Override
              public void onSuccess() { // 修改发布成功
                LogcatUtils.i("修改闲置物品成功");
                dialog.dismiss();
                setResult(CommonConstant.RESULTCODE_MODIFY_SECOND_HAND_OK);
                finish();
              }

              @Override
              public void onFailure(int code, String message) { // 发布失败
                LogcatUtils.e("修改闲置物品失败:" + code + " " + message);
                dialog.dismiss();
                switch (code) {
                  case 9010:
                    { // 网络超时
                      ToastUtils.showToast("网络超时,请检查您的手机网络~");
                      break;
                    }
                  case 9016:
                    { // 无网络连接,请检查您的手机网络
                      ToastUtils.showToast("无网络连接,请检查您的手机网络~");
                      break;
                    }
                  default:
                    {
                      ToastUtils.showToast("修改失物信息失败,请重试~");
                      break;
                    }
                }
              }
            });
      }
    } else {
      // 批量上传
      BmobProFile.getInstance(this)
          .uploadBatch(
              filePaths,
              new UploadBatchListener() {

                @Override
                public void onError(int code, String message) {
                  LogcatUtils.e("批量上传图片失败:" + code + " " + message);
                  dialog.dismiss();
                  switch (code) {
                    case 9010:
                      { // 网络超时
                        ToastUtils.showToast("网络超时,请检查您的手机网络~");
                        break;
                      }
                    case 9016:
                      { // 无网络连接,请检查您的手机网络
                        ToastUtils.showToast("无网络连接,请检查您的手机网络~");
                        break;
                      }
                    default:
                      {
                        ToastUtils.showToast("批量上传图片失败,请重试~");
                        break;
                      }
                  }
                }

                @Override
                public void onSuccess(
                    boolean isFinish, String[] fileNames, String[] urls, BmobFile[] files) {
                  if (isFinish) {
                    LogcatUtils.i("批量上传图片成功");
                    for (int i = 0; i < files.length; i++) {
                      picFileList.add(files[i]);
                    }
                    secondHandInfo.setPicFileList(picFileList);
                    if (isNew) {
                      secondHandInfo.save(
                          AddSecondHandActivity.this,
                          new SaveListener() {

                            @Override
                            public void onSuccess() { // 新增发布成功
                              LogcatUtils.i("新增闲置物品成功");
                              dialog.dismiss();
                              setResult(CommonConstant.RESULTCODE_ADD_SECOND_HAND_OK);
                              finish();
                            }

                            @Override
                            public void onFailure(int code, String message) { // 发布失败
                              LogcatUtils.e("新增闲置物品失败:" + code + " " + message);
                              dialog.dismiss();
                              switch (code) {
                                case 9010:
                                  { // 网络超时
                                    ToastUtils.showToast("网络超时,请检查您的手机网络~");
                                    break;
                                  }
                                case 9016:
                                  { // 无网络连接,请检查您的手机网络
                                    ToastUtils.showToast("无网络连接,请检查您的手机网络~");
                                    break;
                                  }
                                default:
                                  {
                                    ToastUtils.showToast("新增失物信息失败,请重试~");
                                    break;
                                  }
                              }
                            }
                          });
                    } else {
                      secondHandInfo.update(
                          AddSecondHandActivity.this,
                          new UpdateListener() {

                            @Override
                            public void onSuccess() { // 修改发布成功
                              LogcatUtils.i("修改闲置物品成功");
                              dialog.dismiss();
                              setResult(CommonConstant.RESULTCODE_MODIFY_SECOND_HAND_OK);
                              finish();
                            }

                            @Override
                            public void onFailure(int code, String message) { // 发布失败
                              LogcatUtils.e("修改闲置物品失败:" + code + " " + message);
                              dialog.dismiss();
                              switch (code) {
                                case 9010:
                                  { // 网络超时
                                    ToastUtils.showToast("网络超时,请检查您的手机网络~");
                                    break;
                                  }
                                case 9016:
                                  { // 无网络连接,请检查您的手机网络
                                    ToastUtils.showToast("无网络连接,请检查您的手机网络~");
                                    break;
                                  }
                                default:
                                  {
                                    ToastUtils.showToast("修改失物信息失败,请重试~");
                                    break;
                                  }
                              }
                            }
                          });
                    }
                  }
                }

                @Override
                public void onProgress(int curIndex, int curPercent, int total, int totalPercent) {}
              });
    }
  }