com.example.android.unsplash.ui.grid.PhotoViewHolder Java Examples

The following examples show how to use com.example.android.unsplash.ui.grid.PhotoViewHolder. 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 populateGrid() {
    grid.setAdapter(new PhotoAdapter(this, relevantPhotos));
    grid.addOnItemTouchListener(new OnItemSelectedListener(MainActivity.this) {
        public void onItemSelected(RecyclerView.ViewHolder holder, int position) {
            if (!(holder instanceof PhotoViewHolder)) {
                return;
            }
            PhotoItemBinding binding = ((PhotoViewHolder) holder).getBinding();
            final Intent intent = getDetailActivityStartIntent(MainActivity.this,
                    relevantPhotos, position, binding);
            final ActivityOptions activityOptions = getActivityOptions(binding);

            MainActivity.this.startActivityForResult(intent, IntentUtil.REQUEST_CODE,
                    activityOptions.toBundle());
        }
    });
    empty.setVisibility(View.GONE);
}
 
Example #2
Source File: MainActivity.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void populateGrid() {
    grid.setAdapter(new PhotoAdapter(this, relevantPhotos));
    grid.addOnItemTouchListener(new OnItemSelectedListener(MainActivity.this) {
        public void onItemSelected(RecyclerView.ViewHolder holder, int position) {
            if (!(holder instanceof PhotoViewHolder)) {
                return;
            }
            MainActivity activity = MainActivity.this;
            PhotoViewHolder pvh = (PhotoViewHolder) holder;
            final Intent intent = getDetailActivityStartIntent(
                    activity, position, pvh);
            final ActivityOptions activityOptions = getActivityOptions(pvh);

            activity.startActivityForResult(
                    intent, IntentUtil.INSTANCE.getREQUEST_CODE(), activityOptions.toBundle());
        }
    });
    empty.setVisibility(View.GONE);
}
 
Example #3
Source File: MainActivity.java    From atlas with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Intent getDetailActivityStartIntent(Context context,
                                                   int position,
                                                   PhotoViewHolder holder) {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://multi-feature.instantappsample.com/detail/" + position));
    intent.setPackage(context.getPackageName());
    intent.addCategory(Intent.CATEGORY_BROWSABLE);

    TextView author =
            holder.itemView.findViewById(com.example.android.unsplash.base.R.id.author);

    // Working around unboxing issues with multiple dex files on platforms prior to N.
    intent.putExtra(IntentUtil.INSTANCE.getSELECTED_ITEM_POSITION(), position);
    intent.putExtra(IntentUtil.INSTANCE.getFONT_SIZE(), author.getTextSize());
    intent.putExtra(IntentUtil.INSTANCE.getPADDING(),
            new Rect(author.getPaddingLeft(),
                    author.getPaddingTop(),
                    author.getPaddingRight(),
                    author.getPaddingBottom()));
    intent.putExtra(IntentUtil.INSTANCE.getTEXT_COLOR(), author.getCurrentTextColor());
    return intent;
}
 
Example #4
Source File: MainActivity.java    From atlas with Apache License 2.0 6 votes vote down vote up
private ActivityOptions getActivityOptions(PhotoViewHolder holder) {
    TextView author =
            holder.itemView.findViewById(com.example.android.unsplash.base.R.id.author);
    ImageView photo =
            holder.itemView.findViewById(com.example.android.unsplash.base.R.id.photo);
    Pair authorPair = Pair.create(author, author.getTransitionName());
    Pair photoPair = Pair.create(photo, photo.getTransitionName());
    View decorView = getWindow().getDecorView();
    View statusBackground = decorView.findViewById(android.R.id.statusBarBackground);
    View navBackground = decorView.findViewById(android.R.id.navigationBarBackground);
    Pair statusPair = Pair.create(statusBackground,
            statusBackground.getTransitionName());

    final ActivityOptions options;
    if (navBackground == null) {
        options = ActivityOptions.makeSceneTransitionAnimation(this,
                authorPair, photoPair, statusPair);
    } else {
        Pair navPair = Pair.create(navBackground, navBackground.getTransitionName());
        options = ActivityOptions.makeSceneTransitionAnimation(this,
                authorPair, photoPair, statusPair, navPair);
    }
    return options;
}
 
