getWindow().setBackgroundDrawableResource(R.drawable.splash_image);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
// 判断是否是logout注销,退出
boolean isLogout = app.userPreferenceHandler.getBoolean(Setting.sp_is_logout, true);
if (isLogout) {
// 登录页面
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
gotoLoginActivity();
}
}, wait_time);
} else {
phone = app.userPreferenceHandler.getString(Setting.sp_user_phone, null);
password = app.userPreferenceHandler.getString(Setting.sp_user_password, null);
if (TextUtils.isEmpty(phone) || TextUtils.isEmpty(password)) {
// 登录页面 delay延时
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
gotoLoginActivity();
}
}, wait_time);
} else {
// 自动登录
startTime = System.currentTimeMillis();
new LoginAsynctask(this, LOGIN, false).execute(phone, password);
}
}
}
private void gotoMainActivity() {
if (!isBack) {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra(Setting.intent_push_click, getIntent().getIntExtra(Setting.intent_push_click, 0));
startActivity(intent);
finish();
}
}
private void gotoLoginActivity() {
if (!isBack) {
Intent intent = new Intent(SplashActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}
}
@Override //对于Activity 可以单独获取Back键的按下事件
public void onBackPressed() {
super.onBackPressed();
isBack = true;
}
@Override //statusBar状态栏
public int statusBarColor() {
return Color.TRANSPARENT;
}
@Override //请求成功
public void requestSuccess(int id, String data) {
if (id == LOGIN) {
UserInfo info = ResultJsonHandler.getUserInfo(data);
info.setPhone(phone);
app.login(info, password);
long time = System.currentTimeMillis() - startTime;
if (time >= wait_time) {
gotoMainActivity();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
gotoMainActivity();
}
}, wait_time - time);
}
}
}
@Override //请求失败
public void requestFail(int id, int errorCode, String errorMsg) {
if (id == LOGIN) {
ToastUtil.show(this, errorMsg);
long time = System.currentTimeMillis() - startTime;
if (time >= wait_time) {
gotoLoginActivity();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
gotoLoginActivity();
}
}, wait_time - time);
}
}
}
@Override //请求中断
public void requestBreak(int id) {
}
@Override //联网失败
public void networkError(int id) {
if (id == LOGIN) {
ToastUtil.show(this, R.string.network_error_hint);
long time = System.currentTimeMillis() - startTime;
if (time >= wait_time) {
gotoLoginActivity();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
gotoLoginActivity();
}
}, wait_time - time);
}
}
}
}