androidx.leanback.widget.Presenter Java Examples

The following examples show how to use androidx.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: TypeSixContentPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    if (item instanceof Content.DataBean.WidgetsBean) {
        ViewHolder vh = (ViewHolder) viewHolder;
        Log.e(TAG, "onBindViewHolder: " + ((Content.DataBean.WidgetsBean) item).getUrl());
        Glide.with(mContext)
                .load(((Content.DataBean.WidgetsBean) item).getUrl())
                .apply(new RequestOptions()
                        .override(FontDisplayUtil.dip2px(mContext, 124),
                                FontDisplayUtil.dip2px(mContext, 207))
                        .placeholder(R.drawable.bg_shape_default))
                .into(vh.mIvPoster);
        String desc = ((Content.DataBean.WidgetsBean) item).getDesc();
        if (!TextUtils.isEmpty(desc)) {
            vh.mTvDesc.setText(desc);
        }
    }
}
 
Example #2
Source File: AppInstalledPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    if (mContext == null) {
        mContext = parent.getContext();
    }
    View view = LayoutInflater.from(mContext).inflate(R.layout.item_app_installed, parent, false);
    view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            v.findViewById(R.id.tv_app_name).setSelected(hasFocus);
        }
    });
    return new ViewHolder(view);
}
 
Example #3
Source File: ListenerModule.java    From tv-samples 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 #4
Source File: PresenterModule.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@PerFragment
@Provides
PresenterSelector providePresenterSelector(final Map<Class<?>, Presenter> map) {

    return new PresenterSelector() {
        @Override
        public Presenter getPresenter(Object item) {
            Class<?> cls = item.getClass();
            return map.get(cls);
        }

        @Override
        public Presenter[] getPresenters() {
            return map.values().toArray(new Presenter[map.size()]);
        }
    };
}
 
Example #5
Source File: TypeSixContentPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
    public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_type_six_layout, parent, false);
        final ViewHolder viewHolder = new ViewHolder(view);
//        view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                viewHolder.mTvDesc.setSelected(hasFocus);
//                if (hasFocus) {
//                    viewHolder.mTvDesc.setTextColor(mContext.getResources().getColor(R.color.colorBlack));
//                } else {
//                    viewHolder.mTvDesc.setTextColor(mContext.getResources().getColor(R.color.colorWhite));
//                }
//            }
//        });
        return viewHolder;
    }
 
Example #6
Source File: TypeSevenContentPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    if (mBrowseItemFocusHighlight == null) {
        mBrowseItemFocusHighlight =
                new MyFocusHighlightHelper
                        .BrowseItemFocusHighlight(FocusHighlight.ZOOM_FACTOR_MEDIUM, false);
    }
    if (mContext == null) {
        mContext = parent.getContext();
    }
    View view = LayoutInflater.from(mContext).inflate(R.layout.item_type_seven_layout, parent, false);
    final ViewHolder viewHolder = new ViewHolder(view);
    viewHolder.mClTypeSeven.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (mBrowseItemFocusHighlight != null) {
                mBrowseItemFocusHighlight.onItemFocused(v, hasFocus);
            }
            viewHolder.mClTypeSeven.onFocusChange(v, hasFocus);
        }
    });
    return viewHolder;
}
 
Example #7
Source File: ImageRowHeaderPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    HeaderItem headerItem = item == null ? null : ((Row) item).getHeaderItem();
    if (headerItem == null) {
        if ( viewHolder.view.findViewById(R.id.row_header) != null) {
            ((TextView)viewHolder.view.findViewById(R.id.row_header)).setText(null);
        }
        viewHolder.view.setContentDescription(null);
        viewHolder.view.setVisibility(View.GONE);

    } else {
        if (viewHolder.view.findViewById(R.id.row_header) != null) {
            ((TextView)viewHolder.view.findViewById(R.id.row_header)).setText(headerItem.getName());
        }
        viewHolder.view.setContentDescription(headerItem.getContentDescription());
        viewHolder.view.setVisibility(View.VISIBLE);
    }
}
 
Example #8
Source File: PageAndListRowFragment.java    From tv-samples 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 #9
Source File: PageAndListRowFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
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();
        }
    });
}
 