Example #5
Source File: MainActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
private void populateGrid() {
    grid.setAdapter(new PhotoAdapter(this, relevantPhotos));
    grid.addOnItemTouchListener(new OnItemSelectedListener(MainActivity.this) {
        public void onItemSelected(RecyclerView.ViewHolder holder, int position) {
            if (!(holder instanceof PhotoViewHolder)) {
                return;
            }
            MainActivity activity = MainActivity.this;
            PhotoViewHolder pvh = (PhotoViewHolder) holder;
            final Intent intent = getDetailActivityStartIntent(
                    activity, position, pvh);
            final ActivityOptions activityOptions = getActivityOptions(pvh);

            activity.startActivityForResult(
                    intent, IntentUtil.REQUEST_CODE, activityOptions.toBundle());
        }
    });
    empty.setVisibility(View.GONE);
}
 
Example #6
Source File: MainActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
@NonNull
private static Intent getDetailActivityStartIntent(Context context,
                                                   int position,
                                                   PhotoViewHolder holder) {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://multi-feature.instantappsample.com/detail/" + position));
    intent.setPackage(context.getPackageName());
    intent.addCategory(Intent.CATEGORY_BROWSABLE);

    TextView author =
            holder.itemView.findViewById(com.example.android.unsplash.R.id.author);

    // Working around unboxing issues with multiple dex files on platforms prior to N.
    intent.putExtra(IntentUtil.SELECTED_ITEM_POSITION, position);
    intent.putExtra(IntentUtil.FONT_SIZE, author.getTextSize());
    intent.putExtra(IntentUtil.PADDING,
            new Rect(author.getPaddingLeft(),
                    author.getPaddingTop(),
                    author.getPaddingRight(),
                    author.getPaddingBottom()));
    intent.putExtra(IntentUtil.TEXT_COLOR, author.getCurrentTextColor());
    return intent;
}
 
Example #7
Source File: MainActivity.java    From android-instant-apps with Apache License 2.0 6 votes vote down vote up
private ActivityOptions getActivityOptions(PhotoViewHolder holder) {
    TextView author =
            holder.itemView.findViewById(com.example.android.unsplash.R.id.author);
    ImageView photo =
            holder.itemView.findViewById(com.example.android.unsplash.R.id.photo);
    Pair authorPair = Pair.create(author, author.getTransitionName());
    Pair photoPair = Pair.create(photo, photo.getTransitionName());
    View decorView = getWindow().getDecorView();
    View statusBackground = decorView.findViewById(android.R.id.statusBarBackground);
    View navBackground = decorView.findViewById(android.R.id.navigationBarBackground);
    Pair statusPair = Pair.create(statusBackground,
            statusBackground.getTransitionName());

    final ActivityOptions options;
    if (navBackground == null) {
        options = ActivityOptions.makeSceneTransitionAnimation(this,
                authorPair, photoPair, statusPair);
    } else {
        Pair navPair = Pair.create(navBackground, navBackground.getTransitionName());
        options = ActivityOptions.makeSceneTransitionAnimation(this,
                authorPair, photoPair, statusPair, navPair);
    }
    return options;
}
 
Example #8
Source File: MainActivity.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }
    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setBinding(holder.getBinding());
    setExitSharedElementCallback(callback);
}
 
Example #9
Source File: MainActivity.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.INSTANCE.getSELECTED_ITEM_POSITION(), 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }

    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);

}
 
Example #10
Source File: MainActivity.java    From android-instant-apps with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityReenter(int resultCode, Intent data) {
    postponeEnterTransition();
    // Start the postponed transition when the recycler view is ready to be drawn.
    grid.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            grid.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    if (data == null) {
        return;
    }

    final int selectedItem = data.getIntExtra(IntentUtil.SELECTED_ITEM_POSITION, 0);
    grid.scrollToPosition(selectedItem);

    PhotoViewHolder holder = (PhotoViewHolder) grid.
            findViewHolderForAdapterPosition(selectedItem);
    if (holder == null) {
        Log.w(TAG, "onActivityReenter: Holder is null, remapping cancelled.");
        return;
    }

    DetailSharedElementEnterCallback callback =
            new DetailSharedElementEnterCallback(getIntent());
    callback.setView(holder.itemView);
    setExitSharedElementCallback(callback);

}