android.support.v17.leanback.widget.Presenter Java Examples

The following examples show how to use android.support.v17.leanback.widget.Presenter. 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: VideoContentCardPresenter.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    VideoContent clip = (VideoContent) item;
    if (clip.getCardImageUrl() != null) {
        ImageCardView cardView = (ImageCardView) viewHolder.view;
        Resources resources = cardView.getContext().getResources();
        cardView.setTitleText(clip.getTitle());
        cardView.setContentText(clip.getDescription());
        int cardWidth = Math.round(resources.getDimensionPixelSize(R.dimen.card_width)
        );
        int cardHeight = resources.getDimensionPixelSize(R.dimen.card_height);
        cardView.setMainImageDimensions(cardWidth, cardHeight);
        Glide.with(viewHolder.view.getContext())
                .load(clip.getCardImageUrl())
                .into(cardView.getMainImageView());
    }
}
 
Example #2
Source File: AllTvBaseRowsSupportFragment.java    From alltv with MIT License 6 votes vote down vote up
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                           RowPresenter.ViewHolder rowViewHolder, Row row) {

    if(rowViewHolder.getSelectedItem() != null) {
        ChannelData channelData = (ChannelData)rowViewHolder.getSelectedItem();

        mRowIndex = getSelectedPosition();
        mItemIndex = channelData.getItemIndex();

        // Log.e(TAG, "onItemSelected: row: " + Integer.toString(mRowIndex) + ", Cnt: " + Integer.toString(mItemIndex));
    } else {
        mRowIndex = 0;
        mItemIndex = 0;
    }

}
 
Example #3
Source File: MainFragment.java    From alltv with MIT License 6 votes vote down vote up
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                          RowPresenter.ViewHolder rowViewHolder, Row row) {

    if (item instanceof String) {
        if (((String) item).contains(getString(R.string.preferences))) {

            Intent intent = new Intent(getActivity(), SettingsActivity.class);
            intent.putExtra(getStringById(R.string.SETTINGSDATA_STR), mGson.toJson(mSettingsData));
            getActivity().startActivityForResult(intent, Utils.Code.SettingsRequestCode.ordinal());

        } else if (((String) item).contains(getString(R.string.opensource))) {
            showLicensesDialogFragment();
        }
    }

}
 
Example #4
Source File: VideoDetailsFragment.java    From leanback-assistant with Apache License 2.0 6 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    ImageView imageView =
            (ImageView)
                    LayoutInflater.from(parent.getContext())
                            .inflate(
                                    R.layout.lb_fullwidth_details_overview_logo,
                                    parent,
                                    false);

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.detail_thumb_width);
    int height = res.getDimensionPixelSize(R.dimen.detail_thumb_height);
    imageView.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    return new ViewHolder(imageView);
}
 
Example #5
Source File: MainFragment.java    From leanback-homescreen-channels with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
        RowPresenter.ViewHolder rowViewHolder, Row row) {
    if (isAdded()) {
        if (item instanceof Clip) {
            Clip clip = (Clip) item;
            Intent intent = new Intent(getActivity(), PlaybackActivity.class);
            intent.putExtra(PlaybackActivity.EXTRA_CLIP, clip);
            startActivity(intent);
            final long programId = clip.getProgramId();
            if (programId != 0) {
                // This clip is published as a program. Increment the view count for the
                // program to demonstrate updating.
                new SetViewCountInBackground(programId, clip.incrementViewCount());
            }
        }
    }
}
 
Example #6
Source File: CardPresenter.java    From leanback-homescreen-channels with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    Clip clip = (Clip) item;
    if (clip.getCardImageUrl() != null) {
        ImageCardView cardView = (ImageCardView) viewHolder.view;
        Resources resources = cardView.getContext().getResources();
        cardView.setTitleText(clip.getTitle());
        cardView.setContentText(clip.getDescription());
        float widthMultiplier = getWidthMultplier(clip.getAspectRatio());
        int cardWidth = Math.round(resources.getDimensionPixelSize(R.dimen.card_width)
                * widthMultiplier);
        int cardHeight = resources.getDimensionPixelSize(R.dimen.card_height);
        cardView.setMainImageDimensions(cardWidth, cardHeight);
        Glide.with(viewHolder.view.getContext())
                .load(clip.getCardImageUrl())
                .into(cardView.getMainImageView());
    }
}
 
