예제 #1
0
  /**
   * 使用andbase框架 头像上传的方法 @2015-11-20 * 上传用户头像图片uploadUserImg // @param id 用户id // @param file 文件
   * // @param fileName 文件名字
   */
  public static void UpLoad_Portrait(final Context context, Uri uri) {
    AbHttpUtil mAbHttpUtil = AbHttpUtil.getInstance(context);
    String url = DataInit.httpHead + "uploadUserImg" + ".action";
    AbRequestParams params = new AbRequestParams();
    File file1 = null;
    try {
      // 多文件上传添加多个即可
      file1 = new File(ImageTool.getPath(context, uri));
      if (!file1.exists()) {
        throw new Exception("图片路径错误");
      }
      if (file1.getTotalSpace() > 4 * 1024 * 1024) {
        Point point = ImageTool.getScreenSize(context);
        Bitmap bitmap = ImageTool.readUri(uri, context, point.y, point.y, true);
        String ImagesDir =
            BaseDataManager.getMyBaseDataManager(context).getDataInit().getSD_Directory();
        Log.i("正常", "图片过大,转换中的路径ImagesDir=" + ImagesDir);
        String fileName = file1.getName();
        ImageTool.saveFile(bitmap, fileName, ImagesDir);
        file1 = new File(ImagesDir, fileName);
      }
      params.put("fileName", file1.getName());
      params.put("file", file1);
      params.put("id", BaseDataManager.getMyBOSSInfo(context).getId());
    } catch (Exception e) {
      Log.e("异常201511201059", e.toString());
      return;
    }
    mAbHttpUtil.post(
        url,
        params,
        new AbStringHttpResponseListener() {
          @Override
          public void onSuccess(int statusCode, String content) {
            try {
              JSONObject jsonObject = new JSONObject(content);
              Toast.makeText(context, Reader.analysis("message", jsonObject), Toast.LENGTH_SHORT)
                  .show();
            } catch (Exception e) {
              Log.e("异常201511201311", e.toString());
            }
          }

          // 开始执行前
          @Override
          public void onStart() {
            Log.i("正常", "onStart");
          }

          @Override
          public void onFailure(int statusCode, String content, Throwable error) {
            Toast.makeText(context, error.getMessage(), Toast.LENGTH_SHORT).show();
          }

          // 进度
          @Override
          public void onProgress(int bytesWritten, int totalSize) {}

          // 完成后调用,失败,成功,都要调用
          public void onFinish() {
            Log.i("正常", "结束");
          }
        });
  }
