HeadersFragment.java revision 2f5ebf3f6f7bb6a24856f389e369b247118ba119
155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/* 255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Copyright (C) 2014 The Android Open Source Project 355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * in compliance with the License. You may obtain a copy of the License at 655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0 855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License 1055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under 1255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * the License. 1355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 1455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 1555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutpackage android.support.v17.leanback.app; 1655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 173659dc62f9e55b1043edb4105c311c8ef997f2aeDake Guimport android.content.Context; 187a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Guimport android.graphics.Color; 199a49e322d10c1a67860d812352a5ea710843b75eDake Guimport android.graphics.drawable.ColorDrawable; 207a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Guimport android.graphics.drawable.Drawable; 217a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Guimport android.graphics.drawable.GradientDrawable; 223c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.os.Bundle; 2355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.R; 2455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.FocusHighlightHelper; 252f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.HorizontalGridView; 2655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ItemBridgeAdapter; 2755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.PresenterSelector; 2855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.Row; 293c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.support.v17.leanback.widget.RowHeaderPresenter; 30bd80644186ff8622c565f067dc3a4136a4dc0586Dake Guimport android.support.v17.leanback.widget.SinglePresenterSelector; 313c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.support.v17.leanback.widget.VerticalGridView; 320246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView; 3355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.View; 3455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.ViewGroup; 352f97594742886d045ca1ce409ebc6e6e780452f6Dake Guimport android.view.View.OnLayoutChangeListener; 36e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stoutimport android.widget.FrameLayout; 3755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 3855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/** 3955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * An internal fragment containing a list of row headers. 4055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 41a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbournpublic class HeadersFragment extends BaseRowFragment { 423c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 43729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu /** 44729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * Interface definition for a callback to be invoked when a header item is clicked. 45729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu */ 46729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu public interface OnHeaderClickedListener { 47729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu /** 48729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * Called when a header item has been clicked. 49729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * 50729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * @param viewHolder Row ViewHolder object corresponding to the selected Header. 51729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * @param row Row object corresponding to the selected Header. 52729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu */ 53729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu void onHeaderClicked(RowHeaderPresenter.ViewHolder viewHolder, Row row); 543c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 553c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 56729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu /** 57729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * Interface definition for a callback to be invoked when a header item is selected. 58729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu */ 59729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu public interface OnHeaderViewSelectedListener { 60729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu /** 61729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * Called when a header item has been selected. 62729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * 63729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * @param viewHolder Row ViewHolder object corresponding to the selected Header. 64729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu * @param row Row object corresponding to the selected Header. 65729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu */ 668df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu void onHeaderSelected(RowHeaderPresenter.ViewHolder viewHolder, Row row); 678df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu } 688df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu 698df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu private OnHeaderViewSelectedListener mOnHeaderViewSelectedListener; 703c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private OnHeaderClickedListener mOnHeaderClickedListener; 71d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersEnabled = true; 72d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersGone = false; 734cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private int mBackgroundColor; 744cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private boolean mBackgroundColorSet; 753c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 76bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu private static final PresenterSelector sHeaderPresenter = new SinglePresenterSelector( 77268de3d2ea3de1be0725a80bbc79dd7b8b18617eCraig Stout new RowHeaderPresenter(R.layout.lb_header)); 7855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 79a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn public HeadersFragment() { 80bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu setPresenterSelector(sHeaderPresenter); 8155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 8255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 833c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void setOnHeaderClickedListener(OnHeaderClickedListener listener) { 843c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu mOnHeaderClickedListener = listener; 8555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 8655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 878df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu public void setOnHeaderViewSelectedListener(OnHeaderViewSelectedListener listener) { 888df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener = listener; 8955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 9055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 9155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 9242752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu VerticalGridView findGridViewFromRoot(View view) { 937a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu return (VerticalGridView) view.findViewById(R.id.browse_headers); 947a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 957a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 967a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu @Override 970246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder viewHolder, 980246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu int position, int subposition) { 998df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu if (mOnHeaderViewSelectedListener != null) { 1000246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu if (viewHolder != null && position >= 0) { 1010246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) viewHolder; 1028df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener.onHeaderSelected( 103729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu (RowHeaderPresenter.ViewHolder) vh.getViewHolder(), (Row) vh.getItem()); 104d736653bfee7fc83fc68d57d0e0bee5fa807287fDake Gu } else { 1058df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener.onHeaderSelected(null, null); 1062f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson } 10755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 10855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 10955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 1103c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private final ItemBridgeAdapter.AdapterListener mAdapterListener = 1113c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu new ItemBridgeAdapter.AdapterListener() { 1123c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 113729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu public void onCreate(final ItemBridgeAdapter.ViewHolder viewHolder) { 1143c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu View headerView = viewHolder.getViewHolder().view; 1153c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setOnClickListener(new View.OnClickListener() { 1163c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 1173c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void onClick(View v) { 1183c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (mOnHeaderClickedListener != null) { 119729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu mOnHeaderClickedListener.onHeaderClicked( 120729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu (RowHeaderPresenter.ViewHolder) viewHolder.getViewHolder(), 121729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu (Row) viewHolder.getItem()); 1223c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1233c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1243c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }); 1253c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusable(true); 1263c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusableInTouchMode(true); 127e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout if (mWrapper != null) { 128e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener); 129e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } else { 130e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout headerView.addOnLayoutChangeListener(sLayoutChangeListener); 131e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 1323c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1333c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1343c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }; 1353c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1362f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu private static OnLayoutChangeListener sLayoutChangeListener = new OnLayoutChangeListener() { 1372f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1382f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onLayoutChange(View v, int left, int top, int right, int bottom, 1392f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu int oldLeft, int oldTop, int oldRight, int oldBottom) { 1408e3566285de4ac771d6188f62fe947e23d371a3dKris Giesing v.setPivotX(v.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? v.getWidth() : 0); 1412f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu v.setPivotY(v.getMeasuredHeight() / 2); 1422f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1432f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu }; 1442f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1452f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 14642752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu int getLayoutResourceId() { 1472f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu return R.layout.lb_headers_fragment; 1482f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1492f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1502f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1512f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onViewCreated(View view, Bundle savedInstanceState) { 1522f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu super.onViewCreated(view, savedInstanceState); 1534cf79b1c4d38a190317961891f9fd052836710fdCraig Stout final VerticalGridView listView = getVerticalGridView(); 1544cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (listView == null) { 1554cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return; 1563c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1574cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (getBridgeAdapter() != null) { 1584cf79b1c4d38a190317961891f9fd052836710fdCraig Stout FocusHighlightHelper.setupHeaderItemFocusHighlight(listView); 1594cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 1607f43e18536eae40705d5c63830e9edb283f196adDake Gu if (mBackgroundColorSet) { 1619a49e322d10c1a67860d812352a5ea710843b75eDake Gu listView.setBackgroundColor(mBackgroundColor); 1627f43e18536eae40705d5c63830e9edb283f196adDake Gu updateFadingEdgeToBrandColor(mBackgroundColor); 1639a49e322d10c1a67860d812352a5ea710843b75eDake Gu } else { 1649a49e322d10c1a67860d812352a5ea710843b75eDake Gu Drawable d = listView.getBackground(); 1659a49e322d10c1a67860d812352a5ea710843b75eDake Gu if (d instanceof ColorDrawable) { 1669a49e322d10c1a67860d812352a5ea710843b75eDake Gu updateFadingEdgeToBrandColor(((ColorDrawable) d).getColor()); 1679a49e322d10c1a67860d812352a5ea710843b75eDake Gu } 1687f43e18536eae40705d5c63830e9edb283f196adDake Gu } 169d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1703c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1713c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 172d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu private void updateListViewVisibility() { 1733c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu final VerticalGridView listView = getVerticalGridView(); 1742f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu if (listView != null) { 1759652881bb6af5a2b76f89d683bd420336f4bf463Dake Gu getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE); 176d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (!mHeadersGone) { 177d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (mHeadersEnabled) { 178d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.VISIBLE); 179d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } else { 180d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.INVISIBLE); 181d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 182d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 183d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 184d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 185d559710c8763acb37fd444735da7ee770b84df07Craig Stout 186d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu void setHeadersEnabled(boolean enabled) { 187d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu mHeadersEnabled = enabled; 188d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 189d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 190d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu 191d559710c8763acb37fd444735da7ee770b84df07Craig Stout void setHeadersGone(boolean gone) { 192d559710c8763acb37fd444735da7ee770b84df07Craig Stout mHeadersGone = gone; 193d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1943c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1953c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1963659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu static class NoOverlappingFrameLayout extends FrameLayout { 1973659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 1983659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public NoOverlappingFrameLayout(Context context) { 1993659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu super(context); 2003659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 2013659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 2023659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu /** 2033659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu * Avoid creating hardware layer for header dock. 2043659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu */ 2053659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu @Override 2063659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public boolean hasOverlappingRendering() { 2073659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return false; 2083659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 2093659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 2103659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 211e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // Wrapper needed because of conflict between RecyclerView's use of alpha 212e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // for ADD animations, and RowHeaderPresnter's use of alpha for selected level. 213e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout private final ItemBridgeAdapter.Wrapper mWrapper = new ItemBridgeAdapter.Wrapper() { 214e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 215e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public void wrap(View wrapper, View wrapped) { 216e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout ((FrameLayout) wrapper).addView(wrapped); 217e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 218e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout 219e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 220e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public View createWrapper(View root) { 2213659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return new NoOverlappingFrameLayout(root.getContext()); 222e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 223e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout }; 2243c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 22542752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu void updateAdapter() { 22655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout super.updateAdapter(); 22755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout ItemBridgeAdapter adapter = getBridgeAdapter(); 22855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout if (adapter != null) { 2293c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu adapter.setAdapterListener(mAdapterListener); 230e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout adapter.setWrapper(mWrapper); 2313c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 2323c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (adapter != null && getVerticalGridView() != null) { 2333c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView()); 23455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 23555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 2364cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2374cf79b1c4d38a190317961891f9fd052836710fdCraig Stout void setBackgroundColor(int color) { 2384cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColor = color; 2394cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColorSet = true; 2404cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2419a49e322d10c1a67860d812352a5ea710843b75eDake Gu if (getVerticalGridView() != null) { 2429a49e322d10c1a67860d812352a5ea710843b75eDake Gu getVerticalGridView().setBackgroundColor(mBackgroundColor); 243b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu updateFadingEdgeToBrandColor(mBackgroundColor); 2447a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2457a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2467a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 247b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu private void updateFadingEdgeToBrandColor(int backgroundColor) { 2487a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu View fadingView = getView().findViewById(R.id.fade_out_edge); 2497a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu Drawable background = fadingView.getBackground(); 2507a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu if (background instanceof GradientDrawable) { 2517a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu background.mutate(); 2527a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu ((GradientDrawable) background).setColors( 253b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu new int[] {Color.TRANSPARENT, backgroundColor}); 2544cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2554cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2564cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 25749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu @Override 2582f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionStart() { 25949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu super.onTransitionStart(); 26049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (!mHeadersEnabled) { 26149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // When enabling headers fragment, the RowHeaderView gets a focus but 26249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // isShown() is still false because its parent is INVSIBILE, accessibility 26349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // event is not sent. 26449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // Workaround is: prevent focus to a child view during transition and put 26549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // focus on it after transition is done. 26649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu final VerticalGridView listView = getVerticalGridView(); 26749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView != null) { 26849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 26949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView.hasFocus()) { 27049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.requestFocus(); 27149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu 27649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu @Override 2772f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionEnd() { 27849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (mHeadersEnabled) { 27949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu final VerticalGridView listView = getVerticalGridView(); 28049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView != null) { 28149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 28249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView.hasFocus()) { 28349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.requestFocus(); 28449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 28549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 28649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 28749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu super.onTransitionEnd(); 28849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 2892f5ebf3f6f7bb6a24856f389e369b247118ba119susnata 2902f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public boolean isScrolling() { 2912f5ebf3f6f7bb6a24856f389e369b247118ba119susnata return getVerticalGridView().getScrollState() 2922f5ebf3f6f7bb6a24856f389e369b247118ba119susnata != HorizontalGridView.SCROLL_STATE_IDLE; 2932f5ebf3f6f7bb6a24856f389e369b247118ba119susnata } 29455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout} 295