Example #10
Source File: TypeFourContentPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    if (item instanceof Content.DataBean.WidgetsBean) {
        ViewHolder vh = (ViewHolder) viewHolder;
        Glide.with(mContext)
                .load(((Content.DataBean.WidgetsBean) item).getUrl())
                .apply(new RequestOptions()
                        .centerCrop()
                        .override(FontDisplayUtil.dip2px(mContext, 200),
                                FontDisplayUtil.dip2px(mContext, 111))
                        .placeholder(R.drawable.bg_shape_default))
                .into(vh.mIvTypeFourPoster);
        if (!TextUtils.isEmpty(((Content.DataBean.WidgetsBean) item).getName())) {
            vh.mIvTypeFourName.setText(((Content.DataBean.WidgetsBean) item).getName());
        }
    }
}
 
Example #11
Source File: TypeFiveContentPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    if (item instanceof Content.DataBean.WidgetsBean) {
        ViewHolder vh = (ViewHolder) viewHolder;
        Glide.with(mContext)
                .load(((Content.DataBean.WidgetsBean) item).getUrl())
                .apply(new RequestOptions()
                        .centerCrop()
                        .override(FontDisplayUtil.dip2px(mContext, 272),
                                FontDisplayUtil.dip2px(mContext, 124))
                        .placeholder(R.drawable.bg_shape_default))
                .into(vh.mIvTypeFivePoster);
        if (!TextUtils.isEmpty(((Content.DataBean.WidgetsBean) item).getName())) {
            vh.mIvTypeFiveName.setText(((Content.DataBean.WidgetsBean) item).getName());
        }
        if(!TextUtils.isEmpty(((Content.DataBean.WidgetsBean) item).getDesc())){
            vh.mIvTypeFiveDesc.setText(((Content.DataBean.WidgetsBean) item).getDesc());
        }
    }
}
 
Example #12
Source File: DetailViewExampleWithVideoBackgroundFragment.java    From tv-samples 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 #13
Source File: VideoContentCardPresenter.java    From tv-samples 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 #14
Source File: TypeSevenPresenter.java    From LeanbackTvSample with MIT License 6 votes vote down vote up
private void updatePresenter(List<Content.DataBean.WidgetsBean> widgetsBeanList) {
    ArrayObjectAdapter mArrayObjectAdapter = new ArrayObjectAdapter(new TypeSevenContentPresenter());
    MyItemBridgeAdapter myItemBridgeAdapter = new MyItemBridgeAdapter(mArrayObjectAdapter) {
        @Override
        public OnItemViewClickedListener getOnItemViewClickedListener() {
            return new OnItemViewClickedListener() {
                @Override
                public void onItemClicked(View focusView,
                                          Presenter.ViewHolder itemViewHolder,
                                          Object item) {

                }
            };
        }
    };
    mHorizontalGridView.setAdapter(myItemBridgeAdapter);
    mArrayObjectAdapter.addAll(0, widgetsBeanList);
}
 
Example #15
Source File: MainFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void setupUIElements() {
    setBadgeDrawable(
            getActivity().getResources().getDrawable(R.drawable.videos_by_google_banner, null));
    setTitle(getString(R.string.browse_title)); // Badge, when set, takes precedent over title
    setHeadersState(HEADERS_ENABLED);
    setHeadersTransitionOnBackEnabled(true);

    // Set fastLane (or headers) background color
    setBrandColor(ContextCompat.getColor(getActivity(), R.color.fastlane_background));

    // Set search icon color.
    setSearchAffordanceColor(ContextCompat.getColor(getActivity(), R.color.search_opaque));

    setHeaderPresenterSelector(new PresenterSelector() {
        @Override
        public Presenter getPresenter(Object o) {
            return new IconHeaderItemPresenter();
        }
    });
}
 
Example #16
Source File: PlaybackFragment.java    From tv-samples 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 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);
    }
}
 
Example #17
Source File: VideoDetailsFragment.java    From tv-samples 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 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);
    }
}
 
Example #18
Source File: SearchFragment.java    From tv-samples 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 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();
    }
}
 
Example #19
Source File: VerticalGridFragment.java    From tv-samples 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 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);
    }
}
 
Example #20
Source File: CardPresenter.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    Video video = (Video) item;

    ImageCardView cardView = (ImageCardView) viewHolder.view;
    cardView.setTitleText(video.title);
    cardView.setContentText(video.studio);

    if (video.cardImageUrl != null) {
        // Set card size from dimension resources.
        Resources res = cardView.getResources();
        int width = res.getDimensionPixelSize(R.dimen.card_width);
        int height = res.getDimensionPixelSize(R.dimen.card_height);
        cardView.setMainImageDimensions(width, height);

        Glide.with(cardView.getContext())
                .load(video.cardImageUrl)
                .apply(RequestOptions.errorOf(mDefaultCardImage))
                .into(cardView.getMainImageView());
    }
}
 
