|
|
@@ -4,7 +4,7 @@ import android.annotation.SuppressLint;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
-import android.util.Log;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.view.animation.Animation;
|
|
|
import android.view.animation.AnimationUtils;
|
|
|
@@ -15,138 +15,239 @@ import com.android.volley.Response;
|
|
|
import com.android.volley.VolleyError;
|
|
|
import com.xzjmyk.pm.activity.AppConfig;
|
|
|
import com.xzjmyk.pm.activity.MyApplication;
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.bean.ConfigBean;
|
|
|
+import com.xzjmyk.pm.activity.bean.LoginRegisterResult;
|
|
|
+import com.xzjmyk.pm.activity.bean.User;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.UserDao;
|
|
|
import com.xzjmyk.pm.activity.helper.LoginHelper;
|
|
|
+import com.xzjmyk.pm.activity.sp.UserSp;
|
|
|
import com.xzjmyk.pm.activity.ui.account.LoginActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.account.RegisterActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
-import com.xzjmyk.pm.activity.volley.Result;
|
|
|
-import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.DeviceInfoUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.Md5Util;
|
|
|
+import com.xzjmyk.pm.activity.util.ToastUtil;
|
|
|
import com.xzjmyk.pm.activity.volley.ObjectResult;
|
|
|
+import com.xzjmyk.pm.activity.volley.Result;
|
|
|
import com.xzjmyk.pm.activity.volley.StringJsonObjectRequest;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
/**
|
|
|
* 启动页
|
|
|
- *
|
|
|
+ *
|
|
|
* @author Dean Tao
|
|
|
* @version 1.0
|
|
|
*/
|
|
|
public class SplashActivity extends BaseActivity {
|
|
|
- private RelativeLayout mSelectLv;
|
|
|
- private Button mSelectLoginBtn;
|
|
|
- private Button mSelectRegBtn;
|
|
|
-
|
|
|
- private long mStartTimeMs;// 记录进入该界面时间,保证至少在该界面停留3秒
|
|
|
- private boolean mConfigReady = false;// 配置获取成功
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_splash);
|
|
|
-
|
|
|
- mStartTimeMs = System.currentTimeMillis();
|
|
|
-
|
|
|
- mSelectLv = (RelativeLayout) findViewById(R.id.select_lv);
|
|
|
- mSelectLoginBtn = (Button) findViewById(R.id.select_login_btn);
|
|
|
- mSelectRegBtn = (Button) findViewById(R.id.select_register_btn);
|
|
|
-
|
|
|
- mSelectLoginBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- startActivity(new Intent(mContext, LoginActivity.class));
|
|
|
- }
|
|
|
- });
|
|
|
- mSelectRegBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- startActivity(new Intent(mContext, RegisterActivity.class));
|
|
|
- }
|
|
|
- });
|
|
|
- mSelectLv.setVisibility(View.INVISIBLE);
|
|
|
-
|
|
|
- initConfig();// 初始化配置
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 配置参数初始化
|
|
|
- */
|
|
|
- private void initConfig() {
|
|
|
- if (!MyApplication.getInstance().isNetworkActive()) {// 没有网络的情况下
|
|
|
- setConfig(new ConfigBean());
|
|
|
- return;
|
|
|
- }
|
|
|
- StringJsonObjectRequest<ConfigBean> request = new StringJsonObjectRequest<ConfigBean>(AppConfig.CONFIG_URL, new Response.ErrorListener() {
|
|
|
- @Override
|
|
|
- public void onErrorResponse(VolleyError arg0) {
|
|
|
- setConfig(new ConfigBean());// 读取网络配置失败,使用默认配置
|
|
|
- }
|
|
|
- }, new StringJsonObjectRequest.Listener<ConfigBean>() {
|
|
|
- @Override
|
|
|
- public void onResponse(ObjectResult<ConfigBean> result) {
|
|
|
- ConfigBean configBean = null;
|
|
|
- if (result == null || result.getResultCode() != Result.CODE_SUCCESS || result.getData() == null) {
|
|
|
- configBean = new ConfigBean();// 读取网络配置失败,使用默认配置
|
|
|
- } else {
|
|
|
- configBean = result.getData();
|
|
|
- }
|
|
|
- setConfig(configBean);
|
|
|
- }
|
|
|
- }, ConfigBean.class, null);
|
|
|
- addShortRequest(request);
|
|
|
- }
|
|
|
-
|
|
|
- private void setConfig(ConfigBean configBean) {
|
|
|
- MyApplication.getInstance().setConfig(AppConfig.initConfig(this, configBean));// 初始化配置
|
|
|
- mConfigReady = true;
|
|
|
- ready();
|
|
|
- }
|
|
|
-
|
|
|
- private void ready() {
|
|
|
- if (!mConfigReady) {
|
|
|
- return;
|
|
|
- }
|
|
|
- long currentTimeMs = System.currentTimeMillis();
|
|
|
- int useTime = (int) (currentTimeMs - mStartTimeMs);
|
|
|
- int delayTime = useTime > 2000 ? 0 : 2000 - useTime;
|
|
|
- new Handler().postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- jump();
|
|
|
- }
|
|
|
- }, delayTime);
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint("NewApi")
|
|
|
- private void jump() {
|
|
|
- if (isDestroyed()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- int userStatus = LoginHelper.prepareUser(mContext);
|
|
|
- Log.i("Arison", "jump() called with: " + "userStatus:"+userStatus);
|
|
|
- Intent intent = new Intent();
|
|
|
- switch (userStatus) {
|
|
|
- case LoginHelper.STATUS_USER_FULL://5
|
|
|
- case LoginHelper.STATUS_USER_NO_UPDATE://3
|
|
|
- case LoginHelper.STATUS_USER_TOKEN_OVERDUE://2
|
|
|
- //状态,进入主mainactivity
|
|
|
- intent.setClass(mContext, MainActivity.class);
|
|
|
- break;
|
|
|
- case LoginHelper.STATUS_USER_SIMPLE_TELPHONE:
|
|
|
- intent.setClass(mContext, LoginActivity.class);
|
|
|
- break;
|
|
|
- case LoginHelper.STATUS_NO_USER://0
|
|
|
- default:
|
|
|
- stay();
|
|
|
- return;// must return
|
|
|
- }
|
|
|
- startActivity(intent);
|
|
|
- finish();
|
|
|
- }
|
|
|
-
|
|
|
- // 停留在此界面
|
|
|
- private void stay() {
|
|
|
- mSelectLv.setVisibility(View.VISIBLE);
|
|
|
- Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha_in);
|
|
|
- mSelectLv.startAnimation(anim);
|
|
|
- }
|
|
|
+ private RelativeLayout mSelectLv;
|
|
|
+ private Button mSelectLoginBtn;
|
|
|
+ private Button mSelectRegBtn;
|
|
|
+
|
|
|
+ private long mStartTimeMs;// 记录进入该界面时间,保证至少在该界面停留3秒
|
|
|
+ private boolean mConfigReady = false;// 配置获取成功
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_splash);
|
|
|
+
|
|
|
+ mStartTimeMs = System.currentTimeMillis();
|
|
|
+
|
|
|
+ mSelectLv = (RelativeLayout) findViewById(R.id.select_lv);
|
|
|
+ mSelectLoginBtn = (Button) findViewById(R.id.select_login_btn);
|
|
|
+ mSelectRegBtn = (Button) findViewById(R.id.select_register_btn);
|
|
|
+
|
|
|
+ mSelectLoginBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ startActivity(new Intent(mContext, LoginActivity.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mSelectRegBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ startActivity(new Intent(mContext, RegisterActivity.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mSelectLv.setVisibility(View.INVISIBLE);
|
|
|
+
|
|
|
+ initConfig();// 初始化配置
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 配置参数初始化
|
|
|
+ */
|
|
|
+ private void initConfig() {
|
|
|
+ if (!MyApplication.getInstance().isNetworkActive()) {// 没有网络的情况下
|
|
|
+ setConfig(new ConfigBean());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringJsonObjectRequest<ConfigBean> request = new StringJsonObjectRequest<ConfigBean>(AppConfig.CONFIG_URL, new Response.ErrorListener() {
|
|
|
+ @Override
|
|
|
+ public void onErrorResponse(VolleyError arg0) {
|
|
|
+ setConfig(new ConfigBean());// 读取网络配置失败,使用默认配置
|
|
|
+ }
|
|
|
+ }, new StringJsonObjectRequest.Listener<ConfigBean>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(ObjectResult<ConfigBean> result) {
|
|
|
+ ConfigBean configBean = null;
|
|
|
+ if (result == null || result.getResultCode() != Result.CODE_SUCCESS || result.getData() == null) {
|
|
|
+ configBean = new ConfigBean();// 读取网络配置失败,使用默认配置
|
|
|
+ } else {
|
|
|
+ configBean = result.getData();
|
|
|
+ }
|
|
|
+ setConfig(configBean);
|
|
|
+ }
|
|
|
+ }, ConfigBean.class, null);
|
|
|
+ addShortRequest(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setConfig(ConfigBean configBean) {
|
|
|
+ MyApplication.getInstance().setConfig(AppConfig.initConfig(this, configBean));// 初始化配置
|
|
|
+ mConfigReady = true;
|
|
|
+ ready();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ready() {
|
|
|
+ if (!mConfigReady) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long currentTimeMs = System.currentTimeMillis();
|
|
|
+ int useTime = (int) (currentTimeMs - mStartTimeMs);
|
|
|
+ int delayTime = useTime > 2000 ? 0 : 2000 - useTime;
|
|
|
+
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ jump2();
|
|
|
+ }
|
|
|
+ }, delayTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("NewApi")
|
|
|
+ private void jump() {
|
|
|
+ if (isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int userStatus = LoginHelper.prepareUser(mContext);
|
|
|
+ Intent intent = new Intent();
|
|
|
+ switch (userStatus) {
|
|
|
+ case LoginHelper.STATUS_USER_FULL://5
|
|
|
+ case LoginHelper.STATUS_USER_NO_UPDATE://3
|
|
|
+ intent.setClass(mContext, MainActivity.class);
|
|
|
+ break;
|
|
|
+ case LoginHelper.STATUS_USER_TOKEN_OVERDUE://2
|
|
|
+ case LoginHelper.STATUS_USER_SIMPLE_TELPHONE:
|
|
|
+ intent.setClass(mContext, LoginActivity.class);
|
|
|
+ break;
|
|
|
+ case LoginHelper.STATUS_NO_USER://0
|
|
|
+ default:
|
|
|
+ stay();
|
|
|
+ return;// must return
|
|
|
+ }
|
|
|
+ startActivity(intent);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void jump2() {
|
|
|
+ boolean idIsEmpty = TextUtils.isEmpty(UserSp.getInstance(this).getUserId(""));
|
|
|
+ boolean telephoneIsEmpty = TextUtils.isEmpty(UserSp.getInstance(this).getTelephone(null));
|
|
|
+
|
|
|
+ if (!idIsEmpty && !telephoneIsEmpty) {// 用户标识都不为空,那么就能代表一个完整的用户
|
|
|
+ // 进入之前,加载本地已经存在的数据
|
|
|
+ String userId = UserSp.getInstance(this).getUserId("");
|
|
|
+ User user = UserDao.getInstance().getUserByUserId(userId);
|
|
|
+ if (!LoginHelper.isUserValidation(user)) {// 用户数据错误,那么就认为是一个游客
|
|
|
+ jump();
|
|
|
+ } else {
|
|
|
+ MyApplication.getInstance().mLoginUser = user;
|
|
|
+ MyApplication.getInstance().mAccessToken = UserSp.getInstance(this).getAccessToken(null);
|
|
|
+ MyApplication.getInstance().mExpiresIn = UserSp.getInstance(this).getExpiresIn(0);
|
|
|
+ login(user.getTelephone(), user.getPassword());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ jump();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //登陆
|
|
|
+ private void login(final String phoneNumber, final String password) {
|
|
|
+ if (TextUtils.isEmpty(phoneNumber)) {
|
|
|
+ jump();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(password)) {
|
|
|
+ jump();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 加密之后的密码
|
|
|
+ final String requestTag = "login";
|
|
|
+ HashMap<String, String> params = new HashMap<String, String>();
|
|
|
+ params.put("telephone", Md5Util.toMD5(phoneNumber));// 账号登陆的时候需要MD5加密,服务器需求
|
|
|
+ params.put("password", password);
|
|
|
+ // 附加信息
|
|
|
+ params.put("model", DeviceInfoUtil.getModel());
|
|
|
+ params.put("osVersion", DeviceInfoUtil.getOsVersion());
|
|
|
+ params.put("serial", DeviceInfoUtil.getDeviceId(mContext));
|
|
|
+ // 地址信息
|
|
|
+ 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 Response.ErrorListener() {
|
|
|
+ @Override
|
|
|
+ public void onErrorResponse(VolleyError arg0) {
|
|
|
+ ToastUtil.showErrorNet(mContext);
|
|
|
+ }
|
|
|
+ }, new StringJsonObjectRequest.Listener<LoginRegisterResult>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(ObjectResult<LoginRegisterResult> result) {
|
|
|
+ if (result == null) {
|
|
|
+ ToastUtil.showErrorData(mContext);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean success = false;
|
|
|
+ if (result.getResultCode() == Result.CODE_SUCCESS) {
|
|
|
+ success = LoginHelper.setLoginUser(mContext, phoneNumber, password, result);// 设置登陆用户信息
|
|
|
+ }
|
|
|
+ if (success) {// 登陆IM成功
|
|
|
+ startActivity(new Intent(SplashActivity.this, MainActivity.class));
|
|
|
+ } else {// 登录失败
|
|
|
+ String message = TextUtils.isEmpty(result.getResultMsg()) ? getString(R.string.login_failed) : result.getResultMsg();
|
|
|
+ ToastUtil.showToast(mContext, message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 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;
|
|
|
+ }
|
|
|
+ ViewUtil.LoginTask(phone, password, mContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 停留在此界面
|
|
|
+ private void stay() {
|
|
|
+ mSelectLv.setVisibility(View.VISIBLE);
|
|
|
+ Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha_in);
|
|
|
+ mSelectLv.startAnimation(anim);
|
|
|
+ }
|
|
|
}
|