Java Code Examples for com.squareup.picasso.Picasso#load()

The following examples show how to use com.squareup.picasso.Picasso#load() . 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: PicassoLoader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ImageLoader.java    From KlyphMessenger with MIT License 6 votes vote down vote up
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 3
Source File: ImageLoader.java    From Klyph with MIT License 6 votes vote down vote up
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 4
Source File: ImageLoader.java    From Contacts with MIT License 6 votes vote down vote up
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: ElementDescriptorView.java    From px-android with MIT License 6 votes vote down vote up
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 6
Source File: mImage.java    From intra42 with Apache License 2.0 6 votes vote down vote up
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 7
Source File: PicassoHelper.java    From android_sdk_demo_apps with Apache License 2.0 6 votes vote down vote up
/**
 * 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 8
Source File: ImageLoader.java    From Contacts with MIT License 5 votes vote down vote up
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 9
Source File: ImageLoader.java    From Contacts with MIT License 5 votes vote down vote up
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 10
Source File: ImageLoader.java    From Klyph with MIT License 5 votes vote down vote up
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 11
Source File: ImageLoader.java    From KlyphMessenger with MIT License 5 votes vote down vote up
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 12
Source File: ImageRequestExecutionTask.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: PicassoHelper.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public static RequestCreator load(Picasso picasso) {
    return picasso.load((String) null);
}
 
Example 14
Source File: PicassoHelper.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public static RequestCreator load(Picasso picasso, ImageBean imageBean) {
    if (imageBean == null) {
        return load(picasso);
    }
    return picasso.load(imageBean.getUrl());
}
 
Example 15
Source File: CompactSliderView.java    From LoyalNativeSlider with MIT License 4 votes vote down vote up
private void bindEventAndShow(
        @NonNull final ImageView targetImageView,
        @NonNull final String mURI
) {

    //  mLoadListener.onStart(me);
    final Picasso p = Picasso.with(mContext);
    final RequestCreator mreq = p.load(mURI);
    if (getEmpty() != 0) {
        mreq.placeholder(getEmpty());
    }
    if (getError() != 0) {
        mreq.error(getError());
    }
    if (mImageLocalStorageEnable) {
        mreq.memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE);
    }
    switch (mScaleType) {
        case Fit:
            mreq.fit();
            break;
        case CenterCrop:
            mreq.fit().centerCrop();
            break;
        case CenterInside:
            mreq.fit().centerInside();
            break;
    }

    mreq.into(targetImageView, new Callback() {
        @Override
        public void onSuccess() {
            //  if (v.findViewById(R.id.ns_loading_progress) != null) {
            //    hideoutView(v.findViewById(R.id.ns_loading_progress));
            //  }

            if (mLongClickSaveImage && fmg != null) {
                targetImageView.setOnLongClickListener(new View.OnLongClickListener() {
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                    @Override
                    public boolean onLongClick(View v) {
                        prepare_request_save_image = mreq;
                        final saveImageDialog saveImageDial = new saveImageDialog();
                        saveImageDial.show(fmg.get(), "DESC_SAVE_IM");
                        return false;
                    }
                });
            }
        }

        @Override
        public void onError() {
            //if (mLoadListener != null) {
            //     mLoadListener.onEnd(false, me);
            // }
        }
    });

}
 
Example 16
Source File: BaseSliderView.java    From LoyalNativeSlider with MIT License 4 votes vote down vote up
/**
 * When you want to implement your own slider view, please call this method in the end in `getView()` method
 *
 * @param v               the whole view
 * @param targetImageView where to place image
 */
protected void bindEventAndShowPicasso(final View v, final ImageView targetImageView) {
    current_image_holder = targetImageView;
    v.setOnClickListener(click_triggered);
    mLoadListener.onStart(this);
    final Picasso p = Picasso.with(mContext);
    rq = null;
    if (mUrl != null) {
        rq = p.load(mUrl);
    } else if (mFile != null) {
        rq = p.load(mFile);
    } else if (mRes != 0) {
        rq = p.load(mRes);
    } else {
        return;
    }
    if (rq == null) {
        return;
    }
    if (getEmpty() != 0) {
        rq.placeholder(getEmpty());
    }
    if (getError() != 0) {
        rq.error(getError());
    }
    if (mTargetWidth > 0 || mTargetHeight > 0) {
        rq.resize(mTargetWidth, mTargetHeight);
    }
    if (mImageLocalStorageEnable) {
        rq.memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE);
    }

    switch (mScaleType) {
        case Fit:
            rq.fit();
            break;
        case CenterCrop:
            rq.fit().centerCrop();
            break;
        case CenterInside:
            rq.fit().centerInside();
            break;
    }

    rq.into(targetImageView, new Callback() {
        @Override
        public void onSuccess() {
            imageLoaded = true;
            hideLoadingProgress(v);
            triggerOnLongClick(v);
            reportStatusEnd(true);
        }

        @Override
        public void onError() {
            reportStatusEnd(false);
        }
    });
}
 
Example 17
Source File: CompactFrameSliderView.java    From LoyalNativeSlider with MIT License 4 votes vote down vote up
protected void bindCompatPicasso(String mURI, final MiniSliderFrame Fr) {

        final Picasso p = Picasso.with(mContext);
        final RequestCreator mreq = p.load(mURI);
        if (getEmpty() != 0) {
            mreq.placeholder(getEmpty());
        }
        if (getError() != 0) {
            mreq.error(getError());
        }
        if (mImageLocalStorageEnable) {
            mreq.memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE);
        }
        switch (mScaleType) {
            case Fit:
                mreq.fit();
                break;
            case CenterCrop:
                mreq.fit().centerCrop();
                break;
            case CenterInside:
                mreq.fit().centerInside();
                break;
        }


        mreq.into(Fr.getImageTarget(), new Callback() {
            @Override
            public void onSuccess() {
                hideoutView(Fr.getLoadingBar());
                if (mLongClickSaveImage && fmg != null) {
                    Fr.getTouch().setOnLongClickListener(new View.OnLongClickListener() {
                        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                        @Override
                        public boolean onLongClick(View v) {
                            prepare_request_save_image = mreq;
                            final saveImageDialog saveImageDial = new saveImageDialog();
                            saveImageDial.show(fmg.get(), "DESC_SAVE_IM");
                            return false;
                        }
                    });
                }
            }

            @Override
            public void onError() {
                //if (mLoadListener != null) {
                //     mLoadListener.onEnd(false, me);
                // }
            }
        });
    }
 
Example 18
Source File: PicassoHelper.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public static RequestCreator load(Picasso picasso) {
    return picasso.load((String) null);
}
 
Example 19
Source File: PicassoHelper.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public static RequestCreator load(Picasso picasso, ImageBean imageBean) {
    if (imageBean == null) {
        return load(picasso);
    }
    return picasso.load(imageBean.getUrl());
}
 
Example 20
Source File: BasicYouTubeListItemView.java    From RxTube with Apache License 2.0 3 votes vote down vote up
public void bindView(Picasso picasso, Video video) {
  titleTextView.setText(video.getSnippet().getTitle());
  descriptionTextView.setText(video.getSnippet().getDescription());


  request = picasso.load(video.getSnippet().getThumbnails().getMedium().getUrl());

  requestLayout();
}