com.example.android.unsplash.data.model.Photo Java Examples

The following examples show how to use com.example.android.unsplash.data.model.Photo. 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: MainActivity.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
private void displayData() {
    if (relevantPhotos != null) {
        populateGrid();
    } else {
        UnsplashService unsplashApi = new RestAdapter.Builder()
                .setEndpoint(UnsplashService.ENDPOINT)
                .build()
                .create(UnsplashService.class);
        unsplashApi.getFeed(new Callback<List<Photo>>() {
            @Override
            public void success(List<Photo> photos, Response response) {
                // the first items not interesting to us, get the last <n>
                relevantPhotos = new ArrayList<>(photos.subList(photos.size() - PHOTO_COUNT,
                        photos.size()));
                populateGrid();
            }

            @Override
            public void failure(RetrofitError error) {
                Log.e(TAG, "Error retrieving Unsplash feed:", error);
            }
        });
    }
}
 
Example #2
Source File: DetailActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(
            com.example.android.unsplash.R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
Example #3
Source File: PhotoAdapter.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(final PhotoViewHolder holder, final int position) {
    Photo data = photos.get(position);
    TextView authorview = holder.itemView.findViewById(R.id.author);
    ImageView photoview = holder.itemView.findViewById(R.id.photo);
    holder.setAuthor(data.author);
    photoview.setTransitionName(String.format(photoTransitionFormat, data.id));
    authorview.setText(data.author);
    authorview.setTransitionName(String.format(authorTransitionFormat, data.id));
    holder.setId(data.id);
    Glide.with(layoutInflater.getContext())
            .load(data.getPhotoUrl(requestedPhotoWidth))
            .placeholder(R.color.placeholder)
            .override(ImageSize.NORMAL[0], ImageSize.NORMAL[1])
            .into((ImageView) holder.itemView.findViewById(R.id.photo));
}
 
Example #4
Source File: PhotoService.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
public void getPhotosAsync(final PhotoCallback callback) {
    if (mPhotos == null) {
        new RestAdapter.Builder()
                .setEndpoint(UnsplashService.ENDPOINT)
                .build()
                .create(UnsplashService.class).getFeed(new Callback<List<Photo>>() {
            @Override
            public void success(List<Photo> photos, Response response) {
                // the first items not interesting to us, get the last <n>
                mPhotos = new ArrayList<>(photos.subList(photos.size() - PHOTO_COUNT,
                        photos.size()));
                callback.success(mPhotos);
            }

            @Override
            public void failure(RetrofitError error) {
                callback.error();
                Log.e(TAG, "Could not load photos, " + error);
            }
        });
    } else {
        callback.success(mPhotos);
    }
}
 
Example #5
Source File: MainActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
private void displayData() {
    if (relevantPhotos != null) {
        populateGrid();
    } else {
        PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {
            @Override
            public void success(ArrayList<Photo> photos) {
                relevantPhotos = photos;
                populateGrid();
            }

            @Override
            public void error() {
                // no-op
            }
        });
    }
}
 
Example #6
Source File: DetailActivity.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(
            com.example.android.unsplash.base.R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
Example #7
Source File: MainActivity.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void displayData() {
    if (relevantPhotos != null) {
        populateGrid();
    } else {
        PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {
            @Override
            public void success(ArrayList<Photo> photos) {
                relevantPhotos = photos;
                populateGrid();
            }

            @Override
            public void error() {
                // no-op
            }
        });
    }
}
 
Example #8
Source File: PhotoAdapter.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(final PhotoViewHolder holder, final int position) {
    Photo data = photos.get(position);
    TextView authorview = holder.itemView.findViewById(R.id.author);
    ImageView photoview = holder.itemView.findViewById(R.id.photo);
    holder.setAuthor(data.author);
    photoview.setTransitionName(String.format(photoTransitionFormat, data.id));
    authorview.setText(data.author);
    authorview.setTransitionName(String.format(authorTransitionFormat, data.id));
    holder.setId(data.id);
    Glide.with(layoutInflater.getContext())
            .load(data.getPhotoUrl(requestedPhotoWidth))
            .placeholder(R.color.placeholder)
            .override(ImageSize.NORMAL[0], ImageSize.NORMAL[1])
            .into((ImageView) holder.itemView.findViewById(R.id.photo));
}
 
Example #9
Source File: PhotoService.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void getPhotosAsync(final PhotoCallback callback) {
    if (mPhotos == null) {
        new RestAdapter.Builder()
                .setEndpoint(UnsplashService.ENDPOINT)
                .build()
                .create(UnsplashService.class).getFeed(new Callback<List<Photo>>() {
            @Override
            public void success(List<Photo> photos, Response response) {
                // the first items not interesting to us, get the last <n>
                mPhotos = new ArrayList<>(photos.subList(photos.size() - PHOTO_COUNT,
                        photos.size()));
                callback.success(mPhotos);
            }

            @Override
            public void failure(RetrofitError error) {
                callback.error();
                Log.e(TAG, "Could not load photos, " + error);
            }
        });
    } else {
        callback.success(mPhotos);
    }
}
 
