Java Code Examples for com.squareup.picasso.RequestCreator#into()

The following examples show how to use com.squareup.picasso.RequestCreator#into() . 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 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 2
Source File: ImageLoaderManager.java    From Android-MVVMFramework with Apache License 2.0 6 votes vote down vote up
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 3
Source File: RecyclerAdapterScaleTeamsAutomatic.java    From intra42 with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull final ViewHolderScaleTeam holder, int position) {
    TeamsUploads item = getItem(position);

    Picasso picasso = Picasso.get();
    RequestCreator requestCreator;
    String url = UserImage.BASE_URL + "moulinette.jpg";
    requestCreator = picasso.load(url).resize(200, 240);
    requestCreator.into(holder.imageViewUser);

    holder.textViewCorrector.setText(R.string.project_moulinette);
    holder.textViewScale.setText(String.valueOf(item.finalMark));
    holder.textViewComment.setText(item.comment);
    holder.groupFeedback.setVisibility(View.GONE);
    holder.textViewUserFeedback.setVisibility(View.GONE);

}
 
Example 4
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 5
Source File: BoxingPicassoLoader.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
@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 6
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 7
Source File: ImageHelper.java    From AndroidPicker with MIT License 5 votes vote down vote up
@Override
public void display(String urlOrPath, ImageView view, int width, int height) {
    LogUtils.verbose("Image>>>" + urlOrPath);
    if (null == context) {
        context = view.getContext();
    }
    RequestCreator creator = Picasso.with(context).load(urlOrPath);
    creator.placeholder(PLACEHOLDER_LOADING);
    creator.error(PLACEHOLDER_FAILURE);
    creator.config(urlOrPath.endsWith(".png") ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    if (width > 0 && height > 0) {
        creator.resize(width, height);
    }
    creator.into(view);
}
 
Example 8
Source File: PicassoImageLoader.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {
  RequestCreator creator = Picasso.with(imageView != null ? imageView.getContext() : context)
      .load(url);

  if (transformation != null) {
    creator.transform(transformation);
  }

  if (placeholder != null) {
    creator.placeholder(placeholder);
  }

  if (with > 0 && height > 0) {
    creator.resize(with, height);
  }

  if (centerCrop) {
    creator.centerCrop();
  }

  if (fit) {
    creator.fit();
  }

  if (target != null) {
    creator.into(target);
  } else {
    creator.into(imageView);
  }
}
 
Example 9
Source File: ImageViewerActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_viewer);

        String login;
        String displayName;

        if (getIntent().hasExtra(INTENT_LOGIN))
            login = getIntent().getStringExtra(INTENT_LOGIN).toLowerCase();
        else
            return;
        displayName = getIntent().getStringExtra(INTENT_DISPLAY_NAME);

        PhotoView photoView = findViewById(R.id.photoView);
        TextView textView = findViewById(R.id.textView);

        if (displayName != null && !displayName.isEmpty()) {
            textView.setVisibility(View.VISIBLE);
            textView.setText(displayName);
        } else {
            textView.setVisibility(View.GONE);
        }
        UsersLTE user = new UsersLTE();
        user.login = login;
        RequestCreator requestCreator = UserImage.getRequestCreator(this, user, "large");
        if (requestCreator != null)
            requestCreator.into(photoView);

//        photoView.setOnSingleFlingListener(new OnSingleFlingListener() {
//            @Override
//            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//                finish();
//                return true;
//            }
//        });
    }
 
Example 10
Source File: UserImage.java    From intra42 with Apache License 2.0 5 votes vote down vote up
static public void setImageSmall(Context context, UsersLTE user, ImageView imageView) {
    RequestCreator picasso = getRequestCreator(context, user, "small");

    if (picasso == null)
        return;

    picasso.into(imageView);
}
 
Example 11
Source File: UserImage.java    From intra42 with Apache License 2.0 5 votes vote down vote up
static public void setImage(Context context, UsersLTE user, ImageView imageView) {
    RequestCreator picasso = getRequestCreator(context, user);

    if (picasso == null)
        return;

    picasso.into(imageView);
}
 
