HeadersFragment.java revision 0246318f27a905a31df5a8af445cfe67d31dfb68
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; 197a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Guimport android.graphics.drawable.Drawable; 207a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Guimport android.graphics.drawable.GradientDrawable; 213c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.os.Bundle; 2255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.R; 2355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.FocusHighlightHelper; 2455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ItemBridgeAdapter; 2555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.PresenterSelector; 268df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Guimport android.support.v17.leanback.widget.OnItemViewSelectedListener; 2755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.Row; 283c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.support.v17.leanback.widget.RowHeaderPresenter; 29bd80644186ff8622c565f067dc3a4136a4dc0586Dake Guimport android.support.v17.leanback.widget.SinglePresenterSelector; 303c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Guimport android.support.v17.leanback.widget.VerticalGridView; 310246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView; 324cf79b1c4d38a190317961891f9fd052836710fdCraig Stoutimport android.util.TypedValue; 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 433c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu interface OnHeaderClickedListener { 443c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu void onHeaderClicked(); 453c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 463c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 478df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu interface OnHeaderViewSelectedListener { 488df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu void onHeaderSelected(RowHeaderPresenter.ViewHolder viewHolder, Row row); 498df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu } 508df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu 518df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu private OnHeaderViewSelectedListener mOnHeaderViewSelectedListener; 523c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private OnHeaderClickedListener mOnHeaderClickedListener; 53d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersEnabled = true; 54d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersGone = false; 554cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private int mBackgroundColor; 564cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private boolean mBackgroundColorSet; 573c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 58bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu private static final PresenterSelector sHeaderPresenter = new SinglePresenterSelector( 59268de3d2ea3de1be0725a80bbc79dd7b8b18617eCraig Stout new RowHeaderPresenter(R.layout.lb_header)); 6055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 61a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn public HeadersFragment() { 62bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu setPresenterSelector(sHeaderPresenter); 6355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 6455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 653c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void setOnHeaderClickedListener(OnHeaderClickedListener listener) { 663c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu mOnHeaderClickedListener = listener; 6755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 6855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 698df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu public void setOnHeaderViewSelectedListener(OnHeaderViewSelectedListener listener) { 708df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener = listener; 7155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 7255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 7355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 7442752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu VerticalGridView findGridViewFromRoot(View view) { 757a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu return (VerticalGridView) view.findViewById(R.id.browse_headers); 767a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 777a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 787a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu @Override 790246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder viewHolder, 800246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu int position, int subposition) { 818df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu if (mOnHeaderViewSelectedListener != null) { 820246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu if (viewHolder != null && position >= 0) { 832f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson Row row = (Row) getAdapter().get(position); 840246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) viewHolder; 858df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener.onHeaderSelected( 868df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu (RowHeaderPresenter.ViewHolder) vh.getViewHolder(), row); 87d736653bfee7fc83fc68d57d0e0bee5fa807287fDake Gu } else { 888df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu mOnHeaderViewSelectedListener.onHeaderSelected(null, null); 892f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson } 9055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 9155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 9255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 933c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private final ItemBridgeAdapter.AdapterListener mAdapterListener = 943c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu new ItemBridgeAdapter.AdapterListener() { 953c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 963c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) { 973c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu View headerView = viewHolder.getViewHolder().view; 983c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setOnClickListener(new View.OnClickListener() { 993c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 1003c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void onClick(View v) { 1013c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (mOnHeaderClickedListener != null) { 1023c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu mOnHeaderClickedListener.onHeaderClicked(); 1033c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1043c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1053c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }); 1063c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusable(true); 1073c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusableInTouchMode(true); 108e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout if (mWrapper != null) { 109e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener); 110e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } else { 111e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout headerView.addOnLayoutChangeListener(sLayoutChangeListener); 112e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 1133c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1143c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1153c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }; 1163c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1172f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu private static OnLayoutChangeListener sLayoutChangeListener = new OnLayoutChangeListener() { 1182f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1192f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onLayoutChange(View v, int left, int top, int right, int bottom, 1202f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu int oldLeft, int oldTop, int oldRight, int oldBottom) { 1218e3566285de4ac771d6188f62fe947e23d371a3dKris Giesing v.setPivotX(v.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? v.getWidth() : 0); 1222f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu v.setPivotY(v.getMeasuredHeight() / 2); 1232f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1242f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu }; 1252f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1262f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 12742752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu int getLayoutResourceId() { 1282f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu return R.layout.lb_headers_fragment; 1292f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1302f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1312f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1322f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onViewCreated(View view, Bundle savedInstanceState) { 1332f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu super.onViewCreated(view, savedInstanceState); 1344cf79b1c4d38a190317961891f9fd052836710fdCraig Stout final VerticalGridView listView = getVerticalGridView(); 1354cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (listView == null) { 1364cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return; 1373c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1384cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (getBridgeAdapter() != null) { 1394cf79b1c4d38a190317961891f9fd052836710fdCraig Stout FocusHighlightHelper.setupHeaderItemFocusHighlight(listView); 1404cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 1417a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu view.setBackgroundColor(getBackgroundColor()); 142b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu updateFadingEdgeToBrandColor(getBackgroundColor()); 143d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1443c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1453c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 146d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu private void updateListViewVisibility() { 1473c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu final VerticalGridView listView = getVerticalGridView(); 1482f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu if (listView != null) { 1499652881bb6af5a2b76f89d683bd420336f4bf463Dake Gu getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE); 150d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (!mHeadersGone) { 151d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (mHeadersEnabled) { 152d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.VISIBLE); 153d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } else { 154d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.INVISIBLE); 155d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 156d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 157d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 158d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 159d559710c8763acb37fd444735da7ee770b84df07Craig Stout 160d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu void setHeadersEnabled(boolean enabled) { 161d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu mHeadersEnabled = enabled; 162d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 163d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 164d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu 165d559710c8763acb37fd444735da7ee770b84df07Craig Stout void setHeadersGone(boolean gone) { 166d559710c8763acb37fd444735da7ee770b84df07Craig Stout mHeadersGone = gone; 167d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1683c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1693c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1703659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu static class NoOverlappingFrameLayout extends FrameLayout { 1713659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 1723659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public NoOverlappingFrameLayout(Context context) { 1733659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu super(context); 1743659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1753659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 1763659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu /** 1773659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu * Avoid creating hardware layer for header dock. 1783659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu */ 1793659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu @Override 1803659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public boolean hasOverlappingRendering() { 1813659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return false; 1823659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1833659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1843659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 185e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // Wrapper needed because of conflict between RecyclerView's use of alpha 186e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // for ADD animations, and RowHeaderPresnter's use of alpha for selected level. 187e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout private final ItemBridgeAdapter.Wrapper mWrapper = new ItemBridgeAdapter.Wrapper() { 188e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 189e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public void wrap(View wrapper, View wrapped) { 190e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout ((FrameLayout) wrapper).addView(wrapped); 191e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 192e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout 193e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 194e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public View createWrapper(View root) { 1953659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return new NoOverlappingFrameLayout(root.getContext()); 196e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 197e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout }; 1983c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 19942752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu void updateAdapter() { 20055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout super.updateAdapter(); 20155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout ItemBridgeAdapter adapter = getBridgeAdapter(); 20255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout if (adapter != null) { 2033c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu adapter.setAdapterListener(mAdapterListener); 204e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout adapter.setWrapper(mWrapper); 2053c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 2063c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (adapter != null && getVerticalGridView() != null) { 2073c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView()); 20855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 20955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 2104cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2114cf79b1c4d38a190317961891f9fd052836710fdCraig Stout void setBackgroundColor(int color) { 2124cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColor = color; 2134cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColorSet = true; 2144cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2157a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu if (getView() != null) { 2167a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu getView().setBackgroundColor(mBackgroundColor); 217b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu updateFadingEdgeToBrandColor(mBackgroundColor); 2187a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2197a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2207a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 221b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu private void updateFadingEdgeToBrandColor(int backgroundColor) { 2227a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu View fadingView = getView().findViewById(R.id.fade_out_edge); 2237a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu Drawable background = fadingView.getBackground(); 2247a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu if (background instanceof GradientDrawable) { 2257a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu background.mutate(); 2267a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu ((GradientDrawable) background).setColors( 227b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu new int[] {Color.TRANSPARENT, backgroundColor}); 2284cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2294cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2304cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2314cf79b1c4d38a190317961891f9fd052836710fdCraig Stout int getBackgroundColor() { 2324cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (getActivity() == null) { 2334cf79b1c4d38a190317961891f9fd052836710fdCraig Stout throw new IllegalStateException("Activity must be attached"); 2344cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2354cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2364cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (mBackgroundColorSet) { 2374cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return mBackgroundColor; 2384cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2394cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2404cf79b1c4d38a190317961891f9fd052836710fdCraig Stout TypedValue outValue = new TypedValue(); 24146443cb5b092f1d9156342645088eead9da026f6Dake Gu if (getActivity().getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true)) { 24246443cb5b092f1d9156342645088eead9da026f6Dake Gu return getResources().getColor(outValue.resourceId); 24346443cb5b092f1d9156342645088eead9da026f6Dake Gu } 24446443cb5b092f1d9156342645088eead9da026f6Dake Gu return getResources().getColor(R.color.lb_default_brand_color); 2454cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 24649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu 24749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu @Override 24849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu void onTransitionStart() { 24949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu super.onTransitionStart(); 25049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (!mHeadersEnabled) { 25149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // When enabling headers fragment, the RowHeaderView gets a focus but 25249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // isShown() is still false because its parent is INVSIBILE, accessibility 25349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // event is not sent. 25449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // Workaround is: prevent focus to a child view during transition and put 25549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu // focus on it after transition is done. 25649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu final VerticalGridView listView = getVerticalGridView(); 25749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView != null) { 25849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 25949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView.hasFocus()) { 26049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.requestFocus(); 26149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 26249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 26349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 26449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 26549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu 26649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu @Override 26749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu void onTransitionEnd() { 26849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (mHeadersEnabled) { 26949e6a6cd81f3a1117b306323064c53230a7f01adDake Gu final VerticalGridView listView = getVerticalGridView(); 27049e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView != null) { 27149e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 27249e6a6cd81f3a1117b306323064c53230a7f01adDake Gu if (listView.hasFocus()) { 27349e6a6cd81f3a1117b306323064c53230a7f01adDake Gu listView.requestFocus(); 27449e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27549e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27649e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27749e6a6cd81f3a1117b306323064c53230a7f01adDake Gu super.onTransitionEnd(); 27849e6a6cd81f3a1117b306323064c53230a7f01adDake Gu } 27955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout} 280