@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (sRecycledViewPool == null) { // sRecycledViewPool should be initialized by calling preloadRecycledViews() // before the entering animation of this fragment starts, // because it takes long time and if it is called after the animation starts (e.g. here) // it can affect the animation. throw new IllegalStateException("The RecyclerView pool has not been initialized."); } View view = inflater.inflate(getFragmentLayoutResourceId(), container, false); TextView textView = (TextView) view.findViewById(R.id.side_panel_title); textView.setText(getTitle()); mListView = (VerticalGridView) view.findViewById(R.id.side_panel_list); mListView.setRecycledViewPool(sRecycledViewPool); mAdapter = new ItemAdapter(inflater, getItemList()); mListView.setAdapter(mAdapter); mListView.requestFocus(); return view; }
@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); }
/** * 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); } } }
@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); } } }
@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); } }
@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(); } } } }
@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); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); List<Channel> Channels = TvContractUtils.getChannels(getContentResolver()); Channel appLinkChannel = null; String displayNumber = getIntent().getStringExtra(RichFeedUtil.EXTRA_DISPLAY_NUMBER); if (displayNumber != null) { for (Channel channel : Channels) { if (displayNumber.equals(channel.getDisplayNumber())) { appLinkChannel = channel; break; } } } // Sets the size and position of dialog activity. WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; layoutParams.width = getResources().getDimensionPixelSize(R.dimen.side_panel_width); layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; getWindow().setAttributes(layoutParams); setContentView(R.layout.rich_app_link_side_panel); if (appLinkChannel != null && appLinkChannel.getAppLinkColor() != 0) { TextView titleView = (TextView) findViewById(R.id.title); titleView.setBackgroundColor(appLinkChannel.getAppLinkColor()); } mAppLinkMenuList = (VerticalGridView) findViewById(R.id.list); mAppLinkMenuList.setAdapter(new AppLinkMenuAdapter()); }
@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); }
@Override void setVerticalGridViewLayout(VerticalGridView listview) { super.setVerticalGridViewLayout(listview); // This works for leanback 22.1.0 //listview.setWindowAlignmentOffset( (int)(listview.getWindowAlignmentOffset() * mRatio) ); // This works for leanback 22.2.0 listview.setItemAlignmentOffset( (int)(listview.getItemAlignmentOffset() * mRatio) ); }
private void initViews() { VerticalGridView recycleView = (VerticalGridView) findViewById(R.id.rv); recycleView.setItemSpacing(getResources().getDimensionPixelSize(R.dimen.px30)); recycleView.setNumColumns(10); MyAdapter adapter = new MyAdapter(); recycleView.setAdapter(adapter); getViewFocusHandler().setFocusAppearance(recycleView);//给recycleview 添加焦点外观; ViewFocusAppearance appearance = new ViewFocusAppearance() .setFocusStrategy(ViewFocusStrategy.STRATEGY_Y_SCALE_Y_BORDER) .setBorderParams(new BorderView.BorderParams() .setShadowColor(Color.RED) .setShadowWidth(BorderView.BorderParams.SHADOW_MAX_WIDTH)); getViewFocusHandler().setFocusAppearance(findViewById(R.id.ll_btns1), appearance, true); getViewFocusHandler().rememberLastFocusView((ViewGroup) findViewById(R.id.ll_btns1)); ViewFocusAppearance appearance1 = new ViewFocusAppearance() .setAnimTime(200) .setFocusStrategy(ViewFocusStrategy.STRATEGY_Y_SCALE_Y_BORDER) .setBorderParams(new BorderView.BorderParams() .setShadowColor(Color.YELLOW)) .setXScaleValue(1.5f) .setYScaleValue(1.5f); getViewFocusHandler().setFocusAppearance(findViewById(R.id.tv4), appearance1, false); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); VerticalGridView actionsList = getGuidedActionsStylist().getActionsGridView(); actionsList.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE); VerticalGridView buttonActionsList = getGuidedButtonActionsStylist().getActionsGridView(); buttonActionsList.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_BOTH_EDGE); return view; }
@Override public void onStart() { super.onStart(); // TODO: remove the workaround of b/30401180. VerticalGridView container = (VerticalGridView) getActivity() .findViewById(R.id.container_list); // Need to manually modify offset. Please refer DetailsFragment.setVerticalGridViewLayout. container.setItemAlignmentOffset(0); container.setWindowAlignmentOffset( getResources().getDimensionPixelSize(R.dimen.lb_details_rows_align_top)); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (mSelectedPosition != INVALID_POSITION) { setSelectedPosition(mSelectedPosition); } VerticalGridView listView = (VerticalGridView) view.findViewById(R.id.side_panel_list); listView.setOnKeyInterceptListener(new OnRepeatedKeyInterceptListener(listView) { @Override public boolean onInterceptKeyEvent(KeyEvent event) { // In order to send tune operation once for continuous channel up/down events, // we only call the moveToChannel method on ACTION_UP event of channel switch keys. if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: if (mLastFocusedChannelId != Channel.INVALID_ID) { getMainActivity().tuneToChannel( getChannelDataManager().getChannel(mLastFocusedChannelId)); } break; } } return super.onInterceptKeyEvent(event); } }); getActivity().getContentResolver().registerContentObserver(TvContract.Programs.CONTENT_URI, true, mProgramUpdateObserver); getMainActivity().startShrunkenTvView(true, true); return view; }
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!"); } }
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); }
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); }
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; }
private void refreshUi() { try { final JsonListing[] names = getUrls(); items = new RecyclerViewItem[names.length + 1]; items[0] = new RecyclerViewItem(getString(R.string.add_new_link)) { @Override public void onClick() { Intent i = new Intent(JsonListingPanelActivity.this, ListingPlugin.class); i.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD); startActivity(i); } }; if (names.length > 0) { for (int i = 1; i < items.length; i++) { final int finalI = i; Log.d(TAG, "Poll " + finalI); items[i] = new RecyclerViewItem(names[finalI - 1].getUrl()) { @Override public void onClick() { showEditDialog(names[finalI - 1]); } }; } } } catch (JSONException e) { e.printStackTrace(); } mAppLinkMenuList = (VerticalGridView) findViewById(R.id.list); mAppLinkMenuList.setAdapter(new AppLinkMenuAdapter(this, items)); }
void setItemAlignment() { if (mVerticalGridView != null) { // align the top edge of item mVerticalGridView.setItemAlignmentOffset(0); mVerticalGridView.setItemAlignmentOffsetPercent( VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED); } }
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); } }
@Override public void onStart() { super.onStart(); VerticalGridView list = mRowsSupportFragment.getVerticalGridView(); int mContainerListAlignTop = getResources().getDimensionPixelSize(R.dimen.lb_search_browse_rows_align_top); list.setItemAlignmentOffset(0); list.setItemAlignmentOffsetPercent(VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED); list.setWindowAlignmentOffset(mContainerListAlignTop); list.setWindowAlignmentOffsetPercent(VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED); list.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); }
/** * 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); } } }
/** * 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); } } }
@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 RowsSupportFragment. getVerticalGridView().setItemAlignmentViewId(R.id.row_content); getVerticalGridView().setSaveChildrenPolicy(VerticalGridView.SAVE_LIMITED_CHILD); ((ViewGroup) mScaleFrameLayout.getParent()).setClipChildren(!needsScale()); mRecycledViewPool = null; mPresenterMapper = null; }
@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); } }
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); } } }
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); }