Java Code Examples for com.facebook.datasource.DataSource#isFinished()
The following examples show how to use
com.facebook.datasource.DataSource#isFinished() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseBitmapDataSubscriber.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { if (!dataSource.isFinished()) { return; } CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult(); Bitmap bitmap = null; if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) { bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap(); } try { onNewResultImpl(bitmap); } finally { CloseableReference.closeSafely(closeableImageRef); } }
Example 2
Source File: FrescoControllerImpl.java From fresco with MIT License | 6 votes |
@Override public void onNewResult( FrescoState frescoState, DataSource<CloseableReference<CloseableImage>> dataSource) { if (dataSource != null && !dataSource.isClosed()) { final boolean shouldClose = mFrescoContext.getExperiments().closeDatasourceOnNewResult() && dataSource.isFinished(); final CloseableReference<CloseableImage> result = dataSource.getResult(); try { frescoState.setImageFetched(true); if (frescoState.isAttached()) { displayResultOrError(frescoState, result, false, dataSource); } } finally { CloseableReference.closeSafely(result); if (shouldClose) { dataSource.close(); } } } }
Example 3
Source File: BaseBitmapReferenceDataSubscriber.java From fresco with MIT License | 6 votes |
@Override public void onNewResultImpl(@Nonnull DataSource<CloseableReference<CloseableImage>> dataSource) { if (!dataSource.isFinished()) { return; } CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult(); CloseableReference<Bitmap> bitmapReference = null; if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableStaticBitmap) { bitmapReference = ((CloseableStaticBitmap) closeableImageRef.get()).cloneUnderlyingBitmapReference(); } try { onNewResultImpl(bitmapReference); } finally { CloseableReference.closeSafely(bitmapReference); CloseableReference.closeSafely(closeableImageRef); } }
Example 4
Source File: BaseBitmapDataSubscriber.java From fresco with MIT License | 6 votes |
@Override public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { if (!dataSource.isFinished()) { return; } CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult(); Bitmap bitmap = null; if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) { bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap(); } try { onNewResultImpl(bitmap); } finally { CloseableReference.closeSafely(closeableImageRef); } }
Example 5
Source File: MyBaseBitmapDataSubscriber.java From ImageLoader with Apache License 2.0 | 5 votes |
@Override public void onNewResult(DataSource<CloseableReference<CloseableImage>> dataSource) { // isFinished() should be checked before calling onNewResultImpl(), otherwise // there would be a race condition: the final data source result might be ready before // we call isFinished() here, which would lead to the loss of the final result // (because of an early dataSource.close() call). final boolean shouldClose = dataSource.isFinished(); try { onNewResultImpl(dataSource); } finally { if (shouldClose) { dataSource.close(); } } }
Example 6
Source File: MyBaseBitmapDataSubscriber.java From ImageLoader with Apache License 2.0 | 4 votes |
@Override public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) { if (!dataSource.isFinished()) { return; } CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult(); Bitmap bitmap = null; if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) { bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap(); } if(bitmap!=null ){ if(bitmap.isRecycled()){ onFail(new Throwable("bitmap.isRecycled")); }else { onNewResultImpl(bitmap,dataSource); } return; } //如果bitmap为空 Log.e("onNewResultImpl","finalUrl :"+finalUrl); File cacheFile = ImageLoader.getActualLoader().getFileFromDiskCache(finalUrl); if(cacheFile ==null){ onFail(new Throwable("file cache is null:"+finalUrl)); return; } //还要判断文件是不是gif格式的 if (!"gif".equalsIgnoreCase(MyUtil.getRealType(cacheFile))){ onFail(new Throwable("file cache is not gif:"+finalUrl)); return; } Bitmap bitmapGif = GifUtils.getBitmapFromGifFile(cacheFile);//拿到gif第一帧的bitmap if(width>0 && height >0) { bitmapGif = MyUtil.compressBitmap(bitmapGif, false, width, height);//将bitmap压缩到指定宽高。 } if (bitmapGif != null) { onNewResultImpl(bitmapGif,dataSource); } else { onFail(new Throwable("can not create bitmap from gif file:"+cacheFile.getAbsolutePath())); } /* try { onNewResultImpl(bitmap); } finally { //CloseableReference.closeSafely(closeableImageRef); }*/ }
Example 7
Source File: ListDataSource.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
@Override public void onNewResult(DataSource<CloseableReference<T>> dataSource) { if (dataSource.isFinished() && tryFinish()) { ListDataSource.this.onDataSourceFinished(); } }
Example 8
Source File: AbstractDraweeController.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
protected int getProgress(DataSource<T> dataSource, T image) { // IMPORTANT: At the moment, GenericDraweeHierarchy hides progressbar only when progress // reaches 100. Once we implement more accurate estimate, we will have to explicitly specify // whether or not should the progressbar be visible. return dataSource.isFinished() ? 100 : 50; }
Example 9
Source File: ListDataSource.java From fresco with MIT License | 4 votes |
@Override public void onNewResult(DataSource<CloseableReference<T>> dataSource) { if (dataSource.isFinished() && tryFinish()) { ListDataSource.this.onDataSourceFinished(); } }