16193c12a1897723c87b41f4e304a8cd04deef2dcDake Gu/* This file is auto-generated from VerticalGridFragment.java. DO NOT MODIFY. */ 26193c12a1897723c87b41f4e304a8cd04deef2dcDake Gu 361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/* 461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Copyright (C) 2014 The Android Open Source Project 561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * in compliance with the License. You may obtain a copy of the License at 861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * http://www.apache.org/licenses/LICENSE-2.0 1061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 1161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License 1261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * or implied. See the License for the specific language governing permissions and limitations under 1461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * the License. 1561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 1661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupackage android.support.v17.leanback.app; 1761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 1861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.R; 1961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.transition.TransitionHelper; 2061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.BrowseFrameLayout; 2161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.OnItemViewClickedListener; 2261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.OnItemViewSelectedListener; 2361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.Presenter; 2461905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.Row; 2561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.RowPresenter; 2661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.TitleView; 2761905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.VerticalGridPresenter; 2861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ObjectAdapter; 2961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.OnItemClickedListener; 3061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.OnItemSelectedListener; 3161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.SearchOrbView; 324a10f1eb5c4283cfeef34cd71b84173f5ab3eefbKris Giesingimport android.support.v4.view.ViewCompat; 3361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v4.app.Fragment; 344735bfcd924fec2d694523f34fac5f8151257dc7Dake Guimport android.content.Context; 3561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.drawable.Drawable; 3661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.os.Bundle; 3761905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.util.Log; 3861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.LayoutInflater; 3961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View; 4061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.ViewGroup; 4161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.ViewGroup.MarginLayoutParams; 4261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.widget.ImageView; 4361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.widget.TextView; 4461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 4561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/** 4661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * A fragment for creating leanback vertical grids. 4761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 4861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * <p>Renders a vertical grid of objects given a {@link VerticalGridPresenter} and 4961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * an {@link ObjectAdapter}. 5061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 5161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupublic class VerticalGridSupportFragment extends Fragment { 5261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private static final String TAG = "VerticalGridSupportFragment"; 5361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private static boolean DEBUG = false; 5461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 5561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private BrowseFrameLayout mBrowseFrame; 5661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private String mTitle; 5761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private Drawable mBadgeDrawable; 5861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private ObjectAdapter mAdapter; 5961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private VerticalGridPresenter mGridPresenter; 6061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private VerticalGridPresenter.ViewHolder mGridViewHolder; 6161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private OnItemSelectedListener mOnItemSelectedListener; 6261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private OnItemClickedListener mOnItemClickedListener; 6361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private OnItemViewSelectedListener mOnItemViewSelectedListener; 6461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private OnItemViewClickedListener mOnItemViewClickedListener; 6561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private View.OnClickListener mExternalOnSearchClickedListener; 6661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private int mSelectedPosition = -1; 6761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 6861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private TitleView mTitleView; 6961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private SearchOrbView.Colors mSearchAffordanceColors; 7061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private boolean mSearchAffordanceColorSet; 7161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private boolean mShowingTitle = true; 7261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 7361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu // transition related 7461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private static TransitionHelper sTransitionHelper = TransitionHelper.getInstance(); 7561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private Object mTitleUpTransition; 7661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private Object mTitleDownTransition; 7761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private Object mSceneWithTitle; 7861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private Object mSceneWithoutTitle; 7961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 8061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 8161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the badge drawable displayed in the title area. 8261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 8361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setBadgeDrawable(Drawable drawable) { 8461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (drawable != mBadgeDrawable) { 8561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mBadgeDrawable = drawable; 8661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mTitleView != null) { 8761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setBadgeDrawable(drawable); 8861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 8961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 9061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 9161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 9261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 9361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the badge drawable. 9461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 9561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public Drawable getBadgeDrawable() { 9661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mBadgeDrawable; 9761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 9861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 9961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 10061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets a title for the fragment. 10161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 10261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setTitle(String title) { 10361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitle = title; 10461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mTitleView != null) { 10561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setTitle(mTitle); 10661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 10761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 10861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 10961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 11061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the title for the fragment. 11161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 11261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public String getTitle() { 11361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mTitle; 11461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 11561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 11661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 11761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the grid presenter. 11861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 11961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setGridPresenter(VerticalGridPresenter gridPresenter) { 12061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (gridPresenter == null) { 12161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu throw new IllegalArgumentException("Grid presenter may not be null"); 12261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 12361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter = gridPresenter; 12461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.setOnItemViewSelectedListener(mRowSelectedListener); 12561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mOnItemViewClickedListener != null) { 12661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener); 12761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 12861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mOnItemClickedListener != null) { 12961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.setOnItemClickedListener(mOnItemClickedListener); 13061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 13161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 13261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 13361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 13461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the grid presenter. 13561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 13661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public VerticalGridPresenter getGridPresenter() { 13761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mGridPresenter; 13861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 13961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 14061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 14161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the object adapter for the fragment. 14261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 14361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setAdapter(ObjectAdapter adapter) { 14461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mAdapter = adapter; 14561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu updateAdapter(); 14661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 14761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 14861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 14961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the object adapter. 15061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 15161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public ObjectAdapter getAdapter() { 15261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mAdapter; 15361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 15461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 15561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu final private OnItemViewSelectedListener mRowSelectedListener = 15661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu new OnItemViewSelectedListener() { 15761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 15861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, 15961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu RowPresenter.ViewHolder rowViewHolder, Row row) { 16061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu int position = mGridViewHolder.getGridView().getSelectedPosition(); 16161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (DEBUG) Log.v(TAG, "row selected position " + position); 16261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu onRowSelected(position); 16361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mOnItemSelectedListener != null) { 16461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemSelectedListener.onItemSelected(item, row); 16561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 16661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mOnItemViewSelectedListener != null) { 16761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemViewSelectedListener.onItemSelected(itemViewHolder, item, 16861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu rowViewHolder, row); 16961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 17061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 17161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu }; 17261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 17361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 17461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets an item selection listener. 17561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * @deprecated Use {@link #setOnItemViewSelectedListener(OnItemViewSelectedListener)} 17661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 17761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setOnItemSelectedListener(OnItemSelectedListener listener) { 17861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemSelectedListener = listener; 17961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 18061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 18161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 18261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets an item selection listener. 18361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 18461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setOnItemViewSelectedListener(OnItemViewSelectedListener listener) { 18561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemViewSelectedListener = listener; 18661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 18761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 18861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private void onRowSelected(int position) { 18961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (position != mSelectedPosition) { 19061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (!mGridViewHolder.getGridView().hasPreviousViewInSameRow(position)) { 19161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu // if has no sibling in front of it, show title 19261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (!mShowingTitle) { 19361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu sTransitionHelper.runTransition(mSceneWithTitle, mTitleDownTransition); 19461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mShowingTitle = true; 19561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 19661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } else if (mShowingTitle) { 19761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu sTransitionHelper.runTransition(mSceneWithoutTitle, mTitleUpTransition); 19861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mShowingTitle = false; 19961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 20061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSelectedPosition = position; 20161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 20261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 20361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 20461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 20561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets an item clicked listener. 20661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * @deprecated Use {@link #setOnItemViewClickedListener(OnItemViewClickedListener)} 20761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 20861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setOnItemClickedListener(OnItemClickedListener listener) { 20961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemClickedListener = listener; 21061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mGridPresenter != null) { 21161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.setOnItemClickedListener(mOnItemClickedListener); 21261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 21361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 21461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 21561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 21661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the item clicked listener. 21761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * @deprecated Use {@link #getOnItemViewClickedListener()} 21861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 21961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public OnItemClickedListener getOnItemClickedListener() { 22061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mOnItemClickedListener; 22161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 22261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 22361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 22461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets an item clicked listener. 22561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 22661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setOnItemViewClickedListener(OnItemViewClickedListener listener) { 22761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mOnItemViewClickedListener = listener; 22861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mGridPresenter != null) { 22961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener); 23061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 23161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 23261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 23361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 23461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the item clicked listener. 23561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 23661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public OnItemViewClickedListener getOnItemViewClickedListener() { 23761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mOnItemViewClickedListener; 23861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 23961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 24061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 24161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets a click listener for the search affordance. 24261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 24361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * <p>The presence of a listener will change the visibility of the search 24461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * affordance in the title area. When set to non-null, the title area will 24561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * contain a call to search action. 24661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 24761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * <p>The listener's onClick method will be invoked when the user clicks on 24861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * the search action. 24961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 25061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * @param listener The listener to invoke when the search affordance is 25161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * clicked, or null to hide the search affordance. 25261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 25361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setOnSearchClickedListener(View.OnClickListener listener) { 25461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mExternalOnSearchClickedListener = listener; 25561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mTitleView != null) { 25661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setOnSearchClickedListener(listener); 25761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 26061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 26161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the {@link SearchOrbView.Colors} used to draw the search affordance. 26261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 26361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setSearchAffordanceColors(SearchOrbView.Colors colors) { 26461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSearchAffordanceColors = colors; 26561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSearchAffordanceColorSet = true; 26661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mTitleView != null) { 26761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setSearchAffordanceColors(mSearchAffordanceColors); 26861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 26961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 27061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 27161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 27261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the {@link SearchOrbView.Colors} used to draw the search affordance. 27361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 27461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public SearchOrbView.Colors getSearchAffordanceColors() { 27561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mSearchAffordanceColorSet) { 27661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mSearchAffordanceColors; 27761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 27861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mTitleView == null) { 27961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu throw new IllegalStateException("Fragment views not yet created"); 28061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 28161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mTitleView.getSearchAffordanceColors(); 28261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 28361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 28461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 28561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the color used to draw the search affordance. 28661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * A default brighter color will be set by the framework. 28761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 28861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * @param color The color to use for the search affordance. 28961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 29061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setSearchAffordanceColor(int color) { 29161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu setSearchAffordanceColors(new SearchOrbView.Colors(color)); 29261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 29361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 29461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 29561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Returns the color used to draw the search affordance. 29661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 29761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public int getSearchAffordanceColor() { 29861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return getSearchAffordanceColors().color; 29961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 30061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 30161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private final BrowseFrameLayout.OnFocusSearchListener mOnFocusSearchListener = 30261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu new BrowseFrameLayout.OnFocusSearchListener() { 30361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 30461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public View onFocusSearch(View focused, int direction) { 30561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (DEBUG) Log.v(TAG, "onFocusSearch focused " + focused + " + direction " + direction); 30661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 30761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu final View searchOrbView = mTitleView.getSearchAffordanceView(); 3084a10f1eb5c4283cfeef34cd71b84173f5ab3eefbKris Giesing final boolean isRtl = ViewCompat.getLayoutDirection(focused) == 3094a10f1eb5c4283cfeef34cd71b84173f5ab3eefbKris Giesing View.LAYOUT_DIRECTION_RTL; 3104a10f1eb5c4283cfeef34cd71b84173f5ab3eefbKris Giesing final int forward = isRtl ? View.FOCUS_LEFT : View.FOCUS_RIGHT; 31161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (focused == searchOrbView && ( 3124a10f1eb5c4283cfeef34cd71b84173f5ab3eefbKris Giesing direction == View.FOCUS_DOWN || direction == forward)) { 31361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mGridViewHolder.view; 31461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 31561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } else if (focused != searchOrbView && searchOrbView.getVisibility() == View.VISIBLE 31661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu && direction == View.FOCUS_UP) { 31761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return searchOrbView; 31861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 31961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } else { 32061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return null; 32161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 32261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 32361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu }; 32461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 32561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 32661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public View onCreateView(LayoutInflater inflater, ViewGroup container, 32761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu Bundle savedInstanceState) { 32861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu ViewGroup root = (ViewGroup) inflater.inflate(R.layout.lb_vertical_grid_fragment, 32961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu container, false); 33061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 33161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mBrowseFrame = (BrowseFrameLayout) root.findViewById(R.id.browse_frame); 33261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mBrowseFrame.setOnFocusSearchListener(mOnFocusSearchListener); 33361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 33461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView = (TitleView) root.findViewById(R.id.browse_title_group); 33561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setBadgeDrawable(mBadgeDrawable); 33661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setTitle(mTitle); 33761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mSearchAffordanceColorSet) { 33861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setSearchAffordanceColors(mSearchAffordanceColors); 33961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 34061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mExternalOnSearchClickedListener != null) { 34161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setOnSearchClickedListener(mExternalOnSearchClickedListener); 34261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 34361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 34461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSceneWithTitle = sTransitionHelper.createScene(root, new Runnable() { 34561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 34661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void run() { 34761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setVisibility(View.VISIBLE); 34861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 34961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu }); 35061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSceneWithoutTitle = sTransitionHelper.createScene(root, new Runnable() { 35161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 35261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void run() { 35361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mTitleView.setVisibility(View.INVISIBLE); 35461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 35561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu }); 3564735bfcd924fec2d694523f34fac5f8151257dc7Dake Gu Context context = getActivity(); 3574735bfcd924fec2d694523f34fac5f8151257dc7Dake Gu mTitleUpTransition = sTransitionHelper.loadTransition(context, R.transition.lb_title_out); 3584735bfcd924fec2d694523f34fac5f8151257dc7Dake Gu mTitleDownTransition = sTransitionHelper.loadTransition(context, R.transition.lb_title_in); 35961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 36061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return root; 36161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 36261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 36361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 36461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void onViewCreated(View view, Bundle savedInstanceState) { 36561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu ViewGroup gridDock = (ViewGroup) view.findViewById(R.id.browse_grid_dock); 36661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridViewHolder = mGridPresenter.onCreateViewHolder(gridDock); 36761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu gridDock.addView(mGridViewHolder.view); 36861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 36961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu updateAdapter(); 37061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 37161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 37261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 37361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void onStart() { 37461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu super.onStart(); 37561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridViewHolder.getGridView().requestFocus(); 37661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 37761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 37861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 379447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout public void onPause() { 380447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout mTitleView.enableAnimation(false); 381447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout super.onPause(); 382447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout } 383447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout 384447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout @Override 385447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout public void onResume() { 386447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout super.onResume(); 387447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout mTitleView.enableAnimation(true); 388447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout } 389447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout 390447860fd5c105dd0ccd227237ac5f18fdc4c26dcCraig Stout @Override 39161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void onDestroyView() { 39261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu super.onDestroyView(); 39361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridViewHolder = null; 39461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 39561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 39661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 39761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Sets the selected item position. 39861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 39961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setSelectedPosition(int position) { 40061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSelectedPosition = position; 40161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if(mGridViewHolder != null && mGridViewHolder.getGridView().getAdapter() != null) { 40261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridViewHolder.getGridView().setSelectedPositionSmooth(position); 40361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 40461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 40561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 40661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu private void updateAdapter() { 40761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mGridViewHolder != null) { 40861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridPresenter.onBindViewHolder(mGridViewHolder, mAdapter); 40961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mSelectedPosition != -1) { 41061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mGridViewHolder.getGridView().setSelectedPosition(mSelectedPosition); 41161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 41261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 41361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 41461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu} 415