@SuppressWarnings("deprecation") private void initImageLoader() { ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 1) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13) // default .discCacheSize(50 * 1024 * 1024) // 缓冲大小 .discCacheFileCount(100) // 缓冲文件数目 .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(this)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs().build(); // 2.单例ImageLoader类的初始化 ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(config); }
public static ImageLoader getImageLoader(Context context) { if (sImageLoader == null) { DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder() .showImageOnLoading(Drawables.sPlaceholderDrawable) .showImageOnFail(Drawables.sErrorDrawable) .cacheInMemory(true) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .defaultDisplayImageOptions(displayImageOptions) .diskCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE) .memoryCacheSize(ConfigConstants.MAX_MEMORY_CACHE_SIZE) .build(); sImageLoader = ImageLoader.getInstance(); sImageLoader.init(config); } return sImageLoader; }
public static void initImageLoader(Context context) { // This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); config.threadPriority(Thread.NORM_PRIORITY - 2); config.denyCacheImageMultipleSizesInMemory(); config.diskCacheFileNameGenerator(new Md5FileNameGenerator()); config.diskCacheSize(50 * 1024 * 1024); // 50 MiB config.tasksProcessingOrder(QueueProcessingType.LIFO); config.writeDebugLogs(); // Remove for release app // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config.build()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // main activity Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // toolbar setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); getSupportFragmentManager().beginTransaction().replace(R.id.contentframe, new main_fragment()).commit(); Settings.verifyStoragePermissions(this); // make sure we can access settings ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .build(); ImageLoader.getInstance().init(config); }
public void initImageLoader() { File cacheDir = StorageUtils.getCacheDirectory(this); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) // .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
@Override public void onCreate() { super.onCreate(); LogUtils.i(TAG, "onCreate"); enableStrictMode(); sContext = getApplicationContext(); ImageLoaderConfiguration localImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(localImageLoaderConfiguration); 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); }
private void initImageLoader() { File cacheDir = com.nostra13.universalimageloader.utils.StorageUtils .getOwnCacheDirectory(getActivity(), IMAGE_CACHE_PATH); DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(true).cacheOnDisc(true).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getActivity()).defaultDisplayImageOptions(defaultOptions) .memoryCache(new LruMemoryCache(12 * 1024 * 1024)) .memoryCacheSize(12 * 1024 * 1024) .discCacheSize(32 * 1024 * 1024).discCacheFileCount(100) .discCache(new UnlimitedDiscCache(cacheDir)) .threadPriority(Thread.NORM_PRIORITY - 2) .tasksProcessingOrder(QueueProcessingType.LIFO).build(); ImageLoader.getInstance().init(config); }
public static void initImageLoader(Context context) { // This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); config.threadPriority(Thread.NORM_PRIORITY - 2); config.denyCacheImageMultipleSizesInMemory(); config.discCacheFileNameGenerator(new Md5FileNameGenerator()); config.discCacheSize(50 * 1024 * 1024); // 50 MiB config.tasksProcessingOrder(QueueProcessingType.LIFO); config.writeDebugLogs(); // Remove for release app // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config.build()); }
/** * 初始化imageloader,请在application中调用此方法 */ public static void initImageLoader(Context context) { // File cacheDir = StorageUtils.getOwnCacheDirectory(context, // "AppDir/cache/images"); File cacheDir = new File(context.getCacheDir(), "images/cache/"); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( context).threadPriority(Thread.NORM_PRIORITY - 2) //降低线程的优先级保证主UI线程不受太大影响 .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) //图片名称使用md5加密 .tasksProcessingOrder(QueueProcessingType.LIFO) .diskCacheSize(1024 * 1024 * 50) // 硬盘存储缓存大小 .memoryCache(new LruMemoryCache(10 * 1024 * 1024)) //内存缓存 .memoryCacheSize(10 * 1024 * 1024)//内存缓存 .diskCache(new UnlimitedDiskCache(cacheDir)) .imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s) .taskExecutor(taskExecutor) .taskExecutorForCachedImages(executorForCachedImages) .threadPriority(Thread.NORM_PRIORITY - 1) .writeDebugLogs() .build(); com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config); }
public CachingUrlTileProvider(Context ctx, int mTileWidth, int mTileHeight) { this.mTileWidth = mTileWidth; this.mTileHeight = mTileHeight; // if ImageLoader has not been instantiated by parent application yet if (!ImageLoader.getInstance().isInited()) { // Create global configuration and initialize ImageLoader with this config ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(ctx).build(); ImageLoader.getInstance().init(config); } // init ImageLoader display options DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder(); builder.cacheInMemory(true).cacheOnDisk(true); setDisplayImageOptions(builder); mOptions = builder.build(); }
/** * init UIL ImageLoader */ public static void initImageLoader(Context context) { // This configuration tuning is custom. You can tune every option, you // may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( context).threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .discCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO) .writeDebugLogs() // Remove for release app .build(); // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config); }
/** * 初始化图片载入框架 */ private void initImageLoader() { File cacheDir = StorageUtils.getCacheDirectory(this); int MAXMEMONRY = (int) (Runtime.getRuntime().maxMemory()); // System.out.println("dsa-->"+MAXMEMONRY+" "+(MAXMEMONRY/5));//.memoryCache(new // LruMemoryCache(50 * 1024 * 1024)) DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this).memoryCacheExtraOptions(480, 800).defaultDisplayImageOptions(defaultOptions) .diskCacheExtraOptions(480, 800, null).threadPoolSize(3) .threadPriority(Thread.NORM_PRIORITY - 2) .tasksProcessingOrder(QueueProcessingType.FIFO) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(MAXMEMONRY / 5)) .diskCache(new UnlimitedDiskCache(cacheDir)) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(this)) // default .imageDecoder(new BaseImageDecoder(false)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()).build(); ImageLoader.getInstance().init(config); }
@Override public void onCreate() { super.onCreate(); sContext = this; appComponent = DaggerAppComponent.builder() .baseComponent(baseComponent) .build(); Fresco.initialize(getApplicationContext(), ImagePipelineFactory.imagePipelineConfig(getApplicationContext() , getAppComponent().okHttpClient() , getCacheDir().getAbsolutePath())); //ImageLoader初始化 ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(configuration); DBManager.init(this); if (AccountHelper.isLogin()) DBManager.initDefaultRealm(AccountHelper.getCurrentUid(), APPRealmMigration.VERSION, new APPRealmMigration()); startService(new Intent(this, InitializeIntentService.class)); }
private void initImageLoader() { ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .threadPoolSize(5) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024)) .memoryCacheSize(2 * 1024) .defaultDisplayImageOptions(new DisplayImageOptions.Builder() .showImageForEmptyUri(R.drawable.no_photo_group) .showImageOnFail(R.drawable.no_photo_group) .resetViewBeforeLoading(true) .displayer(new FadeInBitmapDisplayer(300)).build()) .tasksProcessingOrder(QueueProcessingType.LIFO).build(); ImageLoader.getInstance().init(config); com.nostra13.universalimageloader.utils.L.writeLogs(false); }
public static void initImageLoader(Context context) { b = new DisplayImageOptions.Builder(); b.cacheOnDisc(true) .cacheInMemory(false) .imageScaleType(ImageScaleType.IN_SAMPLE_INT) .bitmapConfig(Bitmap.Config.RGB_565); ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context); config.threadPriority(Thread.NORM_PRIORITY - 2); config.denyCacheImageMultipleSizesInMemory(); config.discCacheFileNameGenerator(new Md5FileNameGenerator()); config.memoryCacheSize(20 * 1024 * 1024); // 20 MiB config.discCacheSize(100 * 1024 * 1024); // 100 MiB config.tasksProcessingOrder(QueueProcessingType.LIFO); config.defaultDisplayImageOptions(b.build()); config.writeDebugLogs(); ImageLoader.getInstance().init(config.build()); }
public void initUIL() { // options is used for images smaller in size (5kb-150kb) DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.ic_photo_black_48dp) .showImageOnFail(R.drawable.ic_broken_image_black_48dp) .imageScaleType(ImageScaleType.EXACTLY) .cacheInMemory(true) .cacheOnDisk(true) .bitmapConfig(Bitmap.Config.RGB_565) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration .Builder(this) .defaultDisplayImageOptions(options) .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
private ImageLoaderConfiguration getDefaultConfig() throws IOException { int MAX_CACHE_MEMORY_SIZE = (int) (Runtime.getRuntime().maxMemory() / 8); File cacheDir = StorageUtils.getOwnCacheDirectory(context, context.getPackageName() + "/cache/image/"); LogUtil.i(TAG, "ImageLoader memory cache size = " + MAX_CACHE_MEMORY_SIZE / M + "M"); LogUtil.i(TAG, "ImageLoader disk cache directory = " + cacheDir.getAbsolutePath()); ImageLoaderConfiguration config = new ImageLoaderConfiguration .Builder(context) .threadPoolSize(3) // 线程池内加载的数量 .threadPriority(Thread.NORM_PRIORITY - 2) // 降低线程的优先级,减小对UI主线程的影响 .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(MAX_CACHE_MEMORY_SIZE)) .discCache(new LruDiskCache(cacheDir, new Md5FileNameGenerator(), 0)) .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间 .writeDebugLogs() .build(); return config; }
public GankCommonAdapter(@NonNull Context context, List<CommonDate.ResultsEntity> datas) { super(context, datas, R.layout.item_common); //创建默认的ImageLoader配置参数 ImageLoaderConfiguration configuration = ImageLoaderConfiguration.createDefault(context); ImageLoader.getInstance().init(configuration); // Get singleton instance push_left_in = AnimationUtils.loadAnimation(context, R.anim.push_left_in); push_right_in = AnimationUtils.loadAnimation(context, R.anim.push_right_in); push_left_in.setDuration(1000); push_right_in.setDuration(1000); //显示图片的配置 options = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .bitmapConfig(Bitmap.Config.RGB_565) .build(); }
@Override public void onCreate() { super.onCreate(); applicationContext = getApplicationContext(); applicationHandler = new Handler(applicationContext.getMainLooper()); checkDisplaySize(); density = ApertureBasing.applicationContext.getResources().getDisplayMetrics().density; DisplayImageOptions defaultDisplayImageOptions = new DisplayImageOptions.Builder() // .considerExifParams(true) .resetViewBeforeLoading(true) .showImageOnLoading(R.drawable.nophotos) .showImageOnFail(R.drawable.nophotos) .delayBeforeLoading(0) .build(); // ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getApplicationContext()) .defaultDisplayImageOptions(defaultDisplayImageOptions) .memoryCacheExtraOptions(480, 800).threadPoolSize(5).build(); ImageLoader.getInstance().init(config); }
private void initImageLoader() { DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(false) .imageScaleType(ImageScaleType.EXACTLY) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .threadPriority(Thread.NORM_PRIORITY - 2) .defaultDisplayImageOptions(defaultOptions) .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .diskCache(new UnlimitedDiskCache(StorageUtils.getOwnCacheDirectory(this, Constant.APP_IMAGE))) .diskCacheSize(100 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO) .memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024) .threadPoolSize(3) .build(); ImageLoader.getInstance().init(config); }
@Override public void onCreate() { super.onCreate(); AsyncTask.SERIAL_EXECUTOR.execute(new Runnable() { @Override public void run() { //init libraries } }); ContextHolder.set(this); ContextGodObject.getInstance().setContext(this); ImageLoaderConfiguration config = ImageLoaderConfiguration.createDefault(this); ImageLoader.getInstance().init(config); }
private void initLib() { // 初始化日志功能, 开启/关闭 日志输出 L.setLogOpen(AppConstant.LOG_OPEN); // 初始化自定义异常捕获 CrashHandler.getInstance().init(this); // 初始化ImageLoader // 设置图片显示选项 DisplayImageOptions displayOp = new DisplayImageOptions.Builder() .showImageOnLoading(0)// 图片正在加载时显示的背景 .cacheInMemory(true)// 缓存在内存中 .cacheOnDisk(true)// 缓存在磁盘中 .displayer(new FadeInBitmapDisplayer(300))// 显示渐变动画 .bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型 .considerExifParams(true)// 考虑旋转角 .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getApplicationContext()).defaultDisplayImageOptions(displayOp) .denyCacheImageMultipleSizesInMemory()// 不解析多种尺寸 .build(); ImageLoader.getInstance().init(config); }
/** * 初始化ImageLoader * * @param context 上下文对象 */ private void initImageLoader(Context context) { File cacheDir = StorageUtils.getCacheDirectory(context); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) // .taskExecutor(...) // .taskExecutorForCachedImages(...) .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default // .imageDecoder(new BaseImageDecoder()) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build(); ImageLoader.getInstance().init(config); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_searchable); //Views mProgressBar = (ProgressBar) findViewById(R.id.list_progress_bar); mProgressBar.setVisibility(View.INVISIBLE); //Image Loader ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .build(); ImageLoader.getInstance().init(config); //Get the query from the intent Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { mQuery = intent.getStringExtra(SearchManager.QUERY); //Toast.makeText(this, "Query: " + query, Toast.LENGTH_SHORT).show(); String searchUrlApi = MainActivity.apiUrl + "search/users?q=" + mQuery + "&per_page=40"; getContents(searchUrlApi); } }
/** * 初始化 UIL图片加载框架 */ private void initImageLoader() { ImageLoaderConfiguration imageLoaderConfig = new ImageLoaderConfiguration.Builder(getApplicationContext()) // 对于同一张图片有多种尺寸的图, 只存储其中一个 .denyCacheImageMultipleSizesInMemory() // 内存缓存使用 LRU 算法进行存储和删除, 容量10MB .memoryCache(new LruMemoryCache(10 * 1024 * 1024)) // 硬盘缓存容量 50MB .diskCacheSize(50 * 1024 * 1024) // 硬盘上缓存的图片名称是经过使用 md5 转换后的名称. .diskCacheFileNameGenerator(new Md5FileNameGenerator()) // 线程池按照LIFO的顺序进行图片的加载, 即: 越是后加入到线程池队列中的图片, 越是优先进行加载. .tasksProcessingOrder(QueueProcessingType.LIFO) // 设置线程池最大并发数为5 .threadPoolSize(5) // 打开调试日志的开关 .writeDebugLogs() .build(); ImageLoader.getInstance().init(imageLoaderConfig); }
/** * 初始化imageloader */ private void initImageLoader() { File cacheDir = StorageUtils.getOwnCacheDirectory( getApplicationContext(), "imageloader/Cache"); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( this) .threadPoolSize(3) // default .threadPriority(Thread.NORM_PRIORITY - 2) // default .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default .diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) // default .defaultDisplayImageOptions(ImageLoaderHelper.getInstance(this).getDisplayOptions()) // default .writeDebugLogs().build(); ImageLoader.getInstance().init(config); }
@Override public void onCreate() { super.onCreate(); //初始化ImageLoader // ImageLoaderConfiguration configuration=ImageLoaderConfiguration.createDefault(getApplicationContext()); // ImageLoader.getInstance().init(configuration); File cacheDir = StorageUtils.getOwnCacheDirectory(this, "Hungry and hurry/Cache"); ImageLoaderConfiguration config = new ImageLoaderConfiguration .Builder(this) .memoryCacheExtraOptions(480, 800) // maxwidth, max height,即保存的每个缓存文件的最大长宽 .threadPoolSize(3)//线程池内加载的数量 .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现 .memoryCacheSize(2 * 1024 * 1024) .tasksProcessingOrder(QueueProcessingType.LIFO) .diskCache(new UnlimitedDiskCache(cacheDir))//自定义缓存路径 .diskCacheFileCount(70) .diskCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密 .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .imageDownloader(new BaseImageDownloader(this,5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间 .writeDebugLogs() // Remove for releaseapp .build();//开始构建 ImageLoader.getInstance().init(config); }
public static void initImageLoader(Context context) { ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // default = device screen dimensions .diskCacheExtraOptions(480, 800, null) .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) // default .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default .imageDownloader(new BaseImageDownloader(context)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() .build(); // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config); }
private ImageUtil(Context ctx) { this.context = ctx; threadPool = Executors.newFixedThreadPool(5); this.preferences = PreferenceManager.getDefaultSharedPreferences(ctx); provider = ImageServiceProvider.values()[preferences.getInt(PREFERENCE_PROVIDER, ImageServiceProvider.GLIDE.ordinal())]; Fresco.initialize(context); picasso = Picasso.with(ctx); glide = Glide.with(ctx); universalImageLoader = ImageLoader.getInstance(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .diskCache(new UnlimitedDiskCache(ctx.getCacheDir())) // default .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default // .writeDebugLogs() .build(); universalImageLoader.init(config); ion = Ion.getDefault(context); }
/** 初始化imageLoader */ private void initImageLoader() { DisplayImageOptions options = new DisplayImageOptions.Builder().showImageForEmptyUri(com.yiw.circledemo.R.color.bg_no_photo) .showImageOnFail(com.yiw.circledemo.R.color.bg_no_photo).showImageOnLoading(com.yiw.circledemo.R.color.bg_no_photo).cacheInMemory(true) .cacheOnDisk(true).build(); File cacheDir = new File(DEFAULT_SAVE_IMAGE_PATH); ImageLoaderConfiguration imageconfig = new ImageLoaderConfiguration.Builder(this) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(200) .diskCache(new UnlimitedDiskCache(cacheDir)) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .defaultDisplayImageOptions(options).build(); ImageLoader.getInstance().init(imageconfig); }
private void init(Context context) { imageLoaderconfig = new ImageLoaderConfiguration.Builder( context) .memoryCacheExtraOptions(720, 1280) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .diskCacheSize(50 * 1024 * 1024) // 50 Mb .tasksProcessingOrder(QueueProcessingType.LIFO) .build(); if (!_imageLoader.isInited()) _imageLoader.init(imageLoaderconfig); }
private void initImageLoader() { DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(false) .imageScaleType(ImageScaleType.EXACTLY) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .threadPriority(Thread.NORM_PRIORITY - 2) .defaultDisplayImageOptions(defaultOptions) .denyCacheImageMultipleSizesInMemory() .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .diskCache(new UnlimitedDiskCache(StorageUtils.getOwnCacheDirectory(this, AppConstants.APP_IMAGE))) .diskCacheSize(100 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO) .memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024) .threadPoolSize(3) .build(); ImageLoader.getInstance().init(config); }
/** * 初始化 * * @param context */ private UILKit(Context context) { File cacheDir = getDiskCacheDir(context, "img"); ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .memoryCacheSize(10 * 1024 * 1024) .diskCache(new UnlimitedDiskCache(cacheDir)) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .diskCacheSize(50 * 1024 * 1024) // 50 MiB .tasksProcessingOrder(QueueProcessingType.LIFO); ImageLoader.getInstance().init(config.build()); picOptions = new DisplayImageOptions.Builder() .imageScaleType(ImageScaleType.EXACTLY) .cacheOnDisk(false).cacheInMemory(false) .resetViewBeforeLoading(true) .displayer(new FadeInBitmapDisplayer(500)).build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_moment_list); getSupportActionBar().setDisplayHomeAsUpEnabled(true); DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .defaultDisplayImageOptions(defaultOptions) .build(); ImageLoader.getInstance().init(config); updateSnsList(); }
public ImagePagerAdapter(Context context, List<String> imageIdList, List<String> urllist, List<String> urlTitlesList) { this.context = context; this.imageIdList = imageIdList; if (imageIdList != null) { this.size = imageIdList.size(); } this.linkUrlArray = urllist; this.urlTitlesList = urlTitlesList; isInfiniteLoop = false; // 初始化imageLoader 否则会报错 if(imageLoader!=null)imageLoader.destroy(); imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(context)); options = new DisplayImageOptions.Builder() .showStubImage(R.mipmap.ic_launcher) // 设置图片下载期间显示的图片 .showImageForEmptyUri(R.mipmap.meinv) // 设置图片Uri为空或是错误的时候显示的图片 .showImageOnFail(R.mipmap.meinv) // 设置图片加载或解码过程中发生错误显示的图片 .cacheInMemory(true) // 设置下载的图片是否缓存在内存中 .cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中 .build(); }
/** 初始化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);// 全局初始化此配置 }
@Override public void onCreate() { super.onCreate(); File cacheDir = StorageUtils.getCacheDirectory(this); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCache(new UnlimitedDiscCache(cacheDir)) .diskCacheSize(50 * 1024 * 1024) .diskCacheFileCount(100) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) .memoryCacheSize(2 * 1024 * 1024) .memoryCacheSizePercentage(13) .tasksProcessingOrder(QueueProcessingType.LIFO) .build(); ImageLoader.getInstance().init(configuration); }