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