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
17package android.widget.focus;
18
19import android.app.Activity;
20import android.widget.LinearLayout;
21import android.widget.Button;
22import android.widget.TextView;
23import android.os.Bundle;
24import android.view.ViewGroup;
25import android.content.Context;
26
27public class HorizontalFocusSearch extends Activity {
28
29    private LinearLayout mLayout;
30
31    private Button mLeftTall;
32    private Button mMidShort1Top;
33    private Button mMidShort2Bottom;
34    private Button mRightTall;
35
36
37    public LinearLayout getLayout() {
38        return mLayout;
39    }
40
41    public Button getLeftTall() {
42        return mLeftTall;
43    }
44
45    public Button getMidShort1Top() {
46        return mMidShort1Top;
47    }
48
49    public Button getMidShort2Bottom() {
50        return mMidShort2Bottom;
51    }
52
53    public Button getRightTall() {
54        return mRightTall;
55    }
56
57    @Override
58    protected void onCreate(Bundle icicle) {
59        super.onCreate(icicle);
60
61        mLayout = new LinearLayout(this);
62        mLayout.setOrientation(LinearLayout.HORIZONTAL);
63        mLayout.setLayoutParams(new ViewGroup.LayoutParams(
64                ViewGroup.LayoutParams.MATCH_PARENT,
65                ViewGroup.LayoutParams.MATCH_PARENT));
66
67        mLeftTall = makeTall("left tall");
68        mLayout.addView(mLeftTall);
69
70        mMidShort1Top = addShort(mLayout, "mid(1) top", false);
71        mMidShort2Bottom = addShort(mLayout, "mid(2) bottom", true);
72
73        mRightTall = makeTall("right tall");
74        mLayout.addView(mRightTall);
75
76        setContentView(mLayout);
77    }
78
79    // just to get toString non-sucky
80    private static class MyButton extends Button {
81
82        public MyButton(Context context) {
83            super(context);
84        }
85
86
87        @Override
88        public String toString() {
89            return getText().toString();
90        }
91    }
92
93    private Button makeTall(String label) {
94        Button button = new MyButton(this);
95        button.setText(label);
96        button.setLayoutParams(new LinearLayout.LayoutParams(
97                ViewGroup.LayoutParams.WRAP_CONTENT,
98                ViewGroup.LayoutParams.MATCH_PARENT));
99        return button;
100    }
101
102    private Button addShort(LinearLayout root, String label, boolean atBottom) {
103        Button button = new MyButton(this);
104        button.setText(label);
105        button.setLayoutParams(new LinearLayout.LayoutParams(
106                ViewGroup.LayoutParams.WRAP_CONTENT,
107                0, // height
108                490));
109
110        TextView filler = new TextView(this);
111        filler.setText("filler");
112        filler.setLayoutParams(new LinearLayout.LayoutParams(
113                ViewGroup.LayoutParams.WRAP_CONTENT,
114                0, // height
115                510));
116
117        LinearLayout ll = new LinearLayout(this);
118        ll.setOrientation(LinearLayout.VERTICAL);
119        ll.setLayoutParams(new LinearLayout.LayoutParams(
120            ViewGroup.LayoutParams.WRAP_CONTENT,
121            ViewGroup.LayoutParams.MATCH_PARENT));
122
123        if (atBottom) {
124            ll.addView(filler);
125            ll.addView(button);
126            root.addView(ll);
127        } else {
128            ll.addView(button);
129            ll.addView(filler);
130            root.addView(ll);
131        }
132        return button;
133    }
134}
135