예제 #2
0
  private void login() {
    final String username = inputUsername.getText().toString();
    String password = inputPassword.getText().toString();
    if (username == null || password == null || username.equals("") || password.equals("")) {
      Toast.makeText(LoginActivity.this, "用户名、密码不能为空!", Toast.LENGTH_SHORT).show();
      return;
    }
    String jpush_registration_id = "";
    // 从缓存里读jpushid
    jpush_registration_id = application.getProperty("registrationID");
    // 如果缓存中不存在,则设为空值
    if (null == jpush_registration_id) {
      initialLocalConfig();
      JPushInterface.init(getApplicationContext());
      jpush_registration_id = JPushInterface.getRegistrationID(context);
      application.setProperty("registrationID", jpush_registration_id);
    }
    // 绑定参数
    AbRequestParams params = new AbRequestParams();
    params.put("user_name", username);
    params.put("password", password);
    params.put("jpush_registration_id", jpush_registration_id);
    //		params.put("user_imei_id", application.getProperty("imei"));

    if (!application.isNetworkConnected()) {
      UIHelper.ToastMessage(LoginActivity.this, "请检查网络连接");
      return;
    }
    String a = URLs.LOGINURL;
    System.out.println(a);

    mAbHttpUtil.post(
        URLs.LOGINURL,
        params,
        new AbStringHttpResponseListener() {

          // 获取数据成功会调用这里
          @Override
          public void onSuccess(int statusCode, String content) {
            System.out.println(content);
            Log.d(TAG, "onSuccess");
            JSONObject jsonObject = null;
            try {
              jsonObject = new JSONObject(content);
              int code = Integer.parseInt(jsonObject.getString("code").toString());
              if (code == Constants.SUCCESS) {
                JSONObject info = jsonObject.getJSONObject("info");
                String id = info.getString("id");
                String name = info.getString("name");
                application.setProperty("loginKey", id);
                application.setProperty(Constants.USER_NAME, username);
                application.setProperty("userName", name);
                // 跳转到首页

                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                LoginActivity.this.startActivity(intent);
                LoginActivity.this.finish();

              } else {
                Toast.makeText(LoginActivity.this, "用户名或密码错误!", Toast.LENGTH_SHORT).show();
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          };

          // 开始执行前
          @Override
          public void onStart() {
            Log.d(TAG, "onStart");
            // 显示进度框
            showProgressDialog();
          }

          // 失败,调用
          @Override
          public void onFailure(int statusCode, String content, Throwable error) {
            showToast("连接超时!");
          }

          // 完成后调用,失败,成功
          @Override
          public void onFinish() {
            Log.d(TAG, "onFinish");
            // 移除进度框
            removeProgressDialog();
          };
        });
  }
예제 #3
0
  /** 使用andbase框架 聊天图片上传的方法 @2015-11-16 */
  public static void UpLoadImage_Chat(
      final Context context,
      Uri uri,
      String QuestionId,
      String userId,
      String toUserId,
      String petId,
      final Trancaction trancaction) {
    AbHttpUtil mAbHttpUtil = AbHttpUtil.getInstance(context);
    String url = DataInit.httpHead + "chatLogImgSave" + ".action";
    AbRequestParams params = new AbRequestParams();
    File file1 = null;
    try {
      // 多文件上传添加多个即可
      file1 = new File(ImageTool.getPath(context, uri));
      if (!file1.exists()) {
        throw new Exception("图片路径错误");
      }
      if (file1.getTotalSpace() > 4 * 1024 * 1024) {
        Point point = ImageTool.getScreenSize(context);
        Bitmap bitmap = ImageTool.readUri(uri, context, point.y, point.y, true);
        String ImagesDir =
            BaseDataManager.getMyBaseDataManager(context).getDataInit().getSD_Directory();
        Log.i("正常", "图片过大,转换中的路径ImagesDir=" + ImagesDir);
        String fileName = file1.getName();
        ImageTool.saveFile(bitmap, fileName, ImagesDir);
        file1 = new File(ImagesDir, fileName);
      }
      params.put("fileName", file1.getName());
      params.put("file", file1);
      params.put("id", QuestionId);
      params.put("userId", userId);
      params.put("toUserId", toUserId);
      params.put("petId", petId);
    } catch (Exception e) {
      Log.e("异常201511161459", e.toString());
      return;
    }
    mAbHttpUtil.post(
        url,
        params,
        new AbStringHttpResponseListener() {
          @Override
          public void onSuccess(int statusCode, String content) {
            Log.i("正常", "onSuccess=" + statusCode);
            try {
              if (statusCode == 200) {
                trancaction.onResponse(new JSONObject(content));
              } else {
                trancaction.onErrorResponse(new VolleyError());
              }
            } catch (Exception e) {
              Log.e("异常201512021617", e.toString());
            }
          }

          // 开始执行前
          @Override
          public void onStart() {
            Log.i("正常", "onStart");
          }

          @Override
          public void onFailure(int statusCode, String content, Throwable error) {
            Toast.makeText(context, error.getMessage(), Toast.LENGTH_SHORT).show();
          }

          // 进度
          @Override
          public void onProgress(int bytesWritten, int totalSize) {}

          // 完成后调用,失败,成功,都要调用
          public void onFinish() {
            Log.i("正常", "结束");
          }
        });
  }