src\MyApplication\app\src\main\java\com\example\administrator\myapplication\app\BaseApplication.java

This commit is contained in:
zhangnaifu15 2018-05-08 21:14:13 +08:00
parent 513a8cc8c7
commit 6ce544fd06
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
package com.example.administrator.myapplication.app;
import android.app.Application;
import android.content.Context;
import com.example.administrator.myapplication.utils.BmobConstants;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.utils.StorageUtils;
import java.io.File;
import cn.bmob.v3.Bmob;
/**
* Created by htq on 2016/9/5.
*/
public class BaseApplication extends Application {
private String ApplicationId="82cacaa4470ab6b8d61d3f0ce6d6201d";
static public String avatarPath= BmobConstants.MyAvatarDir+"avatarIcon.png";
@Override
public void onCreate() {
super.onCreate();
initImageLoader(this);
Bmob.initialize(this, ApplicationId);
}
/** 初始化ImageLoader */
public static void initImageLoader(Context context) {
File cacheDir = StorageUtils.getOwnCacheDirectory(context,
"beautynote/cache");// 获取到缓存的目录地址
// 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制)这个可以设定在APPLACATION里面设置为全局的配置参数
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context)
// 线程池内加载的数量
.threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
// 将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCache(new UnlimitedDiscCache(cacheDir))// 自定义缓存路径
// .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.writeDebugLogs() // Remove for release app
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);// 全局初始化此配置
}
}