android.support.v17.leanback.widget.VerticalGridView Java Examples

The following examples show how to use android.support.v17.leanback.widget.VerticalGridView. 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: CustomHeadersFragment.java    From BuildingForAndroidTV with MIT License 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
	super.onActivityCreated(savedInstanceState);

	customSetBackground(R.color.fastlane_background);
	setHeaderAdapter();

	setCustomPadding();

	/**
	 * The setOnItemSelectedListener has been not only deprecated, but brutally removed by
	 * Google. To get around this limitation, I went to see how BaseRowFragment handled it.
	 * Turns out it sets a listener to the GridView (which is a RecyclerView): there you go.
	 */
	VerticalGridView gridView = ((MainActivity) getActivity()).getVerticalGridView(this);
	gridView.setOnChildSelectedListener(new OnChildSelectedListener() {
		@Override
		public void onChildSelected(ViewGroup viewGroup, View view, int i, long l) {
			Object obj = ((ListRow) getAdapter().get(i)).getAdapter().get(0);
			getFragmentManager().beginTransaction().replace(R.id.rows_container, (Fragment) obj).commit();
			((MainActivity) getActivity()).updateCurrentFragment((Fragment) obj);
		}
	});

}
 
Example #2
Source File: RowsSupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(ItemBridgeAdapter.ViewHolder vh) {
    VerticalGridView listView = getVerticalGridView();
    if (listView != null && ((RowPresenter) vh.getPresenter()).canDrawOutOfBounds()) {
        listView.setClipChildren(false);
    }
    setupSharedViewPool(vh);
    mViewsCreated = true;
    vh.setExtraObject(new RowViewHolderExtra(vh));
    // selected state is initialized to false, then driven by grid view onChildSelected
    // events.  When there is rebind, grid view fires onChildSelected event properly.
    // So we don't need do anything special later in onBind or onAttachedToWindow.
    setRowViewSelected(vh, false, true);
    if (mExternalAdapterListener != null) {
        mExternalAdapterListener.onCreate(vh);
    }
}
 
Example #3
Source File: RowsSupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRowSelected(ViewGroup parent, View view, int position, long id) {
    VerticalGridView listView = getVerticalGridView();
    if (listView == null) {
        return;
    }
    ItemBridgeAdapter.ViewHolder vh = (view == null) ? null :
        (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);

    if (mSelectedViewHolder != vh) {
        if (DEBUG) Log.v(TAG, "new row selected position " + position + " view " + view);

        if (mSelectedViewHolder != null) {
            setRowViewSelected(mSelectedViewHolder, false, false);
        }
        mSelectedViewHolder = vh;
        if (mSelectedViewHolder != null) {
            setRowViewSelected(mSelectedViewHolder, true, false);
        }
    }
}
 
Example #4
Source File: RowsSupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Set the visibility of titles/hovercard of browse rows.
 */
public void setExpand(boolean expand) {
    mExpand = expand;
    VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        if (!mInTransition) ((ViewGroup) mScaleFrameLayout.getParent()).setClipChildren(!needsScale());
        updateRowScaling();
        final int count = listView.getChildCount();
        if (DEBUG) Log.v(TAG, "setExpand " + expand + " count " + count);
        for (int i = 0; i < count; i++) {
            View view = listView.getChildAt(i);
            ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);
            setRowViewExpanded(vh, mExpand);
        }
    }
}
 
Example #5
Source File: HeadersSupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
void onTransitionStart() {
    super.onTransitionStart();
    if (!mHeadersEnabled) {
        // When enabling headers fragment,  the RowHeaderView gets a focus but
        // isShown() is still false because its parent is INVSIBILE, accessibility
        // event is not sent.
        // Workaround is: prevent focus to a child view during transition and put
        // focus on it after transition is done.
        final VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
            if (listView.hasFocus()) {
                listView.requestFocus();
            }
        }
    }
}
 
