@Override public void onBindViewHolder(final ViewHolder holder, int position) { final LocalPhoto photo = data.get(position); holder.attachPhoto(photo); PicassoInstance.with() .load(LocalPhoto.buildUriForPicasso(photo.getImageId())) .tag(TAG) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .placeholder(R.drawable.background_gray) .into(holder.photoImageView); resolveSelectionVisibility(photo, holder); resolveIndexText(photo, holder); View.OnClickListener listener = v -> { if (clickListener != null) { clickListener.onPhotoClick(holder, photo); } }; holder.photoImageView.setOnClickListener(listener); holder.selectedRoot.setOnClickListener(listener); }
@Override public void onBindViewHolder(Holder holder, int position) { final LocalImageAlbum album = data.get(position); Uri uri = LocalPhoto.buildUriForPicasso(album.getCoverImageId()); PicassoInstance.with() .load(uri) .tag(PICASSO_TAG) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .placeholder(R.drawable.background_gray) .into(holder.image); holder.title.setText(album.getName()); holder.subtitle.setText(holder.itemView.getContext().getString(R.string.photos_count, album.getPhotoCount())); holder.itemView.setOnClickListener(v -> { if(clickListener != null){ clickListener.onClick(album); } }); }
/** * Update image path text and image views. */ private void updateImage() { mImagePathText.setText(TextUtils.isEmpty(mImagePath) ? "-" : mImagePath); if (TextUtils.isEmpty(mImagePath)) { // if there is no selected image, load image placeholder Picasso.with(getActivity()) .load(R.drawable.image_placeholder) .into(mImageView); } else { // It is important to be very careful loading this image because it can be // high resolution, very heavy and cause application memory problems // (there is no danger of out of memory thanks to picasso) Picasso.with(getActivity()) .load(new File(mImagePath)) .placeholder(R.drawable.image_placeholder) .memoryPolicy(MemoryPolicy.NO_CACHE) .resize(IMAGE_MAX_WIDTH_PX, IMAGE_MAX_HEIGHT_PX) .centerInside() .onlyScaleDown() .into(mImageView); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.e("请求码和结果码",requestCode + ".........." + resultCode); if (requestCode == SELECT_PIC && resultCode == RESULT_OK) { Log.e("onActivityResult方法", "执行了"); ArrayList<String> resultList = data.getStringArrayListExtra("resultList"); String imagePath = resultList.get(0); Picasso.with(this) .load(new File(imagePath)) .memoryPolicy(MemoryPolicy.NO_CACHE) .resize(800, 600) .centerCrop() .error(R.drawable.place_holder) .into(imageview); } }
@Override public Object instantiateItem(ViewGroup container, int position) { final View itemView = mLayoutInflater.inflate(R.layout.layout_image_slider_item, container, false); ImageView imageView = (ImageView) itemView.findViewById(R.id.img_pager_slider); Picasso.with(App.getContext()). load(getUrl(position)). error(R.drawable.ic_broken_image). memoryPolicy(MemoryPolicy.NO_CACHE). into(imageView, new Callback() { @Override public void onSuccess() { itemView.findViewById(R.id.pb_fullscreen_loading).setVisibility(View.GONE); } @Override public void onError() { } }); container.addView(itemView); return itemView; }
/** * 单图展示 * * @param url */ @Override public void display(String url) { mIvContent.setVisibility(View.VISIBLE); mViewPager.setVisibility(View.GONE); int w = mIvContent.getMeasuredWidth() > 0 ? mIvContent.getMeasuredWidth() : 400; int h = mIvContent.getMeasuredHeight() > 0 ? mIvContent.getMeasuredHeight() : 400; // TODO 根据需要调整 url = (url.indexOf(AppConsts.AppConfig.PATH_HTTP) != -1 || url.indexOf(AppConsts.AppConfig.PATH_HTTPS) != -1) ? url : AppConsts.AppConfig.PATH_FILE + url; Picasso.with(getContext()) .load(url) .memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE) .config(Bitmap.Config.RGB_565) .resize(w, h) .placeholder(R.drawable.pic_load) .error(R.drawable.pic_load_error) .centerInside() .into(mIvContent); }
@Override public void callNextCycle(String lastImagePath) { if(!TextUtils.isEmpty(lastImagePath)) currentFramePicasso.invalidate(lastImagePath); if(beanImages != null && beanImages.size() > 0) beanImages.remove(0); //because targets are also running sequential, in case of parallel need to shift it to respective class if(targets != null && targets.size() > 0) targets.remove(0); if(beanImages.size() == 0) return; BeanImage beanImage = beanImages.get(0); if(Utils.isLocalPath(beanImage.getImageLink())){ Utils.logVerbose("LADING AS : "+"local image " + beanImage.getImageLink()); new UnframedLocalTask(this).execute(beanImage); } else { Utils.logVerbose("LADING AS : "+"server image " + beanImage.getImageLink()); UnframedPicassoTargetNew target = new UnframedPicassoTargetNew(this, beanImage); targets.add(target); currentFramePicasso.load(beanImage.getImageLink()).memoryPolicy(MemoryPolicy.NO_STORE) .networkPolicy(NetworkPolicy.NO_STORE) .noPlaceholder() .transform(new ScaleTransformation(frameModel.getMaxContainerWidth(), frameModel.getMaxContainerHeight(), totalImages, beanImage.getImageLink(), beanImage, this)) .into(target); } }
public View getView(int position, View convertView, ViewGroup parent) { ActivityData actD = arrayList.get(position); LayoutInflater inflater = ((Activity)context).getLayoutInflater(); convertView = inflater.inflate(R.layout.grid_layout_item, parent, false); TextView tv = (TextView) convertView.findViewById(R.id.myImageViewText); TextView dv = (TextView) convertView.findViewById(R.id.myImageViewDate); ImageView iv = (ImageView) convertView.findViewById(R.id.myImageView); if(tv != null) { tv.setText(actD.getTitle()); iv.setImageResource(R.drawable.placeholder); Long time = new Long((actD.getStartTime().toString())); dv.setText(readableTimeStamp(time)); Picasso.with(context) .load(actD.getImageUrl()) .noFade() .memoryPolicy(MemoryPolicy.NO_CACHE) .into(iv); iv.setScaleType(ImageView.ScaleType.FIT_XY); } return convertView; }
protected ImageView newRelativeLayout(final bind mBind, int size) { ImageView imview = new ImageView(getActivity()); imview.setLayoutParams(findBoxWidth(mBind, size)); getPicassoClient() .load(mBind.image) .memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE) .into(imview); imview.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { trigger_link(mBind); } }); imview.setScaleType(ImageView.ScaleType.CENTER_CROP); return imview; }
private void updateImage(){ Picasso.with(this) .load(currentPicture.getUrl()) //Reduces memory usage by 50%, we likely won't use images after refresh. .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .into(imageView, new Callback() { @Override public void onSuccess() { Log.d("Succeeded", "Loaded image"); hideProgress(); } @Override public void onError() { Log.d("Failed", "Didn't load image"); hideProgress(); } }); }
/** * Just like the loadImageBitmapFromMemory() method, we first call fetch() to load the image in our caches. * In order to make sure this image does not come from the memory cache, we specifically set the request to ignore the memory cache with .memoryPolicy(). * This should result in 99% of the cases that the image loads from the disk cache. */ private void loadImageBitmapFromDisk() { Picasso.with(context).load(UsageExampleListView.eatFoodyImages[1]).fetch(new Callback() { @Override public void onSuccess() { Picasso .with(context) .load(UsageExampleListView.eatFoodyImages[1]) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .into(imageViewFromDisk); } @Override public void onError() { } }); }
private void downloadImages(DhisController.ImageNetworkPolicy imageNetworkPolicy, final List<String> requestUrlList, final Context context) { for (int i = 0; i < requestUrlList.size(); i++) { final String request = requestUrlList.get(i); if (imageNetworkPolicy == DhisController.ImageNetworkPolicy.NO_CACHE) { PicassoProvider.getInstance(context, false) .load(request).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE).fetch(); } else { PicassoProvider.getInstance(context, false) .load(request).fetch(); } } }
public static void picassoImplementation(String u, final ImageView target, Context context, final Runnable callback) { Picasso.with(context) .load(u) .memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE) .into(target, new Callback() { @Override public void onSuccess() { callback.run(); } @Override public void onError() { } }); }
@Override protected void onImagePickedFromDevice(Uri imageUri, int requestCode) { if (requestCode == REQUEST_PICK_AVATAR) { with(getContext()) .load(imageUri) .resize(MAX_WIDTH, 0) .memoryPolicy(MemoryPolicy.NO_CACHE) .into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { setAvatarBitmap(bitmap); } @Override public void onBitmapFailed(Drawable errorDrawable) { showAlert("Error", "Failed to load image"); } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); } }
@Override public void onBind(ImageView view, String url) { Picasso.with(view.getContext()) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE) .into(view); }
public static RequestCreator buildPicasso (Context context, String url) { return Picasso.with(context) .load(url) .placeholder(R.mipmap.ic_avatar) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .error(R.mipmap.ic_avatar); }
@Nullable public static Bitmap fromCache (Context context, String url) { RequestCreator creator = buildPicasso(context, url) .networkPolicy(NetworkPolicy.OFFLINE, NetworkPolicy.OFFLINE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE); try { return creator.get(); } catch (IOException e) { e.printStackTrace(); return null; } }
private void onPictureSaved(String photoPath) { mCapturedPhotoPath = photoPath; setAcceptPanelVisible(); mCameraView.stop(); Picasso.with(getContext()) .load(new File(mCapturedPhotoPath)) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .placeholder(null) .into(mPreview); }
@Override public void displayImage(Activity activity, String path, GFImageView imageView, Drawable defaultDrawable, int width, int height) { Picasso.with(activity) .load(new File(path)) .placeholder(defaultDrawable) .error(defaultDrawable) .config(mConfig) .resize(width, height) .centerInside() .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .into(imageView); }
@BindingAdapter({"compressImageUrl"}) public static void loadImageCompress(ImageView imageView, String url) { //large -> b middle // Picasso.Builder builder = new Picasso.Builder(imageView.getContext().getApplicationContext()); // builder.listener(new Picasso.Listener() { // @Override // public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { // exception.printStackTrace(); // Log.e("Picasso Error", uri.toString()); // } // }); //recycle bitmap // Drawable drawable = imageView.getDrawable(); // if (drawable instanceof BitmapDrawable) { // imageView.setImageDrawable(null); // Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); // Log.d(TAG, "recycle bitmap, w:" + bitmap.getWidth() + ", h:" + bitmap.getHeight()); // bitmap.recycle(); // } Picasso.with(imageView.getContext().getApplicationContext()) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .placeholder(R.drawable.ic_image_load_place_holder) .config(Bitmap.Config.RGB_565) .tag(PicassoOnScrollListener.TAG) .into(imageView); }
/** * 加载高清大图是不需要缓存时使用该方法不缓存改, * 减少对内存的消耗,可以加快对内存的回收,防止内存溢出 * * @param context context * @param url url * @param imageView ImageView */ public static void downBigImage(Context context, String url, ImageView imageView) { Picasso.with(context).setIndicatorsEnabled(idDebug); Picasso.with(context) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .placeholder(R.mipmap.ic_launcher) //图片占位符 .error(R.mipmap.ic_launcher) //图片加载失败是加载的图片 .into(imageView); }
@Override public RequestCreator fetchImageStrip(String url) { if (!AIRPLANE_MODE) { return mPicasso.load(url); } else { return mPicasso.load(url) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .networkPolicy(NetworkPolicy.NO_CACHE); } }
void mapUnframedImages(List<BeanImage> beanImages, List<UnframedPicassoTargetNew> targets){ totalImages = beanImages.size(); this.targets = targets; if(totalImages > frameModel.getMaxFrameCount() && frameModel.isShouldSortImages()){ //sort image a/c to primary and secondary value Collections.sort(beanImages); } this.beanImages.addAll(beanImages); unframedImageCounter = 0; BeanImage beanImage = beanImages.get(0); if(Utils.isLocalPath(beanImage.getImageLink())){ Utils.logVerbose("LADING AS : "+"local image " + beanImage.getImageLink()); new UnframedLocalTask(this).execute(beanImage); } else { Utils.logVerbose("LADING AS : " + "server image " + beanImage.getImageLink()); UnframedPicassoTargetNew target = new UnframedPicassoTargetNew(this, beanImage); targets.add(target); currentFramePicasso.load(beanImage.getImageLink()).memoryPolicy(MemoryPolicy.NO_STORE) .networkPolicy(NetworkPolicy.NO_STORE) .noPlaceholder() .transform(new ScaleTransformation(frameModel.getMaxContainerWidth(), frameModel.getMaxContainerHeight(), totalImages, beanImage.getImageLink(), beanImage, this)) .into(target); } }
public static void downloadToImageView(Context context, String imageUrl, ImageView imageView){ Picasso.with(context) .load(baseUrl + imageUrl) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.NO_CACHE) .placeholder(R.drawable.placeholder) .error(R.drawable.error_loading) .into(imageView); }
@Override public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) { Picasso.with(activity)// .load(Uri.fromFile(new File(path)))// .placeholder(R.drawable.ic_default_image)// .error(R.drawable.ic_default_image)// .resize(width, height)// .centerInside()// .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)// .into(imageView); }
@Override public void displayImagePreview(Activity activity, String path, ImageView imageView, int width, int height) { Picasso.with(activity)// .load(Uri.fromFile(new File(path)))// .resize(width, height)// .centerInside()// .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)// .into(imageView); }
@Override protected void refreshView(final Airport airport) { getActivity().supportInvalidateOptionsMenu(); Picasso.with(getActivity()) .load(airport.imageLarge) .networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE) .memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE) .into(iv); tvCode.setText(airport.code); tvName.setText(airport.name); tvDescription.setText(applyMarkdown(airport.description)); String location = airport.city; if(!TextUtils.isEmpty(airport.stateShort)) location += ", " + airport.stateShort; location += " - " + airport.country; tvLocation.setText(location); String photoBy = "photo by "; SpannableStringBuilder imageCredit = new SpannableStringBuilder(photoBy); imageCredit.append(airport.imageCredit); imageCredit.setSpan(new StyleSpan(Typeface.BOLD), photoBy.length(), imageCredit.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tvImageCredit.setText(imageCredit); tvImageCredit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IntentUtils.goToUrl(getActivity(), airport.imageCreditLink); } }); getToolbar().setTitle(airport.code.toUpperCase()); getToolbar().setSubtitle(airport.city); }
/** * This method forces the image to be loaded from the network by skipping the caches. */ private void loadImageBitmapFromNetwork() { Picasso .with(context) .load(UsageExampleListView.eatFoodyImages[2]) .memoryPolicy(MemoryPolicy.NO_CACHE) .networkPolicy(NetworkPolicy.NO_CACHE) .into(imageViewFromNetwork); }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mImageView = (ImageView) view; mAttacher = new PhotoViewAttacher(mImageView); mAttacher.update(); PicassoProvider.getInstance(getActivity().getApplicationContext(), false) .load(getImageUrl()) .networkPolicy(NetworkPolicy.NO_STORE, NetworkPolicy.OFFLINE) .memoryPolicy(MemoryPolicy.NO_STORE) .placeholder(R.mipmap.ic_stub_dashboard_item) .into(mImageView); }
@Override protected void onImagePickedFromDevice(Uri imageUri, int requestCode) { if (requestCode == REQUEST_PICK_CUSTOM_IMAGE) { with(getContext()) .load(imageUri) .resize(MAX_WIDTH, 0) .memoryPolicy(MemoryPolicy.NO_CACHE) .into(_viewContainer._image); } }
@Override protected void onImagePickedFromDevice(Uri imageUri, int requestCode) { if (requestCode == REQUEST_PICK_CUSTOM_IMAGE) { with(getContext()) .load(imageUri) .resize(MAX_WIDTH, 0) .memoryPolicy(MemoryPolicy.NO_CACHE) .into(_viewContainer._inviteImageView); } }
@Override public void updateImageUrlExample(String value) { Picasso.with(getActivity()) .load(value) .memoryPolicy(MemoryPolicy.NO_CACHE) .placeholder(R.drawable.drawer_background) .error(R.drawable.drawer_background) .into(image); imageUrl.setText(value); }
@Override public void updateAvatarUrlExample(String value) { Picasso.with(getActivity()) .load(value) .memoryPolicy(MemoryPolicy.NO_CACHE) .placeholder(R.drawable.drawer_background) .error(R.drawable.drawer_background) .into(avatar); avatarUrl.setText(value); }
/** * Updates image (CircularImageView) on selecting a thumbnail * * @param v */ private void updateImage(CompoundImageView v) { if (v == mSelectedThumbnail) return; if (null != mSelectedThumbnail) { mSelectedThumbnail.setChecked(false); } mImage.setChecked(false); mSelectedThumbnail = v; mSelectedThumbnail.setChecked(true); switch (mSelectedThumbnail.getId()) { case R.id.thumbnail_1: mImage.setImageResource(R.drawable.c1); updateCode(getString(R.string.java_code_template, "R.drawable.c1")); break; case R.id.thumbnail_2: mImage.setImageResource(R.drawable.c2); updateCode(getString(R.string.java_code_template, "R.drawable.c2")); break; case R.id.thumbnail_no_image: mImage.setImageDrawable(null); updateCode(getString(R.string.java_code_template, "null")); break; case R.id.thumbnail_from_cloud: Toast.makeText(this, R.string.loading_remote_image, Toast.LENGTH_SHORT).show(); Picasso.with(this) .load("https://raw.githubusercontent.com/subinkrishna/CircularImageView/master/art/cat_original.jpg") .noFade() .placeholder(R.drawable.placeholder) .resize(mCivSize, mCivSize) .memoryPolicy(MemoryPolicy.NO_CACHE) .centerCrop() .into(mImage); updateCode(getString(R.string.picasso_code_template)); break; } }
@BindingAdapter({"compressImageUrl"}) public static void loadImageCompress(ImageView imageView, String url) { Picasso.with(imageView.getContext().getApplicationContext()) .load(url) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) //.placeholder(R.drawable.ic_image_load_place_holder) .config(Bitmap.Config.RGB_565) .tag(PicassoOnScrollListener.TAG) .into(imageView); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_crop_result); ButterKnife.bind(this); String filePath = getIntent().getStringExtra(EXTRA_FILE_PATH); File imageFile = new File(filePath); Picasso.with(this) .load(imageFile) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .into(resultView); // Or Glide //Glide.with(this) // .load(imageFile) // .diskCacheStrategy(DiskCacheStrategy.NONE) // .skipMemoryCache(true) // .into(resultView); // Or Android-Universal-Image-Loader //DisplayImageOptions options = new DisplayImageOptions.Builder() // .cacheInMemory(false) // .cacheOnDisk(false) // .build(); //ImageLoader.getInstance().displayImage("file://" + filePath, resultView, options); }
public void loadImageThumbnail(EvercamCamera camera) { imageView.setImageDrawable(null); if (camera.hasThumbnailUrl()) { Picasso.with(this).load(camera.getThumbnailUrl()) .memoryPolicy(MemoryPolicy.NO_CACHE) .into(imageView); } else { Log.e(TAG, camera.toString()); } }
public Bitmap getBitmap( Tile tile, Context context ) { Object data = tile.getData(); if( data instanceof String ) { String unformattedFileName = (String) tile.getData(); String formattedFileName = String.format( unformattedFileName, tile.getColumn(), tile.getRow() ); try { return Picasso.with( context ).load( formattedFileName ).memoryPolicy( MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE ).get(); } catch( Throwable t ) { // probably couldn't find the file, maybe OOME } } return null; }