1 /*
2  * Copyright (C) 2007 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.widget.listview;
18 
19 import android.util.ListItemFactory;
20 import android.util.ListScenario;
21 import android.view.View;
22 import android.view.ViewGroup;
23 
24 import com.google.android.collect.Sets;
25 
26 import java.util.Set;
27 
28 /**
29  * List that interleaves focusable items.
30  */
31 public class ListInterleaveFocusables extends ListScenario {
32 
33     private Set<Integer> mFocusablePositions = Sets.newHashSet(1, 3, 6);
34 
35     @Override
init(Params params)36     protected void init(Params params) {
37         params.setNumItems(7)
38                 .setItemScreenSizeFactor(1.0 / 8)
39                 .setItemsFocusable(true)
40                 .setMustFillScreen(false);
41     }
42 
43     @Override
createView(int position, ViewGroup parent, int desiredHeight)44     protected View createView(int position, ViewGroup parent, int desiredHeight) {
45         if (mFocusablePositions.contains(position)) {
46             return ListItemFactory.button(
47                     position, parent.getContext(), getValueAtPosition(position), desiredHeight);
48         } else {
49             return super.createView(position, parent, desiredHeight);
50         }
51     }
52 
53     @Override
getItemViewType(int position)54     public int getItemViewType(int position) {
55         return mFocusablePositions.contains(position) ? 0 : 1;
56     }
57 
58     @Override
getViewTypeCount()59     public int getViewTypeCount() {
60         return 2;
61     }
62 
63 
64 }
65