コード例 #1
0
  /** @Description: 初始化闲置物品信息 */
  private void initSecondHandInfo() {
    titleET.setText(secondHandInfo.getTitle());
    typeSp.setText(secondHandInfo.getType());
    priceET.setText(secondHandInfo.getPrice());
    describeET.setText(secondHandInfo.getDescribe());
    picFileList = secondHandInfo.getPicFileList();
    if (null == picFileList || 1 > picFileList.size()) {

    } else {
      for (BmobFile bmobFile : picFileList) {
        if (null != bmobFile) {
          ImageItem item = new ImageItem();
          item.setIsLocalPic(false);
          item.setFileName(bmobFile.getFilename());
          item.setImagePath(bmobFile.getFileUrl(AddSecondHandActivity.this));
          picList.add(item);
        }
      }
      editGridAdapter.notifyDataSetChanged();
    }
    if (secondHandInfo.getBargain()) {
      bargainSp.setText("可议价");
    } else {
      bargainSp.setText("不可议价");
    }
    qqET.setText(secondHandInfo.getQq());
    phoneET.setText(secondHandInfo.getPhone());
  }
コード例 #2
0
 /** @Description: 删除图片 */
 private void deletePic(int position) {
   ImageItem item = picList.get(position);
   if (item.getIsLocalPic()) {
     picList.remove(position);
   } else {
     picFileList.remove(position);
     picList.remove(position);
   }
 }
コード例 #3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
      // 访问相册
      if (requestCode == CommonConstant.REQUESTCODE_PHOTO_ALBUM) {
        String fileName = null;
        if (data != null) {
          // 得到图片的全路径
          Uri uri = data.getData();
          ContentResolver cr = getContentResolver();
          Cursor cursor = cr.query(uri, null, null, null, null);
          if (cursor.moveToFirst()) {
            do {
              fileName = cursor.getString(cursor.getColumnIndex("_data"));
            } while (cursor.moveToNext());
          }
          tempFile = new File(fileName);
          if (tempFile.exists() && tempFile.length() > 0) {
            ImageItem albumPic = new ImageItem();
            albumPic.setIsLocalPic(true);
            albumPic.setImagePath(fileName);
            picList.add(albumPic);
            editGridAdapter.notifyDataSetChanged();
          }
        }
      }
      // 访问相机
      if (requestCode == CommonConstant.REQUESTCODE_PHOTO_CAMERA) {
        if (FileUtils.hasSdcard()) {
          Bitmap bitmap = ImageUtils.scale(BitmapFactory.decodeFile(imagePath), 0.7F, 0.7F);
          if (null == imagePath || "".equals(imagePath)) {

          } else {
            tempFile = new File(imagePath);
            if (tempFile.exists() && tempFile.length() > 0) {
              // 判断照片是否被旋转,如果旋转则旋转回0°
              int degree = ImageUtils.getBitmapDegree(imagePath);
              if (degree != 0) {
                bitmap = ImageUtils.rotateBitmapByDegree(bitmap, degree);
              }
              ImageUtils.toFile(bitmap, tempFile);
              ImageItem takePhoto = new ImageItem();
              takePhoto.setIsLocalPic(true);
              takePhoto.setImagePath(imagePath);
              picList.add(takePhoto);
              editGridAdapter.notifyDataSetChanged();
            } else {
            }
          }

        } else {
          ToastUtils.showToast("未找到存储卡,无法存储照片!");
        }
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }
コード例 #4
0
  /** @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) {}
              });
    }
  }