@Override public void produceResults( final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) { final ImageRequest imageRequest = producerContext.getImageRequest(); ProgressiveDecoder progressiveDecoder; if (!UriUtil.isNetworkUri(imageRequest.getSourceUri())) { progressiveDecoder = new LocalImagesProgressiveDecoder( consumer, producerContext, mDecodeCancellationEnabled); } else { ProgressiveJpegParser jpegParser = new ProgressiveJpegParser(mByteArrayPool); progressiveDecoder = new NetworkImagesProgressiveDecoder( consumer, producerContext, jpegParser, mProgressiveJpegConfig, mDecodeCancellationEnabled); } mInputProducer.produceResults(progressiveDecoder, producerContext); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mExecutor = new TestExecutorService(new FakeClock()); mQualifiedResourceFetchProducer = new QualifiedResourceFetchProducer( mExecutor, mPooledByteBufferFactory, mContentResolver); mContentUri = UriUtil.getUriForQualifiedResource(PACKAGE_NAME, RESOURCE_ID); mProducerContext = new SettableProducerContext( mImageRequest, REQUEST_ID, mProducerListener, CALLER_CONTEXT, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM); when(mImageRequest.getSourceUri()).thenReturn(mContentUri); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(UriUtil.class, MediaUtils.class); ProducerFactory producerFactory = mock(ProducerFactory.class, RETURNS_MOCKS); mProducerSequenceFactory = new ProducerSequenceFactory( RuntimeEnvironment.application.getContentResolver(), producerFactory, null, true, false, null, false, false, false); when(mImageRequest.getLowestPermittedRequestLevel()) .thenReturn(ImageRequest.RequestLevel.FULL_FETCH); mUri = Uri.parse("http://dummy"); when(mImageRequest.getSourceUri()).thenReturn(mUri); when(MediaUtils.extractMime(mUri.getPath())).thenReturn(mDummyMime); when(MediaUtils.isVideo(mDummyMime)).thenReturn(false); }
@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); }
private Observable<String> getNetworkThumbObservable(NSearchRequest request){ return Observable.concat(new Observable<String>() { @Override protected void subscribeActual(Observer<? super String> observer) { String imageUrl = SPUtil.getValue(APlayerApplication.getContext(),"HttpCache",request.getKey(),""); if(!TextUtils.isEmpty(imageUrl) && UriUtil.isNetworkUri(Uri.parse(imageUrl))){ observer.onNext(imageUrl); } observer.onComplete(); }},Observable.just(isAutoDownloadCover()) .filter(aBoolean -> aBoolean) .flatMap(aBoolean -> HttpClient.getNeteaseApiservice() .getNeteaseSearch(request.getKey(), 0, 1, request.getNType()) .map(responseBody -> parseNetworkImageUrl(request, responseBody)) .firstElement().toObservable())); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_end, container, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SimpleDraweeView draweeView = (SimpleDraweeView) view.findViewById(R.id.img); Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res" .path(String.valueOf(R.drawable.img_test)) .build(); draweeView.setImageURI(uri); } return view; }
public static String getUriString(String reel_title_pic){ int [] bannerResArray = new int[]{ R.drawable.banner, R.drawable.banner3 }; Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res" .path(String.valueOf( bannerResArray[(int)(Math.random()*2)] // R.drawable.banner )) .build(); String uriString; uriString = uri.toString(); if(!reel_title_pic.endsWith("http") &&!TextUtils.isEmpty(reel_title_pic)){ uriString = Uri.fromFile(new File(reel_title_pic)).toString(); } return uriString; }
public String getUriString(){ int [] bannerResArray = new int[]{ R.drawable.banner, R.drawable.banner3 }; Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res" .path(String.valueOf( bannerResArray[(int)(id%2)] // R.drawable.banner )) .build(); String uriString; uriString = uri.toString(); if(reel_title_pic.startsWith("http") ){ uriString = reel_title_pic; }else if(!TextUtils.isEmpty(reel_title_pic)){ uriString = Uri.fromFile(new File(reel_title_pic)).toString(); } return uriString; }
/** Performs validation. */ protected void validate() { // make sure that the source uri is set correctly. if (mSourceUri == null) { throw new BuilderException("Source must be set!"); } // For local resource we require caller to specify statically generated resource id as a path. if (UriUtil.isLocalResourceUri(mSourceUri)) { if (!mSourceUri.isAbsolute()) { throw new BuilderException("Resource URI path must be absolute."); } if (mSourceUri.getPath().isEmpty()) { throw new BuilderException("Resource URI must not be empty"); } try { Integer.parseInt(mSourceUri.getPath().substring(1)); } catch (NumberFormatException ignored) { throw new BuilderException("Resource URI path must be a resource id."); } } // For local asset we require caller to specify absolute path of an asset, which will be // resolved by AssetManager relative to configured asset folder of an app. if (UriUtil.isLocalAssetUri(mSourceUri) && !mSourceUri.isAbsolute()) { throw new BuilderException("Asset URI path must be absolute."); } }
/** * This is a utility method which returns the type of Uri * @param uri The Uri to test * @return The type of the given Uri if available or SOURCE_TYPE_UNKNOWN if not */ private static @SourceUriType int getSourceUriType(final Uri uri) { if (uri == null) { return SOURCE_TYPE_UNKNOWN; } if (UriUtil.isNetworkUri(uri)) { return SOURCE_TYPE_NETWORK; } else if (UriUtil.isLocalFileUri(uri)) { if (MediaUtils.isVideo(MediaUtils.extractMime(uri.getPath()))) { return SOURCE_TYPE_LOCAL_VIDEO_FILE; } else { return SOURCE_TYPE_LOCAL_IMAGE_FILE; } } else if (UriUtil.isLocalContentUri(uri)) { return SOURCE_TYPE_LOCAL_CONTENT; } else if (UriUtil.isLocalAssetUri(uri)) { return SOURCE_TYPE_LOCAL_ASSET; } else if (UriUtil.isLocalResourceUri(uri)) { return SOURCE_TYPE_LOCAL_RESOURCE; } else if (UriUtil.isDataUri(uri)) { return SOURCE_TYPE_DATA; } else if (UriUtil.isQualifiedResourceUri(uri)) { return SOURCE_TYPE_QUALIFIED_RESOURCE; } else { return SOURCE_TYPE_UNKNOWN; } }
@Override protected EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOException { Uri uri = imageRequest.getSourceUri(); if (UriUtil.isLocalContactUri(uri)) { final InputStream inputStream; if (uri.toString().endsWith("/photo")) { inputStream = mContentResolver.openInputStream(uri); } else { inputStream = ContactsContract.Contacts.openContactPhotoInputStream(mContentResolver, uri); if (inputStream == null) { throw new IOException("Contact photo does not exist: " + uri); } } // If a Contact URI is provided, use the special helper to open that contact's photo. return getEncodedImage( inputStream, EncodedImage.UNKNOWN_STREAM_SIZE); } if (UriUtil.isLocalCameraUri(uri)) { EncodedImage cameraImage = getCameraImage(uri); if (cameraImage != null) { return cameraImage; } } return getEncodedImage( mContentResolver.openInputStream(uri), EncodedImage.UNKNOWN_STREAM_SIZE); }
@Nullable private String getLocalFilePath(ImageRequest imageRequest) { Uri uri = imageRequest.getSourceUri(); if (UriUtil.isLocalFileUri(uri)) { return imageRequest.getSourceFile().getPath(); } else if (UriUtil.isLocalContentUri(uri)) { String selection = null; String[] selectionArgs = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && "com.android.providers.media.documents".equals(uri.getAuthority())) { String documentId = DocumentsContract.getDocumentId(uri); uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; selection = MediaStore.Video.Media._ID + "=?"; selectionArgs = new String[] {documentId.split(":")[1]}; } Cursor cursor = mContentResolver.query( uri, new String[] {MediaStore.Video.Media.DATA}, selection, selectionArgs, null); try { if (cursor != null && cursor.moveToFirst()) { return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); } } finally { if (cursor != null) { cursor.close(); } } } return null; }
@Override protected EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOException { Uri uri = imageRequest.getSourceUri(); if (UriUtil.isLocalCameraUri(uri)) { EncodedImage cameraImage = getCameraImage(uri, imageRequest.getResizeOptions()); if (cameraImage != null) { return cameraImage; } } return null; }
private <T> DataSource<CloseableReference<T>> submitFetchRequest( Producer<CloseableReference<T>> producerSequence, ImageRequest imageRequest, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, Object callerContext) { final RequestListener requestListener = getRequestListenerForRequest(imageRequest); try { ImageRequest.RequestLevel lowestPermittedRequestLevel = ImageRequest.RequestLevel.getMax( imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit); SettableProducerContext settableProducerContext = new SettableProducerContext( imageRequest, generateUniqueFutureId(), requestListener, callerContext, lowestPermittedRequestLevel, /* isPrefetch */ false, imageRequest.getProgressiveRenderingEnabled() || imageRequest.getMediaVariations() != null || !UriUtil.isNetworkUri(imageRequest.getSourceUri()), imageRequest.getPriority()); return CloseableProducerToDataSourceAdapter.create( producerSequence, settableProducerContext, requestListener); } catch (Exception exception) { return DataSources.immediateFailedDataSource(exception); } }
public FrescoLoader load(int resourceId) { return load( new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(resourceId)) .build() ); }
public FrescoLoader lowerLoad(int resourceId) { return lowerLoad( new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(resourceId)) .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); }
public Uri getUri() { if (resUri == null) { if (resId == 0) { return null; } return UriUtil.getUriForResourceId(resId); } return resUri; }
private static @Nullable Uri getResourceDrawableUri(Context context, @Nullable String name) { if (name == null || name.isEmpty()) { return null; } name = name.toLowerCase(Locale.getDefault()).replace("-", "_"); int resId = context.getResources().getIdentifier( name, "drawable", context.getPackageName()); return new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(resId)) .build(); }
private boolean shouldResize(ImageSource imageSource) { // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html#_ // We resize here only for images likely to be from the device's camera, where the app developer // has no control over the original size if (mResizeMethod == ImageResizeMethod.AUTO) { return UriUtil.isLocalContentUri(imageSource.getUri()) || UriUtil.isLocalFileUri(imageSource.getUri()); } else if (mResizeMethod == ImageResizeMethod.RESIZE) { return true; } else { return false; } }
public Uri getResourceDrawableUri(Context context, @Nullable String name) { int resId = getResourceDrawableId(context, name); return resId > 0 ? new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(resId)) .build() : Uri.EMPTY; }
@Override public void displayImage(Activity activity, String path, GFImageView imageView, Drawable defaultDrawable, int width, int height) { Resources resources = context.getResources(); GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources) .setFadeDuration(300) .setPlaceholderImage(defaultDrawable) .setFailureImage(defaultDrawable) .setProgressBarImage(new ProgressBarDrawable()) .build(); final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context); imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() { @Override public void onDetach() { draweeHolder.onDetach(); } @Override public void onAttach() { draweeHolder.onAttach(); } @Override public boolean verifyDrawable(Drawable dr) { if (dr == draweeHolder.getHierarchy().getTopLevelDrawable()) { return true; } return false; } }); Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_FILE_SCHEME) .path(path) .build(); displayImage(uri, new ResizeOptions(width, height), imageView, draweeHolder); }
public static void initializeDefaultArt() { try { defaultUri = new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(R.drawable.default_art)) .build(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onBindViewHolder(ViewHolder holder, int position) { SimpleDraweeView draweeView = holder.imgView; Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res" .path(String.valueOf(R.drawable.img_test)) .build(); draweeView.setImageURI(uri); }
public void displayImage(Context context, String path, GFImageView imageView, int width, int height) { Resources resources = context.getResources(); Drawable defaultDrawable = ContextCompat.getDrawable(context, R.drawable.common_crop_image_placeholder); // imageView.setImageDrawable(defaultDrawable); imageView.setImageDrawable(null); GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources) .setFadeDuration(300) .setPlaceholderImage(defaultDrawable) .setFailureImage(defaultDrawable) .setProgressBarImage(new ProgressBarDrawable()) .build(); final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context); imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() { @Override public void onDetach() { draweeHolder.onDetach(); } @Override public void onAttach() { draweeHolder.onAttach(); } @Override public boolean verifyDrawable(Drawable dr) { if (dr == draweeHolder.getHierarchy().getTopLevelDrawable()) { return true; } return false; } }); Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_FILE_SCHEME) .path(path) .build(); displayImage(uri, new ResizeOptions(width, height), imageView, draweeHolder); }
private static Uri getResourceDrawableUri(Context context, @Nullable String name) { int resId = getResourceDrawableId(context, name); return resId > 0 ? new Uri.Builder() .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) .path(String.valueOf(resId)) .build() : Uri.EMPTY; }