Exemplo n.º 1
0
  private void reqEvaluate() {
    commitLoading.loading();
    titleBarRight.setEnabled(false);
    ArrayList<File> fileList = new ArrayList<File>();

    if (imgList.size() > 0) {
      File file;
      for (ImgPicker img : imgList) {
        if (img.thumb.equals(BLANK.path)) {
          continue;
        }
        file = new File(img.thumb);
        if (file.exists() && file.isFile()) {
          fileList.add(file);
        }
      }
    }

    Map<String, String> param = new HashMap<String, String>();
    try {
      param.put("uId", SecurityUtils.encode2Str(Global.getUserId()));
      param.put("cId", SecurityUtils.encode2Str(Global.getCId()));
      param.put("id", SecurityUtils.encode2Str(id));
      param.put("level", SecurityUtils.encode2Str(level));
      param.put("content", SecurityUtils.encode2Str(editText.getText().toString().trim()));

      Map<String, List<File>> fileMap = new HashMap<String, List<File>>(1);
      if (fileList.size() > 0) {
        param.put("flag", SecurityUtils.encode2Str(Constants.HAVA_IMAGE_FLAG));
        fileMap.put("file", fileList);
        ConnectService.instance()
            .connectServiceUploadFile(
                this,
                param,
                fileMap,
                this,
                BaseResponse.class,
                URLUtil.MY_TICKET_EVALUATE,
                Constants.ENCRYPT_SIMPLE);
      } else {
        param.put("flag", SecurityUtils.encode2Str(Constants.NO_IMAGE_FLAG));
        ConnectService.instance()
            .connectServiceReturnResponse(
                this,
                param,
                this,
                BaseResponse.class,
                URLUtil.MY_TICKET_EVALUATE,
                Constants.ENCRYPT_SIMPLE);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
 /**
  * <根据URL下载图片,并保存到本地> <功能详细描述>
  *
  * @param imageURL
  * @param context
  * @return
  * @see [类、类#方法、类#成员]
  */
 public static Bitmap loadImageFromUrl(String imageURL, File file, Context context) {
   Bitmap bitmap = null;
   try {
     URL url = new URL(imageURL);
     HttpURLConnection con = (HttpURLConnection) url.openConnection();
     con.setDoInput(true);
     con.connect();
     if (con.getResponseCode() == 200) {
       InputStream inputStream = con.getInputStream();
       FileUtil.deleteDirectory(FileSystemManager.getUserHeadPath(context, Global.getUserId()));
       ByteArrayOutputStream OutputStream = new ByteArrayOutputStream();
       FileOutputStream out = new FileOutputStream(file.getPath());
       byte buf[] = new byte[1024 * 20];
       int len = 0;
       while ((len = inputStream.read(buf)) != -1) {
         OutputStream.write(buf, 0, len);
       }
       OutputStream.flush();
       OutputStream.close();
       inputStream.close();
       out.write(OutputStream.toByteArray());
       out.close();
       BitmapFactory.Options imageOptions = new BitmapFactory.Options();
       imageOptions.inPreferredConfig = Bitmap.Config.RGB_565;
       imageOptions.inPurgeable = true;
       imageOptions.inInputShareable = true;
       bitmap = BitmapFactory.decodeFile(file.getPath(), imageOptions);
     }
   } catch (MalformedURLException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return bitmap;
 }