HeadersFragment.java revision b74149016854eb172c0ef121ccfef749c6ef7eb1
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; 2655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.OnItemSelectedListener; 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; 314cf79b1c4d38a190317961891f9fd052836710fdCraig Stoutimport android.util.TypedValue; 3255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.View; 3355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.ViewGroup; 342f97594742886d045ca1ce409ebc6e6e780452f6Dake Guimport android.view.View.OnLayoutChangeListener; 35e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stoutimport android.widget.FrameLayout; 3655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 3755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/** 3855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * An internal fragment containing a list of row headers. 3955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 40a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbournpublic class HeadersFragment extends BaseRowFragment { 413c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 423c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu interface OnHeaderClickedListener { 433c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu void onHeaderClicked(); 443c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 453c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 4655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout private OnItemSelectedListener mOnItemSelectedListener; 473c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private OnHeaderClickedListener mOnHeaderClickedListener; 48d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersEnabled = true; 49d559710c8763acb37fd444735da7ee770b84df07Craig Stout private boolean mHeadersGone = false; 504cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private int mBackgroundColor; 514cf79b1c4d38a190317961891f9fd052836710fdCraig Stout private boolean mBackgroundColorSet; 523c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 53bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu private static final PresenterSelector sHeaderPresenter = new SinglePresenterSelector( 54268de3d2ea3de1be0725a80bbc79dd7b8b18617eCraig Stout new RowHeaderPresenter(R.layout.lb_header)); 5555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 56a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn public HeadersFragment() { 57bd80644186ff8622c565f067dc3a4136a4dc0586Dake Gu setPresenterSelector(sHeaderPresenter); 5855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 5955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 603c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void setOnHeaderClickedListener(OnHeaderClickedListener listener) { 613c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu mOnHeaderClickedListener = listener; 6255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 6355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 6455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout public void setOnItemSelectedListener(OnItemSelectedListener listener) { 6555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout mOnItemSelectedListener = listener; 6655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 6755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 6855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 697a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu protected VerticalGridView findGridViewFromRoot(View view) { 707a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu return (VerticalGridView) view.findViewById(R.id.browse_headers); 717a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 727a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 737a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu @Override 7455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout protected void onRowSelected(ViewGroup parent, View view, int position, long id) { 7555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout if (mOnItemSelectedListener != null) { 762f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson if (position >= 0) { 772f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson Row row = (Row) getAdapter().get(position); 782f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson mOnItemSelectedListener.onItemSelected(null, row); 79d736653bfee7fc83fc68d57d0e0bee5fa807287fDake Gu } else { 80d736653bfee7fc83fc68d57d0e0bee5fa807287fDake Gu mOnItemSelectedListener.onItemSelected(null, null); 812f5fbc79d656fc4966119141aaef48161f08376fAndrew Wilson } 8255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 8355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 8455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 853c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu private final ItemBridgeAdapter.AdapterListener mAdapterListener = 863c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu new ItemBridgeAdapter.AdapterListener() { 873c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 883c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) { 893c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu View headerView = viewHolder.getViewHolder().view; 903c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setOnClickListener(new View.OnClickListener() { 913c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 923c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu public void onClick(View v) { 933c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (mOnHeaderClickedListener != null) { 943c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu mOnHeaderClickedListener.onHeaderClicked(); 953c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 963c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 973c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }); 983c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusable(true); 993c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu headerView.setFocusableInTouchMode(true); 100e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout if (mWrapper != null) { 101e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener); 102e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } else { 103e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout headerView.addOnLayoutChangeListener(sLayoutChangeListener); 104e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 1053c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1063c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1073c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu }; 1083c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1092f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu private static OnLayoutChangeListener sLayoutChangeListener = new OnLayoutChangeListener() { 1102f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1112f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onLayoutChange(View v, int left, int top, int right, int bottom, 1122f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu int oldLeft, int oldTop, int oldRight, int oldBottom) { 1132f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu v.setPivotX(0); 1142f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu v.setPivotY(v.getMeasuredHeight() / 2); 1152f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1162f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu }; 1172f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1182f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1192f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu protected int getLayoutResourceId() { 1202f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu return R.layout.lb_headers_fragment; 1212f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 1222f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 1232f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu @Override 1242f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu public void onViewCreated(View view, Bundle savedInstanceState) { 1252f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu super.onViewCreated(view, savedInstanceState); 1264cf79b1c4d38a190317961891f9fd052836710fdCraig Stout final VerticalGridView listView = getVerticalGridView(); 1274cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (listView == null) { 1284cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return; 1293c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1304cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (getBridgeAdapter() != null) { 1314cf79b1c4d38a190317961891f9fd052836710fdCraig Stout FocusHighlightHelper.setupHeaderItemFocusHighlight(listView); 1324cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 1337a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu view.setBackgroundColor(getBackgroundColor()); 134b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu updateFadingEdgeToBrandColor(getBackgroundColor()); 135d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1363c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1373c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 138d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu private void updateListViewVisibility() { 1393c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu final VerticalGridView listView = getVerticalGridView(); 1402f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu if (listView != null) { 1419652881bb6af5a2b76f89d683bd420336f4bf463Dake Gu getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE); 142d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (!mHeadersGone) { 143d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu if (mHeadersEnabled) { 144d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.VISIBLE); 145d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } else { 146d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu listView.setChildrenVisibility(View.INVISIBLE); 147d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 148d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 149d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 150d559710c8763acb37fd444735da7ee770b84df07Craig Stout } 151d559710c8763acb37fd444735da7ee770b84df07Craig Stout 152d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu void setHeadersEnabled(boolean enabled) { 153d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu mHeadersEnabled = enabled; 154d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 155d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu } 156d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu 157d559710c8763acb37fd444735da7ee770b84df07Craig Stout void setHeadersGone(boolean gone) { 158d559710c8763acb37fd444735da7ee770b84df07Craig Stout mHeadersGone = gone; 159d7618ab69ef591dd5342b9481c4954bfc7e9110cDake Gu updateListViewVisibility(); 1603c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1613c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu 1623659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu static class NoOverlappingFrameLayout extends FrameLayout { 1633659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 1643659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public NoOverlappingFrameLayout(Context context) { 1653659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu super(context); 1663659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1673659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 1683659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu /** 1693659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu * Avoid creating hardware layer for header dock. 1703659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu */ 1713659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu @Override 1723659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu public boolean hasOverlappingRendering() { 1733659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return false; 1743659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1753659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu } 1763659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu 177e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // Wrapper needed because of conflict between RecyclerView's use of alpha 178e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout // for ADD animations, and RowHeaderPresnter's use of alpha for selected level. 179e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout private final ItemBridgeAdapter.Wrapper mWrapper = new ItemBridgeAdapter.Wrapper() { 180e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 181e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public void wrap(View wrapper, View wrapped) { 182e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout ((FrameLayout) wrapper).addView(wrapped); 183e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 184e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout 185e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout @Override 186e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout public View createWrapper(View root) { 1873659dc62f9e55b1043edb4105c311c8ef997f2aeDake Gu return new NoOverlappingFrameLayout(root.getContext()); 188e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout } 189e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout }; 1903c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu @Override 19155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout protected void updateAdapter() { 19255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout super.updateAdapter(); 19355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout ItemBridgeAdapter adapter = getBridgeAdapter(); 19455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout if (adapter != null) { 1953c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu adapter.setAdapterListener(mAdapterListener); 196e51474af2c4b5192a75fd283cb737d02fccc58a4Craig Stout adapter.setWrapper(mWrapper); 1973c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu } 1983c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu if (adapter != null && getVerticalGridView() != null) { 1993c23ada8bc25a05bbaa8c479a9df72e8172c4349Dake Gu FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView()); 20055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 20155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 2024cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2034cf79b1c4d38a190317961891f9fd052836710fdCraig Stout void setBackgroundColor(int color) { 2044cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColor = color; 2054cf79b1c4d38a190317961891f9fd052836710fdCraig Stout mBackgroundColorSet = true; 2064cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2077a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu if (getView() != null) { 2087a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu getView().setBackgroundColor(mBackgroundColor); 209b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu updateFadingEdgeToBrandColor(mBackgroundColor); 2107a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2117a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 2127a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 213b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu private void updateFadingEdgeToBrandColor(int backgroundColor) { 2147a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu View fadingView = getView().findViewById(R.id.fade_out_edge); 2157a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu Drawable background = fadingView.getBackground(); 2167a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu if (background instanceof GradientDrawable) { 2177a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu background.mutate(); 2187a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu ((GradientDrawable) background).setColors( 219b74149016854eb172c0ef121ccfef749c6ef7eb1Dake Gu new int[] {Color.TRANSPARENT, backgroundColor}); 2204cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2214cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2224cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2234cf79b1c4d38a190317961891f9fd052836710fdCraig Stout int getBackgroundColor() { 2244cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (getActivity() == null) { 2254cf79b1c4d38a190317961891f9fd052836710fdCraig Stout throw new IllegalStateException("Activity must be attached"); 2264cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2274cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2284cf79b1c4d38a190317961891f9fd052836710fdCraig Stout if (mBackgroundColorSet) { 2294cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return mBackgroundColor; 2304cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 2314cf79b1c4d38a190317961891f9fd052836710fdCraig Stout 2324cf79b1c4d38a190317961891f9fd052836710fdCraig Stout TypedValue outValue = new TypedValue(); 233056561d81012983d2d27b8665c4aeabb427174cbTim Kilbourn getActivity().getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true); 2344cf79b1c4d38a190317961891f9fd052836710fdCraig Stout return getResources().getColor(outValue.resourceId); 2354cf79b1c4d38a190317961891f9fd052836710fdCraig Stout } 23655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout} 237