Example #6
Source File: PlaybackOverlayFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
void setVerticalGridViewLayout(VerticalGridView listview) {
    if (listview == null) {
        return;
    }
    // Padding affects alignment when last row is focused
    // (last is first when there's only one row).
    setBottomPadding(listview, mPaddingBottom);

    // Item alignment affects focused row that isn't the last.
    listview.setItemAlignmentOffset(mAlignPosition);
    listview.setItemAlignmentOffsetPercent(100);

    // Push rows to the bottom.
    listview.setWindowAlignmentOffset(0);
    listview.setWindowAlignmentOffsetPercent(100);
    listview.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_HIGH_EDGE);
}
 
Example #7
Source File: PlaybackOverlaySupportFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
void setVerticalGridViewLayout(VerticalGridView listview) {
    if (listview == null) {
        return;
    }
    // Padding affects alignment when last row is focused
    // (last is first when there's only one row).
    setBottomPadding(listview, mPaddingBottom);

    // Item alignment affects focused row that isn't the last.
    listview.setItemAlignmentOffset(mAlignPosition);
    listview.setItemAlignmentOffsetPercent(100);

    // Push rows to the bottom.
    listview.setWindowAlignmentOffset(0);
    listview.setWindowAlignmentOffsetPercent(100);
    listview.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_HIGH_EDGE);
}
 
Example #8
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Set the visibility of titles/hovercard of browse rows.
 */
public void setExpand(boolean expand) {
    mExpand = expand;
    VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        if (!mInTransition) ((ViewGroup) mScaleFrameLayout.getParent()).setClipChildren(!needsScale());
        updateRowScaling();
        final int count = listView.getChildCount();
        if (DEBUG) Log.v(TAG, "setExpand " + expand + " count " + count);
        for (int i = 0; i < count; i++) {
            View view = listView.getChildAt(i);
            ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);
            setRowViewExpanded(vh, mExpand);
        }
    }
}
 
Example #9
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRowSelected(ViewGroup parent, View view, int position, long id) {
    VerticalGridView listView = getVerticalGridView();
    if (listView == null) {
        return;
    }
    ItemBridgeAdapter.ViewHolder vh = (view == null) ? null :
        (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);

    if (mSelectedViewHolder != vh) {
        if (DEBUG) Log.v(TAG, "new row selected position " + position + " view " + view);

        if (mSelectedViewHolder != null) {
            setRowViewSelected(mSelectedViewHolder, false, false);
        }
        mSelectedViewHolder = vh;
        if (mSelectedViewHolder != null) {
            setRowViewSelected(mSelectedViewHolder, true, false);
        }
    }
}
 
Example #10
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(ItemBridgeAdapter.ViewHolder vh) {
    VerticalGridView listView = getVerticalGridView();
    if (listView != null && ((RowPresenter) vh.getPresenter()).canDrawOutOfBounds()) {
        listView.setClipChildren(false);
    }
    setupSharedViewPool(vh);
    mViewsCreated = true;
    vh.setExtraObject(new RowViewHolderExtra(vh));
    // selected state is initialized to false, then driven by grid view onChildSelected
    // events.  When there is rebind, grid view fires onChildSelected event properly.
    // So we don't need do anything special later in onBind or onAttachedToWindow.
    setRowViewSelected(vh, false, true);
    if (mExternalAdapterListener != null) {
        mExternalAdapterListener.onCreate(vh);
    }
}
 
Example #11
Source File: HeadersFragment.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
void onTransitionStart() {
    super.onTransitionStart();
    if (!mHeadersEnabled) {
        // When enabling headers fragment,  the RowHeaderView gets a focus but
        // isShown() is still false because its parent is INVSIBILE, accessibility
        // event is not sent.
        // Workaround is: prevent focus to a child view during transition and put
        // focus on it after transition is done.
        final VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
            if (listView.hasFocus()) {
                listView.requestFocus();
            }
        }
    }
}
 
Example #12
Source File: HeadersSupportFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void updateListViewVisibility() {
    final VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE);
        if (!mHeadersGone) {
            if (mHeadersEnabled) {
                listView.setChildrenVisibility(View.VISIBLE);
            } else {
                listView.setChildrenVisibility(View.INVISIBLE);
            }
        }
    }
}
 
