use of com.nostra13.universalimageloader.core.ImageLoader in project CustomViews by AndroidStudy233.
the class MyApplication method initImageLoader.
/**
* 初始化ImageLoader
*/
private void initImageLoader() {
File cacheDir = getCacheDir();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(480, // max width, max height,即保存的每个缓存文件的最大长宽
800).threadPoolSize(// 线程池内加载的数量
3).threadPriority(// 线程优先级
Thread.NORM_PRIORITY - 1).denyCacheImageMultipleSizesInMemory().memoryCache(new WeakMemoryCache()).memoryCacheSize(// 内存缓存2MB
2 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO).diskCache(// 限制缓存时长
new LimitedAgeDiskCache(cacheDir, 7 * 24 * 60 * 60)).diskCacheSize(// 本地缓存50MB
50 * 1024 * 1024).diskCacheFileNameGenerator(// MD5加密名字
new Md5FileNameGenerator()).defaultDisplayImageOptions(// 设置默认选项
DisplayImageOptions.createSimple()).imageDownloader(// connectTimeout (5 s), readTimeout (30 s)超时时间
new BaseImageDownloader(getApplicationContext(), 5 * 1000, 20 * 1000)).build();
// 开始构建
ImageLoader.getInstance().init(config);
}
use of com.nostra13.universalimageloader.core.ImageLoader in project Slide by ccrama.
the class ImageFlairs method initFlairImageLoader.
public static FlairImageLoader initFlairImageLoader(Context context) {
// 100 MB limit
long discCacheSize = 1024 * 1024 * 100;
DiskCache discCache;
File dir = getCacheDirectory(context);
int threadPoolSize;
discCacheSize *= 100;
threadPoolSize = 7;
if (discCacheSize > 0) {
try {
dir.mkdir();
discCache = new LruDiskCache(dir, new Md5FileNameGenerator(), discCacheSize);
} catch (IOException e) {
discCache = new UnlimitedDiskCache(dir);
}
} else {
discCache = new UnlimitedDiskCache(dir);
}
options = new DisplayImageOptions.Builder().cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).resetViewBeforeLoading(false).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(threadPoolSize).denyCacheImageMultipleSizesInMemory().diskCache(discCache).threadPoolSize(4).imageDownloader(new OkHttpImageDownloader(context)).defaultDisplayImageOptions(options).build();
if (FlairImageLoader.getInstance().isInited()) {
FlairImageLoader.getInstance().destroy();
}
imageLoader = FlairImageLoader.getInstance();
imageLoader.init(config);
return imageLoader;
}
use of com.nostra13.universalimageloader.core.ImageLoader in project android by testpress.
the class ProductDetailsActivity method onLoadFinished.
public void onLoadFinished(final Loader<ProductDetails> loader, final ProductDetails productDetails) {
if (productDetails == null) {
// noinspection ThrowableResultOfMethodCallIgnored
Exception exception = ((ThrowableLoader<ProductDetails>) loader).clearException();
exception.printStackTrace();
if (exception.getMessage() != null && exception.getMessage().equals("404 NOT FOUND")) {
gotoMainActivity();
} else if (exception.getCause() instanceof IOException) {
setEmptyText(R.string.network_error, R.string.no_internet_try_again, R.drawable.ic_error_outline_black_18dp);
} else {
setEmptyText(R.string.error_loading_products, R.string.try_after_sometime, R.drawable.ic_error_outline_black_18dp);
}
progressBar.setVisibility(View.GONE);
return;
}
progressBar.setVisibility(View.GONE);
productDetailsView.setVisibility(View.VISIBLE);
FormatDate date = new FormatDate();
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).resetViewBeforeLoading(true).showImageForEmptyUri(R.drawable.icon).showImageOnFail(R.drawable.icon).showImageOnLoading(R.drawable.icon).build();
// download and display image from url
imageLoader.displayImage(productDetails.getImages()[0].getOriginal(), image, options);
titleText.setText(productDetails.getTitle());
try {
if (Float.parseFloat(productDetails.getPrice()) == 0) {
buyButton.setText("Start Now - Free");
}
} catch (Exception e) {
}
if (productDetails.getExams().size() != 0) {
totalExams.setText(productDetails.getExams().size() + " Exams");
totalExamsContainer.setVisibility(View.VISIBLE);
} else {
totalExamsContainer.setVisibility(View.GONE);
}
if (productDetails.getNotes().size() != 0) {
totalNotes.setText(productDetails.getNotes().size() + " Documents");
totalNotesContainer.setVisibility(View.VISIBLE);
} else {
totalNotesContainer.setVisibility(View.GONE);
}
if (date.getDate(productDetails.getStartDate(), productDetails.getEndDate()) != null) {
dateText.setVisibility(View.VISIBLE);
dateText.setText(date.getDate(productDetails.getStartDate(), productDetails.getEndDate()));
}
// Price & Categories
String categories = Arrays.toString(productDetails.getCategories().toArray());
categoriesText.setText(categories.substring(1, categories.length() - 1));
priceText.setText(productDetails.getPrice());
// Update product description
if (productDetails.getDescription().isEmpty()) {
descriptionContainer.setVisibility(View.GONE);
} else {
descriptionContainer.setVisibility(View.VISIBLE);
Spanned html = Html.fromHtml(productDetails.getDescription(), new UILImageGetter(descriptionText, this), null);
ZoomableImageString zoomableImageHtml = new ZoomableImageString(this);
descriptionText.setText(zoomableImageHtml.convertString(html), TextView.BufferType.SPANNABLE);
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
descriptionText.setVisibility(View.VISIBLE);
}
// Update exams list
if (productDetails.getExams().isEmpty()) {
examsListContainer.setVisibility(View.GONE);
} else {
examsListContainer.setVisibility(View.VISIBLE);
examsListView.setFocusable(false);
examsListView.setAdapter(new ProductExamsAdapter(this.getApplicationContext(), productDetails.getExams()));
setListViewHeightBasedOnChildren(examsListView);
}
// Update notes list
if (productDetails.getNotes().isEmpty()) {
notesListContainer.setVisibility(View.GONE);
} else {
notesListContainer.setVisibility(View.VISIBLE);
notesListView.setFocusable(false);
notesListView.setAdapter(new NotesListAdapter(this.getLayoutInflater(), productDetails.getNotes(), R.layout.product_notes_list_item));
setListViewHeightBasedOnChildren(notesListView);
}
this.productDetails = productDetails;
}
use of com.nostra13.universalimageloader.core.ImageLoader in project fresco by facebook.
the class SampleUilFactory method getImageLoader.
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;
}
use of com.nostra13.universalimageloader.core.ImageLoader in project SeaStar by 13120241790.
the class App method onCreate.
@Override
public void onCreate() {
super.onCreate();
// rongcloud 初始化
RongIM.init(this);
if (getApplicationInfo().packageName.equals(getCurProcessName(getApplicationContext()))) {
RongCloudEvent.init(this);
RongIM.registerMessageType(AgreedFriendRequestMessage.class);
RongIM.registerMessageTemplate(new ContactNotificationMessageProvider());
}
// BugTags 初始化
Bugtags.start(BUGTAGS_APPKEY, this, Bugtags.BTGInvocationEventBubble);
// 友盟session时间间隔
MobclickAgent.setSessionContinueMillis(30 * 60 * 1000);
// oneCore 打印参数
NLog.setDebug(true);
options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.rp_default_head).showImageOnFail(R.drawable.rp_default_head).showImageOnLoading(R.drawable.rp_default_head).displayer(new FadeInBitmapDisplayer(300)).cacheInMemory(true).cacheOnDisk(true).build();
// 初始化图片下载组件
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(200).diskCacheFileNameGenerator(new Md5FileNameGenerator()).defaultDisplayImageOptions(options).build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
Aggregations