com.squareup.picasso.RequestCreator Java Examples
The following examples show how to use
com.squareup.picasso.RequestCreator.
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: ImageLoader.java From KlyphMessenger with MIT License | 6 votes |
public static void displayNoScaling(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); requestCreator.into(imageView, listener); }
Example #2
Source File: PicassoLoader.java From ImageLoader with Apache License 2.0 | 6 votes |
@Nullable private RequestCreator getDrawableTypeRequest(SingleConfig config) { RequestCreator request = null; Picasso picasso = getPicasso(); if(!TextUtils.isEmpty(config.getUrl())){ request= picasso.load(MyUtil.appendUrl(config.getUrl())); paths.add(config.getUrl()); }else if(!TextUtils.isEmpty(config.getFilePath())){ request= picasso.load(new File(config.getFilePath())); paths.add(config.getFilePath()); }else if(!TextUtils.isEmpty(config.getContentProvider())){ request= picasso.load(Uri.parse(config.getContentProvider())); paths.add(config.getContentProvider()); }else if(config.getResId()>0){ request= picasso.load(config.getResId()); paths.add(config.getResId()+""); } return request; }
Example #3
Source File: FantasyFragment.java From catnut with MIT License | 6 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { boolean fitXY = getArguments().getBoolean(FIT_XY); if (getActivity() instanceof HelloActivity) { if (!((HelloActivity) getActivity()).isNetworkAvailable()) { if (fitXY) { Toast.makeText(getActivity(), R.string.network_unavailable, Toast.LENGTH_SHORT).show(); mFantasy.setImageResource(R.drawable.default_fantasy); return; // 没有网络,直接结束第一张fantasy } } } RequestCreator creator = Picasso.with(getActivity()).load(mUrl); if (fitXY) { creator.placeholder(R.drawable.default_fantasy); } creator.error(R.drawable.error) .into(target); }
Example #4
Source File: ImageLoader.java From Contacts with MIT License | 6 votes |
public static void displayNoScaling(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); requestCreator.into(imageView, listener); }
Example #5
Source File: ImageLoader.java From Klyph with MIT License | 6 votes |
public static void displayNoScaling(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); requestCreator.into(imageView, listener); }
Example #6
Source File: BrowseFragment.java From Amphitheatre with Apache License 2.0 | 6 votes |
private void updateBackground(String url) { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); RequestCreator requestCreator = Picasso.with(getActivity()) .load(url) .placeholder(R.drawable.placeholder) .resize(mMetrics.widthPixels, mMetrics.heightPixels) .centerCrop() .skipMemoryCache(); switch(Enums.BlurState.valueOf(sharedPrefs.getString(Constants.BACKGROUND_BLUR, ""))) { case ON: requestCreator = requestCreator.transform(mBlurTransformation); break; } requestCreator.into(mBackgroundTarget); }
Example #7
Source File: PicassoLoaderProcessor.java From ImageLoaderProcessor with Apache License 2.0 | 6 votes |
@Override public ILoaderProxy loadImage(View view, String path) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; //判断缓存中是否已经缓存过该图片,有则直接拿Bitmap,没有则直接调用Glide加载并缓存Bitmap Bitmap bitmap = LruCacheUtils.getInstance().getBitmapFromMemCache(path); if (bitmap != null) { imageView.setImageBitmap(bitmap); } else { RequestCreator requestCreator = getPicasso().load(path); loadOptions(requestCreator).into(imageView); } } return obtain(); }
Example #8
Source File: BoxingPicassoLoader.java From kcanotify_h5-master with GNU General Public License v3.0 | 6 votes |
@Override public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, final IBoxingCallback callback) { String path = "file://" + absPath; RequestCreator creator = Picasso.with(img.getContext()) .load(path); if (width > 0 && height > 0) { creator.transform(new BitmapTransform(width, height)); } creator.into(img, new Callback() { @Override public void onSuccess() { if (callback != null) { callback.onSuccess(); } } @Override public void onError() { if (callback != null) { callback.onFail(null); } } }); }
Example #9
Source File: PicassoLoaderProcessor.java From ImageLoaderProcessor with Apache License 2.0 | 6 votes |
private RequestCreator loadOptions(RequestCreator requestCreator) { if (options == null) { return requestCreator; } if (options.targetHeight > 0 && options.targetWidth > 0) { requestCreator.resize(options.targetWidth, options.targetHeight); } if (options.isCenterInside) { requestCreator.centerInside(); } else if (options.isCenterCrop) { requestCreator.centerCrop(); } if (options.config != null) { requestCreator.config(options.config); } if (options.errorResId != 0) { requestCreator.error(options.errorResId); } if (options.placeholderResId != 0) { requestCreator.placeholder(options.placeholderResId); } if (options.bitmapAngle != 0) { requestCreator.transform(new PicassoTransformation(options.bitmapAngle)); } return requestCreator; }
Example #10
Source File: BoxingPicassoLoader.java From boxing with Apache License 2.0 | 6 votes |
@Override public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, final IBoxingCallback callback) { String path = "file://" + absPath; RequestCreator creator = Picasso.with(img.getContext()) .load(path); if (width > 0 && height > 0) { creator.transform(new BitmapTransform(width, height)); } creator.into(img, new Callback() { @Override public void onSuccess() { if (callback != null) { callback.onSuccess(); } } @Override public void onError() { if (callback != null) { callback.onFail(null); } } }); }
Example #11
Source File: PicassoBitmapLoader.java From scissors with Apache License 2.0 | 6 votes |
@Override public void load(@Nullable Object model, @NonNull ImageView imageView) { final RequestCreator requestCreator; if (model instanceof Uri || model == null) { requestCreator = picasso.load((Uri) model); } else if (model instanceof String) { requestCreator = picasso.load((String) model); } else if (model instanceof File) { requestCreator = picasso.load((File) model); } else if (model instanceof Integer) { requestCreator = picasso.load((Integer) model); } else { throw new IllegalArgumentException("Unsupported model " + model); } requestCreator .skipMemoryCache() .transform(transformation) .into(imageView); }
Example #12
Source File: mImage.java From intra42 with Apache License 2.0 | 6 votes |
public static void setPicasso(Uri url, ImageView imageView, @DrawableRes int placeHolder) { Picasso picasso = Picasso.get(); if (BuildConfig.DEBUG) picasso.setLoggingEnabled(true); RequestCreator requestCreator = picasso.load(url); if (placeHolder != 0) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { requestCreator.placeholder(placeHolder); requestCreator.error(placeHolder); } else { Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), placeHolder); requestCreator.placeholder(drawable); requestCreator.error(drawable); } } requestCreator.into(imageView); }
Example #13
Source File: ImageLoaderManager.java From Android-MVVMFramework with Apache License 2.0 | 6 votes |
public void displayImage(ImageView view, String url) { if(url == null) { view.setImageResource(R.mipmap.ic_launcher); return; } else if (TextUtils.isEmpty(url)) {//空图片显示 view.setImageResource(R.mipmap.ic_launcher); return; } RequestCreator creator = imageLoader .load(url) .placeholder(R.mipmap.ic_launcher) .error(R.mipmap.ic_launcher) .config(Bitmap.Config.RGB_565);//不透明的图片使用减少内存 if (view.getWidth() == 0 && view.getHeight() == 0){ } else { creator.centerCrop() .resize(view.getWidth(), view.getHeight()); } creator.into(view); }
Example #14
Source File: PicassoHelper.java From android_sdk_demo_apps with Apache License 2.0 | 6 votes |
/** * Load an agent's or visitor's avatar into an {@link ImageView}. * <br> * Images get transformed into circular shaped. If there's no or no valid * url to the image {@code R.drawable.ic_chat_default_avatar} will be displayed. * * @param imageView the {@link ImageView} * @param avatarUri uri as a {@link String} to avatar image */ static void loadAvatarImage(@NonNull final ImageView imageView, @Nullable final String avatarUri) { final Picasso picasso = Picasso.with(imageView.getContext()); final RequestCreator requestCreator; if(StringUtils.hasLength(avatarUri)) { requestCreator = picasso .load(avatarUri).error(DEFAULT_AVATAR) .error(DEFAULT_AVATAR) .placeholder(DEFAULT_AVATAR); } else { requestCreator = picasso .load(DEFAULT_AVATAR); } requestCreator .transform(new CircleTransform()) .into(imageView); }
Example #15
Source File: CellRepo.java From AndroidStarterAlt with Apache License 2.0 | 6 votes |
@Override public void bind(@NonNull final RepoEntity poRepo) { mTextView.setText(poRepo.getUrl()); final RequestCreator loRequest = mPicasso.load(poRepo.getAvatarUrl()); if (loRequest != null) { loRequest .placeholder(R.drawable.git_icon) .error(R.drawable.git_icon) .into(mImageViewAvatar); } setOnClickListener((final View poView) -> notifyItemAction(ROW_PRESSED) ); }
Example #16
Source File: ElementDescriptorView.java From px-android with MIT License | 6 votes |
public void update(@NonNull final ElementDescriptorView.Model model) { title.setText(model.getTitle()); if (model.hasSubtitle()) { subtitle.setVisibility(VISIBLE); subtitle.setText(model.getSubtitle()); } else { subtitle.setVisibility(GONE); } final Picasso picasso = PicassoDiskLoader.get(getContext()); final RequestCreator requestCreator; if (TextUtil.isNotEmpty(model.getUrlIcon())) { requestCreator = picasso.load(model.getUrlIcon()); } else { requestCreator = picasso.load(model.getIconResourceId()); } requestCreator .transform(new CircleTransform()) .placeholder(model.getIconResourceId()) .error(model.getIconResourceId()) .into(icon); }
Example #17
Source File: CellRepo.java From AndroidStarter with Apache License 2.0 | 6 votes |
@Override public void bind(@NonNull final RepoEntity poRepo) { mTextView.setText(poRepo.url); final RequestCreator loRequest = mPicasso.load(poRepo.avatarUrl); if (loRequest != null) { loRequest .placeholder(R.drawable.git_icon) .error(R.drawable.git_icon) .into(mImageViewAvatar); } setOnClickListener((final View poView) -> notifyItemAction(ROW_PRESSED) ); }
Example #18
Source File: ImageLoader.java From Contacts with MIT License | 5 votes |
public static void display(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; uri = Uri.encode(uri, ALLOWED_URI_CHARS); Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); LayoutParams params = imageView.getLayoutParams(); if (params.width > 0 && params.height > 0) { requestCreator.resize(params.width, params.height, true); } requestCreator.inSampleSize(true); requestCreator.into(imageView, listener); }
Example #19
Source File: ImageLoader.java From Klyph with MIT License | 5 votes |
public static void display(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; /*uri = uri.replace("�", URLEncoder.encode("�")); uri = uri.replace("�", URLEncoder.encode("�")); uri = uri.replace("'", URLEncoder.encode("'")); uri = uri.replace("�", URLEncoder.encode("�"));*/ uri = Uri.encode(uri, ALLOWED_URI_CHARS); Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); LayoutParams params = imageView.getLayoutParams(); if (params.width > 0 && params.height > 0) { requestCreator.resize(params.width, params.height, true); } requestCreator.inSampleSize(true); requestCreator.into(imageView, listener); }
Example #20
Source File: PicassoImageLoader.java From Nox with Apache License 2.0 | 5 votes |
/** * Uses the configuration previously applied using this ImageLoader builder to download a * resource asynchronously and notify the result to the listener. */ private void loadImage() { List<Transformation> transformations = getTransformations(); boolean hasUrl = url != null; boolean hasResourceId = resourceId != null; boolean hasPlaceholder = placeholderId != null; ListenerTarget listenerTarget = getLinearTarget(listener); if (hasUrl) { RequestCreator bitmapRequest = Picasso.with(context).load(url).tag(PICASSO_IMAGE_LOADER_TAG); applyPlaceholder(bitmapRequest).resize(size, size) .transform(transformations) .into(listenerTarget); } else if (hasResourceId || hasPlaceholder) { Resources resources = context.getResources(); Drawable placeholder = null; Drawable drawable = null; if (hasPlaceholder) { placeholder = resources.getDrawable(placeholderId); listenerTarget.onPrepareLoad(placeholder); } if (hasResourceId) { drawable = resources.getDrawable(resourceId); listenerTarget.onDrawableLoad(drawable); } } else { throw new IllegalArgumentException( "Review your request, you are trying to load an image without a url or a resource id."); } }
Example #21
Source File: GenericPicassoBitmapAdapter.java From android-slideshow-widget with Apache License 2.0 | 5 votes |
@Override protected void loadBitmap(final int position) { if (position < 0 || position >= items.size()) onBitmapNotAvailable(position); SlideTarget target = new SlideTarget(position); activeTargets.put(position, target); RequestCreator rc = createRequestCreator(Picasso.with(getContext()), items.get(position)); rc.into(target); }
Example #22
Source File: ImageLoader.java From Contacts with MIT License | 5 votes |
public static void display(ImageView imageView, Uri uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { /*if (uri == null || uri.length() == 0) uri = FAKE_URI; //uri = Uri.encode(uri, ALLOWED_URI_CHARS);*/ Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); LayoutParams params = imageView.getLayoutParams(); if (params.width > 0 && params.height > 0) { requestCreator.resize(params.width, params.height, true); } requestCreator.inSampleSize(true); requestCreator.into(imageView, listener); }
Example #23
Source File: Images.java From ratebeer with GNU General Public License v3.0 | 5 votes |
public RequestCreator loadUser(String username, boolean highResolution) { RequestCreator request = Picasso.with(context).load(highResolution ? ImageUrls.getUserPhotoHighResUrl(username) : ImageUrls.getUserPhotoUrl(username)); if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi) request.networkPolicy(NetworkPolicy.OFFLINE); return request; }
Example #24
Source File: Images.java From ratebeer with GNU General Public License v3.0 | 5 votes |
public RequestCreator loadBrewery(long breweryId, boolean highResolution) { RequestCreator request = Picasso.with(context).load(highResolution ? ImageUrls.getBreweryPhotoHighResUrl(breweryId) : ImageUrls .getBreweryPhotoUrl(breweryId)); if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi) request.networkPolicy(NetworkPolicy.OFFLINE); return request; }
Example #25
Source File: Images.java From ratebeer with GNU General Public License v3.0 | 5 votes |
public RequestCreator loadBeer(long beerId, boolean highResolution) { RequestCreator request = Picasso.with(context).load(highResolution ? ImageUrls.getBeerPhotoHighResUrl(beerId) : ImageUrls.getBeerPhotoUrl(beerId)); if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi) request.networkPolicy(NetworkPolicy.OFFLINE); return request; }
Example #26
Source File: SearchSuggestionsAdapter.java From ratebeer with GNU General Public License v3.0 | 5 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { SearchSuggestion searchSuggestion = searchSuggestions.get(position); int typeResId = 0; if (searchSuggestion.type == SearchSuggestion.TYPE_HISTORY) { typeResId = R.drawable.ic_type_historic; } else if (searchSuggestion.type == SearchSuggestion.TYPE_BREWERY) { typeResId = R.drawable.ic_type_brewery; } else if (searchSuggestion.type == SearchSuggestion.TYPE_PLACE) { typeResId = R.drawable.ic_type_place; } else if (searchSuggestion.type == SearchSuggestion.TYPE_BEER) { typeResId = R.drawable.ic_type_beer; } else if (searchSuggestion.type == SearchSuggestion.TYPE_RATING) { typeResId = R.drawable.ic_type_rating; } holder.typeImage.setImageResource(typeResId); holder.nameText.setText(searchSuggestion.suggestion); RequestCreator request = null; if (searchSuggestion.type == SearchSuggestion.TYPE_BEER && searchSuggestion.itemId != null) { request = Images.with(holder.photoImage.getContext()).loadBeer(searchSuggestion.itemId); } else if (searchSuggestion.type == SearchSuggestion.TYPE_BREWERY && searchSuggestion.itemId != null) { request = Images.with(holder.photoImage.getContext()).loadBrewery(searchSuggestion.itemId); } if (request != null) { holder.photoImage.setVisibility(View.VISIBLE); request.placeholder(android.R.color.white).fit().centerInside().into(holder.photoImage); } else { holder.photoImage.setVisibility(View.GONE); } }
Example #27
Source File: ImageRequestExecutionTask.java From arcusandroid with Apache License 2.0 | 5 votes |
@Nullable private RequestCreator intoPicasso (@NonNull ImageLocationSpec locationSpec, @NonNull Picasso picasso, @Nullable Integer... fallbackImageResIds) { Object location = locationSpec.getLocation(); // Special case: No image location specified. Something's busted. (Missing SSR URL?) if (location == null) { // Try to use a placeholder image instead (if one has been defined) for (Integer thisFallback : fallbackImageResIds) { if (thisFallback != null && thisFallback != 0) { builder.log("No image location specified for placement; falling back to image resource ID {}", thisFallback); location = thisFallback; break; } } // ... otherwise, abort if (location == null) { return null; } } if (location instanceof String) { return picasso.load((String) location); } else if (location instanceof Integer) { return picasso.load((int) location); } else if (location instanceof File) { return picasso.load((File) location); } else if (location instanceof Uri) { return picasso.load((Uri) location); } else { throw new IllegalArgumentException("Unimplemented. Don't know how to load an image specified by " + location.getClass().getSimpleName()); } }
Example #28
Source File: HomeScreenFragment.java From Gazetti_Newspaper_Reader with MIT License | 5 votes |
private void setupImageBackground(View view) { kenBurnsView = (KenBurnsView) view.findViewById(R.id.kenBurnsView_Background); phoneMode = (kenBurnsView == null); //height and width of screen final int MAX_HEIGHT = getResources().getDisplayMetrics().heightPixels; final int MAX_WIDTH = getResources().getDisplayMetrics().widthPixels; try { new AsyncTask<Void, Void, Integer>(){ @Override protected Integer doInBackground(Void... params) { if (phoneMode) { return getPhoneBackground(); } else { return getTabletBackground(); } } @Override protected void onPostExecute(Integer resID) { RequestCreator requestCreator = Picasso.with(getActivity()) .load(resID) .transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT)); if(phoneMode){ requestCreator.into(phoneBackgroundImage); } else { requestCreator.into(kenBurnsView); } } }.execute(); } catch (Exception e) { Crashlytics.logException(e); } }
Example #29
Source File: ImageProxy.java From BrainPhaser with GNU General Public License v3.0 | 5 votes |
/** * Loads an image using Picasso while caching it. * @param imagePath path as described above * @param context context to use * @return cached or newly created RequestCreator */ public static RequestCreator loadImage(String imagePath, Context context) { if (!isDrawableImage(imagePath)) { return Picasso.with(context).load(new File(imagePath)); } else { int resourceId = getResourceId(imagePath, context); RequestCreator requestCreator = requestCache.get(resourceId); if (requestCreator == null) { requestCreator = Picasso.with(context).load(resourceId); requestCache.put(resourceId, requestCreator); } return requestCreator; } }
Example #30
Source File: CompactTweetViewTest.java From twitter-kit-android with Apache License 2.0 | 5 votes |
public void testSetTweetPhoto() { final Picasso mockPicasso = mock(Picasso.class); final RequestCreator mockRequestCreator = mock(RequestCreator.class); MockUtils.mockPicasso(mockPicasso, mockRequestCreator); when(mockDependencyProvider.getImageLoader()).thenReturn(mockPicasso); final CompactTweetView tv = createViewWithMocks(context, TestFixtures.TEST_PHOTO_TWEET, R.style.tw__TweetLightStyle, mockDependencyProvider); // assert 1 load for profile photo, tweet photo loaded in TweetMediaView verify(mockPicasso, times(1)).load(TestFixtures.TEST_PROFILE_IMAGE_URL); }