Example #13
Source File: HeadersSupportFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final VerticalGridView listView = getVerticalGridView();
    if (listView == null) {
        return;
    }
    if (getBridgeAdapter() != null) {
        FocusHighlightHelper.setupHeaderItemFocusHighlight(listView);
    }
    view.setBackgroundColor(getBackgroundColor());
    updateFadingEdgeToBrandColor(getBackgroundColor());
    updateListViewVisibility();
}
 
Example #14
Source File: JustifiedVerticalGridPresenter.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
@Override
protected ViewHolder createGridViewHolder(ViewGroup parent) {
	View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.presenter_justified_vertical_grid,
			parent, false);

	gridView = (VerticalGridView) root.findViewById(android.support.v17.leanback.R.id.browse_grid);

	return new ViewHolder(gridView);
}
 
Example #15
Source File: HeadersFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void updateListViewVisibility() {
    final VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE);
        if (!mHeadersGone) {
            if (mHeadersEnabled) {
                listView.setChildrenVisibility(View.VISIBLE);
            } else {
                listView.setChildrenVisibility(View.INVISIBLE);
            }
        }
    }
}
 
Example #16
Source File: BaseRowSupportFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void setItemAlignment() {
    if (mVerticalGridView != null) {
        // align the top edge of item
        mVerticalGridView.setItemAlignmentOffset(0);
        mVerticalGridView.setItemAlignmentOffsetPercent(
                VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED);
    }
}
 
Example #17
Source File: HeadersFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final VerticalGridView listView = getVerticalGridView();
    if (listView == null) {
        return;
    }
    if (getBridgeAdapter() != null) {
        FocusHighlightHelper.setupHeaderItemFocusHighlight(listView);
    }
    view.setBackgroundColor(getBackgroundColor());
    updateFadingEdgeToBrandColor(getBackgroundColor());
    updateListViewVisibility();
}
 
Example #18
Source File: BaseRowSupportFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void setWindowAlignmentFromTop(int alignedTop) {
    if (mVerticalGridView != null) {
        // align to a fixed position from top
        mVerticalGridView.setWindowAlignmentOffset(alignedTop);
        mVerticalGridView.setWindowAlignmentOffsetPercent(
                VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
        mVerticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
    }
}
 
Example #19
Source File: DetailsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void setVerticalGridViewLayout(VerticalGridView listview) {
    // align the top edge of item to a fixed position
    listview.setItemAlignmentOffset(0);
    listview.setItemAlignmentOffsetPercent(VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED);
    listview.setWindowAlignmentOffset(mContainerListAlignTop);
    listview.setWindowAlignmentOffsetPercent(VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
    listview.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
}
 
Example #20
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void freezeRows(boolean freeze) {
    VerticalGridView verticalView = getVerticalGridView();
    if (verticalView != null) {
        final int count = verticalView.getChildCount();
        for (int i = 0; i < count; i++) {
            ItemBridgeAdapter.ViewHolder ibvh = (ItemBridgeAdapter.ViewHolder)
                verticalView.getChildViewHolder(verticalView.getChildAt(i));
            RowPresenter rowPresenter = (RowPresenter) ibvh.getPresenter();
            RowPresenter.ViewHolder vh = rowPresenter.getRowViewHolder(ibvh.getViewHolder());
            rowPresenter.freeze(vh, freeze);
        }
    }
}
 
Example #21
Source File: HeadersFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
void onTransitionEnd() {
    if (mHeadersEnabled) {
        final VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
            if (listView.hasFocus()) {
                listView.requestFocus();
            }
        }
    }
    super.onTransitionEnd();
}
 
Example #22
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
void setWindowAlignmentFromTop(int alignedTop) {
    mAlignedTop = alignedTop;
    final VerticalGridView gridView = getVerticalGridView();
    if (gridView != null) {
        updateWindowAlignOffset();
        // align to a fixed position from top
        gridView.setWindowAlignmentOffsetPercent(
                VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
        gridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
    }
}
 
Example #23
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    if (DEBUG) Log.v(TAG, "onViewCreated");
    super.onViewCreated(view, savedInstanceState);
    // Align the top edge of child with id row_content.
    // Need set this for directly using RowsFragment.
    getVerticalGridView().setItemAlignmentViewId(R.id.row_content);
    getVerticalGridView().setSaveChildrenPolicy(VerticalGridView.SAVE_LIMITED_CHILD);

    ((ViewGroup) mScaleFrameLayout.getParent()).setClipChildren(!needsScale());

    mRecycledViewPool = null;
    mPresenterMapper = null;
}
 
Example #24
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an item selection listener.
 * @deprecated Use {@link #setOnItemViewSelectedListener(OnItemViewSelectedListener)}
 */
public void setOnItemSelectedListener(OnItemSelectedListener listener) {
    mOnItemSelectedListener = listener;
    VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        final int count = listView.getChildCount();
        for (int i = 0; i < count; i++) {
            View view = listView.getChildAt(i);
            ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder)
                    listView.getChildViewHolder(view);
            setOnItemSelectedListener(vh, mOnItemSelectedListener);
        }
    }
}
 