Example #21
Source File: TypeFourContentPresenter.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    if (mContext == null) {
        mContext = parent.getContext();
    }
    View view = LayoutInflater.from(mContext).inflate(R.layout.item_type_four_layout, parent, false);
    return new ViewHolder(view);
}
 
Example #22
Source File: MyFocusHighlightHelper.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
void setFocusLevel(float level) {
    Presenter presenter = mViewHolder.getPresenter();
    if (presenter instanceof RowHeaderPresenter) {
        ((RowHeaderPresenter) presenter).setSelectLevel(
                ((RowHeaderPresenter.ViewHolder) mViewHolder.getViewHolder()), level);
    }
    super.setFocusLevel(level);
}
 
Example #23
Source File: TypeFiveContentPresenter.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    if (mContext == null) {
        mContext = parent.getContext();
    }
    View view = LayoutInflater.from(mContext).inflate(R.layout.item_type_five_layout, parent, false);
    return new ViewHolder(view);
}
 
Example #24
Source File: TypeOneContentPresenter.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    if (mContext == null) {
        mContext = parent.getContext();
    }
    View view = LayoutInflater.from(mContext).inflate(R.layout.item_type_one_layout, parent, false);
    return new ViewHolder(view);
}
 
Example #25
Source File: TypeOneContentPresenter.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    if (item instanceof Content.DataBean.WidgetsBean) {
        ViewHolder vh = (ViewHolder) viewHolder;
        Glide.with(mContext)
                .load(((Content.DataBean.WidgetsBean) item).getUrl())
                .apply(new RequestOptions()
                        .centerCrop()
                        .override(FontDisplayUtil.dip2px(mContext, 198),
                                FontDisplayUtil.dip2px(mContext, 111))
                        .placeholder(R.drawable.bg_shape_default))
                .into(vh.mIvTypeTwoPoster);
    }
}
 
Example #26
Source File: BasePresenterSelector.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public Presenter getPresenter(Object item) {
    Class<?> cls = item.getClass();
    Presenter presenter;
    presenter = mClassSingleMap.get(cls);
    if (presenter != null) {
        return presenter;
    }
    ArrayMap<Class<?>, Presenter> presenters = mClassMap.get(cls);
    if (presenters != null) {
        if (presenters.size() == 1) {
            return presenters.valueAt(0);
        } else if (presenters.size() > 1) {
            if (item instanceof ListRow) {
                ListRow listRow = (ListRow) item;
                Presenter childPresenter = listRow.getAdapter().getPresenter(listRow);
                Class<?> childCls = childPresenter.getClass();
                do {
                    presenter = presenters.get(childCls);
                    childCls = childCls.getSuperclass();
                } while (presenter == null && childCls != null);
            } else {
                throw new NullPointerException("presenter == null, please add presenter to PresenterSelector");
            }
        }
    }
    if (presenter == null) {
        throw new NullPointerException("presenter == null, please add presenter to PresenterSelector");
    }
    return presenter;
}
 
Example #27
Source File: BasePresenterSelector.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
/**
 * Adds a presenter to be used for the given class.
 * @param cls item 类型
 * @param presenter presenter
 * @param childType  当包含多个相同{@param cls}时,并且presenter不同,则通过子item{@param childType}区分
 */
public void addClassPresenter(Class<?> cls, Presenter presenter, Class<?> childType) {
    ArrayMap<Class<?>, Presenter> classPresenterArrayMap = mClassMap.get(cls);
    if (classPresenterArrayMap == null) {
        classPresenterArrayMap = new ArrayMap<>();
    }
    classPresenterArrayMap.put(childType, presenter);
    mClassMap.put(cls, classPresenterArrayMap);
    if (!mPresenters.contains(presenter)) {
        mPresenters.add(presenter);
    }
}
 
Example #28
Source File: BasePresenterSelector.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
/**
 * Adds a presenter to be used for the given class.
 * @param cls item 类型
 * @param presenter  presenter
 */
public void addClassPresenter(Class<?> cls, Presenter presenter) {
    mClassSingleMap.put(cls, presenter);
    if (!mPresenters.contains(presenter)) {
        mPresenters.add(presenter);
    }
}
 
Example #29
Source File: CardPresenter.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
    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 #30
Source File: TitlePresenter.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    if (item instanceof Title.DataBean) {
        ViewHolder vh = (ViewHolder) viewHolder;
        vh.mTvMainTitle.setText(((Title.DataBean) item).getName());
    }

}