|
|
@@ -3,6 +3,7 @@ package com.xzjmyk.pm.activity.ui;
|
|
|
import android.Manifest;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.text.TextUtils;
|
|
|
@@ -13,11 +14,13 @@ import android.view.animation.AnimationUtils;
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.android.volley.Response;
|
|
|
import com.android.volley.VolleyError;
|
|
|
import com.common.LogUtil;
|
|
|
import com.common.data.JSONUtil;
|
|
|
+import com.common.file.FileUtils;
|
|
|
import com.common.hmac.Md5Util;
|
|
|
import com.common.preferences.PreferenceUtils;
|
|
|
import com.common.system.SystemUtil;
|
|
|
@@ -29,6 +32,8 @@ import com.core.dao.UserDao;
|
|
|
import com.core.model.ConfigBean;
|
|
|
import com.core.model.LoginRegisterResult;
|
|
|
import com.core.model.User;
|
|
|
+import com.core.net.ProgressDownloader;
|
|
|
+import com.core.net.ProgressResponseBody;
|
|
|
import com.core.net.volley.ObjectResult;
|
|
|
import com.core.net.volley.Result;
|
|
|
import com.core.net.volley.StringJsonObjectRequest;
|
|
|
@@ -46,7 +51,10 @@ import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.activity.ADActivity;
|
|
|
import com.xzjmyk.pm.activity.ui.me.TimeStatisticsActivity;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import pl.droidsonroids.gif.AnimationListener;
|
|
|
import pl.droidsonroids.gif.GifDrawable;
|
|
|
@@ -58,7 +66,7 @@ import pl.droidsonroids.gif.GifImageView;
|
|
|
* @author Dean Tao
|
|
|
* @version 1.0
|
|
|
*/
|
|
|
-public class SplashActivity extends BaseActivity {
|
|
|
+public class SplashActivity extends BaseActivity implements ProgressResponseBody.ProgressListener {
|
|
|
private RelativeLayout mSelectLv;
|
|
|
private GifImageView mGifImageView;
|
|
|
private final String IS_FIRST = "IS_FIRST";
|
|
|
@@ -67,6 +75,9 @@ public class SplashActivity extends BaseActivity {
|
|
|
private boolean mConfigReady = false;// 配置获取成功
|
|
|
private GifDrawable mGifDrawable;
|
|
|
private boolean mAnimationCompleted = false;
|
|
|
+ private ProgressDownloader mDownloader;
|
|
|
+ private String mSplshUrl;
|
|
|
+ private long mStartTime;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -75,38 +86,135 @@ public class SplashActivity extends BaseActivity {
|
|
|
getSupportActionBar().hide();
|
|
|
StatusBarUtil.immersive(this, 0x00000000, 0.0f);
|
|
|
|
|
|
+ mStartTime = System.currentTimeMillis();
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
jump();
|
|
|
}
|
|
|
- }, 3000);
|
|
|
+ }, 2500);
|
|
|
mGifImageView = findViewById(R.id.splash_gif_view);
|
|
|
+ showSplash();
|
|
|
+ mSelectLv = (RelativeLayout) findViewById(R.id.select_lv);
|
|
|
+ mSelectLv.setVisibility(View.INVISIBLE);
|
|
|
+ initConfig();// 初始化配置
|
|
|
+ updateAccountToken();//更新账户中心token
|
|
|
+ requestSplash();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showSplash() {
|
|
|
try {
|
|
|
- mGifDrawable = new GifDrawable(getAssets(), "gif_splash_welcome.gif");
|
|
|
- mGifDrawable.setLoopCount(1);
|
|
|
- mGifDrawable.setSpeed(1f);
|
|
|
- mGifDrawable.addAnimationListener(new AnimationListener() {
|
|
|
- @Override
|
|
|
- public void onAnimationCompleted(int loopNumber) {
|
|
|
- Log.d("gifdrawable", "AnimationCompleted");
|
|
|
- mAnimationCompleted = true;
|
|
|
- if (isJumpable) {
|
|
|
- jump();
|
|
|
+ List<String> pictures = FileUtils.getPictures(Constants.SPLASH_FILE_PATH);
|
|
|
+ if (pictures != null && pictures.size() > 0) {
|
|
|
+ String localSplash = pictures.get(0);
|
|
|
+ int dotIndex = localSplash.lastIndexOf(".");
|
|
|
+ if (dotIndex >= 0) {
|
|
|
+ String resExtension = localSplash.substring(dotIndex + 1).toLowerCase();
|
|
|
+ if ("gif".equals(resExtension)) {
|
|
|
+ mGifDrawable = new GifDrawable(new File(localSplash));
|
|
|
+ } else {
|
|
|
+ Bitmap localBitmap = FileUtils.getLocalBitmap(localSplash);
|
|
|
+ mGifImageView.setImageBitmap(localBitmap);
|
|
|
+ mAnimationCompleted = true;
|
|
|
+ return;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ mGifDrawable = new GifDrawable(getAssets(), "gif_splash_welcome.gif");
|
|
|
}
|
|
|
- });
|
|
|
- mGifImageView.setImageDrawable(mGifDrawable);
|
|
|
-
|
|
|
- mGifDrawable.start();
|
|
|
+ } else {
|
|
|
+ mGifDrawable = new GifDrawable(getAssets(), "gif_splash_welcome.gif");
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
+ try {
|
|
|
+ mGifDrawable = new GifDrawable(getAssets(), "gif_splash_welcome.gif");
|
|
|
+ } catch (IOException e1) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mGifDrawable.setLoopCount(1);
|
|
|
+ mGifDrawable.setSpeed(1f);
|
|
|
+ mGifDrawable.addAnimationListener(new AnimationListener() {
|
|
|
+ @Override
|
|
|
+ public void onAnimationCompleted(int loopNumber) {
|
|
|
+ mAnimationCompleted = true;
|
|
|
+ if (isJumpable) {
|
|
|
+ jump();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mGifImageView.setImageDrawable(mGifDrawable);
|
|
|
+ mGifDrawable.start();
|
|
|
+ }
|
|
|
|
|
|
+ private void requestSplash() {
|
|
|
+ if (!CommonUtil.isNetWorkConnected(mContext)) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ HttpRequest.getInstance().sendRequest(Constants.IM_BASE_URL,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url("user/appStart")
|
|
|
+ .method(Method.GET)
|
|
|
+ .addParam("token", 1)
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ if (JSONUtil.validate(result)) {
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONArray resArray = resultObject.getJSONArray("result");
|
|
|
+ if (resArray != null && resArray.size() > 0) {
|
|
|
+ JSONObject resObject = resArray.getJSONObject(0);
|
|
|
+ String resUrl = JSONUtil.getText(resObject, "aa_urlc");
|
|
|
+ if (!TextUtils.isEmpty(resUrl)) {
|
|
|
+ String oldUrl = CommonUtil.getSharedPreferences(mContext, Constants.CACHE.CACHE_SPLASH_URL);
|
|
|
+ if (resUrl.equals(oldUrl)) {
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ initSplashDir();
|
|
|
+ mSplshUrl = resUrl;
|
|
|
+ downloadSplash(resUrl);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ initSplashDir();
|
|
|
+ CommonUtil.setSharedPreferences(mContext, Constants.CACHE.CACHE_SPLASH_URL, "");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ initSplashDir();
|
|
|
+ CommonUtil.setSharedPreferences(mContext, Constants.CACHE.CACHE_SPLASH_URL, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- mSelectLv = (RelativeLayout) findViewById(R.id.select_lv);
|
|
|
- mSelectLv.setVisibility(View.INVISIBLE);
|
|
|
- initConfig();// 初始化配置
|
|
|
- updateAccountToken();//更新账户中心token
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initSplashDir() {
|
|
|
+ File directory = new File(Constants.SPLASH_FILE_PATH);
|
|
|
+ if (!directory.exists() && !directory.isDirectory()) {
|
|
|
+ boolean mkdirs = directory.mkdirs();
|
|
|
+ } else {
|
|
|
+ CommonUtil.delAllFile(Constants.SPLASH_FILE_PATH);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void downloadSplash(String resUrl) {
|
|
|
+ int dotIndex = resUrl.lastIndexOf(".");
|
|
|
+ if (dotIndex >= 0) {
|
|
|
+ String resExtension = resUrl.substring(dotIndex);
|
|
|
+ File splashFile = new File(Constants.SPLASH_FILE_PATH, Constants.SPLASH_FILE_NAME + resExtension);
|
|
|
+ try {
|
|
|
+ splashFile.createNewFile();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ mDownloader = new ProgressDownloader(resUrl, splashFile, SplashActivity.this);
|
|
|
+ mDownloader.download(0L);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -192,6 +300,18 @@ public class SplashActivity extends BaseActivity {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ long currentTime = System.currentTimeMillis();
|
|
|
+ long duration = currentTime - mStartTime;
|
|
|
+ if (duration < 2500) {
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ jump();
|
|
|
+ }
|
|
|
+ }, 2500 - duration);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
int userStatus = LoginHelper.prepareUser(mContext);
|
|
|
switch (userStatus) {
|
|
|
case LoginHelper.STATUS_USER_FULL://5
|
|
|
@@ -340,7 +460,23 @@ public class SplashActivity extends BaseActivity {
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
- mGifDrawable.recycle();
|
|
|
- mGifDrawable = null;
|
|
|
+ if (mGifDrawable != null) {
|
|
|
+ mGifDrawable.recycle();
|
|
|
+ mGifDrawable = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPreExecute(long contentLength) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void update(long totalBytes, boolean done) {
|
|
|
+ if (done) {
|
|
|
+ if (!TextUtils.isEmpty(mSplshUrl)) {
|
|
|
+ CommonUtil.setSharedPreferences(mContext, Constants.CACHE.CACHE_SPLASH_URL, mSplshUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|