Example 12
Source File: PhotoActivity.java    From STUer-client with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);
    ButterKnife.inject(this);
    final String picName = getIntent().getStringExtra("picName");
    RequestCreator requestCreator = Picasso.with(this)
            .load(IMAGE_HOST + picName + ".jpg");
    requestCreator.into(mImageView);
    requestCreator.fetch(new Callback() {
        @Override
        public void onSuccess() {
            // 一开始为wrap_content使其居中,成功加载后match_parent使其放缩效果更佳
            mImageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
        }

        @Override
        public void onError() {
            Toast.makeText(PhotoActivity.this, "加载图片失败", Toast.LENGTH_SHORT).show();
        }
    });


    mAttacher = new PhotoViewAttacher(mImageView);
    mAttacher.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(PhotoActivity.this);
            builder.setItems(new String[]{"保存"}, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    savePhoto(picName);
                }
            });
            builder.create().show();
            return false;
        }
    });

}
 
Example 13
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 14
Source File: VirtualViewRenderService.java    From Tangram-Android with MIT License 5 votes vote down vote up
@Override
public void bindImage(String uri, final ImageBase imageBase, int reqWidth, int reqHeight) {
    RequestCreator requestCreator = Picasso.with(tangramEngine.getContext()).load(uri);
    Log.d("TangramActivity", "bindImage request width height " + reqHeight + " " + reqWidth);
    if (reqHeight > 0 || reqWidth > 0) {
        requestCreator.resize(reqWidth, reqHeight);
    }
    ImageTarget imageTarget = new ImageTarget(imageBase);
    cache.add(imageTarget);
    requestCreator.into(imageTarget);
}
 
Example 15
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 16
Source File: BasicActivity.java    From intra42 with Apache License 2.0 4 votes vote down vote up
/**
 * This function setup Navigation and Navigation's header (the menu)
 */
private void setViewNavigation() {
    if (navigationView != null) {
        navigationView.setNavigationItemSelectedListener(this);

        View headerLayout = navigationView.getHeaderView(0);
        ImageView imageView = headerLayout.findViewById(R.id.imageViewNav);
        ImageView imageViewNavBackground = headerLayout.findViewById(R.id.imageViewNavBackground);
        TextView name = headerLayout.findViewById(R.id.textViewNavName);
        TextView email = headerLayout.findViewById(R.id.textViewNavEmail);
        ImageButton imageButtonDayLight = headerLayout.findViewById(R.id.imageButtonDayLight);

        if (app.me != null) {
            name.setText(app.me.displayName);
            email.setText(app.me.email);
            RequestCreator picassoRounded = UserImage.getPicassoRounded(this, app.me);
            if (picassoRounded != null)
                picassoRounded.into(imageView);

            AppSettings.Theme.EnumTheme coalition = app.themeSettings;
            if (coalition != null) {
                switch (coalition) {
                    case BLUE:
                        imageViewNavBackground.setImageResource(R.drawable.federation_background);
                        break;
                    case GREEN:
                        imageViewNavBackground.setImageResource(R.drawable.alliance_background);
                        break;
                    case PURPLE:
                        imageViewNavBackground.setImageResource(R.drawable.assembly_background);
                        break;
                    case RED:
                        imageViewNavBackground.setImageResource(R.drawable.order_background);
                        break;
                }
            }

            headerLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (app.me != null)
                        UserActivity.openIt(BasicActivity.this, app.me);
                }
            });

            if (AppSettings.getAppCampus(app) != 7)
                navigationView.getMenu().getItem(4).getSubMenu().getItem(3).setVisible(false);
        }

        /* ***** Setup dark theme button ***** */
        switch (AppSettings.Theme.getBrightness(this)) {
            case LIGHT:
                imageButtonDayLight.setImageResource(R.drawable.ic_wb_sunny_black_24dp);
                break;
            case DARK:
                imageButtonDayLight.setImageResource(R.drawable.ic_brightness_3_24dp);
                break;
            case SYSTEM:
                imageButtonDayLight.setImageResource(R.drawable.ic_theme_light_dark);
                break;
        }

        imageButtonDayLight.setOnClickListener(this::openThemeBrightnessChoice);
    }
}
 
