@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_common, null); DragLayout dragLayout = (DragLayout) rootView.findViewById(R.id.drag_layout); imageView = (ImageView) dragLayout.findViewById(R.id.image); ImageLoader.getInstance().displayImage(imageUrl, imageView); address1 = dragLayout.findViewById(R.id.address1); address2 = dragLayout.findViewById(R.id.address2); address3 = dragLayout.findViewById(R.id.address3); address4 = dragLayout.findViewById(R.id.address4); address5 = dragLayout.findViewById(R.id.address5); ratingBar = (RatingBar) dragLayout.findViewById(R.id.rating); head1 = dragLayout.findViewById(R.id.head1); head2 = dragLayout.findViewById(R.id.head2); head3 = dragLayout.findViewById(R.id.head3); head4 = dragLayout.findViewById(R.id.head4); dragLayout.setGotoDetailListener(this); return rootView; }
@Override public void onBindViewHolder(ViewHolder holder, final int position) { final IHistoryDailyPicks data = this.datas.get(position); if (data != null) { holder.titleTv.setText(data.getTitle()); holder.contentTv.setText(data.getDescribe()); holder.timeTv.setText(data.getTime()); holder.discussTv.setText(data.getDiscuss()); ImageLoader.getInstance().displayImage(data.getImgHref(), holder.picIv); holder.rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mListener.itemClicked(position, data.getTitle(), data.getHref()); } }); } }
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()); }
/** * 初始化图片载入框架 */ 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 onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { File file = ImageLoader.getInstance().getDiskCache().get(mWallpaper.getUrl()); if (newState == SlidingUpPanelLayout.PanelState.COLLAPSED && mTooltip == null && Preferences.get(this).isShowWallpaperTooltip() && !file.exists() && !Preferences.get(this).isTimeToShowWallpaperPreviewIntro() && !Preferences.get(this).isHighQualityPreviewEnabled()) { mTooltip = Tooltip.Builder(this) .to(mMenuPreview) .content(R.string.wallpaper_tooltip_preview) .desc(R.string.wallpaper_tooltip_preview_icon_tap) .descIcon(R.drawable.ic_toolbar_preview_full) .visibleDontShowAgain(true) .cancelable(false) .buttonCallback(tooltip -> { Preferences.get(this).setShowWallpaperTooltip(!tooltip.getCheckboxState()); tooltip.dismiss(); }) .build(); mTooltip.show(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: this.finish(); return true; case R.id.item_clear_memory_cache: ImageLoader.getInstance().clearMemoryCache(); return true; case R.id.item_clear_disc_cache: ImageLoader.getInstance().clearDiskCache(); return true; default: return false; } }
@Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; final ViewHolder holder; if (convertView == null) { view = inflater.inflate(R.layout.item_list_image, parent, false); holder = new ViewHolder(); holder.text = (TextView) view.findViewById(R.id.text); holder.image = (ImageView) view.findViewById(R.id.image); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.text.setText("Item " + (position + 1)); ImageLoader.getInstance().displayImage(IMAGE_URLS[position], holder.image, options, animateFirstListener); return view; }
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .imageScaleType(ImageScaleType.NONE) .showImageOnLoading(R.drawable.screenshot_placeholder) .showImageForEmptyUri(R.drawable.screenshot_placeholder) .bitmapConfig(Bitmap.Config.RGB_565) .build(); View rootView = inflater.inflate(R.layout.activity_screenshots_page, container, false); ImageView screenshotView = (ImageView) rootView.findViewById(R.id.screenshot); ImageLoader.getInstance().displayImage(screenshotUrl, screenshotView, displayImageOptions); return rootView; }
@Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder viewHolder = null; if(convertView == null) { convertView = View.inflate(MainActivity.this,R.layout.list_item_layout,null); viewHolder = new ViewHolder(convertView); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } viewHolder.button.setText(position + ""); viewHolder.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { VideoPlayerManager.getInstance().listVideoPlayer(listView, R.id.container, position, mDatas.get(position), position + "", mThumbs.get(position), ImageLoader.getInstance()); } }); return convertView; }
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 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 onBindViewHolder(ItemHolder itemHolder, int i) { Song localItem = arraylist.get(i); itemHolder.title.setText(localItem.title); itemHolder.artist.setText(localItem.artistName); if (MusicPlayer.getCurrentAudioId() == localItem.id) { itemHolder.title.setTextColor(Config.accentColor(mContext, ateKey)); if (MusicPlayer.isPlaying()) { itemHolder.visualizer.setColor(Config.accentColor(mContext, ateKey)); itemHolder.visualizer.setVisibility(View.VISIBLE); } } else { itemHolder.title.setTextColor(Config.textColorPrimary(mContext, ateKey)); itemHolder.visualizer.setVisibility(View.GONE); } ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.albumId).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build()); setOnPopupMenuListener(itemHolder, i); }
@Override public void onBindViewHolder(ItemHolder itemHolder, int i) { Album localItem = arraylist.get(i); itemHolder.title.setText(localItem.title); String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount); itemHolder.details.setText(songCount); ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(localItem.id).toString(), itemHolder.albumArt, new DisplayImageOptions.Builder().cacheInMemory(true) .showImageOnFail(R.drawable.ic_empty_music2) .resetViewBeforeLoading(true) .build()); if (TimberUtils.isLollipop()) itemHolder.albumArt.setTransitionName("transition_album_art" + i); }
/** * 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 = 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()); }
/** * 为ImageView设置图片 * * @param viewId * @return */ public ViewHolder setImageByUrl(int viewId, String url) { ImageView iv = getView(viewId); DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.mipmap.ic_launcher) .showImageOnFail(R.mipmap.ic_launcher) // 设置图片质量 .bitmapConfig(Bitmap.Config.RGB_565) // 设置内存缓存 .cacheInMemory(true) // 设置磁盘缓存 .cacheOnDisk(true) // 设置图片特效 .displayer(new FadeInBitmapDisplayer(300)).build(); ImageLoader.getInstance().displayImage(url,iv, ImageLoaderUtil.getFadeInOption(200,true,true,true)); return this; }
public void updateFetchedDetails(String artUrl, String trackName, String albumName, String artistName, String primaryGenreName, String releaseDate, int trackNumber, int trackCount) { artWorkUrl = artUrl; ImageLoader.getInstance().displayImage(artUrl, mAlbumArtImage); albumArtistEdited = true; mTitleEditText.setText(trackName); mAlbumEditText.setText(albumName); mArtistEditText.setText(artistName); mGenreEditText.setText(primaryGenreName); mYearEditText.setText(releaseDate.substring(0, 10)); mTrackEditText.setText("" + trackNumber); mTotalTrackEditText.setText("" + trackCount); }
public View getItemView(int position, View convertView, ViewHolder holder) { CustomSport customSport = (CustomSport) getItem(position); if (customSport != null) { ImageView civ_title = (ImageView) holder.getView(R.id.civ_icon); TextView tv_calory = (TextView) holder.getView(R.id.tv_calory); TextView tv_unit = (TextView) holder.getView(R.id.tv_unit); ImageView iv_health_light = (ImageView) holder.getView(R.id.iv_light); ((TextView) holder.getView(R.id.tv_name)).setText(customSport.activity_name); ImageLoader.getInstance().displayImage("", civ_title, ImageLoaderOptions.global((int) R.drawable.aa5)); if (TextUtils.isEmpty(customSport.calory)) { tv_calory.setText("0"); } else { tv_calory.setText(Math.round(Float.parseFloat(customSport.calory)) + ""); } tv_unit.setText(String.format(" 千卡/%1$s%2$s", new Object[]{customSport.amount, customSport.unit_name})); iv_health_light.setBackgroundResource(R.drawable.a9a); iv_health_light.setOnClickListener(new DelListener(position)); } return convertView; }
@Override public void onResume() { super.onResume(); if (UserUtils.isLogin(getActivity())) { LoginResult userInfo = UserUtils.getUserInfo(getActivity()); btnLogin.setVisibility(View.GONE); llPerName.setVisibility(View.VISIBLE); String nickName = UserUtils.getUserInfo(getActivity()).getNickname(); if (null == nickName) { nickName = ""; } tv_userName.setText("Welcome, " + nickName); textView.setText(UserUtils.getUserInfo(getActivity()).getEmail()); ImageLoader.getInstance().displayImage(userInfo.getImage(), userIcon, ImageLoaderOptions.getImageLoaderOptions()); } else { ImageLoader.getInstance().displayImage("", userIcon, ImageLoaderOptions.getImageLoaderOptions()); btnLogin.setVisibility(View.VISIBLE); llPerName.setVisibility(View.GONE); } }
public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(this.ctx).inflate(R.layout.e6, null); holder.icon = (ImageView) convertView.findViewById(R.id.icon); holder.name = (TextView) convertView.findViewById(R.id.name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ImageLoader imageLoader = this.imageLoader; StringBuilder stringBuilder = new StringBuilder(); BooheeClient.build(BooheeClient.ONE); imageLoader.displayImage(stringBuilder.append(BooheeClient.getHost(BooheeClient.ONE)) .append(getItem(position).icon).toString(), holder.icon, this.option); holder.name.setText(getItem(position).name); return convertView; }
@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)); }
@Override public void onCreate() { super.onCreate(); mContext = this; ImageLoader.getInstance().init(new ImageLoaderConfiguration.Builder(this) .diskCache(new UnlimitedDiskCache(getCacheDir())) .build()); }
/**初始化方法 * @must 使用其它方法前必须调用,建议在自定义Application的onCreate方法中调用 * @param context */ public static void init(Context context) { if (context == null) { Log.e(TAG, "\n\n\n\n\n !!!!!! <<<<<< init context == null >> return; >>>>>>>> \n\n\n\n"); return; } imageLoader = ImageLoader.getInstance(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .defaultDisplayImageOptions(getOption(0)) // .threadPoolSize(5) // //.threadPriority(Thread.MIN_PRIORITY + 3) .tasksProcessingOrder(QueueProcessingType.LIFO) // .discCacheSize((int)(Runtime.getRuntime().maxMemory()/2)) // .discCache(new UnlimitedDiscCache(getCachePath())) // .memoryCacheSize(2 * 1024 * 1024) // .memoryCacheExtraOptions(147, 147) // .writeDebugLogs() // .httpConnectTimeout(5000) // .httpReadTimeout(20000) .diskCacheExtraOptions(ScreenUtil.getScreenWidth(context), ScreenUtil.getScreenHeight(context), null) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .diskCacheSize(50 * 1024 * 1024) // 50 Mb // .displayer(new RoundedBitmapDisplayer(5)) .build(); imageLoader.init(config); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); imageView = (ImageView) findViewById(R.id.image); address1 = findViewById(R.id.address1); address2 = findViewById(R.id.address2); address3 = findViewById(R.id.address3); address4 = findViewById(R.id.address4); address5 = findViewById(R.id.address5); ratingBar = (RatingBar) findViewById(R.id.rating); listContainer = (LinearLayout) findViewById(R.id.detail_list_container); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window window = getWindow(); window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } String imageUrl = getIntent().getStringExtra(EXTRA_IMAGE_URL); ImageLoader.getInstance().displayImage(imageUrl, imageView); ViewCompat.setTransitionName(imageView, IMAGE_TRANSITION_NAME); ViewCompat.setTransitionName(address1, ADDRESS1_TRANSITION_NAME); ViewCompat.setTransitionName(address2, ADDRESS2_TRANSITION_NAME); ViewCompat.setTransitionName(address3, ADDRESS3_TRANSITION_NAME); ViewCompat.setTransitionName(address4, ADDRESS4_TRANSITION_NAME); ViewCompat.setTransitionName(address5, ADDRESS5_TRANSITION_NAME); ViewCompat.setTransitionName(ratingBar, RATINGBAR_TRANSITION_NAME); dealListView(); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.imageLoader = ImageLoader.getInstance(); if (getArguments() != null) { this.mImageUrl = getArguments().getString(KEY_IMAGE_URL); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.item_clear_memory_cache: ImageLoader.getInstance().clearMemoryCache(); return true; case R.id.item_clear_disc_cache: ImageLoader.getInstance().clearDiskCache(); return true; default: return false; } }
public static void initImageLoaderConfig(Context context) { try { File cacheDir = StorageUtils.getOwnCacheDirectory(context, CommonUtil.getSavePath(SysConstant.FILE_SAVE_TYPE_IMAGE)); File reserveCacheDir = StorageUtils.getCacheDirectory(context); int maxMemory = (int) (Runtime.getRuntime().maxMemory() ); // 使用最大可用内存值的1/8作为缓存的大小。 int cacheSize = maxMemory/8; DisplayMetrics metrics=new DisplayMetrics(); WindowManager mWm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); mWm.getDefaultDisplay().getMetrics(metrics); IMImageLoaderConfig = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(metrics.widthPixels, metrics.heightPixels) .threadPriority(Thread.NORM_PRIORITY-2) // .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(cacheSize)) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO) .diskCacheExtraOptions(metrics.widthPixels, metrics.heightPixels, null) .diskCache(new UnlimitedDiscCache(cacheDir,reserveCacheDir,new Md5FileNameGenerator())) .diskCacheSize(1024 * 1024 * 1024) .diskCacheFileCount(1000) .build(); IMImageLoadInstance = ImageLoader.getInstance(); IMImageLoadInstance.init(IMImageLoaderConfig); }catch (Exception e){ logger.e(e.toString()); } }
@Override public void onBindViewHolder(SongsAdapter.ItemHolder itemHolder, int position) { switch (itemHolder.getItemViewType()) { default: SongsAdapter.SongHolder holder = (SongsAdapter.SongHolder) itemHolder; holder.title.setText(mData.get(position)._title); holder.artist.setText(mData.get(position)._artist); holder.duration.setText(MusicUtils.makeShortTimeString(mContext, mData.get(position)._duration / 1000)); holder.mAlbumArt.setVisibility(View.VISIBLE); ImageLoader.getInstance().displayImage(MusicUtils.getAlbumArtUri(mData.get(position)._albumId).toString(), holder.mAlbumArt); break; } }
@Before public void setup() { ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(context)); Preferences.setup(context); Repo repo = RepoProviderTest.insertRepo(context, "http://www.example.com/fdroid/repo", "", "", "Test Repo"); app = AppProviderTest.insertApp(contentResolver, context, "com.example.app", "Test App", new ContentValues(), repo.getId()); }
public String putBitmapInDiskCache(long artistId, String artistName, LastFmInterface lastFmInterface) { File cacheDir = new File(Common.getInstance().getCacheDir(), "artistThumbnails"); Bitmap avatar = null; if (!cacheDir.exists()) { cacheDir.mkdirs(); } File cacheFile = new File(cacheDir, "" + artistId); try { if (cacheFile.exists()) { return "file://" + cacheFile.getPath(); } else { cacheFile.createNewFile(); } Response<ArtistModel> responseBodyCall = lastFmInterface.getArtist(artistName).execute(); if (responseBodyCall.isSuccessful()) { avatar = ImageLoader.getInstance().loadImageSync(responseBodyCall.body().artist.image.get(4).url); } if (avatar != null) { FileOutputStream fos = new FileOutputStream(cacheFile); avatar.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); return "file://" + cacheFile.getPath(); } else { cacheFile.delete(); return null; } } catch (Exception e) { Logger.log("" + e.getCause()); return null; } }
/** * 初始化ImageLoader */ public static void initImageLoader(Context context) { // 哪个地方想要清除自定义路径下的缓存,就在那里调用这个方法 // ImageLoader.getInstance().clearDiscCache(); // 清除自定义的ImageLoader缓存的图片 // 自定义的缓存路径ImageLoaderCache:sdcard/picture/ImageLoaderCache ,属于外部缓存 File cacheDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "ImageLoaderCache"); if (!cacheDir.exists()) { cacheDir.mkdir(); } ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .memoryCacheExtraOptions(480, 800) // maxwidth, max height,即保存的每个缓存文件的最大长宽 .threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)//线程池内加载的数量 .denyCacheImageMultipleSizesInMemory() //.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) //你可以通过自己的内存缓存实现,那么getCache()就能获取到缓存图片,在data/data/xxx.xxx.xxx/cache 文件夹下 //.memoryCacheSize(2 * 1024 * 1024) // 内存缓存大小 .tasksProcessingOrder(QueueProcessingType.LIFO) .diskCacheFileCount(100) //缓存图片的个数 .discCache(new UnlimitedDiscCache(cacheDir))// 自定义缓存路径 ,这个注释的话,就没有自定的缓存了,不过还可以设置内部缓存 .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间 .writeDebugLogs() // Remove for releaseapp .build();//开始构建 ImageLoader.getInstance().init(config); }
@Override public void onCreate() { super.onCreate(); context = this.getApplicationContext(); Fresco.initialize(this); CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore()); OkHttpClient okHttpClient = new OkHttpClient.Builder() .connectTimeout(10000L, TimeUnit.MILLISECONDS) .readTimeout(10000L, TimeUnit.MILLISECONDS) .addInterceptor(new LoggerInterceptor("TAG")) .cookieJar(cookieJar1) .build(); OkHttpUtils.initClient(okHttpClient); MultiDex.install(this); //开启debug模式,方便定位错误,具体错误检查方式可以查看http://dev.umeng.com/social/android/quick-integration的报错必看,正式发布,请关闭该模式 //Config.DEBUG = true; initXY(context); //Thread.setDefaultUncaughtExceptionHandler(crashHandler); SharedPreferencesUtil.init(context,"deepSP",MODE_PRIVATE); /** * 初始化imageloader */ ImageLoaderConfiguration configuration = ImageLoaderConfiguration.createDefault(this); ImageLoader.getInstance().init(configuration); }
/** * 设置导航栏最右侧按钮 * <p> * 参数: * isShow:是否显示,0:隐藏 其他:显示 * text:文字按钮 * imageUrl:图片按钮,格式为url地址,优先级高 */ public static void setRightBtn(IQuickFragment webLoader, WebView wv, JSONObject param, Callback callback) { int which = param.optInt("which", 0); boolean isShow = !"0".equals(param.optString("isShow")); String text = param.optString("text"); String imageUrl = param.optString("imageUrl"); INbControl.ViewHolder holder = webLoader.getPageControl().getNbBar().getViewHolder(); if (isShow) { if (!TextUtils.isEmpty(imageUrl)) { //设置图片 holder.nbRightIvs[which].setVisibility(View.INVISIBLE); holder.nbRightTvs[which].setVisibility(View.INVISIBLE); ImageLoader.getInstance().displayImage(imageUrl, holder.nbRightIvs[which], AppUtil.getImageLoaderOptions(0, 0, true, true)); holder.nbRightIvs[which].setVisibility(View.VISIBLE); } else { //设置文字 holder.nbRightIvs[which].setVisibility(View.INVISIBLE); holder.nbRightTvs[which].setVisibility(View.VISIBLE); holder.nbRightTvs[which].setText(text); } webLoader.getWebloaderControl().addPort(AutoCallbackDefined.OnClickNbRight + which, callback.getPort()); } else { //隐藏按钮 holder.nbRightTvs[which].setVisibility(View.INVISIBLE); holder.nbRightIvs[which].setVisibility(View.INVISIBLE); webLoader.getWebloaderControl().removePort(AutoCallbackDefined.OnClickNbRight + which); } }
@Override public void onBindViewHolder(ViewHolder holder, int position) { Category category = mCategories.get(position); holder.title.setText(category.getName()); ImageLoader.getInstance().displayImage( category.getThumbUrl(), new ImageViewAware(holder.image), mOptions.build(), ImageConfig.getBigThumbnailSize(), null, null); }