Example #25
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
/**
 * Sets an item selection listener.
 */
public void setOnItemViewSelectedListener(OnItemViewSelectedListener listener) {
    mOnItemViewSelectedListener = listener;
    VerticalGridView listView = getVerticalGridView();
    if (listView != null) {
        final int count = listView.getChildCount();
        for (int i = 0; i < count; i++) {
            View view = listView.getChildAt(i);
            ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder)
                    listView.getChildViewHolder(view);
            setOnItemViewSelectedListener(vh, mOnItemViewSelectedListener);
        }
    }
}
 
Example #26
Source File: RowsSupportFragment.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void freezeRows(boolean freeze) {
    VerticalGridView verticalView = getVerticalGridView();
    if (verticalView != null) {
        final int count = verticalView.getChildCount();
        for (int i = 0; i < count; i++) {
            ItemBridgeAdapter.ViewHolder ibvh = (ItemBridgeAdapter.ViewHolder)
                verticalView.getChildViewHolder(verticalView.getChildAt(i));
            RowPresenter rowPresenter = (RowPresenter) ibvh.getPresenter();
            RowPresenter.ViewHolder vh = rowPresenter.getRowViewHolder(ibvh.getViewHolder());
            rowPresenter.freeze(vh, freeze);
        }
    }
}
 
Example #27
Source File: DetailsFragment.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void insertHeader(LayoutInflater inflater, FrameLayout container) {
    VerticalGridView grid = findFirstGrid(container);
    if (grid != null) {
        View header = inflater.inflate(R.layout.episode_details_view, container, false);
        View bottom = inflater.inflate(R.layout.dark_gradient, container, false);
        container.addView(header, 0);
        container.addView(bottom, 1);
        setupGridAlignment(grid);
        setupHeaderView(grid, header);
        setupGradient(bottom);
    } else {
        Utils.showToast(getActivity(), "No Grid Found!");
    }
}
 
Example #28
Source File: DetailsFragment.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void setupHeaderView(VerticalGridView grid, View header) {
    mDetailView = new EpisodeDetailsView(getActivity(), header);
    if (mCurrentEpisode != null) {
        mDetailView.setEpisode(mCurrentEpisode);
    }
    int height = getResources().getDimensionPixelSize(R.dimen.episode_detail_padding_bottom);
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) header.getLayoutParams();
    lp.height = mHeaderHeight + height;
    header.setLayoutParams(lp);
}
 
Example #29
Source File: DetailsFragment.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void setupGridAlignment(VerticalGridView grid) {
    int cardHeight = getResources().getDimensionPixelSize(R.dimen.card_height);
    int titleHeight = getResources().getDimensionPixelSize(R.dimen.lb_browse_header_height);
    grid.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_LOW_EDGE);
    grid.setWindowAlignmentOffset(cardHeight + titleHeight);
    grid.setWindowAlignmentOffsetPercent(VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);

    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) grid.getLayoutParams();
    lp.topMargin = mHeaderHeight;
    grid.setLayoutParams(lp);
}
 
Example #30
Source File: DetailsFragment.java    From iview-android-tv with MIT License 5 votes vote down vote up
private VerticalGridView findFirstGrid(ViewGroup container) {
    for (int i = 0, k = container.getChildCount(); i < k; i++) {
        View view = container.getChildAt(i);
        if (view instanceof VerticalGridView) {
            return (VerticalGridView) view;
        }
    }
    return null;
}