Example 17
Source File: MainActivityAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
protected void loadImagePreview(String previewURL, E element, final ElementsViewHolder viewHolder) {
	if(previewURL != null && !previewURL.isEmpty()) {

		RequestCreator creator =
				Picasso.with(context)
						.load(previewURL)
						.placeholder(ContextCompat.getDrawable(context, element.getPlaceHolder(getContext())));

		if(isBelowLollipop) {
			creator.transform(new RoundedTopTransformation(context.getResources().getDimension(getCornerRadiusRessource())));
		}

		if(mTargets.get(viewHolder.getTargetsKey()) != null) {
			viewHolder.getPreviewView().setImageBitmap(mTargets.get(viewHolder.getTargetsKey()).getPreview());
		} else {
			PreviewTarget mTarget = new PreviewTarget() {
				private boolean loaded = false;

				@Override
				public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
					if(!loaded) {
						loaded = true;

						if (removeBlackbars) {
							bitmap = Service.removeBlackBars(bitmap);
						}

						AnimationService.setPicassoShowImageAnimationTwo(viewHolder.getPreviewView(), bitmap, context);
						setPreview(bitmap);
					}
				}

				@Override
				public void onBitmapFailed(Drawable errorDrawable) {

				}

				@Override
				public void onPrepareLoad(Drawable placeHolderDrawable) {
					viewHolder.getPreviewView().setImageDrawable(placeHolderDrawable);
				}
			};

			creator.into(mTarget);
			mTargets.put(viewHolder.getTargetsKey(), mTarget);
		}

	} else {
		viewHolder.getPreviewView().setImageDrawable(ContextCompat.getDrawable(context, element.getPlaceHolder(getContext())));
	}
}
 
Example 18
Source File: MovieDetailsFragment.java    From udacity-p1-p2-popular-movies with MIT License 4 votes vote down vote up
private void updateMovieDetails() {
    Picasso picasso = Picasso.with(getActivity());

    mToolbar.setTitle(mMovie.getTitle());

    if (mAnimBackdropAnimateAlpha) {
        mBackdrop.setAlpha(0f); // wait for enter animation
    }
    mBackdrop.setTranslationY(0);
    int backdropWidth = mBackdrop.getWidth();   // this will be correct because this function is
                                                // only called after layout is complete
    int backdropHeight = getResources().getDimensionPixelSize(R.dimen.details_backdrop_height);
    RequestCreator backdropRequest = picasso
            .load(TMDbUtil.buildBackdropUrl(mMovie.getBackdropPath(), backdropWidth))
            .resize(backdropWidth, backdropHeight)
            .centerCrop()
            .transform(PaletteTransformation.instance());
    if (! mAnimBackdropAnimateAlpha) {
        backdropRequest.noFade();
    }
    backdropRequest.into(mBackdrop, new PaletteTransformationCallback(mBackdrop));

    if (mAnimBackdropAnimateAlpha) {
        mPoster.setAlpha(0f); // wait for enter animation
    }
    mPoster.setTranslationY(0);
    int posterWidth = getResources().getDimensionPixelSize(R.dimen.details_poster_width);
    int posterHeight = getResources().getDimensionPixelSize(R.dimen.details_poster_height);
    RequestCreator posterRequest = picasso
            .load(TMDbUtil.buildPosterUrl(mMovie.getPosterPath(), posterWidth))
            .resize(posterWidth, posterHeight)
            .centerCrop();
    if (! mAnimBackdropAnimateAlpha) {
        posterRequest.noFade();
    }
    posterRequest.into(mPoster);

    mTitle.setText(mMovie.getTitle());

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mMovie.getReleaseDate());
    mReleaseDate.setText(String.valueOf(calendar.get(Calendar.YEAR)));

    mRating.setText(String.format("%1$2.1f", mMovie.getRating()));
    mSynopsis.setText(mMovie.getSynopsis());
}
 
Example 19
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 20
Source File: BaseAdapterHelper.java    From VSigner with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Will download an image from a URL and put it in an ImageView.<br/>
 * @param viewId         The view id.
 * @param requestBuilder The Picasso request builder. (e.g. Picasso.with(context).load(imageUrl))
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setImageBuilder(int viewId, RequestCreator requestBuilder) {
    ImageView view = retrieveView(viewId);
    requestBuilder.into(view);
    return this;
}