Example #7
Source File: CardPresenterSelector.java    From leanback-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public Presenter getPresenter(Object o) {
	if (o instanceof Movie) {
		if (((Movie) o).getCategory().equals(MOVIE_CATEGORY[0])) {
			return new IconCardPresenter();
		} else if (((Movie) o).getCategory().equals(MOVIE_CATEGORY[1])) {
			return new LoadingCardPresenter();
		} else if (((Movie) o).getCategory().equals(MOVIE_CATEGORY[2])) {
			return new OverlayCardPresenter();
		} else {
			return new ProcessCardPresenter();
		}
	} else {
		return new CardPresenter();
	}
}
 
Example #8
Source File: CardPresenter.java    From leanback-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
	Movie movie = (Movie) item;
	ImageCardView cardView = (ImageCardView) viewHolder.view;

	Log.d(TAG, "onBindViewHolder");
	if (movie.getCardImageUrl() != null) {
		cardView.setTitleText(movie.getTitle());
		cardView.setContentText(movie.getStudio());
		cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);
		Glide.with(viewHolder.view.getContext())
				.load(movie.getCardImageUrl())
				.centerCrop()
				.error(mDefaultCardImage)
				.into(cardView.getMainImageView());
	}
}
 
Example #9
Source File: VideoGridExampleFragment.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                          RowPresenter.ViewHolder rowViewHolder, Row row) {
    if (item instanceof  VideoCard) {
        VideoCard itemCard = (VideoCard) item;
        List<String> videoSources = itemCard.getVideoSources();
        if (videoSources == null || videoSources.isEmpty()) {
            return;
        }

        MediaMetaData metaData = new MediaMetaData();
        metaData.setMediaSourcePath(videoSources.get(0));
        metaData.setMediaTitle(itemCard.getTitle());
        metaData.setMediaArtistName(itemCard.getDescription());
        metaData.setMediaAlbumArtUrl(itemCard.getImageUrl());
        Intent intent = new Intent(getActivity(), VideoExampleActivity.class);
        intent.putExtra(VideoExampleActivity.TAG, metaData);
        intent.setData(Uri.parse(metaData.getMediaSourcePath()));
        getActivity().startActivity(intent);
    }
}
 
Example #10
Source File: DetailsFragment.java    From iview-android-tv with MIT License 6 votes vote down vote up
private OnItemViewClickedListener getItemClickedListener() {
    return new OnItemViewClickedListener() {
        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
            Log.d(TAG, "Clicked item:" + item);
            if (item instanceof EpisodeBaseModel) {
                EpisodeBaseModel ep = (EpisodeBaseModel) item;
                Intent intent = new Intent(getActivity(), getPlayerActivityClass());
                intent.putExtra(ContentManagerBase.CONTENT_ID, ep);
                String[] others = getOtherEpisodeUrls().toArray(new String[getOtherEpisodeUrls().size()]);
                intent.putExtra(ContentManagerBase.OTHER_EPISODES, others);
                startActivity(intent);
            }
        }
    };
}
 
Example #11
Source File: ListenerModule.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@PerFragment
@Provides
@IntoMap
@ListenerModuleKey(LiveDataFragment.class)
public OnItemViewSelectedListener provideOnItemViewSelectedListener(final Activity activity,
        final DisplayMetrics metrics, final BackgroundManager backgroundManager,
        final RequestOptions defaultPlaceHolder, final Drawable finalDrawable, final Handler mainHandler) {
    return new OnItemViewSelectedListener() {
        @Override
        public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                RowPresenter.ViewHolder rowViewHolder, Row row) {
            VideoEntity selectedVideo = (VideoEntity) item;
            RunnableClass backgroundRunnable = new RunnableClass(selectedVideo, activity,
                    metrics, backgroundManager, defaultPlaceHolder, finalDrawable);

            if (lastTime != null) {
                mainHandler.removeCallbacks(lastTime);
            }
            mainHandler.postDelayed(backgroundRunnable, BACKGROUND_UPDATE_DELAY);
            lastTime = backgroundRunnable;
        }
    };
}
 
Example #12
Source File: PageAndListRowFragment.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
public SampleFragmentB() {
    mRowsAdapter = new ArrayObjectAdapter(new ShadowRowPresenterSelector());

    setAdapter(mRowsAdapter);
    setOnItemViewClickedListener(new OnItemViewClickedListener() {
        @Override
        public void onItemClicked(
                Presenter.ViewHolder itemViewHolder,
                Object item,
                RowPresenter.ViewHolder rowViewHolder,
                Row row) {
            Toast.makeText(getActivity(), "Implement click handler", Toast.LENGTH_SHORT)
                    .show();
        }
    });
}
 
