Search in sources :

Example 1 with Photo

use of com.bumptech.glide.samples.flickr.api.Photo in project glide by bumptech.

the class FullscreenActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fullscreen_activity);
    ImageView fullscreenView = (ImageView) findViewById(R.id.fullscreen_view);
    Photo photo = getIntent().getParcelableExtra(ARG_PHOTO);
    Glide.with(this).load(photo).apply(fitCenterTransform(this)).into(fullscreenView);
}
Also used : Photo(com.bumptech.glide.samples.flickr.api.Photo) ImageView(android.widget.ImageView)

Example 2 with Photo

use of com.bumptech.glide.samples.flickr.api.Photo in project glide by bumptech.

the class FlickrPhotoList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View result = inflater.inflate(R.layout.flickr_photo_list, container, false);
    list = (RecyclerView) result.findViewById(R.id.flickr_photo_list);
    layoutManager = new LinearLayoutManager(getActivity());
    list.setLayoutManager(layoutManager);
    adapter = new FlickrPhotoListAdapter();
    list.setAdapter(adapter);
    preloadSizeProvider = new ViewPreloadSizeProvider<>();
    RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);
    list.addOnScrollListener(preloader);
    list.setItemViewCacheSize(0);
    if (currentPhotos != null) {
        adapter.setPhotos(currentPhotos);
    }
    final RequestManager requestManager = Glide.with(this);
    fullRequest = requestManager.asDrawable().apply(centerCropTransform(getActivity()).placeholder(new ColorDrawable(Color.GRAY)));
    thumbRequest = requestManager.asDrawable().apply(diskCacheStrategyOf(DiskCacheStrategy.DATA).override(Api.SQUARE_THUMB_SIZE)).transition(withCrossFade());
    list.setRecyclerListener(new RecyclerView.RecyclerListener() {

        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder;
            requestManager.clear(vh.imageView);
        }
    });
    if (savedInstanceState != null) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
        layoutManager.scrollToPositionWithOffset(index, offset);
    }
    return result;
}
Also used : RecyclerViewPreloader(com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader) Photo(com.bumptech.glide.samples.flickr.api.Photo) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RequestManager(com.bumptech.glide.RequestManager) ColorDrawable(android.graphics.drawable.ColorDrawable) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with Photo

use of com.bumptech.glide.samples.flickr.api.Photo in project glide by bumptech.

the class FlickrPhotoGrid method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = getArguments();
    photoSize = args.getInt(IMAGE_SIZE_KEY);
    thumbnail = args.getBoolean(THUMBNAIL_KEY);
    fullRequest = Glide.with(this).asDrawable().transition(withNoTransition()).apply(centerCropTransform(getActivity()));
    thumbnailRequest = Glide.with(this).asDrawable().transition(withNoTransition()).apply(diskCacheStrategyOf(DiskCacheStrategy.DATA).centerCrop(getActivity()).override(Api.SQUARE_THUMB_SIZE));
    preloadRequest = thumbnail ? thumbnailRequest.clone().apply(priorityOf(Priority.HIGH)) : fullRequest;
    final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false);
    final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin);
    int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin));
    grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid);
    layoutManager = new GridLayoutManager(getActivity(), spanCount);
    grid.setLayoutManager(layoutManager);
    grid.addItemDecoration(new RecyclerView.ItemDecoration() {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(gridMargin, gridMargin, gridMargin, gridMargin);
        }
    });
    grid.setRecyclerListener(new RecyclerView.RecyclerListener() {

        @Override
        public void onViewRecycled(RecyclerView.ViewHolder holder) {
            PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder;
            Glide.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView);
        }
    });
    int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize;
    grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2);
    grid.setItemViewCacheSize(0);
    adapter = new PhotoAdapter();
    grid.setAdapter(adapter);
    FixedPreloadSizeProvider<Photo> preloadSizeProvider = new FixedPreloadSizeProvider<>(photoSize, photoSize);
    RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter, preloadSizeProvider, args.getInt(PRELOAD_KEY));
    grid.addOnScrollListener(preloader);
    if (currentPhotos != null) {
        adapter.setPhotos(currentPhotos);
    }
    if (savedInstanceState != null) {
        int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
        grid.scrollToPosition(index);
    }
    return result;
}
Also used : FixedPreloadSizeProvider(com.bumptech.glide.util.FixedPreloadSizeProvider) Rect(android.graphics.Rect) RecyclerViewPreloader(com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader) Bundle(android.os.Bundle) Photo(com.bumptech.glide.samples.flickr.api.Photo) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

ImageView (android.widget.ImageView)3 Photo (com.bumptech.glide.samples.flickr.api.Photo)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 RecyclerViewPreloader (com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader)2 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Bundle (android.os.Bundle)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 TextView (android.widget.TextView)1 RequestManager (com.bumptech.glide.RequestManager)1 FixedPreloadSizeProvider (com.bumptech.glide.util.FixedPreloadSizeProvider)1