From 6ce544fd0657e658f6991efec219dcd2215577dd Mon Sep 17 00:00:00 2001 From: zhangnaifu15 <1361423499@qq.com> Date: Tue, 8 May 2018 21:14:13 +0800 Subject: [PATCH] src\MyApplication\app\src\main\java\com\example\administrator\myapplication\app\BaseApplication.java --- .../myapplication/app/BaseApplication.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/MyApplication/app/src/main/java/com/example/administrator/myapplication/app/BaseApplication.java diff --git a/src/MyApplication/app/src/main/java/com/example/administrator/myapplication/app/BaseApplication.java b/src/MyApplication/app/src/main/java/com/example/administrator/myapplication/app/BaseApplication.java new file mode 100644 index 0000000..f597f43 --- /dev/null +++ b/src/MyApplication/app/src/main/java/com/example/administrator/myapplication/app/BaseApplication.java @@ -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);// 全局初始化此配置 + } + +}