當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSource.getResult方法代碼示例

本文整理匯總了Java中com.facebook.datasource.DataSource.getResult方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSource.getResult方法的具體用法?Java DataSource.getResult怎麽用?Java DataSource.getResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.facebook.datasource.DataSource的用法示例。


在下文中一共展示了DataSource.getResult方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onNewResultImpl

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
@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);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:BaseBitmapDataSubscriber.java

示例2: verifyState

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
private void verifyState(
    boolean isFinished,
    boolean hasResult,
    CloseableReference<Object> resultRef,
    boolean hasFailed,
    Throwable failureCause) {
  DataSource<CloseableReference<Object>> dataSource = mDataSource;
  assertEquals("isFinished", isFinished, dataSource.isFinished());
  assertEquals("hasResult", hasResult, dataSource.hasResult());
  CloseableReference<Object> dataSourceRef = dataSource.getResult();
  assertReferencesSame("getResult", resultRef, dataSourceRef);
  CloseableReference.closeSafely(dataSourceRef);
  assertEquals("hasFailed", hasFailed, dataSource.hasFailed());
  if (failureCause == NPE) {
    assertNotNull("failure", dataSource.getFailureCause());
    assertSame("failure", NullPointerException.class, dataSource.getFailureCause().getClass());
  } else {
    assertSame("failure", failureCause, dataSource.getFailureCause());
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:CloseableProducerToDataSourceAdapterTest.java

示例3: onRun

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
@Override
public void onRun() throws Throwable {
  Log.i(TAG, "RUNNING UploadJob for Item["+itemId+"] Uri["+uri.toString()+"]");

  if(MediaUtils.isPhoto(UriUtils.extractMimeType(weakReference.get(), uri))) {
    DataSource<CloseableReference<CloseableImage>> dataSource = Fresco.getImagePipeline().fetchDecodedImage(ImageRequest.fromUri(uri), weakReference.get());
    Throwable failureCause = dataSource.getFailureCause();
    if (failureCause != null) {
      throw failureCause;
    }

    CloseableReference<CloseableImage> result = dataSource.getResult();
    if (result != null) {
      CloseableImage closeableImage = result.get();
      if (closeableImage instanceof CloseableBitmap) {
        Bitmap bitmap = ((CloseableBitmap) closeableImage).getUnderlyingBitmap();
        uploadFile(createImageTempFile(bitmap));
      }
    }
  }else{
    uploadFile(new File(uri.getPath()));
  }
}
 
開發者ID:bnsantos,項目名稱:android-upload-service,代碼行數:24,代碼來源:UploadJob.java

示例4: onNewResultImpl

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
@Override
protected void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
    if (!dataSource.isFinished() || dataSource.getResult() == null) {
        return;
    }

    // if we try to retrieve image file by cache key, it will return null
    // so we need to create a temp file, little bit hack :(
    PooledByteBufferInputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = new PooledByteBufferInputStream(dataSource.getResult().get());
        outputStream = new FileOutputStream(mTempFile);
        IOUtils.copy(inputStream, outputStream);

        mFinished = true;
        onSuccess(mTempFile);
    } catch (IOException e) {
        onFail(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(outputStream);
    }
}
 
開發者ID:love-311,項目名稱:BigImageViewer-master,代碼行數:25,代碼來源:ImageDownloadSubscriber.java

示例5: isCached

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
/**
 * 圖片是否已經存在了
 */
public static boolean isCached(Context context, Uri uri) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<Boolean> dataSource = imagePipeline.isInDiskCache(uri);
    if (dataSource == null) {
        return false;
    }
    ImageRequest imageRequest = ImageRequest.fromUri(uri);
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(imageRequest, context);
    BinaryResource resource = ImagePipelineFactory.getInstance()
            .getMainFileCache().getResource(cacheKey);
    return resource != null && dataSource.getResult() != null && dataSource.getResult();
}
 
