1 /* 2 * Copyright (C) 2014 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 com.android.tv.settings.widget; 18 19 import java.util.List; 20 21 import android.content.Context; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.ArrayAdapter; 26 import android.widget.TextView; 27 28 public class ScrollArrayAdapter<T> extends ArrayAdapter<T> implements ScrollAdapter { 29 30 private int mLayoutResource = -1; 31 32 public ScrollArrayAdapter(Context context, int textViewResourceId) { 33 super(context, textViewResourceId); 34 } 35 36 public ScrollArrayAdapter(Context context, int resource, int textViewResourceId) { 37 super(context, resource, textViewResourceId); 38 mLayoutResource = resource; 39 } 40 41 public ScrollArrayAdapter(Context context, int textViewResourceId, T[] objects) { 42 super(context, textViewResourceId, objects); 43 } 44 45 public ScrollArrayAdapter(Context context, int resource, int textViewResourceId, 46 T[] objects) { 47 super(context, resource, textViewResourceId, objects); 48 mLayoutResource = resource; 49 } 50 51 public ScrollArrayAdapter(Context context, int textViewResourceId, List<T> objects) { 52 super(context, textViewResourceId, objects); 53 } 54 55 public ScrollArrayAdapter(Context context, int resource, int textViewResourceId, 56 List<T> objects) { 57 super(context, resource, textViewResourceId, objects); 58 mLayoutResource = resource; 59 } 60 61 @Override 62 public View getScrapView(ViewGroup parent) { 63 if (getCount() > 0) { 64 return getView(0, null, parent); 65 } else { 66 if (mLayoutResource != -1) { 67 LayoutInflater inflater = (LayoutInflater) 68 parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 69 return inflater.inflate(mLayoutResource, parent); 70 } else { 71 return new TextView(parent.getContext()); 72 } 73 } 74 } 75 76 @Override 77 public void viewRemoved(View view) { 78 } 79 80 @Override 81 public ScrollAdapterBase getExpandAdapter() { 82 return null; 83 } 84 } 85