Example #1
0
  private void goToSelectPicture(int position) {
    switch (position) {
      case ACTION_TYPE_ALBUM:
        Intent intent;
        if (Build.VERSION.SDK_INT < 19) {
          intent = new Intent();
          intent.setAction(Intent.ACTION_GET_CONTENT);
          intent.setType("image/*");
          startActivityForResult(
              Intent.createChooser(intent, "选择图片"), ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
        } else {
          intent = new Intent(Intent.ACTION_PICK, Images.Media.EXTERNAL_CONTENT_URI);
          intent.setType("image/*");
          startActivityForResult(
              Intent.createChooser(intent, "选择图片"), ImageUtils.REQUEST_CODE_GETIMAGE_BYSDCARD);
        }
        break;
      case ACTION_TYPE_PHOTO:
        // 判断是否挂载了SD卡
        String savePath = "";
        String storageState = Environment.getExternalStorageState();
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {
          savePath =
              Environment.getExternalStorageDirectory().getAbsolutePath() + "/oschina/Camera/";
          File savedir = new File(savePath);
          if (!savedir.exists()) {
            savedir.mkdirs();
          }
        }

        // 没有挂载SD卡,无法保存文件
        if (StringUtils.isEmpty(savePath)) {
          AppContext.showToastShort("无法保存照片,请检查SD卡是否挂载");
          return;
        }

        String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String fileName = "osc_" + timeStamp + ".jpg"; // 照片命名
        File out = new File(savePath, fileName);
        Uri uri = Uri.fromFile(out);

        theLarge = savePath + fileName; // 该照片的绝对路径

        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA);
        break;
      default:
        break;
    }
  }
Example #2
0
  private void handleSubmit() {
    String content = mEtInput.getText().toString();
    if (StringUtils.isEmpty(content) || mTeam == null) return;
    OSChinaTeamApi.pubTeamNewActive(
        mTeam.getId(),
        content,
        imgFile,
        new AsyncHttpResponseHandler() {

          @Override
          public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            Result result = XmlUtils.toBean(ResultBean.class, arg2).getResult();
            if (result != null && result.OK()) {
              AppContext.showToast(result.getErrorMessage());
              finish();
            } else {
              AppContext.showToast(result.getErrorMessage());
            }
          }

          @Override
          public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            AppContext.showToast("发表失败,请检查下你的网络");
          }

          @Override
          public void onStart() {
            super.onStart();
            showWaitDialog("提交中...");
          }

          @Override
          public void onFinish() {
            super.onFinish();
            hideWaitDialog();
          }
        });
  }