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.cts.jank.leanback.presenter; 18 19 import android.graphics.Color; 20 import android.support.v17.leanback.widget.Presenter; 21 import android.view.Gravity; 22 import android.view.ViewGroup; 23 import android.widget.TextView; 24 25 import android.cts.jank.leanback.R; 26 import android.cts.jank.leanback.ui.MainFragment; 27 28 public class GridItemPresenter extends Presenter { 29 private static int GRID_ITEM_WIDTH = 200; 30 private static int GRID_ITEM_HEIGHT = 200; 31 32 private MainFragment mainFragment; 33 34 public GridItemPresenter(MainFragment mainFragment) { 35 this.mainFragment = mainFragment; 36 } 37 38 @Override 39 public ViewHolder onCreateViewHolder(ViewGroup parent) { 40 TextView view = new TextView(parent.getContext()); 41 view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT)); 42 view.setFocusable(true); 43 view.setFocusableInTouchMode(true); 44 view.setBackgroundColor( 45 mainFragment.getResources().getColor(R.color.default_background, null)); 46 view.setTextColor(Color.WHITE); 47 view.setGravity(Gravity.CENTER); 48 return new ViewHolder(view); 49 } 50 51 @Override 52 public void onBindViewHolder(ViewHolder viewHolder, Object item) { 53 ((TextView) viewHolder.view).setText((String) item); 54 } 55 56 @Override 57 public void onUnbindViewHolder(ViewHolder viewHolder) { 58 } 59 } 60