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); } } }); }
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(); } }); }
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 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setSearchResultProvider(this); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (!(item instanceof BaseRowItem)) return; ItemLauncher.launch((BaseRowItem) item, TvApp.getApplication(), getActivity(), itemViewHolder); } }); mDelayedLoad = new SearchRunnable(); prepareBackgroundManager(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); loadVideoData(); setCustomPadding(); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { Movie movie = (Movie) item; Intent intent = new Intent(getActivity(), MovieDetailsActivity.class); intent.putExtra(MovieDetailsActivity.MOVIE, movie); Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( getActivity(), ((ImageCardView) itemViewHolder.view).getMainImageView(), MovieDetailsActivity.SHARED_ELEMENT_NAME).toBundle(); getActivity().startActivity(intent, bundle); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mScraper = new Scraper(getActivity()); mSearchExecutor = new SerialExecutor(); ClassPresenterSelector rowsPresenterSelector = new ClassPresenterSelector(); rowsPresenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter()); rowsPresenterSelector.addClassPresenter(ShadowLessListRow.class, new ShadowLessRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(rowsPresenterSelector); setBadgeDrawable(getResources().getDrawable(R.mipmap.video2)); setSearchResultProvider(this); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof BaseTags) { saveTagsAndFinish((BaseTags) item); } } }); mSpeechRecognitionCallback = new SpeechRecognitionCallback() { @Override public void recognizeSpeech() { // ACTION_RECOGNIZE_SPEECH try{ startActivityForResult(getRecognizerIntent(), SEARCH_REQUEST_CODE); }catch (ActivityNotFoundException e){/*non google device*/} } }; setSpeechRecognitionCallback(mSpeechRecognitionCallback); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTopOffsetRatio(0.6f); final Intent intent = getActivity().getIntent(); mShowId = intent.getLongExtra(EXTRA_TVSHOW_ID, -1); mColor = ContextCompat.getColor(getActivity(), R.color.leanback_details_background); mOverviewRowPresenter = new DetailsOverviewRowPresenter(new TvshowMoreDetailsDescriptionPresenter()); mOverviewRowPresenter.setSharedElementEnterTransition(getActivity(), SHARED_ELEMENT_NAME, 1000); mOverviewRowPresenter.setBackgroundColor(getResources().getColor(R.color.leanback_details_background)); mOverviewRowPresenter.setStyleLarge(false); mOverviewRowPresenter.setOnActionClickedListener(null); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof ScraperImage) { if (row == mPostersRow) { mShowPosterSaverTask = new ShowPosterSaverTask().execute((ScraperImage) item); } else if (row == mBackdropsRow) { mBackdropSaverTask = new BackdropSaverTask().execute((ScraperImage) item); } } else if (item instanceof WebPageLink) { WebPageLink link = (WebPageLink)item; WebUtils.openWebLink(getActivity(), link.getUrl()); } } }); // WORKAROUND: at least one instance of BackdropTask must be created soon in the process (onCreate ?) // else it does not work later. // --> This instance of BackdropTask() will not be used but it must be created here! mBackdropTask = new BackdropTask(getActivity(), VideoInfoCommonClass.getDarkerColor(mColor)); }
/** * Sets an item clicked listener. */ public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { mOnItemViewClickedListener = listener; if (mGridPresenter != null) { mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener); } }
protected OnItemViewClickedListener getDefaultItemClickedListener() { return new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object object, RowPresenter.ViewHolder rowViewHolder, Row row) { if (object instanceof MediaCardPresenter.MediaCardItem) { MediaCardPresenter.MediaCardItem item = (MediaCardPresenter.MediaCardItem) object; Media media = item.getMedia(); PTVMediaDetailActivity.startActivity(getActivity(), media); } } }; }
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(); }
@PerFragment @Provides @IntoMap @ListenerModuleKey(LiveDataFragment.class) public OnItemViewClickedListener provideOnItemViewClickListenerForLiveDataFragment( final Activity currentActivity) { return new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { Intent intent; Long videoItemId = ((VideoEntity) item).getId(); intent = new Intent(currentActivity, LiveDataDetailActivity.class); intent.putExtra(LiveDataDetailActivity.VIDEO_ID, videoItemId); VideoEntity cachedBundle = (VideoEntity) item; intent.putExtra(LiveDataDetailActivity.CACHED_CONTENT, cachedBundle); // enable the scene transition animation when the detail's activity is launched Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( currentActivity, ((ImageCardView) itemViewHolder.view).getMainImageView(), LiveDataDetailActivity.SHARED_ELEMENT_NAME).toBundle(); currentActivity.startActivity(intent, bundle); } }; }
@PerFragment @Provides @IntoMap @ListenerModuleKey(SearchFragment.class) public OnItemViewClickedListener provideOnItemViewClickListenerForLiveDataDetailFragmentSearch( final Activity currentActivity) { return new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof VideoEntity) { Intent intent; Long videoItemId = ((VideoEntity) item).getId(); intent = new Intent(currentActivity, LiveDataDetailActivity.class); intent.putExtra(LiveDataDetailActivity.VIDEO_ID, videoItemId); VideoEntity cachedBundle = (VideoEntity) item; intent.putExtra(LiveDataDetailActivity.CACHED_CONTENT, cachedBundle); // enable the scene transition animation when the detail's activity is launched Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( currentActivity, ((ImageCardView) itemViewHolder.view).getMainImageView(), LiveDataDetailActivity.SHARED_ELEMENT_NAME).toBundle(); currentActivity.startActivity(intent, bundle); } } }; }
@PerFragment @Provides @IntoMap @ListenerModuleKey(LiveDataDetailViewWithVideoBackgroundFragment.class) public OnItemViewClickedListener provideOnItemViewClickListenerForLiveDataDetailFragment( final Activity currentActivity) { return new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof VideoEntity) { Intent intent; Long videoItemId = ((VideoEntity) item).getId(); intent = new Intent(currentActivity, LiveDataDetailActivity.class); intent.putExtra(LiveDataDetailActivity.VIDEO_ID, videoItemId); VideoEntity cachedBundle = (VideoEntity) item; intent.putExtra(LiveDataDetailActivity.CACHED_CONTENT, cachedBundle); // enable the scene transition animation when the detail's activity is launched Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation( currentActivity, ((ImageCardView) itemViewHolder.view).getMainImageView(), LiveDataDetailActivity.SHARED_ELEMENT_NAME).toBundle(); currentActivity.startActivity(intent, bundle); } } }; }
@Inject public ListenerFactory(Map<Class, OnItemViewClickedListener> onItemViewClickedListenerMap, Map<Class, OnItemViewSelectedListener> onItemViewSelectedListenerMap, Map<Class, View.OnClickListener> viewOnClickListenerMap) { mOnItemViewClickedListenerMap = onItemViewClickedListenerMap; mOnItemViewSelectedListenerMap = onItemViewSelectedListenerMap; mViewOnClickListenerMap = viewOnClickListenerMap; }
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); } } }; }
private void initListeners() { setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (row instanceof DetailsOverviewRow) { onDetailsRowClicked((DetailsOverviewRow) row, item); } else { Log.w(TAG, "Unhandled row: " + row); } } }); }
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); } }; }
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); } } }; }
private void setupFragment() { mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); setAdapter(mRowsAdapter); setupTopTracksRow(); setupAlbumsRows(); setupRelatedArtistsRows(); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof Track) { String trackUri = ((Track) item).uri; SpotifyPlayerController spotifyPlayerController = SpotifyTvApplication.getInstance().getSpotifyPlayerController(); if (spotifyPlayerController.getPlayingState().isCurrentTrack(trackUri)) { spotifyPlayerController.togglePauseResume(); } else { // get song and following ones List<String> trackUris = new ArrayList<>(); List<TrackSimple> tracks = new ArrayList<TrackSimple>(); for (int i = mTopTrackAdapter.indexOf(item); i < mTopTrackAdapter.size() && i < Constants.MAX_SONGS_PLAYED; i++) { tracks.add((TrackSimple) mTopTrackAdapter.get(i)); trackUris.add(((Track) mTopTrackAdapter.get(i)).uri); } spotifyPlayerController.play(trackUri, trackUris, tracks); } } else { SpotifyTvApplication.getInstance().launchDetailScreen(getActivity(), item); } } }); }
private void setupFragment() { mDetailsPresenter = new DetailsOverviewRowPresenter(getDetailsPresenter()); mDetailsPresenter.setStyleLarge(false); ClassPresenterSelector ps = new ClassPresenterSelector(); ps.addClassPresenter(DetailsOverviewRow.class, mDetailsPresenter); ps.addClassPresenter(TracksHeaderRow.class, new TracksHeaderRowPresenter()); OnItemViewClickedListener onTrackRowItemClicked = new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { if (item instanceof TrackSimple) { playFromTrack(((TrackSimple) item)); } } }; ps.addClassPresenter(TrackRow.class, getTrackRowPresenter(onTrackRowItemClicked)); mRowsAdapter = new ArrayObjectAdapter(ps); setAdapter(mRowsAdapter); setOnActionClickedListener(new OnActionClickedListener() { @Override public void onActionClicked(Action action) { TracksDetailsFragment.this.onActionClicked(action); } }); }
private void setupFragment() { mAdapter = new ArrayObjectAdapter(new PlaylistSimpleCardPresenter()); setAdapter(mAdapter); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { SpotifyTvApplication.getInstance().launchDetailScreen(getActivity(), item); } }); }
@Override protected void onPostExecute(String title) { ((BrowserActivity)getActivity()).showProgress(false); setTitle(title); setOnItemViewClickedListener(new OnItemViewClickedListener() { @Override public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { ListItem listItem = (ListItem) item; Intent intent; if (CATEGORY_ARTISTS == mCategory) { intent = new Intent(mContext, VerticalGridActivity.class); intent.putExtra(MainTvActivity.BROWSER_TYPE, MainTvActivity.HEADER_CATEGORIES); intent.putExtra(AUDIO_CATEGORY, CATEGORY_ALBUMS); intent.putExtra(MEDIA_SECTION, FILTER_ARTIST); intent.putExtra(AUDIO_FILTER, listItem.mediaList.get(0).getArtist()); } else if (CATEGORY_GENRES == mCategory) { intent = new Intent(mContext, VerticalGridActivity.class); intent.putExtra(MainTvActivity.BROWSER_TYPE, MainTvActivity.HEADER_CATEGORIES); intent.putExtra(AUDIO_CATEGORY, CATEGORY_ALBUMS); intent.putExtra(MEDIA_SECTION, FILTER_GENRE); intent.putExtra(AUDIO_FILTER, listItem.mediaList.get(0).getGenre()); } else { if (CATEGORY_ALBUMS == mCategory) Collections.sort(listItem.mediaList, MediaComparators.byTrackNumber); intent = new Intent(mContext, AudioPlayerActivity.class); intent.putExtra(AudioPlayerActivity.MEDIA_LIST, listItem.mediaList); } startActivity(intent); } }); }
/** * Sets an item clicked listener on the fragment. * OnItemViewClickedListener will override {@link View.OnClickListener} that * item presenter sets during {@link Presenter#onCreateViewHolder(ViewGroup)}. * So in general, developer should choose one of the listeners but not both. */ public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { mOnItemViewClickedListener = listener; if (mViewsCreated) { throw new IllegalStateException( "Item clicked listener must be set before views are created"); } }
/** * Sets an item Clicked listener. */ public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { mOnItemViewClickedListener = listener; if (mRowsSupportFragment != null) { mRowsSupportFragment.setOnItemViewClickedListener(listener); } }
/** * Sets an item Clicked listener. */ public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { mOnItemViewClickedListener = listener; if (mRowsFragment != null) { mRowsFragment.setOnItemViewClickedListener(listener); } }
/** * Sets an item clicked listener on the fragment. * OnItemViewClickedListener will override {@link View.OnClickListener} that * item presenter sets during {@link Presenter#onCreateViewHolder(ViewGroup)}. * So in general, developer should choose one of the listeners but not both. */ public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { mOnItemViewClickedListener = listener; if (mRowsFragment != null) { mRowsFragment.setOnItemViewClickedListener(listener); } }