@Override public void registerComponents(Context context, Glide glide) { //配置OkHttp OkHttpClient mOkHttpClient = new OkHttpClient() .newBuilder() .connectTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS) .build(); //设置Glide请求为Okhttp glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(mOkHttpClient)); //设置Glide的内存缓存和BitmapPool使用最多他们初始值的最大大小的一半 glide.setMemoryCategory(MemoryCategory.LOW); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); GlideApp.get(this).setMemoryCategory(MemoryCategory.HIGH); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestStoragePermission(); } else { replaceFragment(); } }
private void config() { MemorySizeCalculator calculator = new MemorySizeCalculator(this); //默认由该类计算内存缓存size int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); //自动计算出的默认缓存size int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); //bitmap pool size Glide.get(this).setMemoryCategory(MemoryCategory.HIGH); //动态设置内存缓存size }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); GlideApp.get(this).setMemoryCategory(MemoryCategory.HIGH); }
@Override public void registerComponents(Context context, Glide glide) { //glide.clearDiskCache(); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); glide.setMemoryCategory(MemoryCategory.NORMAL); }
public GlideLoader(Application context) { this.context = context; Glide.get(context).setMemoryCategory(MemoryCategory.LOW); }
public ImageLoader(Application context) { this.context = context; Glide.get(context).setMemoryCategory(MemoryCategory.LOW); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MiuiStatusBarCompat.enableLightStatusBar(getWindow()); binding = DataBindingUtil.setContentView(this, R.layout.main_activity); setSupportActionBar(binding.toolbar); images = MrSharedState.getInstance().getImages(); Glide.get(this).setMemoryCategory(MemoryCategory.HIGH); binding.content.setAdapter(new MainAdapter(this, images, Glide.with(this), this)); setExitSharedElementCallback(new SharedElementCallback() { @Override public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) { if (reenterState != null) { int index = reenterState.getInt("index", 0); Image image = images.get(index); MainAdapter.ViewHolder holder = (MainAdapter.ViewHolder) binding.content .findViewHolderForLayoutPosition(index); sharedElements.clear(); if (holder != null && holder.binding != null) { sharedElements.put(String.format("%s.image", image.getObjectId()), holder.binding.image); } reenterState = null; } } }); Observable<List<Image>> load = Observable.just(images) .doOnSubscribe(() -> binding.refresher.setRefreshing(true)) .doOnCompleted(() -> binding.refresher.setRefreshing(false)) .map(whatever -> images.isEmpty() ? Image.all() : Image.since(images.get(0))) .observeOn(Schedulers.io()) .flatMap(RxAVQuery::find) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(RxList.prependTo(images)); RxSwipeRefreshLayout.refreshes(binding.refresher) .compose(bindToLifecycle()) .flatMap(whatever -> load) .retry((count, tr) -> { Log.e(TAG, "An error occurred while fetching images", tr); ToastUtil.shorts(this, tr.getMessage()); binding.refresher.setRefreshing(false); return true; }) .filter(loaded -> !loaded.isEmpty()) .subscribe(loaded -> binding.content.smoothScrollToPosition(0)); load.compose(bindToLifecycle()) .onErrorReturn(tr -> { Log.e(TAG, "An error occurred while fetching images", tr); ToastUtil.shorts(this, tr.getMessage()); binding.refresher.setRefreshing(false); return null; }) .subscribe(); UpdateUtil.checkForUpdate(version -> UpdateUtil.promptUpdate(this, version)); }
public GirlAdapter(Context context, List<Image> images) { Glide.get(context).setMemoryCategory(MemoryCategory.HIGH); this.context = context; this.images = images; }
@Override public void onCreate() { super.onCreate(); Glide.get(this).setMemoryCategory(MemoryCategory.HIGH); }