1/*
2 * Copyright (C) 2008 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
17package android.widget.listview;
18
19import android.util.ListItemFactory;
20import static android.util.ListItemFactory.Slot;
21import android.util.ListScenario;
22
23import android.content.Context;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.Button;
27
28public class ListHorizontalFocusWithinItemWins extends ListScenario {
29
30    @Override
31    protected void init(Params params) {
32        params.setItemsFocusable(true)
33                .setNumItems(2)
34                .setItemScreenSizeFactor(0.2)
35                .setMustFillScreen(false);
36    }
37
38    public Button getTopLeftButton() {
39        return (Button) ((ViewGroup) getListView().getChildAt(0)).getChildAt(0);
40    }
41
42    public Button getTopRightButton() {
43        return (Button) ((ViewGroup) getListView().getChildAt(0)).getChildAt(2);
44    }
45
46    public Button getBottomMiddleButton() {
47        return (Button) ((ViewGroup) getListView().getChildAt(1)).getChildAt(1);
48    }
49
50    @Override
51    protected View createView(int position, ViewGroup parent,
52            int desiredHeight) {
53        final Context context = parent.getContext();
54        if (position == 0) {
55            return ListItemFactory.horizontalButtonSlots(
56                    context, desiredHeight, Slot.Left, Slot.Right);
57        } else if (position == 1) {
58            return ListItemFactory.horizontalButtonSlots(
59                    context, desiredHeight, Slot.Middle);
60        } else {
61            throw new IllegalArgumentException("expecting position 0 or 1");
62        }
63    }
64}
65