Example #10
Source File: DetailActivity.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
private void setUpViewPager(ArrayList<Photo> photos) {
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(new DetailViewPagerAdapter(this, photos, sharedElementCallback));
    viewPager.setCurrentItem(initialItem);

    viewPager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (viewPager.getChildCount() > 0) {
                viewPager.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        }
    });

    viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.padding_mini));
    viewPager.setPageMarginDrawable(R.drawable.page_margin);
}
 
Example #11
Source File: DetailActivity.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);

    postponeEnterTransition();

    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this,
            android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);

    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    initialItem = intent.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    setUpViewPager(intent.<Photo>getParcelableArrayListExtra(IntentUtil.PHOTO));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);

    super.onCreate(savedInstanceState);
}
 
Example #12
Source File: MainActivity.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Intent getDetailActivityStartIntent(Activity host, ArrayList<Photo> photos,
                                                   int position, PhotoItemBinding binding) {
    final Intent intent = new Intent(host, DetailActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putParcelableArrayListExtra(IntentUtil.PHOTO, photos);
    intent.putExtra(IntentUtil.SELECTED_ITEM_POSITION, position);
    intent.putExtra(IntentUtil.FONT_SIZE, binding.author.getTextSize());
    intent.putExtra(IntentUtil.PADDING,
            new Rect(binding.author.getPaddingLeft(),
                    binding.author.getPaddingTop(),
                    binding.author.getPaddingRight(),
                    binding.author.getPaddingBottom()));
    intent.putExtra(IntentUtil.TEXT_COLOR, binding.author.getCurrentTextColor());
    return intent;
}
 
Example #13
Source File: DetailViewPagerAdapter.java    From android-instant-apps with Apache License 2.0 5 votes vote down vote up
private void onViewBound(ImageView imageView, Photo photo) {
    Glide.with(host)
            .load(photo.getPhotoUrl(photoWidth))
            .placeholder(R.color.placeholder)
            .override(ImageSize.NORMAL[0], ImageSize.NORMAL[1])
            .into(imageView);
}
 
Example #14
Source File: PhotoAdapter.java    From atlas with Apache License 2.0 5 votes vote down vote up
public PhotoAdapter(@NonNull Context context, @NonNull ArrayList<Photo> photos) {
    this.photos = photos;
    requestedPhotoWidth = context.getResources().getDisplayMetrics().widthPixels;
    authorTransitionFormat = context.getResources().getString(R.string.transition_author);
    photoTransitionFormat = context.getResources().getString(R.string.transition_photo);
    layoutInflater = LayoutInflater.from(context);
}
 
Example #15
Source File: DetailViewPagerAdapter.java    From atlas with Apache License 2.0 5 votes vote down vote up
public DetailViewPagerAdapter(@NonNull Activity activity, @NonNull List<Photo> photos,
                              @NonNull DetailSharedElementEnterCallback callback) {
    layoutInflater = LayoutInflater.from(activity);
    allPhotos = photos;
    photoWidth = activity.getResources().getDisplayMetrics().widthPixels;
    host = activity;
    sharedElementCallback = callback;
    authorTransitionFormat = activity.getResources().getString(R.string.transition_author);
    photoTransitionFormat = activity.getResources().getString(R.string.transition_photo);
}
 
Example #16
Source File: DetailViewPagerAdapter.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void onViewBound(ImageView imageView, Photo photo) {
    Glide.with(host)
            .load(photo.getPhotoUrl(photoWidth))
            .placeholder(R.color.placeholder)
            .override(ImageSize.NORMAL[0], ImageSize.NORMAL[1])
            .into(imageView);
}
 
Example #17
Source File: DetailViewPagerAdapter.java    From android-instant-apps with Apache License 2.0 5 votes vote down vote up
public DetailViewPagerAdapter(@NonNull Activity activity, @NonNull List<Photo> photos,
                              @NonNull DetailSharedElementEnterCallback callback) {
    layoutInflater = LayoutInflater.from(activity);
    allPhotos = photos;
    photoWidth = activity.getResources().getDisplayMetrics().widthPixels;
    host = activity;
    sharedElementCallback = callback;
    authorTransitionFormat = activity.getResources().getString(R.string.transition_author);
    photoTransitionFormat = activity.getResources().getString(R.string.transition_photo);
}
 
Example #18
Source File: DetailViewPagerAdapter.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
public DetailViewPagerAdapter(@NonNull Activity activity, @NonNull List<Photo> photos,
                              @NonNull DetailSharedElementEnterCallback callback) {
    layoutInflater = LayoutInflater.from(activity);
    allPhotos = photos;
    photoWidth = activity.getResources().getDisplayMetrics().widthPixels;
    host = activity;
    sharedElementCallback = callback;
}
 
Example #19
Source File: PhotoAdapter.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final PhotoViewHolder holder, final int position) {
    PhotoItemBinding binding = holder.getBinding();
    Photo data = photos.get(position);
    binding.setData(data);
    binding.executePendingBindings();
    Glide.with(layoutInflater.getContext())
            .load(holder.getBinding().getData().getPhotoUrl(requestedPhotoWidth))
            .placeholder(R.color.placeholder)
            .override(ImageSize.NORMAL[0], ImageSize.NORMAL[1])
            .into(holder.getBinding().photo);
}
 
