@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view); ImageDecodeOptions imageDecodeOptionsWithCustomDecoder = new ImageDecodeOptionsBuilder() .setCustomImageDecoder(CUSTOM_COLOR_DECODER) .build(); AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest( ImageRequestBuilder.newBuilderWithResourceId(R.raw.custom_color1) .setImageDecodeOptions(imageDecodeOptionsWithCustomDecoder) .build()) .build(); simpleDraweeView.setController(controller); }
@Override public void onCreate() { super.onCreate(); app=this; getScreen(this); Fresco.initialize(this); Recovery.getInstance() .debug(true) .recoverInBackground(false) .recoverStack(true) .mainPage(MainActivity.class) .init(this); String[] urls = getResources().getStringArray(R.array.url); String[] tips = getResources().getStringArray(R.array.title); List list = Arrays.asList(urls); images = new ArrayList(list); List list1 = Arrays.asList(tips); titles= new ArrayList(list1); }
private void init(Context context) { ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context) .setDownsampleEnabled(true); String cache = BoxingFileHelper.getCacheDir(context); if (TextUtils.isEmpty(cache)) { throw new IllegalStateException("the cache dir is null"); } if (cache != null) { DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(new File(cache)) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(MAX_DISK_CACHE_SIZE) .setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE) .setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE) .build(); builder.setMainDiskCacheConfig(diskCacheConfig); } ImagePipelineConfig config = builder.build(); Fresco.initialize(context, config); }
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); try { if (!Fresco.hasBeenInitialized()) { UdeskSDKManager.getInstance().init(this); } setContentView(R.layout.udesk_zoom_imageview); zoomImageView = (PhotoDraweeView) findViewById(R.id.udesk_zoom_imageview); Bundle bundle = getIntent().getExtras(); uri = bundle.getParcelable("image_path"); UdeskUtil.loadImage(zoomImageView, uri); saveIdBtn = findViewById(R.id.udesk_zoom_save); saveIdBtn.setOnClickListener(this); } catch (Exception e) { e.printStackTrace(); }catch (OutOfMemoryError error){ error.printStackTrace(); } }
@Override protected void onBind(String uriString) { Uri uri = Uri.parse(uriString); ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (UriUtil.isNetworkUri(uri)) { imageRequestBuilder.setProgressiveRenderingEnabled(true); } else { imageRequestBuilder.setResizeOptions(new ResizeOptions( mImageView.getLayoutParams().width, mImageView.getLayoutParams().height)); } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()) .setOldController(mImageView.getController()) .setControllerListener(mImageView.getListener()) .setAutoPlayAnimations(true) .build(); mImageView.setController(draweeController); }
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) private void initAnimation(View view) { mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view); mSimpleDraweeView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mSimpleDraweeView.getController()) .setUri(URI_KEYFRAMES_ANIMATION) .setAutoPlayAnimations(true) .build(); mSimpleDraweeView.setController(controller); final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background); switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSimpleDraweeView.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null); } }); }
@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 loadThumb( SimpleDraweeView draweeView, Size size, ImageRequest.RequestLevel requestLevel) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(size.uri) .setMediaVariations(MediaVariations.newBuilderForMediaId(MEDIA_ID) .setForceRequestForSpecifiedUri(true) .build()) .setLowestPermittedRequestLevel(requestLevel) .setResizeOptions(new ResizeOptions(draweeView.getWidth(), draweeView.getHeight())) .setCacheChoice(size.cacheChoice) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(draweeView.getController()) .build(); draweeView.setController(controller); }
public static void setImageSmall(String url, SimpleDraweeView simpleDraweeView, int width, int height, SquareRelativeLayout relativeLayout, boolean playGif) { Uri uri = Uri.parse(url); ImageRequest request = ImageRequestBuilder .newBuilderWithSource(uri) .setRotationOptions(RotationOptions.autoRotate()) .setResizeOptions(new ResizeOptions(width, height)) .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setTapToRetryEnabled(true) .setImageRequest(request) .setAutoPlayAnimations(playGif) .setOldController(simpleDraweeView.getController()) .build(); relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(width - 5, height)); simpleDraweeView.setController(controller); }
@Override public void onCreate() { super.onCreate(); final Config config = Config.load(this); ImagePipelineConfig.Builder imagePipelineConfigBuilder = ImagePipelineConfig.newBuilder(this) .setResizeAndRotateEnabledForNetwork(false) .setDownsampleEnabled(config.downsampling); if (WebpSupportStatus.sIsWebpSupportRequired) { imagePipelineConfigBuilder.experiment().setWebpSupportEnabled(config.webpSupportEnabled); } if (config.decodingThreadCount == 0) { imagePipelineConfigBuilder.setExecutorSupplier( new DefaultExecutorSupplier(Const.NUMBER_OF_PROCESSORS)); } else { imagePipelineConfigBuilder.setExecutorSupplier( new ScrollPerfExecutorSupplier(Const.NUMBER_OF_PROCESSORS, config.decodingThreadCount)); } imagePipelineConfigBuilder.experiment().setDecodeCancellationEnabled(config.decodeCancellation); DraweeConfig draweeConfig = DraweeConfig.newBuilder() .setDrawDebugOverlay(config.draweeOverlayEnabled) .build(); Fresco.initialize(this, imagePipelineConfigBuilder.build(), draweeConfig); }
private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) { String uri = source != null ? source.getString("uri") : null; if (uri == null) { controllerListener.setIconImageInfo(null); controllerListener.setDrawable(null); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { controllerListener.setIconImageInfo(getIconImageInfo(source)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(uri)) .setControllerListener(controllerListener) .setOldController(holder.getController()) .build(); holder.setController(controller); holder.getTopLevelDrawable().setVisible(true, true); } else { controllerListener.setDrawable(getDrawableByName(uri)); } }
private void FrescoInit() { DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this) .setMaxCacheSize(40 * ByteConstants.MB) .setBaseDirectoryPathSupplier(new Supplier<File>() { @Override public File get() { return getCacheDir(); } }) .build(); final FrescoCacheParams bitmapCacheParams = new FrescoCacheParams(activityManager); //Set<RequestListener> listeners = new HashSet<>(); ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(this, RetrofitClient.getInstance().getOkHttpClient()) .setMainDiskCacheConfig(diskCacheConfig) .setBitmapMemoryCacheParamsSupplier(bitmapCacheParams) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, imagePipelineConfig); }
private void displayImage(SimpleDraweeView draweeView, String url) { GenericDraweeHierarchy hierarchy = draweeView.getHierarchy(); //设置占位图 if (hierarchy == null) { hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()) .setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER).build(); draweeView.setHierarchy(hierarchy); } else { hierarchy.setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER); } //构建ImageRequestBuilder,传入请求Uri ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)); //构建Controller DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeView.getController()) .setImageRequest(requestBuilder.build()) .build(); //设置图片,Fresco设置显示图片都是通过Controller来实现 draweeView.setController(controller); }
@Override public Object instantiateItem(ViewGroup container, int position) { View view = LayoutInflater.from(mContext).inflate(R.layout.zoomable_view_pager_item, null); ZoomableDraweeView zoomableDraweeView = (ZoomableDraweeView) view.findViewById(R.id.zoomable_image); //允许缩放时切换 zoomableDraweeView.setAllowTouchInterceptionWhileZoomed(true); //长按 zoomableDraweeView.setIsLongpressEnabled(false); //双击击放大或缩小 zoomableDraweeView.setTapListener(new DoubleTapGestureListener(zoomableDraweeView)); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setUri(mPaths.get(position)) .build(); //加载图片 zoomableDraweeView.setController(draweeController); container.addView(view); view.requestLayout(); return view; }
@Override public void onCreate() { super.onCreate(); app = this; // 存放所有activity的集合 mActivityList = new ArrayList<>(); // 渐进式图片 ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig()) .build(); Fresco.initialize(this, config); }
@Override public void onCreate() { super.onCreate(); // initDebugEnvironment(true, false, "DEBUG_SERVER_HOST"); WXSDKEngine.addCustomOptions("appName", "WXSample"); WXSDKEngine.addCustomOptions("appGroup", "WXApp"); WXSDKEngine.initialize(this, new InitConfig.Builder() .setImgAdapter(new ImageAdapter()) .build() ); try { WXSDKEngine.registerModule("event", WXEventModule.class); } catch (WXException e) { e.printStackTrace(); } Fresco.initialize(this); AppConfig.init(this); PluginManager.init(this); }
@ReactMethod public void queryCache(final ReadableArray uris, final Promise promise) { // perform cache interrogation in async task as disk cache checks are expensive new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { WritableMap result = Arguments.createMap(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); for (int i = 0; i < uris.size(); i++) { String uriString = uris.getString(i); final Uri uri = Uri.parse(uriString); if (imagePipeline.isInBitmapMemoryCache(uri)) { result.putString(uriString, "memory"); } else if (imagePipeline.isInDiskCacheSync(uri)) { result.putString(uriString, "disk"); } } promise.resolve(result); } }.executeOnExecutor(GuardedAsyncTask.THREAD_POOL_EXECUTOR); }
private void refreshImageChild() { int childrenCount = getChildCount(); if (childrenCount > 0) { for (int i = 0; i < childrenCount; i++) { ViewGroup childImageLayout = (ViewGroup) getChildAt(i); SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0); if (mOnItemClickListener != null) { final int finalI = i; childImageLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mOnItemClickListener.OnItemClick(finalI); } }); } ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i))) .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(childImageView.getController()) .build(); childImageView.setController(controller); } } }
@Override public void onCreate() { super.onCreate(); CrashReport.initCrashReport(getApplicationContext(), "e1a62089c6", false); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig()) .build(); Fresco.initialize(this, config); SDKInitializer.initialize(this); Bmob.initialize(this, "b0cb494256d9b86fc931ca930a055b75"); Logger.addLogAdapter(new AndroidLogAdapter(){ @Override public boolean isLoggable(int priority, String tag) { return true;// TODO: 2017/6/5 } }); sInstance = this; initUser(); }
/** * 清除缓存 */ private void clearCache() { // 清理新闻json数据 - 不清理json数据 // NewsDALManager.shared.clearCache(); // Fresco清除图片缓存 ImagePipeline imagePipeline = Fresco.getImagePipeline(); imagePipeline.clearCaches(); // 清除缓存目录 - 清除所有缓存目录文件 FileCacheUtils.clearAllCache(mContext); final KProgressHUD hud = ProgressHUD.show(mContext, "正在清理..."); new Handler().postDelayed(new Runnable() { @Override public void run() { hud.dismiss(); ProgressHUD.showInfo(mContext, "清理缓存完成"); } }, 2000); }
/** * 初始化 */ public static void init(@NonNull Application application) { DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(application) .setBaseDirectoryName(CACHE_DIR_NAME) .setBaseDirectoryPath(CacheUtil.getCacheDirectory(application, null)) .build(); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(application) .setResizeAndRotateEnabledForNetwork(true) .setDownsampleEnabled(true) .setBitmapMemoryCacheParamsSupplier(new MemoryCacheParamsSupplier( (ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE))) // 内存缓存配置 .setMainDiskCacheConfig(diskCacheConfig) // 磁盘缓存配置 .setCacheKeyFactory(DefaultCacheKeyFactory.getInstance()) // 自定义缓存key .build(); Fresco.initialize(application, config); }
@Override public void onCreate() { super.onCreate(); OkHttpClient okHttpClient = new OkHttpClient.Builder() .build(); ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, okHttpClient) .setMainDiskCacheConfig(getDiskCacheConfig()) .setNetworkFetcher(new OkHttpNetworkFetcher(okHttpClient)) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, config); Context context = getApplicationContext(); String packageName = context.getPackageName(); String processName = getProcessName(android.os.Process.myPid()); CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context); strategy.setUploadProcess(processName == null || processName.equals(packageName)); CrashReport.initCrashReport(getApplicationContext(), "0a6e92fb70", false, strategy); registerActivityLifecycleCallbacks(ActivityLifecycleHelper.build()); }
public static void setBlurFrescoController(SimpleDraweeView simpleDraweeView, String url, int iterations, int blurRadius) { try { Uri uri = Uri.parse(url); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setPostprocessor(new IterativeBoxBlurPostProcessor(iterations, blurRadius)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(simpleDraweeView.getController()) .setImageRequest(request) .build(); simpleDraweeView.setController(controller); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onCreate() { super.onCreate(); // di if (appComponent == null) { appComponent = DaggerAppComponent.builder() .appModule(new AppModule(this)) .build(); } getAppComponent().inject(this); // fresco ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(this, mOkHttpClient) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, imagePipelineConfig); // logging if (BuildConfig.DEBUG) { Timber.plant(new ThreadAwareDebugTree()); } }
@Override public void onCreate() { super.onCreate(); FLog.setMinimumLoggingLevel(FLog.VERBOSE); Set<RequestListener> listeners = new HashSet<>(); listeners.add(new RequestLoggingListener()); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setRequestListeners(listeners) .build(); Fresco.initialize(this, config); }
/** * 配置recyclerView资讯列表 */ private void setupRecyclerView() { mNewsListRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); newsListAdapter = new NewsListRecyclerViewAdapter(mContext); mNewsListRecyclerView.setAdapter(newsListAdapter); newsListAdapter.setOnItemTapListener(new NewsListRecyclerViewAdapter.OnItemTapListener() { @Override public void onItemTapListener(ArticleListBean articleListBean) { // 打开文章详情 openArticleDetail(articleListBean); } }); // 监听滚动 mNewsListRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { switch (newState) { case RecyclerView.SCROLL_STATE_SETTLING: if (!Fresco.getImagePipeline().isPaused()) { Fresco.getImagePipeline().pause(); } break; case RecyclerView.SCROLL_STATE_DRAGGING: case RecyclerView.SCROLL_STATE_IDLE: if (Fresco.getImagePipeline().isPaused()) { Fresco.getImagePipeline().resume(); } break; } } }); }
public static void loadFileFromSdcard(final Context context, final SimpleDraweeView draweeView, Uri loackUri, final int reqWidth, final int reqHeight) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(loackUri) .setRotationOptions(RotationOptions.autoRotate()) .setLocalThumbnailPreviewsEnabled(true) .setResizeOptions(new ResizeOptions(dip2px(context, 140), dip2px(context, 220))) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(draweeView.getController()) .setTapToRetryEnabled(true) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) { if (imageInfo == null) { return; } ViewGroup.LayoutParams layoutParams = draweeView.getLayoutParams(); int width = reqWidth; int height = reqHeight; int imgWidth = dip2px(context, 140); int imgHight = dip2px(context, 220); int bitScalew = getRatioSize(width, height, imgHight, imgWidth); layoutParams.height = height / bitScalew; layoutParams.width = width / bitScalew; draweeView.requestLayout(); } }) .setAutoPlayAnimations(true) .build(); draweeView.setController(controller); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.media_variations_clear_cache) { Fresco.getImagePipeline().clearCaches(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActivity().recreate(); } else { Toast.makeText( getActivity(), R.string.imagepipeline_media_variations_restart_toast, Toast.LENGTH_SHORT).show(); getActivity().finish(); } return true; } else if (item.getGroupId() == R.id.media_variations_modes) { for (Mode mode : Mode.values()) { if (mode.menuItemId == item.getItemId()) { setMode(mode); break; } } clearMainImageAndBitmapCache(); item.setChecked(true); } return super.onOptionsItemSelected(item); }
private void setDraweeControllerForRequest(ImageRequest imageRequest) { DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setOldController(mMainImageDraweeView.getController()) .setRetainImageOnFailure(true) .build(); mMainImageDraweeView.setController(controller); }
@Override public void bindImage(ImageView photoImageView, Uri uri, int width, int height) { DraweeView draweeView = (DraweeView) photoImageView; final ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (width > 0 && height > 0) { requestBuilder.setResizeOptions(new ResizeOptions(width, height)); } ImageRequest imageRequest = requestBuilder.build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeView.getController()) .setImageRequest(imageRequest).build(); draweeView.setController(controller); }
public static DraweeController buildDraweeController(BaseFrescoImageView fresco){ return Fresco.newDraweeControllerBuilder() .setImageRequest(fresco.getImageRequest()) .setAutoPlayAnimations(fresco.isAnim()) .setTapToRetryEnabled(fresco.getTapToRetryEnabled()) .setLowResImageRequest(fresco.getLowImageRequest()) .setControllerListener(fresco.getControllerListener()) .setOldController(fresco.getDraweeController()) .build(); }
private void setUri(SimpleDraweeView draweeView, Uri uri, boolean retryEnabled) { draweeView.setController(Fresco.newDraweeControllerBuilder() .setOldController(draweeView.getController()) .setTapToRetryEnabled(retryEnabled) .setUri(uri) .build()); }
public void init(final Context context) { final int MAX_HEAP_SIZE = (int) Runtime.getRuntime().maxMemory(); final int MAX_DISK_CACHE_SIZE = 300 * ByteConstants.MB; final int MAX_MEMORY_CACHE_SIZE = MAX_HEAP_SIZE / 3; final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, MAX_MEMORY_CACHE_SIZE, Integer.MAX_VALUE, Integer.MAX_VALUE); DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context) .setMaxCacheSize(MAX_DISK_CACHE_SIZE)//最大缓存 .setBaseDirectoryName("udesk")//子目录 .setBaseDirectoryPathSupplier(new Supplier<File>() { @Override public File get() { return UdeskUtil.getExternalCacheDir(context); } }) .build(); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context) .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig(diskCacheConfig) .setDownsampleEnabled(true) .setBitmapsConfig(Bitmap.Config.RGB_565) .build(); Fresco.initialize(context, config); }
@Override public View getView(int position, View convertView, ViewGroup parent) { InstrumentedDraweeView draweeView; if (convertView == null) { final Context context = parent.getContext(); GenericDraweeHierarchy gdh = DraweeUtil.createDraweeHierarchy(context, mConfig); draweeView = new InstrumentedDraweeView(context, gdh, mConfig); SizeUtil.setConfiguredSize(parent, draweeView, mConfig); draweeView.setPadding(mPaddingPx, mPaddingPx, mPaddingPx, mPaddingPx); } else { draweeView = (InstrumentedDraweeView) convertView; } final Uri uri = getItem(position); draweeView.initInstrumentation(uri.toString(), mPerfListener); ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder .newBuilderWithSource(uri) .setResizeOptions( new ResizeOptions( draweeView.getLayoutParams().width, draweeView.getLayoutParams().height)); PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig); // Create the Builder PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()); if (mConfig.reuseOldController) { builder.setOldController(draweeView.getController()); } if (mConfig.instrumentationEnabled) { draweeView.setListener(builder); } draweeView.setController(builder.build()); return draweeView; }
@Override public void onCreate() { super.onCreate(); Fresco.initialize(this); Twitter.initialize(this); DCSharedPreferences.initialize(this); }
@OnCreateLayout static ComponentLayout onCreateLayout(ComponentContext c, @Prop SingleBannerSection payload) { final DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(payload.banner().imageUrl()) .build(); return Column.create(c) .child( Text.create(c) .text(payload.title()) .glyphWarming(true) .textSizeSp(16) .withLayout() .paddingDip(TOP,8) .paddingDip(BOTTOM,4) .heightDip(44) ) .paddingDip(LEFT, 8) .paddingDip(RIGHT, 8) .child( FrescoImage.create(c) .controller(controller) .actualImageScaleType( ScalingUtils .ScaleType .CENTER_CROP ) .withLayout() .heightPx((int) (DisplayUtil.getScreenWidth(c) / payload.banner().ratio())) ) .clickHandler(SingleBannerComponent.onClick(c)) .build(); }
/** * 自定义控件调用该方法显示 * @param draweeView * @param uri * @param resizeOptions * @param defaultDrawable * @param scaleType */ public void disPlay(DraweeView draweeView, Uri uri, String lowResUri, ResizeOptions resizeOptions, Drawable defaultDrawable, ScalingUtils.ScaleType scaleType, ControllerListener controllerListener) { // System.out.println(draweeView.hasHierarchy()); if (!draweeView.hasHierarchy()) { setDefaultHierarchy(draweeView,defaultDrawable,scaleType); } ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (UriUtil.isNetworkUri(uri)) { imageRequestBuilder.setProgressiveRenderingEnabled(true); } else { imageRequestBuilder.setLocalThumbnailPreviewsEnabled(true); imageRequestBuilder.setProgressiveRenderingEnabled(false); if ( resizeOptions != null ) { imageRequestBuilder.setResizeOptions(resizeOptions); } } // imageRequestBuilder.setAutoRotateEnabled(true); // imageRequestBuilder.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()) .setOldController(draweeView.getController()) .setLowResImageRequest(ImageRequest.fromUri(lowResUri)) .setControllerListener(controllerListener) .build(); draweeView.setController(draweeController); }
@Override public void clear(Context ctx, FrescoImageConfig config) { Fresco.getImagePipeline().clearMemoryCaches(); Fresco.getImagePipeline().clearCaches(); Fresco.getImagePipeline().clearDiskCaches(); String url = appendUrl(config.getUrl()); ImagePipeline imagePipeline = Fresco.getImagePipeline(); Uri uri = Uri.parse(url); imagePipeline.evictFromMemoryCache(uri); }
@Override public void setImageURI(Uri uri) { ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri) .setAutoRotateEnabled(true) .setLocalThumbnailPreviewsEnabled(true) .setResizeOptions(resizeOptions); ImageRequest request = imageRequestBuilder.build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setAutoPlayAnimations(true) .setImageRequest(request) .setTapToRetryEnabled(false)//加载失败时点击重新加载 .setOldController(getController()) .build(); setController(controller); }
@Override public void onCreate() { super.onCreate(); MultiDex.install(this); //init firebase FirebaseDatabase.getInstance().setPersistenceEnabled(true); Fresco.initialize(this, ImagePipelineConfigFactory.getImagePipelineConfig(this)); }