• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Context;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.ArrayAdapter;
24 import android.widget.TextView;
25 
26 import java.util.List;
27 
28 public class ScrollArrayAdapter<T> extends ArrayAdapter<T> implements ScrollAdapter {
29 
30     private int mLayoutResource = -1;
31 
ScrollArrayAdapter(Context context, int textViewResourceId)32     public ScrollArrayAdapter(Context context, int textViewResourceId) {
33         super(context, textViewResourceId);
34     }
35 
ScrollArrayAdapter(Context context, int resource, int textViewResourceId)36     public ScrollArrayAdapter(Context context, int resource, int textViewResourceId) {
37         super(context, resource, textViewResourceId);
38         mLayoutResource = resource;
39     }
40 
ScrollArrayAdapter(Context context, int textViewResourceId, T[] objects)41     public ScrollArrayAdapter(Context context, int textViewResourceId, T[] objects) {
42         super(context, textViewResourceId, objects);
43     }
44 
ScrollArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)45     public ScrollArrayAdapter(Context context, int resource, int textViewResourceId,
46             T[] objects) {
47         super(context, resource, textViewResourceId, objects);
48         mLayoutResource = resource;
49     }
50 
ScrollArrayAdapter(Context context, int textViewResourceId, List<T> objects)51     public ScrollArrayAdapter(Context context, int textViewResourceId, List<T> objects) {
52         super(context, textViewResourceId, objects);
53     }
54 
ScrollArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)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
getScrapView(ViewGroup parent)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
viewRemoved(View view)77     public void viewRemoved(View view) {
78     }
79 
80     @Override
getExpandAdapter()81     public ScrollAdapterBase getExpandAdapter() {
82         return null;
83     }
84 }
85