|
|
@@ -1,474 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity;
|
|
|
-
|
|
|
-import android.app.Activity;
|
|
|
-import android.content.Context;
|
|
|
-import android.graphics.Bitmap;
|
|
|
-import android.graphics.Bitmap.Config;
|
|
|
-import android.os.Build;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.os.Environment;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.StrictMode;
|
|
|
-import android.support.multidex.MultiDex;
|
|
|
-import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
-
|
|
|
-import com.android.volley.RequestQueue;
|
|
|
-import com.android.volley.toolbox.Volley;
|
|
|
-import com.baidu.mapapi.SDKInitializer;
|
|
|
-import com.common.config.BaseApplication;
|
|
|
-import com.common.preferences.PreferenceUtils;
|
|
|
-import com.common.preferences.SharedUtil;
|
|
|
-import com.core.app.AppConfig;
|
|
|
-import com.core.model.ConfigBean;
|
|
|
-import com.core.model.User;
|
|
|
-import com.core.net.NetWorkObservable;
|
|
|
-import com.core.net.location.BdLocationHelper;
|
|
|
-import com.core.net.ssl.AuthImageDownloader;
|
|
|
-import com.core.net.volley.FastVolley;
|
|
|
-import com.facebook.stetho.Stetho;
|
|
|
-import com.iflytek.cloud.SpeechConstant;
|
|
|
-import com.iflytek.cloud.SpeechUtility;
|
|
|
-import com.lidroid.xutils.HttpUtils;
|
|
|
-import com.nostra13.universalimageloader.cache.disc.impl.TotalSizeLimitedDiscCache;
|
|
|
-import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
|
|
|
-import com.nostra13.universalimageloader.cache.memory.MemoryCacheAware;
|
|
|
-import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache;
|
|
|
-import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
|
|
|
-import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
-import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
-import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
|
|
-import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
|
|
|
-import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
|
|
|
-import com.umeng.analytics.MobclickAgent;
|
|
|
-import com.umeng.socialize.PlatformConfig;
|
|
|
-import com.uuzuche.lib_zxing.activity.ZXingLibrary;
|
|
|
-import com.core.db.DatabaseManager;
|
|
|
-import com.core.db.SQLiteHelper;
|
|
|
-import com.xzjmyk.pm.activity.ui.SplashActivity;
|
|
|
-import com.core.db.DBOpenHelper;
|
|
|
-import com.xzjmyk.pm.activity.ui.me.TimeStatisticsActivity;
|
|
|
-import com.core.utils.TimeUtils;
|
|
|
-import com.xzjmyk.pm.activity.util.im.Constants;
|
|
|
-import com.core.app.MyActivityManager;
|
|
|
-
|
|
|
-import org.apache.http.cookie.Cookie;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-
|
|
|
-import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
|
|
|
-
|
|
|
-public class MyApplication extends BaseApplication {
|
|
|
-
|
|
|
- public String JSESSION_B2B;
|
|
|
-// public static Cookie cookie;
|
|
|
- public static Cookie cookieERP;
|
|
|
-
|
|
|
- public static RequestQueue mRequestQueue;
|
|
|
- public static HttpUtils mHttpUtils;
|
|
|
-
|
|
|
-
|
|
|
- private static MyApplication INSTANCE = null;
|
|
|
-
|
|
|
- public static MyApplication getInstance() {
|
|
|
- return INSTANCE;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void initConfig() throws Exception {
|
|
|
- //内存泄漏检测工具初始化
|
|
|
- /*if (AppConfig.DEBUG){
|
|
|
- if (LeakCanary.isInAnalyzerProcess(this)) {
|
|
|
- // This process is dedicated to LeakCanary for heap analysis.
|
|
|
- // You should not init your app in this process.
|
|
|
- return;
|
|
|
- }
|
|
|
- LeakCanary.install(this);
|
|
|
- }*/
|
|
|
- //Stetho调试工具初始化
|
|
|
- Stetho.initializeWithDefaults(this);
|
|
|
- SpeechUtility.createUtility(this, SpeechConstant.APPID + "=5876dc99");
|
|
|
- //自定义闪退页面初始化
|
|
|
- CustomActivityOnCrash.install(this);
|
|
|
- //设置ErrorActivity在后台启动,默认为true
|
|
|
- CustomActivityOnCrash.setLaunchErrorActivityWhenInBackground(true);
|
|
|
- //设置展示详细错误信息,默认为true
|
|
|
- CustomActivityOnCrash.setShowErrorDetails(true);
|
|
|
- //启用APP Restart,默认为true
|
|
|
- CustomActivityOnCrash.setEnableAppRestart(true);
|
|
|
- //设置重新启动的activity
|
|
|
- CustomActivityOnCrash.setRestartActivityClass(SplashActivity.class);
|
|
|
-
|
|
|
- INSTANCE = this;
|
|
|
- ZXingLibrary.initDisplayOpinion(this);
|
|
|
- mRequestQueue = Volley.newRequestQueue(this);
|
|
|
-
|
|
|
- mHttpUtils = new HttpUtils();
|
|
|
- configHttpUtils();
|
|
|
-
|
|
|
- SharedUtil.init(this);
|
|
|
- initShareAPI();
|
|
|
- // CrashReport.initCrashReport(getApplicationContext(), "900050585", false);
|
|
|
- PreferenceUtils.putBoolean(this, Constants.IS_NOTIFICATION, false);//不进行通知
|
|
|
- new Handler().postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- //定位场景设置
|
|
|
- MobclickAgent.setScenarioType(MyApplication.this, MobclickAgent.EScenarioType.E_UM_NORMAL);
|
|
|
- initUmengStatistics();
|
|
|
- SDKInitializer.initialize(getApplicationContext());
|
|
|
- // 初始化数据库
|
|
|
- SQLiteHelper.copyDatabaseFile(getApplicationContext());
|
|
|
-
|
|
|
- // 初始化定位
|
|
|
- getBdLocationHelper();
|
|
|
-
|
|
|
- // 初始化App目录
|
|
|
- initAppDir();
|
|
|
- // 初始化图片加载
|
|
|
- initImageLoader();
|
|
|
- }
|
|
|
- }, 1);
|
|
|
- if (AppConfig.DEBUG) {
|
|
|
- Log.d(AppConfig.TAG, "MyApplication onCreate");
|
|
|
- }
|
|
|
- if (AppConfig.DEBUG) {
|
|
|
- StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
|
|
|
- StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
|
|
|
- }
|
|
|
- // 初始化网络监听
|
|
|
- mNetWorkObservable = new NetWorkObservable(this);
|
|
|
- initErpDB();
|
|
|
- /* try {
|
|
|
- com.core.app.Constants.cleanRed(this);
|
|
|
- } catch (PackageManager.NameNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
|
|
- @Override
|
|
|
- public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
|
|
|
- @Override
|
|
|
- public void onActivityStarted(Activity activity) {}
|
|
|
- @Override
|
|
|
- public void onActivityResumed(Activity activity) {
|
|
|
- MyActivityManager.getInstance().setCurrentActivity(activity);
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void onActivityPaused(Activity activity) {}
|
|
|
- @Override
|
|
|
- public void onActivityStopped(Activity activity) {}
|
|
|
- @Override
|
|
|
- public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
|
|
|
- @Override
|
|
|
- public void onActivityDestroyed(Activity activity) {}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void initErpDB() {
|
|
|
- DatabaseManager.initializeInstance(DBOpenHelper.getInstance(this));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc:初始化分享组件
|
|
|
- * @author:Arison on 2016/9/29
|
|
|
- */
|
|
|
- public void initShareAPI() {
|
|
|
- PlatformConfig.setWeixin("wx2539cc96bf158e00", "b057aa3e807ba7c505a2f03cc541bbf6");
|
|
|
- PlatformConfig.setSinaWeibo("493318722", "7def652c3683603b08bab87d34b1f944");
|
|
|
- PlatformConfig.setQQZone("1104894295", "Nk8zMIz5YSqwRQ1F");
|
|
|
- }
|
|
|
-
|
|
|
- private void initUmengStatistics() {
|
|
|
- MobclickAgent.UMAnalyticsConfig config = new MobclickAgent.UMAnalyticsConfig(this, "57ea27bb67e58e088c003bbf",
|
|
|
- "baidu", MobclickAgent.EScenarioType.E_UM_NORMAL);
|
|
|
- MobclickAgent.startWithConfigure(config);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 为HttpUtils配置参数
|
|
|
- */
|
|
|
- private void configHttpUtils() {
|
|
|
- mHttpUtils.configRequestThreadPoolSize(4);
|
|
|
- mHttpUtils.configRequestRetryCount(3);
|
|
|
- mHttpUtils.configResponseTextCharset("utf-8");
|
|
|
- mHttpUtils.configTimeout(10000);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 在程序内部关闭时,调用此方法
|
|
|
- */
|
|
|
- public void destory() {
|
|
|
- if (AppConfig.DEBUG) {
|
|
|
- Log.d(AppConfig.TAG, "MyApplication destory");
|
|
|
- }
|
|
|
- // 结束百度定位
|
|
|
- if (mBdLocationHelper != null) {
|
|
|
- mBdLocationHelper.release();
|
|
|
- }
|
|
|
- // 关闭网络状态的监听
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.release();
|
|
|
- }
|
|
|
- // 清除图片加载
|
|
|
- ImageLoader.getInstance().destroy();
|
|
|
- //
|
|
|
- releaseFastVolley();
|
|
|
- // 释放数据库
|
|
|
- // SQLiteHelper.release();
|
|
|
- android.os.Process.killProcess(android.os.Process.myPid());
|
|
|
-
|
|
|
- //TODO 获取此刻精确时间并转换为yyyy-MM-dd HH:mm:ss
|
|
|
- String nowtime = TimeUtils.f_long_2_str(System.currentTimeMillis());
|
|
|
- String saved_time = PreferenceUtils.getString(MyApplication.getInstance(), TimeStatisticsActivity.Killed);
|
|
|
-
|
|
|
- if (!TextUtils.isEmpty(saved_time)) {
|
|
|
- PreferenceUtils.putString(TimeStatisticsActivity.Killed, saved_time + "," + nowtime);
|
|
|
- } else {
|
|
|
- PreferenceUtils.putString(TimeStatisticsActivity.Killed, nowtime);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*********************
|
|
|
- * 百度地图定位服务
|
|
|
- ************************/
|
|
|
- private BdLocationHelper mBdLocationHelper;
|
|
|
-
|
|
|
- public BdLocationHelper getBdLocationHelper() {
|
|
|
- if (mBdLocationHelper == null)
|
|
|
- mBdLocationHelper = new BdLocationHelper(this);
|
|
|
- mBdLocationHelper.requestLocation();
|
|
|
- return mBdLocationHelper;
|
|
|
- }
|
|
|
-
|
|
|
- /*********************
|
|
|
- * 提供网络全局监听
|
|
|
- ************************/
|
|
|
- private NetWorkObservable mNetWorkObservable;
|
|
|
-
|
|
|
- public boolean isNetworkActive() {
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- return mNetWorkObservable.isNetworkActive();
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- public void registerNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.registerObserver(observer);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void unregisterNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.unregisterObserver(observer);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* 文件缓存的目录 */
|
|
|
- public String mAppDir;
|
|
|
- public String mPicturesDir;
|
|
|
- public String mVoicesDir;
|
|
|
- public String mVideosDir;
|
|
|
- public String mFilesDir;
|
|
|
-
|
|
|
- private void initAppDir() {
|
|
|
- File file = getExternalFilesDir(null);
|
|
|
- if (file != null) {
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- mAppDir = file.getAbsolutePath();
|
|
|
- }
|
|
|
-
|
|
|
- file = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
|
|
- if (file != null) {
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- mPicturesDir = file.getAbsolutePath();
|
|
|
- }
|
|
|
-
|
|
|
- file = getExternalFilesDir(Environment.DIRECTORY_MUSIC);
|
|
|
- if (file != null) {
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- mVoicesDir = file.getAbsolutePath();
|
|
|
- }
|
|
|
- file = getExternalFilesDir(Environment.DIRECTORY_MOVIES);
|
|
|
- if (file != null) {
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- mVideosDir = file.getAbsolutePath();
|
|
|
- }
|
|
|
- file = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
|
|
- if (file != null) {
|
|
|
- if (!file.exists()) {
|
|
|
- file.mkdirs();
|
|
|
- }
|
|
|
- mFilesDir = file.getAbsolutePath();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*******************
|
|
|
- * 初始化图片加载
|
|
|
- **********************/
|
|
|
- // 显示的设置
|
|
|
- public static DisplayImageOptions mNormalImageOptions;
|
|
|
- public static DisplayImageOptions mAvatarRoundImageOptions;
|
|
|
- public static DisplayImageOptions mAvatarNormalImageOptions;
|
|
|
-
|
|
|
- private void initImageLoader() {
|
|
|
- int memoryCacheSize = (int) (Runtime.getRuntime().maxMemory() / 5);
|
|
|
- MemoryCacheAware<String, Bitmap> memoryCache;
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
|
|
- memoryCache = new LruMemoryCache(memoryCacheSize);
|
|
|
- } else {
|
|
|
- memoryCache = new LRULimitedMemoryCache(memoryCacheSize);
|
|
|
- }
|
|
|
-
|
|
|
- mNormalImageOptions = new DisplayImageOptions.Builder().bitmapConfig(Config.RGB_565).cacheInMemory(true).cacheOnDisc(true)
|
|
|
- .resetViewBeforeLoading(false).showImageForEmptyUri(com.xzjmyk.pm.activity.R.drawable.image_download_fail_icon)
|
|
|
- .showImageOnFail(com.xzjmyk.pm.activity.R.drawable.image_download_fail_icon).build();
|
|
|
-
|
|
|
- mAvatarRoundImageOptions = new DisplayImageOptions.Builder().bitmapConfig(Config.RGB_565).
|
|
|
- cacheInMemory(true).cacheOnDisc(true)
|
|
|
- .displayer(new RoundedBitmapDisplayer(10)).
|
|
|
- resetViewBeforeLoading(true).
|
|
|
- showImageForEmptyUri(com.xzjmyk.pm.activity.R.drawable.avatar_normal)
|
|
|
- .showImageOnFail(com.xzjmyk.pm.activity.R.drawable.avatar_normal).showImageOnLoading(com.xzjmyk.pm.activity.R.drawable.avatar_normal).build();
|
|
|
-
|
|
|
- mAvatarNormalImageOptions = new DisplayImageOptions.Builder().bitmapConfig(Config.RGB_565).cacheInMemory(true).cacheOnDisc(true)
|
|
|
- .resetViewBeforeLoading(true).showImageForEmptyUri(com.xzjmyk.pm.activity.R.drawable.avatar_normal).showImageOnFail(com.xzjmyk.pm.activity.R.drawable.avatar_normal)
|
|
|
- .showImageOnLoading(com.xzjmyk.pm.activity.R.drawable.avatar_normal).build();
|
|
|
-
|
|
|
- ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).defaultDisplayImageOptions(mNormalImageOptions)
|
|
|
- // .denyCacheImageMultipleSizesInMemory()
|
|
|
- .discCache(new TotalSizeLimitedDiscCache(new File(mPicturesDir), 50 * 1024 * 1024))
|
|
|
- // 最多缓存50M的图片
|
|
|
- .discCacheFileNameGenerator(new Md5FileNameGenerator())
|
|
|
- .memoryCache(memoryCache)
|
|
|
- .tasksProcessingOrder(QueueProcessingType.LIFO)
|
|
|
- .threadPriority(Thread.NORM_PRIORITY - 2)
|
|
|
- .imageDownloader(new AuthImageDownloader(this))
|
|
|
- .denyCacheImageMultipleSizesInMemory()
|
|
|
- .threadPoolSize(4)
|
|
|
- .build();
|
|
|
- // Initialize ImageLoader with configuration.
|
|
|
- ImageLoader.getInstance().init(config);
|
|
|
- }
|
|
|
-
|
|
|
- /*********************
|
|
|
- * 提供全局配置
|
|
|
- ************************/
|
|
|
- private AppConfig mConfig;
|
|
|
-
|
|
|
- public void setConfig(AppConfig config) {
|
|
|
- mConfig = config;
|
|
|
- }
|
|
|
-
|
|
|
- public AppConfig getConfig() {
|
|
|
- if (mConfig == null) {
|
|
|
- mConfig = AppConfig.initConfig(getApplicationContext(), new ConfigBean());
|
|
|
- }
|
|
|
- return mConfig;
|
|
|
- }
|
|
|
-
|
|
|
- /*****************
|
|
|
- * 提供全局的Volley
|
|
|
- ***************************/
|
|
|
-
|
|
|
- private FastVolley mFastVolley;
|
|
|
-
|
|
|
- public FastVolley getFastVolley() {
|
|
|
- if (mFastVolley == null) {
|
|
|
- synchronized (MyApplication.class) {
|
|
|
- if (mFastVolley == null) {
|
|
|
- mFastVolley = new FastVolley(this);
|
|
|
- mFastVolley.start();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return mFastVolley;
|
|
|
- }
|
|
|
-
|
|
|
- private void releaseFastVolley() {
|
|
|
- if (mFastVolley != null) {
|
|
|
- mFastVolley.stop();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void attachBaseContext(Context base) {
|
|
|
- super.attachBaseContext(base);
|
|
|
- MultiDex.install(this);
|
|
|
- }
|
|
|
-
|
|
|
- /***********************
|
|
|
- * 保存当前登陆用户的全局信息
|
|
|
- ***************/
|
|
|
- public String roomName;
|
|
|
- public String mAccessToken;
|
|
|
- public long mExpiresIn;
|
|
|
- public int mUserStatus;
|
|
|
- public boolean mUserStatusChecked = false;
|
|
|
- public User mLoginUser = new User();// 当前登陆的用户
|
|
|
-
|
|
|
- /***********************
|
|
|
- * 保存其他用户坐标信息
|
|
|
- ***************/
|
|
|
-
|
|
|
- public String getJSESSION_B2B() {
|
|
|
- return JSESSION_B2B;
|
|
|
- }
|
|
|
-
|
|
|
- public void setJSESSION_B2B(String jSESSION_B2B) {
|
|
|
- JSESSION_B2B = jSESSION_B2B;
|
|
|
- }
|
|
|
-
|
|
|
-// public static Cookie getCookie() {
|
|
|
-// return cookie;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static void setCookie(Cookie cookie) {
|
|
|
-// MyApplication.cookie = cookie;
|
|
|
-// }
|
|
|
-
|
|
|
-/* public void clearWebViewCache() {
|
|
|
- Log.i("clearWebViewCache", "clearWebViewCache");
|
|
|
- // 清理WebView缓存数据库
|
|
|
- try {
|
|
|
- deleteDatabase("webview.db");
|
|
|
- deleteDatabase("webviewCache.db");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- // WebView缓存文件
|
|
|
- File appCacheDir = new File(getFilesDir().getAbsolutePath()
|
|
|
- + SubscribeDetailActivity.APP_CACHE_DIRNAME);
|
|
|
-
|
|
|
- File webviewCacheDir = new File(getCacheDir().getAbsolutePath()
|
|
|
- + "/webviewCache");
|
|
|
-
|
|
|
- // 删除webView缓存目录
|
|
|
- if (webviewCacheDir.exists()) {
|
|
|
- com.common.file.FileUtils.deleteFileOrDir(webviewCacheDir);
|
|
|
- }
|
|
|
- // 删除webView缓存,缓存目录
|
|
|
- if (appCacheDir.exists()) {
|
|
|
- com.common.file.FileUtils.deleteFileOrDir(appCacheDir);
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
- public String getLoginUserId() {
|
|
|
- return (mLoginUser!=null&&!TextUtils.isEmpty(mLoginUser.getUserId()))?mLoginUser.getUserId():"";
|
|
|
- }
|
|
|
-}
|