• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.leanbackjank.app.presenter;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import androidx.leanback.widget.HeaderItem;
22 import androidx.leanback.widget.ListRow;
23 import androidx.leanback.widget.Presenter;
24 import androidx.leanback.widget.RowHeaderPresenter;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ImageView;
29 import android.widget.TextView;
30 
31 import android.leanbackjank.app.R;
32 
33 public class IconHeaderItemPresenter extends RowHeaderPresenter {
34     private float mUnselectedAlpha;
35 
36     @Override
onCreateViewHolder(ViewGroup viewGroup)37     public ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
38         mUnselectedAlpha = viewGroup.getResources()
39                 .getFraction(R.fraction.lb_browse_header_unselect_alpha, 1, 1);
40         LayoutInflater inflater = (LayoutInflater) viewGroup.getContext()
41                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
42 
43         View view = inflater.inflate(R.layout.icon_header_item, null);
44 
45         return new ViewHolder(view);
46     }
47 
48     @Override
onBindViewHolder(Presenter.ViewHolder viewHolder, Object o)49     public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
50         HeaderItem headerItem = ((ListRow) o).getHeaderItem();
51         View rootView = viewHolder.view;
52 
53         ImageView iconView = (ImageView) rootView.findViewById(R.id.header_icon);
54         Drawable icon = rootView.getResources().getDrawable(R.drawable.android_header, null);
55         iconView.setImageDrawable(icon);
56 
57         TextView label = (TextView) rootView.findViewById(R.id.header_label);
58         label.setText(headerItem.getName());
59     }
60 
61     @Override
onUnbindViewHolder(Presenter.ViewHolder viewHolder)62     public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
63     }
64 
65     // TODO: TEMP - remove me when leanback onCreateViewHolder no longer sets the mUnselectAlpha,AND
66     // also assumes the xml inflation will return a RowHeaderView
67     @Override
onSelectLevelChanged(RowHeaderPresenter.ViewHolder holder)68     protected void onSelectLevelChanged(RowHeaderPresenter.ViewHolder holder) {
69         // this is a temporary fix
70         holder.view.setAlpha(mUnselectedAlpha + holder.getSelectLevel() *
71                 (1.0f - mUnselectedAlpha));
72     }
73 }
74