開發者ID:CarGuo,項目名稱:FrescoUtils,代碼行數:17,代碼來源:FrescoHelper.java

示例6: onNewResultImpl

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
@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()){
                onFailure(dataSource);
            }else {
                onNewResultImpl(bitmap,dataSource);
            }
            return;
        }

//        //如果bitmap為空
//        File cacheFile  = ImageLoader.getActualLoader().getFileFromDiskCache(finalUrl);
//        if(cacheFile ==null){
//            onFailure(dataSource);
//            return;
//        }
//        //還要判斷文件是不是gif格式的
//        if (!"gif".equalsIgnoreCase(MyUtil.getRealType(cacheFile))){
//            onFailure(dataSource);
//            return;
//        }
//        Bitmap bitmapGif = GifUtils.getBitmapFromGifFile(cacheFile);//拿到gif第一幀的bitmap
//        if(width>0 && height >0) {
//            bitmapGif = MyUtil.compressBitmap(bitmapGif, true, width, height);//將bitmap壓縮到指定寬高。
//        }

//        if (bitmapGif != null) {
//            onNewResultImpl(bitmap,dataSource);
//        } else {
//            onFailure(dataSource);
//        }




       /* try {
            onNewResultImpl(bitmap);
        } finally {
            //CloseableReference.closeSafely(closeableImageRef);
        }*/
    }
 
開發者ID:BaoBaoJianqiang,項目名稱:CustomListView,代碼行數:55,代碼來源:BaseBitmapDataSubscriber.java

示例7: onNewResult

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
@Override
public void onNewResult(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    // only interested in final image, no need to close the dataSource
    return;
  }

  try {
    if (mDataSource != dataSource) {
      // Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
      return;
    }

    mDataSource = null;

    CloseableReference<CloseableImage> imageReference = dataSource.getResult();
    if (imageReference == null) {
      // Shouldn't ever happen, but let's be safe (dataSource got closed by callback still fired?)
      return;
    }

    CloseableImage image = imageReference.get();
    if (!(image instanceof CloseableBitmap)) {
      // only bitmaps are supported
      imageReference.close();
      return;
    }

    mImageRef = imageReference;

    Bitmap bitmap = getBitmap();
    if (bitmap == null) {
      // Shouldn't ever happen, but let's be safe.
      return;
    }

    BitmapUpdateListener listener = Assertions.assumeNotNull(mBitmapUpdateListener);
    listener.onBitmapReady(bitmap);
    listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD);
    listener.onImageLoadEvent(ImageLoadEvent.ON_LOAD_END);
  } finally {
    dataSource.close();
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:45,代碼來源:PipelineRequestHelper.java

示例8: getBitmapFromCache

import com.facebook.datasource.DataSource; //導入方法依賴的package包/類
/**
 * 從Fresco的緩存中獲取Bitmap
 * @return
 */
private Bitmap getBitmapFromCache(String imgUrl){

    Bitmap bm = null;

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder
            .newBuilderWithSource(Uri.parse(imgUrl))
            .build();


    DataSource<CloseableReference<CloseableImage>> dataSource =
            imagePipeline.fetchImageFromBitmapCache(request, this);
    try{
        CloseableReference<CloseableImage> imageReference = dataSource.getResult();
        if(imageReference != null){
            try{
                // do something
                CloseableImage image = imageReference.get();
                if(image instanceof CloseableBitmap){

                    Bitmap bitmap = ((CloseableBitmap)image).getUnderlyingBitmap();

                    Log.i(TAG, "getBitmapFromCache>>> get cached bitmap success");
                    bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight());

                    return bm;
                }
            }finally {
                CloseableReference.closeSafely(imageReference);
            }
        }else {
            // cache miss
            return null;
        }
    }finally {
        dataSource.close();
    }

    return null;
}
 
開發者ID:zjupure,項目名稱:SneezeReader,代碼行數:45,代碼來源:ShareActivity.java


注:本文中的com.facebook.datasource.DataSource.getResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。