示例#1
0
  /**
   * 下载数据
   *
   * @param mDialogFragment
   */
  public void downRss(final AbDialogFragment mDialogFragment) {
    // 一个url地址
    String urlString = "http://www.amsoft.cn/rss.php";
    httpUtil.get(
        urlString,
        new AbStringHttpResponseListener() {

          @Override
          public void onSuccess(int statusCode, String content) {

            mDialogFragment.loadFinish();
            AbDialogUtil.showAlertDialog(
                DialogActivity.this,
                R.drawable.ic_alert,
                "返回结果",
                content,
                new AbDialogOnClickListener() {

                  @Override
                  public void onPositiveClick() {
                    AbToastUtil.showToast(DialogActivity.this, "点击了确认");
                  }

                  @Override
                  public void onNegativeClick() {
                    AbToastUtil.showToast(DialogActivity.this, "点击了取消");
                  }
                });
          }

          @Override
          public void onStart() {}

          @Override
          public void onFinish() {}

          @Override
          public void onFailure(int statusCode, String content, Throwable error) {
            mDialogFragment.loadStop();

            // 模拟用,真是开发中需要直接调用run内的内容
            new Handler()
                .postDelayed(
                    new Runnable() {

                      @Override
                      public void run() {
                        // 显示重试的框
                        showRefreshDialog();
                      }
                    },
                    3000);

            // 错误提示
            AbToastUtil.showToast(DialogActivity.this, content);
          }
        });
  }
示例#2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setAbContentView(R.layout.dialog_main);

    AbTitleBar mAbTitleBar = this.getTitleBar();
    mAbTitleBar.setTitleText(R.string.dialog_name);
    mAbTitleBar.setLogo(R.drawable.button_selector_back);
    mAbTitleBar.setTitleBarBackground(R.drawable.top_bg);
    mAbTitleBar.setTitleTextMargin(10, 0, 0, 0);
    mAbTitleBar.setLogoLine(R.drawable.line);

    application = (MyApplication) abApplication;
    httpUtil = AbHttpUtil.getInstance(this);
  }
示例#3
0
/**
 * @author wlj
 * @date 2014-4-17上午10:40:17
 */
public class LoginActivity extends AbActivity {
  private static final String TAG = "LoginActivity";

  @AbIocView(id = R.id.username_edit)
  private EditText inputUsername;

  @AbIocView(id = R.id.password_edit)
  private EditText inputPassword;

  @AbIocView(id = R.id.layoutpic2)
  private LinearLayout full_screen_layout;

  private MyApplication application;
  Context context = null;
  // 获取Http工具类
  final AbHttpUtil mAbHttpUtil = AbHttpUtil.getInstance(this);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 添加百度地图SDK
    SDKInitializer.initialize(getApplicationContext());
    // setContentView(R.layout.activity_main);

    setContentView(R.layout.layout_login);
    application = (MyApplication) this.getApplication();
    context = LoginActivity.this;
    AbTitleBar mAbTitleBar = this.getTitleBar();
    mAbTitleBar.setVisibility(View.GONE);

    String username = application.getProperty(Constants.USER_NAME);
    if (null != username && username.length() > 0) {
      inputUsername.setText(username);
    }

    Button button = (Button) findViewById(R.id.login_button);

    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            login();
          }
        });

    inputPassword.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              // 隐藏软键盘
              InputMethodManager imm =
                  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(inputPassword.getWindowToken(), 0);
              login();
              return true;
            }
            return false;
          }
        });

    OnClickListener keyboard_hide =
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            InputMethodManager imm =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
          }
        };
    full_screen_layout.setClickable(true);
    full_screen_layout.setOnClickListener(keyboard_hide);
  }

  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();
          };
        });
  }
  /** 初始化本地数据 */
  private void initialLocalConfig() {
    // 初始化imei信息
    String user_imei_id = application.getProperty("imei");
    if (user_imei_id == null || user_imei_id.equals("")) {
      // 第一次登陆逻辑处理,能获取imei就获取不能获取到换成时间戳
      TelephonyManager mTm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
      String _user_imei_id = mTm.getDeviceId();
      if (_user_imei_id == null || _user_imei_id.length() <= 2) {
        // 如果获取不到imei则获取当前时间戳
        Constants.USER_IMEI_ID = String.valueOf(new Date().getTime());
      } else {
        Constants.USER_IMEI_ID = mTm.getDeviceId();
      }
      // imei写到缓存中,以后直接用缓存的
      application.setProperty("imei", Constants.USER_IMEI_ID);
    } else {
      Constants.USER_IMEI_ID = user_imei_id;
    }
  }

  @Override
  protected void onResume() {
    super.onResume();
    JPushInterface.onResume(this);
  }

  @Override
  protected void onPause() {
    super.onPause();
    JPushInterface.onPause(this);
  }
}
示例#4
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();
          };
        });
  }
示例#5
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("正常", "结束");
          }
        });
  }
示例#6
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("正常", "结束");
          }
        });
  }