2

I have a fragment extending RowsFragment and no matter what I try I cannot disable the dimming effect on the unselected rows (First Picture).

Can't disable the dimming of unselected rows

Here is my code:

public class MainFragment extends RowsFragment {
private static final String TAG = MainFragment.class.getSimpleName();

private ArrayObjectAdapter mRowsAdapter;
private static final int GRID_ITEM_WIDTH = 300;
private static final int GRID_ITEM_HEIGHT = 200;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Log.i(TAG, "onActivityCreated");
    super.onActivityCreated(savedInstanceState);

    loadRows();

}

private void loadRows() {
    mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE, false));


    HeaderItem cardPresenterHeader = new HeaderItem(1, "CardPresenter");
    CardPresenter cardPresenter = new CardPresenter();
    ArrayObjectAdapter cardRowAdapter = new ArrayObjectAdapter(cardPresenter);


    for(int i=0; i<10; i++) {
        Movie movie = new Movie();
        movie.setTitle("title" + i);
        movie.setStudio("studio" + i);
        cardRowAdapter.add(movie);
    }

    mRowsAdapter.add(new ListRow(cardPresenterHeader, cardRowAdapter));
    mRowsAdapter.add(new ListRow(cardPresenterHeader, cardRowAdapter));

    setAdapter(mRowsAdapter);

}

No matter what changes or combinations I try (Playing with the useFocusDimmer flag, trying to use BrowseFragment etc) I can't get the result i'm looking for.

The closest I got was changing to a VerticalGridFragment and Presenter, but this functionality is lacking and it only resembles what i'm trying to accomplish (Second Picture).

Example of how I want it to look

Thanks in advance,

Danny Ofir
  • 23
  • 3

1 Answers1

11

You must use RowsFragment together with a RowPresenter subclass. In the RowPresenter subclass you can define your custom Selection animation or try to call setSelectEffectEnabled.

Excerpt from the documentation:

When a user scrolls through rows, a fragment will initiate animation and call setSelectLevel(Presenter.ViewHolder, float) with float value between 0 and 1. By default, the RowPresenter draws a dim overlay on top of the row view for views that are not selected. Subclasses may override this default effect by having isUsingDefaultSelectEffect() return false and overriding onSelectLevelChanged(ViewHolder) to apply a different selection effect.

Call setSelectEffectEnabled(boolean) to enable/disable the select effect, This will not only enable/disable the default dim effect but also subclasses must respect this flag as well.

ULazdins
  • 1,975
  • 4
  • 25
  • 31
  • Wow setSelectEffectEnabled(boolean) pretty much solved my problem! Now I am trying to change the RowHeader text color. I tried doing this: http://stackoverflow.com/questions/41780279/android-tv-how-to-change-color-of-title-and-color-of-headeritem but non of it is helping me. – Danny Ofir Feb 07 '17 at 15:49
  • See my answer at the SO link you referenced, hope it will help – ULazdins Feb 07 '17 at 16:01
  • 1
    Thanks! Indeed it did, though I had to change one line – Danny Ofir Feb 11 '17 at 16:21
  • @DannyOfir How did you able to change the text color of header? When shadow is not enabled, it actually dim the header color, that's why color is changing but not showing clearly because of black gradient. Any solution? – Akhilesh Dhar Dubey Feb 06 '22 at 13:12