|
|
@@ -1,232 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.ui.account;
|
|
|
-
|
|
|
-import android.Manifest;
|
|
|
-import android.app.ProgressDialog;
|
|
|
-import android.content.DialogInterface;
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.EditText;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.android.volley.Response.ErrorListener;
|
|
|
-import com.android.volley.VolleyError;
|
|
|
-import com.common.LogUtil;
|
|
|
-import com.common.data.StringUtil;
|
|
|
-import com.common.hmac.Md5Util;
|
|
|
-import com.common.preferences.PreferenceUtils;
|
|
|
-import com.common.system.PermissionUtil;
|
|
|
-import com.common.system.SystemUtil;
|
|
|
-import com.common.ui.ProgressDialogUtil;
|
|
|
-import com.core.app.MyApplication;
|
|
|
-import com.core.base.BaseActivity;
|
|
|
-import com.core.model.LoginRegisterResult;
|
|
|
-import com.core.net.volley.ObjectResult;
|
|
|
-import com.core.net.volley.Result;
|
|
|
-import com.core.net.volley.StringJsonObjectRequest;
|
|
|
-import com.core.utils.CommonUtil;
|
|
|
-import com.core.utils.ToastUtil;
|
|
|
-import com.core.utils.helper.AvatarHelper;
|
|
|
-import com.core.utils.helper.LoginHelper;
|
|
|
-import com.xzjmyk.pm.activity.R;
|
|
|
-import com.core.net.http.ViewUtil;
|
|
|
-import com.core.utils.IntentUtils;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-
|
|
|
-import de.hdodenhof.circleimageview.CircleImageView;
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * 登陆界面
|
|
|
- *
|
|
|
- * @author Arison
|
|
|
- * @version 1.0
|
|
|
- */
|
|
|
-public class LoginActivity extends BaseActivity implements View.OnClickListener {
|
|
|
-
|
|
|
- private String PASS_WORDS = "PASS_WORDS";
|
|
|
- private CircleImageView mHeader;
|
|
|
- private EditText mPhoneNumberEdit;
|
|
|
- private EditText mPasswordEdit;
|
|
|
-
|
|
|
- private TextView tv_register;
|
|
|
- private TextView tv_findPwd;
|
|
|
- private String[] permissions = {Manifest.permission.READ_PHONE_STATE};
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_login);
|
|
|
- getSupportActionBar().hide();
|
|
|
- initView();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onNewIntent(Intent intent) {
|
|
|
- super.onNewIntent(intent);
|
|
|
- if (!StringUtil.isEmpty(MyApplication.getInstance().mLoginUser.getUserId())) {
|
|
|
- AvatarHelper.getInstance().display(MyApplication.getInstance().mLoginUser.getUserId(), mHeader, true, true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
- if (PermissionUtil.lacksPermissions(this, permissions)) {
|
|
|
- PermissionUtil.requestPermission(this, PermissionUtil.DEFAULT_REQUEST, permissions);
|
|
|
- }
|
|
|
- if (!MyApplication.getInstance().getBdLocationHelper().isLocationUpdate()) {
|
|
|
- MyApplication.getInstance().getBdLocationHelper().requestLocation();
|
|
|
- }
|
|
|
- if (ViewUtil.mdProcessDialog!=null){
|
|
|
- ViewUtil.mdProcessDialog.cancel();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
- if (requestCode == PermissionUtil.DEFAULT_REQUEST) {
|
|
|
- if (grantResults.length != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
|
|
- LogUtil.i("没有获取到权限");
|
|
|
- } else {
|
|
|
- LogUtil.i("已经用户赋予权限获取到权限");
|
|
|
- }
|
|
|
- }
|
|
|
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- mPhoneNumberEdit = (EditText) findViewById(R.id.phone_numer_edit);
|
|
|
- mPasswordEdit = (EditText) findViewById(R.id.password_edit);
|
|
|
- mHeader = (CircleImageView) findViewById(R.id.iv_head);
|
|
|
- tv_findPwd = (TextView) findViewById(R.id.tv_findPwd);
|
|
|
- tv_register = (TextView) findViewById(R.id.tv_register);
|
|
|
- if (CommonUtil.getSharedPreferences(this, "user_phone") != null && CommonUtil.getSharedPreferences(this, "user_phone").length() > 0) {
|
|
|
- mPhoneNumberEdit.setText(CommonUtil.getSharedPreferences(this, "user_phone"));
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- if (PreferenceUtils.getString(this, PASS_WORDS) != null && PreferenceUtils.getString(this, PASS_WORDS).length() > 0) {
|
|
|
- mPasswordEdit.setText(PreferenceUtils.getString(this, PASS_WORDS));
|
|
|
-
|
|
|
- }
|
|
|
- //登陆账号
|
|
|
- findViewById(R.id.login_btn).setOnClickListener(this);
|
|
|
- tv_findPwd.setOnClickListener(this);
|
|
|
- tv_register.setOnClickListener(this);
|
|
|
- if (!StringUtil.isEmpty(MyApplication.getInstance().mLoginUser.getUserId())) {
|
|
|
- AvatarHelper.getInstance().display(MyApplication.getInstance().mLoginUser.getUserId(), mHeader, true, true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- switch (v.getId()) {
|
|
|
- case R.id.login_btn:
|
|
|
- login();
|
|
|
- break;
|
|
|
- case R.id.tv_register:
|
|
|
- startActivity(new Intent(mContext,RegisterSelectActivity.class));
|
|
|
- break;
|
|
|
- case R.id.tv_findPwd:
|
|
|
- IntentUtils.webLinks(mContext,
|
|
|
- "https://account.ubtob.com/user/pwd?appId=home&returnURL=http%3A%2F%2Fwww.ubtob.com%2F",
|
|
|
- getString(R.string.login_getpwd));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void login() {
|
|
|
- final String phoneNumber = mPhoneNumberEdit.getText().toString().trim();
|
|
|
- final String password = mPasswordEdit.getText().toString().trim();
|
|
|
- PreferenceUtils.putString(this, PASS_WORDS, password);
|
|
|
- if (TextUtils.isEmpty(phoneNumber)) {
|
|
|
- ToastMessage(getString(R.string.login_account_empty));
|
|
|
- return;
|
|
|
- }
|
|
|
- if (TextUtils.isEmpty(password)) {
|
|
|
- ToastMessage(getString(R.string.login_pwd_empty));
|
|
|
- return;
|
|
|
- }
|
|
|
- // 加密之后的密码
|
|
|
- final String digestPwd = new String(Md5Util.toMD5(password));
|
|
|
- final String requestTag = "login";
|
|
|
- final ProgressDialog dialog = ProgressDialogUtil.init(mContext, null, getString(R.string.please_wait), true);
|
|
|
- dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
|
- @Override
|
|
|
- public void onCancel(DialogInterface dialog) {
|
|
|
- cancelAll(requestTag);
|
|
|
- }
|
|
|
- });
|
|
|
- dialog.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.progress_color));
|
|
|
- ProgressDialogUtil.show(dialog);
|
|
|
-
|
|
|
- HashMap<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("telephone", Md5Util.toMD5(phoneNumber));// 账号登陆的时候需要MD5加密,服务器需求
|
|
|
-// params.put("loginNo", phoneNumber);// 账号登陆的时候需要MD5加密,服务器需求
|
|
|
- params.put("password", digestPwd);
|
|
|
- // 附加信息
|
|
|
- params.put("model", SystemUtil.getModel());
|
|
|
- params.put("osVersion", SystemUtil.getOsVersion());
|
|
|
- params.put("serial", SystemUtil.getDeviceId(MyApplication.getInstance()));
|
|
|
- // 地址信息
|
|
|
- double latitude = MyApplication.getInstance().getBdLocationHelper().getLatitude();
|
|
|
- double longitude = MyApplication.getInstance().getBdLocationHelper().getLongitude();
|
|
|
- if (latitude != 0)
|
|
|
- params.put("latitude", String.valueOf(latitude));
|
|
|
- if (longitude != 0)
|
|
|
- params.put("longitude", String.valueOf(longitude));
|
|
|
- final StringJsonObjectRequest<LoginRegisterResult> request = new StringJsonObjectRequest<LoginRegisterResult>(mConfig.USER_LOGIN,
|
|
|
- new ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- ProgressDialogUtil.dismiss(dialog);
|
|
|
- ToastUtil.showErrorNet(mContext);
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<LoginRegisterResult>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<LoginRegisterResult> result) {
|
|
|
- if (result == null) {
|
|
|
- ProgressDialogUtil.dismiss(dialog);
|
|
|
- ToastUtil.showErrorData(mContext);
|
|
|
- return;
|
|
|
- }
|
|
|
- boolean success = false;
|
|
|
- if (result.getResultCode() == Result.CODE_SUCCESS) {
|
|
|
- success = LoginHelper.setLoginUser(mContext, phoneNumber, digestPwd, result);// 设置登陆用户信息
|
|
|
- }
|
|
|
- if (success) {
|
|
|
- login_manage(phoneNumber, password);
|
|
|
- } else {
|
|
|
- String message = TextUtils.isEmpty(result.getResultMsg()) ? getString(R.string.login_failed) : result.getResultMsg();
|
|
|
- ToastUtil.showToast(mContext, message);
|
|
|
- }
|
|
|
- ProgressDialogUtil.dismiss(dialog);
|
|
|
- }
|
|
|
- }, LoginRegisterResult.class, params);
|
|
|
- request.setTag(requestTag);
|
|
|
- addDefaultRequest(request);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void login_manage(String phone, String password) {
|
|
|
- if (TextUtils.isEmpty(phone)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (TextUtils.isEmpty(password)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (mContext == null) {
|
|
|
- mContext = this;
|
|
|
- return;
|
|
|
- }
|
|
|
- ViewUtil.LoginTask(phone, password, mContext);
|
|
|
- }
|
|
|
-
|
|
|
-}
|