Example #20
Source File: PhotoAdapter.java    From android-instant-apps with Apache License 2.0 5 votes vote down vote up
public PhotoAdapter(@NonNull Context context, @NonNull ArrayList<Photo> photos) {
    this.photos = photos;
    requestedPhotoWidth = context.getResources().getDisplayMetrics().widthPixels;
    authorTransitionFormat = context.getResources().getString(R.string.transition_author);
    photoTransitionFormat = context.getResources().getString(R.string.transition_photo);
    layoutInflater = LayoutInflater.from(context);
}
 
Example #21
Source File: UnsplashService.java    From animation-samples with Apache License 2.0 4 votes vote down vote up
@GET("/list")
void getFeed(Callback<List<Photo>> callback);
 
Example #22
Source File: DetailActivity.java    From android-instant-apps with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);

    postponeEnterTransition();

    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this,
            android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);

    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    try {
        initialItem = Integer.parseInt(intent.getData().getLastPathSegment());
    } catch (NumberFormatException e) {
        initialItem = 0;
    }
    PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {
        @Override
        public void success(ArrayList<Photo> photos) {
            setUpViewPager(photos);
            findViewById(android.R.id.empty).setVisibility(View.GONE);
        }

        @Override
        public void error() {
            finishAfterTransition();
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);

    super.onCreate(savedInstanceState);
}
 
Example #23
Source File: PhotoViewHolder.java    From android-instant-apps with Apache License 2.0 4 votes vote down vote up
public PhotoViewHolder(View view, Photo photo) {
    super(view);
    author = photo.author;
    id = photo.id;
}
 
Example #24
Source File: UnsplashService.java    From android-instant-apps with Apache License 2.0 4 votes vote down vote up
@GET("/list")
void getFeed(Callback<List<Photo>> callback);
 
Example #25
Source File: PhotoAdapter.java    From animation-samples with Apache License 2.0 4 votes vote down vote up
public PhotoAdapter(@NonNull Context context, @NonNull ArrayList<Photo> photos) {
    this.photos = photos;
    requestedPhotoWidth = context.getResources().getDisplayMetrics().widthPixels;
    layoutInflater = LayoutInflater.from(context);
}
 
Example #26
Source File: DetailActivity.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_detail);

    postponeEnterTransition();

    TransitionSet transitions = new TransitionSet();
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(AnimationUtils.loadInterpolator(this,
            android.R.interpolator.linear_out_slow_in));
    slide.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
    transitions.addTransition(slide);
    transitions.addTransition(new Fade());
    getWindow().setEnterTransition(transitions);

    Intent intent = getIntent();
    sharedElementCallback = new DetailSharedElementEnterCallback(intent);
    setEnterSharedElementCallback(sharedElementCallback);
    try {
        initialItem = Integer.parseInt(intent.getData().getLastPathSegment());
    } catch (NumberFormatException e) {
        initialItem = 0;
    }
    PhotoService.getInstance().getPhotosAsync(new PhotoService.PhotoCallback() {
        @Override
        public void success(ArrayList<Photo> photos) {
            setUpViewPager(photos);
            findViewById(android.R.id.empty).setVisibility(View.GONE);
        }

        @Override
        public void error() {
            finishAfterTransition();
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(navigationOnClickListener);

    super.onCreate(savedInstanceState);
}
 
Example #27
Source File: PhotoViewHolder.java    From atlas with Apache License 2.0 4 votes vote down vote up
public PhotoViewHolder(View view, Photo photo) {
    super(view);
    author = photo.author;
    id = photo.id;
}
 
Example #28
Source File: UnsplashService.java    From atlas with Apache License 2.0 4 votes vote down vote up
@GET("/list")
void getFeed(Callback<List<Photo>> callback);
 
Example #29
Source File: PhotoService.java    From android-instant-apps with Apache License 2.0 votes vote down vote up
void success(ArrayList<Photo> photos); 
Example #30
Source File: PhotoService.java    From atlas with Apache License 2.0 votes vote down vote up
void success(ArrayList<Photo> photos);