com.squareup.picasso.MemoryPolicy Java Examples

The following examples show how to use com.squareup.picasso.MemoryPolicy. 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: FourActivity.java    From YCGallery with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_four);

    zoomView = findViewById(R.id.zoomView);
    zoomView.setLoadingVisibility(true);
    Uri parse = Uri.parse("file:///android_asset/yc.png");
    Picasso.with(this)
            .load(parse)
            .memoryPolicy(MemoryPolicy.NO_CACHE)
            .into(zoomView.getImageView(), new Callback() {
                @Override
                public void onSuccess() {
                    zoomView.setZoomViewVisibility(true);
                }

                @Override
                public void onError() {

                }
            });
}
 
Example #2
Source File: LoyalUtil.java    From LoyalNativeSlider with MIT License 6 votes vote down vote up
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() {

                }
            });
}
 
Example #3
Source File: template_automatic_ll.java    From KickAssSlidingMenu with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: template_automatic_ll.java    From KickAssSlidingMenu with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: PullImageController.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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).invalidate(request);
            PicassoProvider.getInstance(context, false)
                    .load(request).networkPolicy(NetworkPolicy.NO_CACHE)
                    .memoryPolicy(MemoryPolicy.NO_CACHE).fetch();
        } else {
            PicassoProvider.getInstance(context, false)
                    .load(request).fetch();
        }

    }
}
 
Example #6
Source File: UrlFragment.java    From Faker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: UrlFragment.java    From Faker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: MainActivity.java    From CircularImageView with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #9
Source File: PicassoImageLoader.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: CropResultActivity.java    From scissors with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: ImageViewFragment.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: PicassoImageLoader.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: PicassoImageLoader.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: PicassoBinding.java    From AndroidAgeraTutorial with Apache License 2.0 5 votes vote down vote up
@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);
    }
 
Example #15
Source File: StudentDetailActivity.java    From Base with Apache License 2.0 5 votes vote down vote up
@Override
public void updateImage(String someUrl) {
    Picasso.with(this)
            .load(someUrl)
            .placeholder(R.drawable.ic_account_box_24dp)
            .error(R.drawable.ic_account_box_24dp)
            .memoryPolicy(MemoryPolicy.NO_CACHE)
            .into(mImage);
}
 
Example #16
Source File: VideoActivity.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void loadImageThumbnail(EvercamCamera camera) {
    imageView.setImageDrawable(null);

    if (camera.hasThumbnailUrl()) {
        Picasso.get().load(camera.getThumbnailUrl())
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .into(imageView);
    } else {
        Log.e(TAG, camera.toString());
    }
}
 
Example #17
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 #18
Source File: LoyalUtil.java    From LoyalNativeSlider with MIT License 4 votes vote down vote up
public static void picassoImplementation(String u, ImageView target, Context context) {
    Picasso.with(context)
            .load(u)
            .memoryPolicy(MemoryPolicy.NO_STORE, MemoryPolicy.NO_CACHE)
            .into(target);
}
 
Example #19
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 #20
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 #21
Source File: CardPresenter.java    From alltv with MIT License 4 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {

    ChannelData tvCh = (ChannelData) item;
    ImageCardView cardView = (ImageCardView) viewHolder.view;

    //Log.d(TAG, "onBindViewHolder");

    if (tvCh.getStillImageUrl() != null) {

        ArrayList<EPGData> epgData = tvCh.getEPG();
        Date date = new Date();

        Boolean isAdultContent = false;

        for(int i=0; i<epgData.size(); i++) {
            if(date.compareTo(epgData.get(i).getEndTime()) < 0) {
                tvCh.setProgramName(epgData.get(i).getProgramName());
                isAdultContent = epgData.get(i).isAdultContent();
                break;
            }
        }

        if(tvCh.getProgramName().equals("") || isAdultContent)
            cardView.setTitleText(tvCh.getTitle());
        else
            cardView.setTitleText(tvCh.getTitle() + " - " + tvCh.getProgramName());

        cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);

        int ret = tvCh.getFavorite();

        if(ret == 0)
            cardView.setBadgeImage(null);
        else if(ret == 1)
            cardView.setBadgeImage(cardView.getResources().getDrawable(R.drawable.star_icon, null));
        else if(ret == 2)
            cardView.setBadgeImage(cardView.getResources().getDrawable(R.drawable.wavve_icon_24, null));
        else if(ret == 3)
            cardView.setBadgeImage(cardView.getResources().getDrawable(R.drawable.tving_icon_24, null));
        else if(ret == 4)
            cardView.setBadgeImage(cardView.getResources().getDrawable(R.drawable.oksusu_icon_24, null));

        Picasso.get().load(tvCh.getStillImageUrl())
                .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                .into(cardView.getMainImageView());

    }
}
 
Example #22
Source File: ThirdActivity.java    From YCGallery with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    // 设置contentFeature,可使用切换动画

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        }
        Transition explode = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            explode = TransitionInflater.from(this).inflateTransition(android.R.transition.explode);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setEnterTransition(explode);
        }
    }



    setContentView(R.layout.activity_third);

    imageView = findViewById(R.id.image);
    Uri parse = Uri.parse("file:///android_asset/yc.png");
    Picasso.with(this)
            .load(parse)
            .memoryPolicy(MemoryPolicy.NO_CACHE)
            .into(imageView, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError() {

                }
            });


}
 
Example #23
Source File: PicturePresenter.java    From AndroidDemo with MIT License 4 votes vote down vote up
public void loadImageView() {

        iPictureView.clearImageView();

        boolean cache = iPictureView.getCache();
        boolean disk = iPictureView.getDisk();
        boolean transformation = iPictureView.getTransformation();

        Picasso picasso = Picasso.with(context.get());
        picasso.setIndicatorsEnabled(true);
        picasso.setLoggingEnabled(true);

        String path = "https://avatars2.githubusercontent.com/u/9563634?s=400&u=6c9844a5ee91e0385888cbd5708af59f4062d651&v=4";
        RequestCreator requestCreator = picasso.load(path)
                .config(Bitmap.Config.RGB_565)
                .placeholder(R.drawable.ic_empty_zhihu)
                .error(R.drawable.ic_failed)
                .fit();

        if (!cache) {
            requestCreator.memoryPolicy(MemoryPolicy.NO_CACHE);
        }
        if (!disk) {
            requestCreator.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE);
        }

        if (transformation) {
            final Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(0xffcccccc);
            paint.setStyle(Paint.Style.FILL);
            final float round = Tools.dip2pxf(context.get(), 8);
            requestCreator.transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {

                    Bitmap src = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
                    Canvas canvas = new Canvas(src);
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                        float r = source.getWidth() / 4 * 3;
                        canvas.drawCircle(source.getWidth() / 2, source.getHeight() / 2, r, paint);
                    } else {
                        canvas.drawRoundRect(round, round, source.getWidth() - round, source.getHeight() - round,
                                round, round, paint);
                    }
                    canvas.drawBitmap(source, 0, 0, paint);
                    if (!source.isRecycled()) {
                        source.recycle();
                    }
                    return src;
                }

                @Override
                public String key() {
                    return "PicassoTransformation";
                }
            });
        }
        requestCreator.into(iPictureView.getTarget(), new Callback() {
            @Override
            public void onSuccess() {
                iPictureView.showToast("success");
            }

            @Override
            public void onError() {
                iPictureView.showToast("error");
            }
        });
    }