1e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout/* This file is auto-generated from BrandedFragment.java. DO NOT MODIFY. */ 2e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 3e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout/* 4e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Copyright (C) 2014 The Android Open Source Project 5e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 6e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * in compliance with the License. You may obtain a copy of the License at 8e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 9e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * http://www.apache.org/licenses/LICENSE-2.0 10e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 11e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License 12e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 13e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * or implied. See the License for the specific language governing permissions and limitations under 14e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * the License. 15e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 16e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutpackage android.support.v17.leanback.app; 17e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 18e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.support.v4.app.Fragment; 19e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.graphics.drawable.Drawable; 20e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.os.Bundle; 21e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.support.v17.leanback.R; 22e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.support.v17.leanback.widget.SearchOrbView; 23e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.support.v17.leanback.widget.TitleHelper; 24a373804d10f93a9488adc35cf6ce44dce09b3778Dake Guimport android.support.v17.leanback.widget.TitleViewAdapter; 25a373804d10f93a9488adc35cf6ce44dce09b3778Dake Guimport android.util.TypedValue; 26a373804d10f93a9488adc35cf6ce44dce09b3778Dake Guimport android.view.LayoutInflater; 27e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.view.View; 28e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stoutimport android.view.ViewGroup; 29e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 30e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout/** 31a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Fragment class for managing search and branding using a view that implements 32a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * {@link TitleViewAdapter.Provider}. 33e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 34a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gupublic class BrandedSupportFragment extends Fragment { 35e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 36e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout // BUNDLE attribute for title is showing 37e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private static final String TITLE_SHOW = "titleShow"; 38e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 39e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private boolean mShowingTitle = true; 40a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu private CharSequence mTitle; 41e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private Drawable mBadgeDrawable; 42a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu private View mTitleView; 43a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu private TitleViewAdapter mTitleViewAdapter; 44e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private SearchOrbView.Colors mSearchAffordanceColors; 45e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private boolean mSearchAffordanceColorSet; 46e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private View.OnClickListener mExternalOnSearchClickedListener; 47e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout private TitleHelper mTitleHelper; 48e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 49e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 50a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Called by {@link #installTitleView(LayoutInflater, ViewGroup, Bundle)} to inflate 51a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * title view. Default implementation uses layout file lb_browse_title. 52a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Subclass may override and use its own layout, the layout must have a descendant with id 53a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * browse_title_group that implements {@link TitleViewAdapter.Provider}. Subclass may return 54a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * null if no title is needed. 55a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * 56a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param inflater The LayoutInflater object that can be used to inflate 57a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * any views in the fragment, 58a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param parent Parent of title view. 59a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param savedInstanceState If non-null, this fragment is being re-constructed 60a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * from a previous saved state as given here. 61a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @return Title view which must have a descendant with id browse_title_group that implements 62a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * {@link TitleViewAdapter.Provider}, or null for no title view. 63a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu */ 64a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public View onInflateTitleView(LayoutInflater inflater, ViewGroup parent, 65a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu Bundle savedInstanceState) { 66a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu TypedValue typedValue = new TypedValue(); 67a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu boolean found = parent.getContext().getTheme().resolveAttribute( 68a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu R.attr.browseTitleViewLayout, typedValue, true); 69a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu return inflater.inflate(found ? typedValue.resourceId : R.layout.lb_browse_title, 70a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu parent, false); 71a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } 72a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu 73a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu /** 74a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Inflate title view and add to parent. This method should be called in 75a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * {@link Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)}. 76a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param inflater The LayoutInflater object that can be used to inflate 77a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * any views in the fragment, 78a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param parent Parent of title view. 79a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param savedInstanceState If non-null, this fragment is being re-constructed 80a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * from a previous saved state as given here. 81a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu */ 82a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public void installTitleView(LayoutInflater inflater, ViewGroup parent, 83a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu Bundle savedInstanceState) { 84a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu View titleLayoutRoot = onInflateTitleView(inflater, parent, savedInstanceState); 85a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (titleLayoutRoot != null) { 86a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu parent.addView(titleLayoutRoot); 87a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu setTitleView(titleLayoutRoot.findViewById(R.id.browse_title_group)); 88a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } else { 89a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu setTitleView(null); 90a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } 91a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } 92a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu 93a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu /** 94a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Sets the view that implemented {@link TitleViewAdapter}. 95a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param titleView The view that implemented {@link TitleViewAdapter.Provider}. 96e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 97a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public void setTitleView(View titleView) { 98e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleView = titleView; 99e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mTitleView == null) { 100a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter = null; 101e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleHelper = null; 102e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } else { 103a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter = ((TitleViewAdapter.Provider) mTitleView).getTitleViewAdapter(); 104a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setTitle(mTitle); 105a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setBadgeDrawable(mBadgeDrawable); 106e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mSearchAffordanceColorSet) { 107a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setSearchAffordanceColors(mSearchAffordanceColors); 108e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 109e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mExternalOnSearchClickedListener != null) { 110a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu setOnSearchClickedListener(mExternalOnSearchClickedListener); 111e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 112e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (getView() instanceof ViewGroup) { 113e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleHelper = new TitleHelper((ViewGroup) getView(), mTitleView); 114e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 115e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 116e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 117e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 118e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 119a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Returns the view that implements {@link TitleViewAdapter.Provider}. 120a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @return The view that implements {@link TitleViewAdapter.Provider}. 121e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 122a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public View getTitleView() { 123e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return mTitleView; 124e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 125e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 126e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 127a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Returns the {@link TitleViewAdapter} implemented by title view. 128a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @return The {@link TitleViewAdapter} implemented by title view. 129a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu */ 130a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public TitleViewAdapter getTitleViewAdapter() { 131a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu return mTitleViewAdapter; 132a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } 133a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu 134a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu /** 135e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Returns the {@link TitleHelper}. 136e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 137f01172a8028e20a2d86c71c1024fbc973e67afa4Craig Stout TitleHelper getTitleHelper() { 138e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return mTitleHelper; 139e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 140e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 141e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout @Override 142e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void onSaveInstanceState(Bundle outState) { 143e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout super.onSaveInstanceState(outState); 144e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout outState.putBoolean(TITLE_SHOW, mShowingTitle); 145e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 146e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 147e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout @Override 148e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void onViewCreated(View view, Bundle savedInstanceState) { 149e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout super.onViewCreated(view, savedInstanceState); 150e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (savedInstanceState != null) { 151e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mShowingTitle = savedInstanceState.getBoolean(TITLE_SHOW); 152e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 153e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mTitleView != null && view instanceof ViewGroup) { 154e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleHelper = new TitleHelper((ViewGroup) view, mTitleView); 155e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 156e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 157e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 158e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout @Override 159e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void onDestroyView() { 160e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout super.onDestroyView(); 161e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleHelper = null; 162e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 163e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 164e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 165a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Shows or hides the title view. 166a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param show True to show title view, false to hide title view. 167e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 168a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public void showTitle(boolean show) { 169e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout // TODO: handle interruptions? 170e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (show == mShowingTitle) { 171e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return; 172e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 173e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mShowingTitle = show; 174e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mTitleHelper != null) { 175e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitleHelper.showTitle(show); 176e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 177e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 178e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 179a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu /** 180a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Changes title view's components visibility and shows title. 181a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param flags Flags representing the visibility of components inside title view. 182a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @see TitleViewAdapter#SEARCH_VIEW_VISIBLE 183a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @see TitleViewAdapter#BRANDING_VIEW_VISIBLE 184a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @see TitleViewAdapter#FULL_VIEW_VISIBLE 185a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @see TitleViewAdapter#updateComponentsVisibility(int) 186a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu */ 187a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public void showTitle(int flags) { 188a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 189a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.updateComponentsVisibility(flags); 190a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu } 1917350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata showTitle(true); 1927350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata } 1937350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata 194e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 195a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Sets the drawable displayed in the fragment title. 196e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 197a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param drawable The Drawable to display in the fragment title. 198e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 199e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void setBadgeDrawable(Drawable drawable) { 200e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mBadgeDrawable != drawable) { 201e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mBadgeDrawable = drawable; 202a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 203a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setBadgeDrawable(drawable); 204e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 205e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 206e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 207e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 208e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 209e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Returns the badge drawable used in the fragment title. 210a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @return The badge drawable used in the fragment title. 211e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 212e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public Drawable getBadgeDrawable() { 213e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return mBadgeDrawable; 214e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 215e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 216e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 217a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Sets title text for the fragment. 218e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 219a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param title The title text of the fragment. 220e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 221a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public void setTitle(CharSequence title) { 222e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mTitle = title; 223a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 224a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setTitle(title); 225e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 226e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 227e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 228e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 229a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Returns the title text for the fragment. 230a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @return Title text for the fragment. 231e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 232a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu public CharSequence getTitle() { 233e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return mTitle; 234e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 235e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 236e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 237e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Sets a click listener for the search affordance. 238e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 239e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * <p>The presence of a listener will change the visibility of the search 240e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * affordance in the fragment title. When set to non-null, the title will 241e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * contain an element that a user may click to begin a search. 242e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 243e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * <p>The listener's {@link View.OnClickListener#onClick onClick} method 244e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * will be invoked when the user clicks on the search element. 245e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 246e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * @param listener The listener to call when the search element is clicked. 247e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 248e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void setOnSearchClickedListener(View.OnClickListener listener) { 249e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mExternalOnSearchClickedListener = listener; 250a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 251a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setOnSearchClickedListener(listener); 252e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 253e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 254e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 255e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 256a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * Sets the {@link android.support.v17.leanback.widget.SearchOrbView.Colors} used to draw the 257a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * search affordance. 258a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * 259a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu * @param colors Colors used to draw search affordance. 260e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 261e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void setSearchAffordanceColors(SearchOrbView.Colors colors) { 262e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mSearchAffordanceColors = colors; 263e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout mSearchAffordanceColorSet = true; 264a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 265a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setSearchAffordanceColors(mSearchAffordanceColors); 266e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 267e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 268e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 269e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 270f01172a8028e20a2d86c71c1024fbc973e67afa4Craig Stout * Returns the {@link android.support.v17.leanback.widget.SearchOrbView.Colors} 271f01172a8028e20a2d86c71c1024fbc973e67afa4Craig Stout * used to draw the search affordance. 272e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 273e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public SearchOrbView.Colors getSearchAffordanceColors() { 274e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout if (mSearchAffordanceColorSet) { 275e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return mSearchAffordanceColors; 276e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 277a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter == null) { 278e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout throw new IllegalStateException("Fragment views not yet created"); 279e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 280a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu return mTitleViewAdapter.getSearchAffordanceColors(); 281e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 282e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 283e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 284e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Sets the color used to draw the search affordance. 285e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * A default brighter color will be set by the framework. 286e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * 287e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * @param color The color to use for the search affordance. 288e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 289e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void setSearchAffordanceColor(int color) { 290e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout setSearchAffordanceColors(new SearchOrbView.Colors(color)); 291e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 292e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 293e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout /** 294e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout * Returns the color used to draw the search affordance. 295e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout */ 296e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public int getSearchAffordanceColor() { 297e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout return getSearchAffordanceColors().color; 298e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 299e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 300e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout @Override 301e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout public void onStart() { 302e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout super.onStart(); 303a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 304b10ba3b01290ce801180a3d5dc992825af8cb3absusnata showTitle(mShowingTitle); 305a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setAnimationEnabled(true); 306e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 307e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 308e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout 309e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout @Override 3107350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata public void onPause() { 311a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 312a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setAnimationEnabled(false); 313e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 3147350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata super.onPause(); 3157350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata } 3167350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata 3177350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata @Override 3187350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata public void onResume() { 3197350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata super.onResume(); 320a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu if (mTitleViewAdapter != null) { 321a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu mTitleViewAdapter.setAnimationEnabled(true); 3227350fc450e5850b7a3dddff6d63fb87bd24886ddsusnata } 323e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout } 3246fd4441435b14669deced90a05097dd5fe459acesusnata 325dc1492d3655550b7a9c861aae1bd538410c7324dDake Gu /** 326b10ba3b01290ce801180a3d5dc992825af8cb3absusnata * Returns true/false to indicate the visibility of TitleView. 327dc1492d3655550b7a9c861aae1bd538410c7324dDake Gu * 328dc1492d3655550b7a9c861aae1bd538410c7324dDake Gu * @return boolean to indicate whether or not it's showing the title. 329dc1492d3655550b7a9c861aae1bd538410c7324dDake Gu */ 3306fd4441435b14669deced90a05097dd5fe459acesusnata public final boolean isShowingTitle() { 3316fd4441435b14669deced90a05097dd5fe459acesusnata return mShowingTitle; 3326fd4441435b14669deced90a05097dd5fe459acesusnata } 333a373804d10f93a9488adc35cf6ce44dce09b3778Dake Gu 334e7246ef136ed686d8caf339d4d1fd8e37b499c6aCraig Stout} 335