Example #13
Source File: DetailViewExampleWithVideoBackgroundFragment.java    From leanback-showcase with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
                          RowPresenter.ViewHolder rowViewHolder, Row row) {
    if (!(item instanceof Action)) return;
    Action action = (Action) item;
    long id = action.getId();

    if (id == ACTION_RENT) {
        startWizardActivityForPayment();
    } else if (action.getId() == ACTION_PLAY) {
        playMainVideoOnBackground();
    } else if (action.getId() == ACTION_RELATED) {
        setSelectedPosition(1);
    } else {
        Toast.makeText(getActivity(), getString(R.string.action_cicked), Toast.LENGTH_LONG)
                .show();
    }
}
 
Example #14
Source File: LeanbackBrowseFragment.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
protected OnItemViewClickedListener getDefaultItemViewClickedListener() {
    return new OnItemViewClickedListener() {

        @Override
        public void onItemClicked(Presenter.ViewHolder viewHolder, Object o, RowPresenter.ViewHolder viewHolder2, Row row) {

            Intent intent = new Intent(getActivity(), VideoDetailsActivity.class);
            intent.putExtra(Video.INTENT_EXTRA_VIDEO, (Serializable) o);
            startActivity(intent);

        }
    };
}
 
Example #15
Source File: DynamicRowsFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                           RowPresenter.ViewHolder rowViewHolder, Row row) {
    if (item instanceof VideoContent) {
        mBackgroundURI = ((VideoContent) item).getBackgroundImageURI();
        startBackgroundTimer();
    } else {
        /**
         * make sure the background of other items are removed so the setting icon can be
         * seen clearly
         */
        mHandler.removeCallbacks(mBackgroudUpdateRunnable);
        mBackgroundManager.setDrawable(null);
    }
}
 
Example #16
Source File: LeanbackBrowseFragment.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
protected OnItemViewClickedListener getDefaultItemViewClickedListener() {
    return new OnItemViewClickedListener() {

        @Override
        public void onItemClicked(Presenter.ViewHolder viewHolder, Object o, RowPresenter.ViewHolder viewHolder2, Row row) {

            Intent intent = new Intent(getActivity(), VideoDetailsActivity.class);
            intent.putExtra(Video.INTENT_EXTRA_VIDEO, (Serializable) o);
            startActivity(intent);

        }
    };
}
 
Example #17
Source File: GridFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                           RowPresenter.ViewHolder rowViewHolder, Row row) {
    int position = mGridViewHolder.getGridView().getSelectedPosition();
    if (DEBUG) Log.v(TAG, "grid selected position " + position);
    gridOnItemSelected(position);
    if (mOnItemViewSelectedListener != null) {
        mOnItemViewSelectedListener.onItemSelected(itemViewHolder, item,
                rowViewHolder, row);
    }
}
 
Example #18
Source File: LeanbackBrowseFragment.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
protected OnItemViewSelectedListener getDefaultItemSelectedListener() {

        return new OnItemViewSelectedListener() {
            public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
                                       RowPresenter.ViewHolder rowViewHolder, Row row) {
                if (item instanceof Video) {
                    bgHelper.setBackgroundUrl(((Video) item).getThumbUrl());
                    bgHelper.startBackgroundTimer();
                }

            }
        };
    }
 
Example #19
Source File: CardPresenter.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
    Video video = (Video) o;
    ((ViewHolder) viewHolder).mCardView.setTitleText(video.getTitle());
    ((ViewHolder) viewHolder).mCardView.setContentText(video.getDescription());
    ((ViewHolder) viewHolder).mCardView.setMainImageDimensions(CARD_WIDTH * 2, CARD_HEIGHT * 2);
    ((ViewHolder) viewHolder).updateCardViewImage(video.getThumbUrl());
}
 
Example #20
Source File: CardPresenter.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
    Video video = (Video) o;
    ((ViewHolder) viewHolder).mCardView.setTitleText(video.getTitle());
    ((ViewHolder) viewHolder).mCardView.setContentText(video.getDescription());
    ((ViewHolder) viewHolder).mCardView.setMainImageDimensions(CARD_WIDTH * 2, CARD_HEIGHT * 2);
    ((ViewHolder) viewHolder).updateCardViewImage(video.getThumbUrl());
}
 
Example #21
Source File: CardPresenter.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
    Video video = (Video) o;
    ((ViewHolder) viewHolder).mCardView.setTitleText(video.getTitle());
    ((ViewHolder) viewHolder).mCardView.setContentText(video.getDescription());
    ((ViewHolder) viewHolder).mCardView.setMainImageDimensions(CARD_WIDTH * 2, CARD_HEIGHT * 2);
    ((ViewHolder) viewHolder).updateCardViewImage(video.getThumbUrl());
}
 
