|
|
@@ -44,6 +44,8 @@ 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.tencent.mm.opensdk.openapi.IWXAPI;
|
|
|
+import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
import com.umeng.analytics.MobclickAgent;
|
|
|
import com.umeng.socialize.Config;
|
|
|
import com.umeng.socialize.PlatformConfig;
|
|
|
@@ -60,376 +62,381 @@ import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
|
|
|
*/
|
|
|
public class MyApplication extends BaseApplication {
|
|
|
|
|
|
- private static MyApplication INSTANCE = null;
|
|
|
- /*********************
|
|
|
- * 提供全局配置
|
|
|
- ************************/
|
|
|
- private AppConfig mConfig;
|
|
|
- /*****************
|
|
|
- * 提供全局的Volley
|
|
|
- ***************************/
|
|
|
-
|
|
|
- private FastVolley mFastVolley;
|
|
|
- public static Cookie cookieERP;
|
|
|
- public static RequestQueue mRequestQueue;
|
|
|
- public static HttpUtils mHttpUtils;
|
|
|
-
|
|
|
- /* 文件缓存的目录 */
|
|
|
- public String mAppDir;
|
|
|
- public String mPicturesDir;
|
|
|
- public String mVoicesDir;
|
|
|
- public String mVideosDir;
|
|
|
- public String mFilesDir;
|
|
|
- /***********************
|
|
|
- * 保存当前登陆用户的全局信息
|
|
|
- ***************/
|
|
|
- public String roomName;
|
|
|
- public String mAccessToken;
|
|
|
- public long mExpiresIn;
|
|
|
- public int mUserStatus;
|
|
|
- public boolean mUserStatusChecked = false;
|
|
|
- public User mLoginUser = new User();// 当前登陆的用户
|
|
|
-
|
|
|
- /*******************
|
|
|
- * 初始化图片加载
|
|
|
- **********************/
|
|
|
- // 显示的设置
|
|
|
- public static DisplayImageOptions mNormalImageOptions;
|
|
|
- public static DisplayImageOptions mAvatarRoundImageOptions;
|
|
|
- public static DisplayImageOptions mAvatarNormalImageOptions;
|
|
|
-
|
|
|
- /*********************
|
|
|
- * 提供网络全局监听
|
|
|
- ************************/
|
|
|
- private NetWorkObservable mNetWorkObservable;
|
|
|
- /*********************
|
|
|
- * 百度地图定位服务
|
|
|
- ************************/
|
|
|
- private BdLocationHelper mBdLocationHelper;
|
|
|
-
|
|
|
- public BdLocationHelper getBdLocationHelper() {
|
|
|
- if (mBdLocationHelper == null)
|
|
|
- mBdLocationHelper = new BdLocationHelper(this);
|
|
|
- mBdLocationHelper.requestLocation();
|
|
|
- return mBdLocationHelper;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void initConfig() throws Exception {
|
|
|
- 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);
|
|
|
- Config.REDIRECT_URL = "http://sns.whalecloud.com/sina2/callback";
|
|
|
- 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);
|
|
|
+ private static MyApplication INSTANCE = null;
|
|
|
+ /*********************
|
|
|
+ * 提供全局配置
|
|
|
+ ************************/
|
|
|
+ private AppConfig mConfig;
|
|
|
+ /*****************
|
|
|
+ * 提供全局的Volley
|
|
|
+ ***************************/
|
|
|
+
|
|
|
+ private FastVolley mFastVolley;
|
|
|
+ public static Cookie cookieERP;
|
|
|
+ public static RequestQueue mRequestQueue;
|
|
|
+ public static HttpUtils mHttpUtils;
|
|
|
+
|
|
|
+ /* 文件缓存的目录 */
|
|
|
+ public String mAppDir;
|
|
|
+ public String mPicturesDir;
|
|
|
+ public String mVoicesDir;
|
|
|
+ public String mVideosDir;
|
|
|
+ public String mFilesDir;
|
|
|
+ /***********************
|
|
|
+ * 保存当前登陆用户的全局信息
|
|
|
+ ***************/
|
|
|
+ public String roomName;
|
|
|
+ public String mAccessToken;
|
|
|
+ public long mExpiresIn;
|
|
|
+ public int mUserStatus;
|
|
|
+ public boolean mUserStatusChecked = false;
|
|
|
+ public User mLoginUser = new User();// 当前登陆的用户
|
|
|
+
|
|
|
+ /*******************
|
|
|
+ * 初始化图片加载
|
|
|
+ **********************/
|
|
|
+ // 显示的设置
|
|
|
+ public static DisplayImageOptions mNormalImageOptions;
|
|
|
+ public static DisplayImageOptions mAvatarRoundImageOptions;
|
|
|
+ public static DisplayImageOptions mAvatarNormalImageOptions;
|
|
|
+
|
|
|
+ /*********************
|
|
|
+ * 提供网络全局监听
|
|
|
+ ************************/
|
|
|
+ private NetWorkObservable mNetWorkObservable;
|
|
|
+ /*********************
|
|
|
+ * 百度地图定位服务
|
|
|
+ ************************/
|
|
|
+ private BdLocationHelper mBdLocationHelper;
|
|
|
+
|
|
|
+ public BdLocationHelper getBdLocationHelper() {
|
|
|
+ if (mBdLocationHelper == null)
|
|
|
+ mBdLocationHelper = new BdLocationHelper(this);
|
|
|
+ mBdLocationHelper.requestLocation();
|
|
|
+ return mBdLocationHelper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initConfig() throws Exception {
|
|
|
+ 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);
|
|
|
+ Config.REDIRECT_URL = "http://sns.whalecloud.com/sina2/callback";
|
|
|
+ INSTANCE = this;
|
|
|
+ ZXingLibrary.initDisplayOpinion(this);
|
|
|
+ mRequestQueue = Volley.newRequestQueue(this);
|
|
|
+
|
|
|
+ mHttpUtils = new HttpUtils();
|
|
|
+ configHttpUtils();
|
|
|
+
|
|
|
+ SharedUtil.init(this);
|
|
|
+ initShareAPI();
|
|
|
+
|
|
|
+ initWxPay(this);
|
|
|
+ // 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) {
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void destory() {
|
|
|
- if (AppConfig.DEBUG) {
|
|
|
- Log.d(AppConfig.TAG, "MyApplication destory");
|
|
|
- }
|
|
|
- // 结束百度定位
|
|
|
- if (mBdLocationHelper != null) {
|
|
|
- mBdLocationHelper.release();
|
|
|
- }
|
|
|
- // 关闭网络状态的监听
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.release();
|
|
|
- }
|
|
|
- // 清除图片加载
|
|
|
+ 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) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
- android.os.Process.killProcess(android.os.Process.myPid());
|
|
|
- }
|
|
|
-
|
|
|
- private void initErpDB() {
|
|
|
- DatabaseManager.initializeInstance(DBOpenHelper.getInstance(this));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void initShareAPI() {
|
|
|
- PlatformConfig.setWeixin("wx2539cc96bf158e00", "b057aa3e807ba7c505a2f03cc541bbf6");
|
|
|
- PlatformConfig.setSinaWeibo("493318722", "7def652c3683603b08bab87d34b1f944");
|
|
|
- PlatformConfig.setQQZone("1104894295", "Nk8zMIz5YSqwRQ1F");
|
|
|
- Config.IsToastTip = false;
|
|
|
- }
|
|
|
-
|
|
|
- private void initUmengStatistics() {
|
|
|
- MobclickAgent.UMAnalyticsConfig config = new MobclickAgent.UMAnalyticsConfig(this, "57ea27bb67e58e088c003bbf",
|
|
|
- "baidu", MobclickAgent.EScenarioType.E_UM_NORMAL);
|
|
|
- MobclickAgent.startWithConfigure(config);
|
|
|
- if (!CommonUtil.isReleaseVersion()) {//当前为开发版本时候不需要上传友盟
|
|
|
- MobclickAgent.setCatchUncaughtExceptions(false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private void configHttpUtils() {
|
|
|
- mHttpUtils.configRequestThreadPoolSize(4);
|
|
|
- mHttpUtils.configRequestRetryCount(3);
|
|
|
- mHttpUtils.configResponseTextCharset("utf-8");
|
|
|
- mHttpUtils.configTimeout(10000);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isNetworkActive() {
|
|
|
+ releaseFastVolley();
|
|
|
+ android.os.Process.killProcess(android.os.Process.myPid());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initErpDB() {
|
|
|
+ DatabaseManager.initializeInstance(DBOpenHelper.getInstance(this));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void initShareAPI() {
|
|
|
+ PlatformConfig.setWeixin("wx2539cc96bf158e00", "b057aa3e807ba7c505a2f03cc541bbf6");
|
|
|
+ PlatformConfig.setSinaWeibo("493318722", "7def652c3683603b08bab87d34b1f944");
|
|
|
+ PlatformConfig.setQQZone("1104894295", "Nk8zMIz5YSqwRQ1F");
|
|
|
+ Config.IsToastTip = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initUmengStatistics() {
|
|
|
+ MobclickAgent.UMAnalyticsConfig config = new MobclickAgent.UMAnalyticsConfig(this, "57ea27bb67e58e088c003bbf",
|
|
|
+ "baidu", MobclickAgent.EScenarioType.E_UM_NORMAL);
|
|
|
+ MobclickAgent.startWithConfigure(config);
|
|
|
+ if (!CommonUtil.isReleaseVersion()) {//当前为开发版本时候不需要上传友盟
|
|
|
+ MobclickAgent.setCatchUncaughtExceptions(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void configHttpUtils() {
|
|
|
+ mHttpUtils.configRequestThreadPoolSize(4);
|
|
|
+ mHttpUtils.configRequestRetryCount(3);
|
|
|
+ mHttpUtils.configResponseTextCharset("utf-8");
|
|
|
+ mHttpUtils.configTimeout(10000);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isNetworkActive() {
|
|
|
// if (mNetWorkObservable != null) {
|
|
|
// return mNetWorkObservable.isNetworkActive();
|
|
|
// }else{
|
|
|
// return true;
|
|
|
// }
|
|
|
- return NetUtils.isNetWorkConnected(BaseConfig.getContext());
|
|
|
- }
|
|
|
-
|
|
|
- public void registerNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.registerObserver(observer);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void unregisterNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
- if (mNetWorkObservable != null) {
|
|
|
- mNetWorkObservable.unregisterObserver(observer);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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(Bitmap.Config.RGB_565)
|
|
|
- .cacheInMemory(true).cacheOnDisc(true)
|
|
|
- .displayer(new RoundedBitmapDisplayer(10))
|
|
|
- .resetViewBeforeLoading(false)
|
|
|
- .showImageForEmptyUri(R.drawable.image_download_fail_icon)
|
|
|
- .showImageOnFail(R.drawable.image_download_fail_icon)
|
|
|
- .build();
|
|
|
-
|
|
|
- mAvatarRoundImageOptions = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).
|
|
|
- cacheInMemory(true).cacheOnDisc(true)
|
|
|
- .displayer(new RoundedBitmapDisplayer(10))
|
|
|
- .resetViewBeforeLoading(true)
|
|
|
- .showImageForEmptyUri(R.drawable.avatar_normal)
|
|
|
- .showImageOnFail(R.drawable.avatar_normal)
|
|
|
- .showImageOnLoading(R.drawable.avatar_normal)
|
|
|
- .build();
|
|
|
-
|
|
|
- mAvatarNormalImageOptions = new DisplayImageOptions.Builder()
|
|
|
- .bitmapConfig(Bitmap.Config.RGB_565)
|
|
|
- .cacheInMemory(true)
|
|
|
- .cacheOnDisc(true)
|
|
|
- .resetViewBeforeLoading(true)
|
|
|
- .showImageForEmptyUri(R.drawable.avatar_normal)
|
|
|
- .showImageOnFail(R.drawable.avatar_normal)
|
|
|
- .showImageOnLoading(R.drawable.avatar_normal).build();
|
|
|
-
|
|
|
- if (mPicturesDir!=null) {
|
|
|
- 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();
|
|
|
- ImageLoader.getInstance().init(config);
|
|
|
- }else{
|
|
|
- //getCacheDir()
|
|
|
- ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
|
|
|
- .defaultDisplayImageOptions(mNormalImageOptions)
|
|
|
- // .denyCacheImageMultipleSizesInMemory()
|
|
|
- .discCache(new TotalSizeLimitedDiscCache(getCacheDir(), 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();
|
|
|
- ImageLoader.getInstance().init(config);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void setConfig(AppConfig config) {
|
|
|
- mConfig = config;
|
|
|
- }
|
|
|
-
|
|
|
- public AppConfig getConfig() {
|
|
|
- if (mConfig == null) {
|
|
|
- mConfig = AppConfig.initConfig(getApplicationContext(), new ConfigBean());
|
|
|
- }
|
|
|
- return mConfig;
|
|
|
- }
|
|
|
-
|
|
|
- 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 getLoginUserId() {
|
|
|
- return (mLoginUser != null && !TextUtils.isEmpty(mLoginUser.getUserId())) ? mLoginUser.getUserId() : "";
|
|
|
- }
|
|
|
-
|
|
|
- public static MyApplication getInstance() {
|
|
|
- return INSTANCE;
|
|
|
- }
|
|
|
+ return NetUtils.isNetWorkConnected(BaseConfig.getContext());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void registerNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
+ if (mNetWorkObservable != null) {
|
|
|
+ mNetWorkObservable.registerObserver(observer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void unregisterNetWorkObserver(NetWorkObservable.NetWorkObserver observer) {
|
|
|
+ if (mNetWorkObservable != null) {
|
|
|
+ mNetWorkObservable.unregisterObserver(observer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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(Bitmap.Config.RGB_565)
|
|
|
+ .cacheInMemory(true).cacheOnDisc(true)
|
|
|
+ .displayer(new RoundedBitmapDisplayer(10))
|
|
|
+ .resetViewBeforeLoading(false)
|
|
|
+ .showImageForEmptyUri(R.drawable.image_download_fail_icon)
|
|
|
+ .showImageOnFail(R.drawable.image_download_fail_icon)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ mAvatarRoundImageOptions = new DisplayImageOptions.Builder().bitmapConfig(Bitmap.Config.RGB_565).
|
|
|
+ cacheInMemory(true).cacheOnDisc(true)
|
|
|
+ .displayer(new RoundedBitmapDisplayer(10))
|
|
|
+ .resetViewBeforeLoading(true)
|
|
|
+ .showImageForEmptyUri(R.drawable.avatar_normal)
|
|
|
+ .showImageOnFail(R.drawable.avatar_normal)
|
|
|
+ .showImageOnLoading(R.drawable.avatar_normal)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ mAvatarNormalImageOptions = new DisplayImageOptions.Builder()
|
|
|
+ .bitmapConfig(Bitmap.Config.RGB_565)
|
|
|
+ .cacheInMemory(true)
|
|
|
+ .cacheOnDisc(true)
|
|
|
+ .resetViewBeforeLoading(true)
|
|
|
+ .showImageForEmptyUri(R.drawable.avatar_normal)
|
|
|
+ .showImageOnFail(R.drawable.avatar_normal)
|
|
|
+ .showImageOnLoading(R.drawable.avatar_normal).build();
|
|
|
+
|
|
|
+ if (mPicturesDir != null) {
|
|
|
+ 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();
|
|
|
+ ImageLoader.getInstance().init(config);
|
|
|
+ } else {
|
|
|
+ //getCacheDir()
|
|
|
+ ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
|
|
|
+ .defaultDisplayImageOptions(mNormalImageOptions)
|
|
|
+ // .denyCacheImageMultipleSizesInMemory()
|
|
|
+ .discCache(new TotalSizeLimitedDiscCache(getCacheDir(), 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();
|
|
|
+ ImageLoader.getInstance().init(config);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initWxPay(Context context) {
|
|
|
+ IWXAPI wxApi = WXAPIFactory.createWXAPI(context, Constants.WXPAY_APPID);
|
|
|
+ wxApi.registerApp(Constants.WXPAY_APPID);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setConfig(AppConfig config) {
|
|
|
+ mConfig = config;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AppConfig getConfig() {
|
|
|
+ if (mConfig == null) {
|
|
|
+ mConfig = AppConfig.initConfig(getApplicationContext(), new ConfigBean());
|
|
|
+ }
|
|
|
+ return mConfig;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 getLoginUserId() {
|
|
|
+ return (mLoginUser != null && !TextUtils.isEmpty(mLoginUser.getUserId())) ? mLoginUser.getUserId() : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MyApplication getInstance() {
|
|
|
+ return INSTANCE;
|
|
|
+ }
|
|
|
}
|