androidandroid-fragmentsandroid-tv

Android TV RowsFragment - Can't disable row dimming effect


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,


Solution

  • 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.