Example #22
Source File: SearchFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
protected OnItemViewClickedListener getDefaultItemClickedListener() {
    return new OnItemViewClickedListener() {
        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
            if (item instanceof MediaWrapper) {
                TvUtil.openMedia(mActivity, (MediaWrapper) item, row);
            }
        }
    };
}
 
Example #23
Source File: LeanbackBrowseFragment.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
protected OnItemViewClickedListener getDefaultItemViewClickedListener() {
    return new OnItemViewClickedListener() {

        @Override
        public void onItemClicked(Presenter.ViewHolder viewHolder, Object o, RowPresenter.ViewHolder viewHolder2, Row row) {

            Intent intent = new Intent(getActivity(), VideoDetailsActivity.class);
            intent.putExtra(Video.INTENT_EXTRA_VIDEO, (Serializable) o);
            startActivity(intent);

        }
    };
}
 
Example #24
Source File: SearchFragment.java    From iview-android-tv with MIT License 5 votes vote down vote up
private OnItemViewClickedListener getItemClickedListener() {
    return new OnItemViewClickedListener() {
        @Override
        public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
            if (item instanceof EpisodeBaseModel) {
                Intent intent = new Intent(getActivity(), getDetailsActivityClass());
                intent.putExtra(ContentManagerBase.CONTENT_ID, (EpisodeBaseModel) item);
                startActivity(intent);
            }
        }
    };
}
 
Example #25
Source File: PresenterModule.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@PerFragment
@Provides
@IntoMap
@PresenterSelectorKey(ListRow.class)
public Presenter provideListRowPresenter() {
    return new ListRowPresenter();
}
 
Example #26
Source File: PresenterModule.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
@PerFragment
@Provides
@IntoMap
@PresenterSelectorKey(DetailsOverviewRow.class)
public Presenter provideDetailsOverviewRowPresenter() {

    DetailsDescriptionPresenter pre = new DetailsDescriptionPresenter();
    return new FullWidthDetailsOverviewRowPresenter(pre);
}
 
Example #27
Source File: CardPresenter.java    From alltv with MIT License 5 votes vote down vote up
@Override
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {

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

    ImageCardView cardView = (ImageCardView) viewHolder.view;

    // Remove references to images so that the garbage collector can free up memory
    cardView.setBadgeImage(null);
    cardView.setMainImage(null);
}
 
Example #28
Source File: CardExampleFragment.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
private void setupUi() {
    setHeadersState(HEADERS_ENABLED);
    setHeadersTransitionOnBackEnabled(true);
    setTitle(getString(R.string.card_examples_title));
    setOnSearchClickedListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getActivity(), getString(R.string.implement_search),
                    Toast.LENGTH_LONG).show();
        }
    });
    setOnItemViewClickedListener(new OnItemViewClickedListener() {

        @Override
        public void onItemClicked(Presenter.ViewHolder viewHolder, Object item, RowPresenter.ViewHolder viewHolder1, Row row) {
            if (!(item instanceof Card)) return;
            if (!(viewHolder.view instanceof ImageCardView)) return;

            ImageView imageView = ((ImageCardView) viewHolder.view).getMainImageView();
            Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                    imageView, DetailViewExampleFragment.TRANSITION_NAME).toBundle();
            Intent intent = new Intent(getActivity().getBaseContext(),
                    DetailViewExampleActivity.class);
            Card card = (Card) item;
            int imageResId = card.getLocalImageResourceId(getContext());
            intent.putExtra(DetailViewExampleFragment.EXTRA_CARD, imageResId);
            startActivity(intent, bundle);
        }

    });

    prepareEntranceTransition();
}
 
Example #29
Source File: CardPresenter.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
    Video video = (Video) o;
    ((ViewHolder) viewHolder).mCardView.setTitleText(video.getTitle());
    ((ViewHolder) viewHolder).mCardView.setContentText(video.getDescription());
    ((ViewHolder) viewHolder).mCardView.setMainImageDimensions(CARD_WIDTH * 2, CARD_HEIGHT * 2);
    ((ViewHolder) viewHolder).updateCardViewImage(video.getThumbUrl());
}
 
Example #30
Source File: CardSelector.java    From iview-android-tv with MIT License 5 votes vote down vote up
@Override
public Presenter getPresenter(Object item) {
    if (item instanceof CategoryModel) {
        return cat;
    }
    if (item instanceof EpisodeBaseModel) {
        EpisodeBaseModel model = (EpisodeBaseModel) item;
        if (model.hasCover()) {
            return film;
        }
    }
    return card;
}