@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Movie) { Movie movie = (Movie) item; Log.d(TAG, "Item: " + item.toString()); Intent intent = new Intent(getActivity(), DetailsActivity.class); intent.putExtra(getResources().getString(R.string.movie), mSelectedMovie); intent.putExtra(getResources().getString(R.string.should_start), true); startActivity(intent); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), DetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Movie) { Log.d(TAG, "Item: " + item.toString()); Intent intent = new Intent(getActivity(), DetailsActivity.class); intent.putExtra(getResources().getString(R.string.movie), mSelectedMovie); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), DetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Video) { Video video = (Video) item; Intent intent = new Intent(getActivity(), PlaybackOverlayActivity.class); intent.putExtra(VideoDetailsActivity.VIDEO, video); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), VideoDetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Video) { Video video = (Video) item; Intent intent = new Intent(getActivity(), VideoDetailsActivity.class); intent.putExtra(VideoDetailsActivity.VIDEO, video); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), VideoDetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Video) { Video video = (Video) item; Intent intent = new Intent(getActivity(), VideoDetailsActivity.class); intent.putExtra(VideoDetailsActivity.VIDEO, video); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), VideoDetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } else { Toast.makeText(getActivity(), ((String) item), Toast.LENGTH_SHORT).show(); } }
@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()); } } } }
private OnItemViewClickedListener getDefaultItemClickedListener() { return new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Clip) { Toast.makeText(getActivity(), "** toggle selected **", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(), "** add as playlist **", Toast.LENGTH_LONG).show(); } } }; }
protected void setupEventListeners() { setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof MetaFile2) { MetaFile2 file = (MetaFile2) item; if (file.isDirectory()) { openDirectory(file); } else { String mimeType = MimeUtils.guessMimeTypeFromExtension(file.getExtension()); PlayUtils.openAnyFile(file, getActivity()); } } else if (item instanceof Video) { openDetailsActivity((Video) item, itemViewHolder); } else { throw new IllegalArgumentException("Click on an unexpected item type " + item); } } }); }
@Override protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { mR = parent.getResources(); // We create the base class view holder first ViewHolder fullWidthViewHolder = (ViewHolder)super.createRowViewHolder(parent); // We expand the info view and put it inside the parent fullwidth container ViewGroup fullwidthContainer = (ViewGroup)fullWidthViewHolder.getMainContainer(); View detailsView = LayoutInflater.from(parent.getContext()).inflate(R.layout.androidtv_details_text_only_group, fullwidthContainer, false); fullwidthContainer.addView(detailsView); fullwidthContainer.setBackgroundColor(mColor); return new FullTextRowViewHolder(fullWidthViewHolder, detailsView); }
@Override protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { mR = parent.getResources(); // We create the base class view holder first FullWidthRowPresenter.ViewHolder fullWidthViewHolder = (FullWidthRowPresenter.ViewHolder)super.createRowViewHolder(parent); // We expand the info view and put it inside the parent fullwidth container ViewGroup fullwidthContainer = (ViewGroup)fullWidthViewHolder.getMainContainer(); View detailsView = LayoutInflater.from(parent.getContext()).inflate(R.layout.androidtv_detailled_info_group, fullwidthContainer, false); fullwidthContainer.addView(detailsView); fullwidthContainer.setBackgroundColor(mColor); return new FileDetailsViewHolder(fullWidthViewHolder, detailsView); }
@Override protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { mR = parent.getResources(); // We create the base class view holder first ViewHolder fullWidthViewHolder = (ViewHolder)super.createRowViewHolder(parent); // We expand the info view and put it inside the parent fullwidth container ViewGroup fullwidthContainer = (ViewGroup)fullWidthViewHolder.getMainContainer(); View detailsView = LayoutInflater.from(parent.getContext()).inflate(R.layout.leanback_details_plot_and_genres_group, fullwidthContainer, false); fullwidthContainer.addView(detailsView); fullwidthContainer.setBackgroundColor(mColor); return new PlotAndGenresViewHolder(fullWidthViewHolder, detailsView); }
@Override protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { super.onBindRowViewHolder(holder, item); PlotAndGenresViewHolder vh = (PlotAndGenresViewHolder) holder; vh.mFullWidthViewHolder.getMainContainer().setBackgroundColor(mColor); PlotAndGenresRow row = (PlotAndGenresRow) item; vh.mPlotTv.setText(row.getPlot()); if (row.getGenres()!=null && !row.getGenres().isEmpty()) { vh.mGenresTv.setText(row.getGenres()); vh.mGenresTv.setVisibility(View.VISIBLE); } else { vh.mGenresTv.setVisibility(View.GONE); } }
@Override protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { mR = parent.getResources(); // We create the base class view holder first ViewHolder fullWidthViewHolder = (ViewHolder)super.createRowViewHolder(parent); // We expand the info view and put it inside the parent fullwidth container ViewGroup fullwidthContainer = (ViewGroup)fullWidthViewHolder.getMainContainer(); View detailsView = LayoutInflater.from(parent.getContext()).inflate(R.layout.leanback_details_director_and_cast_group, fullwidthContainer, false); fullwidthContainer.addView(detailsView); fullwidthContainer.setBackgroundColor(mColor); return new CastViewHolder(fullWidthViewHolder, detailsView); }
@Override protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) { super.onBindRowViewHolder(holder, item); CastViewHolder vh = (CastViewHolder) holder; CastRow row = (CastRow) item; vh.mCastTv.setText(row.getCast()); if (row.getDirectors()!=null && !row.getDirectors().isEmpty()) { vh.mDirectorsTv.setText( mR.getString(R.string.scrap_director_format, row.getDirectors())); vh.mDirectorsTv.setVisibility(View.VISIBLE); } else { vh.mDirectorsTv.setVisibility(View.GONE); } }
@Override public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { Video v = (Video) item; long pospage = 40*page; if(getPosition() >= pospage-5 && getPosition() <= pospage) { if(page < ((pospage/40) + 1)) { page++; final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // Do something after 5s = 5000ms loadVideos(page); } }, 1000); } } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, final Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Apk) { Apk application = (Apk) item; Log.d(TAG, "Item: " + item.toString()); Intent intent = new Intent(getActivity(), DetailsActivity.class); intent.putExtra(DetailsActivity.APPLICATION, application.toString()); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), DetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } else if (item instanceof SettingOption) { ((SettingOption) item).getClickListener().onClick(); } else if (item instanceof File) { Log.d(TAG, "Open file " + ((File) item).getAbsolutePath()); mApkDownloadHelper.install((File) item); } else if (item instanceof ResolveInfo) { GenerateShortcutHelper.begin(mMainActivity, (ResolveInfo) item); } }
@SuppressWarnings("SuspiciousMethodCalls") @Override public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof MediaCardPresenter.MediaCardItem) { MediaCardPresenter.MediaCardItem overviewItem = (MediaCardPresenter.MediaCardItem) item; if (overviewItem.isLoading()) return; mBackgroundUpdater.updateBackgroundAsync(((MediaCardPresenter.MediaCardItem) item).getMedia().headerImage); } //really hacky way of making and 'endless' adapter //trigger items to update int itemPosition = mItems.indexOf(item); //when we are within 3 rows of the end, load more items if (itemPosition>getAdapter().size()-(NUM_COLUMNS*3)){ Timber.d("Loading more items: page "+mCurrentPage); loadMore(); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof VideoCard) { VideoCard itemCard = (VideoCard) item; MediaMetaData metaData = new MediaMetaData(); metaData.setMediaSourcePath(itemCard.getVideoSource()); 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); } }
@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; } }; }
private void setupAdapter() { VerticalGridPresenter presenter = new VerticalGridPresenter(ZOOM_FACTOR); presenter.setNumberOfColumns(COLUMNS); setGridPresenter(presenter); CardPresenterSelector cardPresenter = new CardPresenterSelector(getActivity()); mAdapter = new ArrayObjectAdapter(cardPresenter); setAdapter(mAdapter); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked( Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { Card card = (Card)item; Toast.makeText(getActivity(), "Clicked on "+card.getTitle(), Toast.LENGTH_SHORT).show(); } }); }
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(); } }); }
@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(); } }
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); } } }; }
private void initUi() { PlaybackControlsRowPresenter presenter = mediaControllerHelper.createControlsRowAndPresenter(); rows = new ArrayObjectAdapter(presenter); rows.add(mediaControllerHelper.getControlsRow()); setAdapter(rows); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Action) { mediaControllerHelper.onActionClicked((Action) item); } } }); }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Movie) { Movie movie = (Movie) item; Log.d(TAG, "Item: " + item.toString()); Intent intent = new Intent(getActivity(), DetailsActivity.class); intent.putExtra(DetailsActivity.MOVIE, movie); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), DetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object clickedItem, RowPresenter.ViewHolder rowViewHolder, Row row) { if (clickedItem instanceof MediaSessionCompat.QueueItem) { LogHelper.d(TAG, "item: ", clickedItem.toString()); MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity()); MediaSessionCompat.QueueItem item = (MediaSessionCompat.QueueItem) clickedItem; if (!QueueHelper.isQueueItemPlaying(getActivity(), item) || controller.getPlaybackState().getState() != PlaybackStateCompat.STATE_PLAYING) { controller.getTransportControls().skipToQueueItem(item.getQueueId()); } } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity()); if (controller == null) { return; } MediaControllerCompat.TransportControls controls = controller.getTransportControls(); MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item; if (!MediaIDHelper.isMediaItemPlaying(getActivity(), mediaItem)) { controls.playFromMediaId(mediaItem.getMediaId(), null); } Intent intent = new Intent(getActivity(), TvPlaybackActivity.class); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), TvVerticalGridActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof ServerInfo) { ServerInfoUtil.connect(getActivity(), (ServerInfo) item); } else if (item instanceof Action) { Action action = (Action) item; if (action.getActionId() == R.id.preferences) { Intent i = new Intent(getActivity(), SettingsActivity.class); startActivity(i); } else if (action.getActionId() == R.id.btn_add_server) { // add new server AddServerFragment f = AddServerFragment.newInstance("My Server", ""); f.setRetainInstance(true); f.show(getFragmentManager(), "addserver"); } else { Toast.makeText(getActivity(), item.toString(), Toast.LENGTH_SHORT) .show(); } } }
@Override public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Action) { mBackgroundURI = ((Action) item).getBackground(); if (mBackgroundURI == null) mBackgroundURI = mDefaultBackgroundNoBackground; startBackgroundTimer(); } else if (item instanceof ServerInfo) { if (((ServerInfo) item).isLocatorOnly()) { mBackgroundURI = R.drawable.back_film_wall; startBackgroundTimer(); } else { mBackgroundURI = R.drawable.back_dark_knight; startBackgroundTimer(); } } else { mBackgroundURI = mDefaultBackgroundNoBackground; startBackgroundTimer(); } }
@Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Movie) { Movie movie = (Movie) item; Log.d(TAG, "Item: " + item.toString()); Intent intent = new Intent(getActivity(), DetailsActivity.class); intent.putExtra(DetailsActivity.MOVIE, movie); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), DetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } else if (item instanceof String) { Toast.makeText(getActivity(), ((String) item), Toast.LENGTH_SHORT) .show(); } }