• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.view.cts;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.widget.LinearLayout;
22 import android.widget.Button;
23 import android.widget.TextView;
24 import android.view.Gravity;
25 import android.view.ViewGroup;
26 import android.content.Context;
27 
28 /**
29  * Holds a few buttons of various sizes and horizontal placements in a vertical
30  * layout to excercise some core focus searching.
31  */
32 public class FocusFinderStubActivity extends Activity {
33 
34     private LinearLayout mLayout;
35 
36     private Button mTopWide;
37     private Button mMidSkinny1Left;
38     private Button mBottomWide;
39 
40     private Button mMidSkinny2Right;
41     public static final String mTopWideLable = "top wide";
42     public static final String mBottomWideLable = "bottom wide";
43     public static final String mMidSkinny1LeftLable = "mid skinny 1(L)";
44     public static final String mMidSkinny2RightLable = "mid skinny 2(R)";
45 
getLayout()46     public LinearLayout getLayout() {
47         return mLayout;
48     }
49 
getTopWide()50     public Button getTopWide() {
51         return mTopWide;
52     }
53 
getMidSkinny1Left()54     public Button getMidSkinny1Left() {
55         return mMidSkinny1Left;
56     }
57 
getMidSkinny2Right()58     public Button getMidSkinny2Right() {
59         return mMidSkinny2Right;
60     }
61 
getBottomWide()62     public Button getBottomWide() {
63         return mBottomWide;
64     }
65 
66     @Override
onCreate(Bundle icicle)67     protected void onCreate(Bundle icicle) {
68         super.onCreate(icicle);
69 
70         mLayout = new LinearLayout(this);
71         mLayout.setOrientation(LinearLayout.VERTICAL);
72         mLayout.setHorizontalGravity(Gravity.LEFT);
73         mLayout.setLayoutParams(new ViewGroup.LayoutParams(
74                 ViewGroup.LayoutParams.FILL_PARENT,
75                 ViewGroup.LayoutParams.FILL_PARENT));
76 
77         mTopWide = makeWide(mTopWideLable);
78         mLayout.addView(mTopWide);
79 
80         mMidSkinny1Left = addSkinny(mLayout, mMidSkinny1LeftLable, false);
81 
82         mMidSkinny2Right = addSkinny(mLayout,mMidSkinny2RightLable, true);
83 
84         mBottomWide = makeWide(mBottomWideLable);
85         mLayout.addView(mBottomWide);
86 
87         setContentView(mLayout);
88     }
89 
90     // just to get toString non-sucky
91     private static class MyButton extends Button {
92 
MyButton(Context context)93         public MyButton(Context context) {
94             super(context);
95         }
96 
97         @Override
toString()98         public String toString() {
99             return getText().toString();
100         }
101     }
102 
makeWide(String label)103     private Button makeWide(String label) {
104         Button button = new MyButton(this);
105         button.setText(label);
106         button.setLayoutParams(new LinearLayout.LayoutParams(
107                 ViewGroup.LayoutParams.FILL_PARENT,
108                 ViewGroup.LayoutParams.WRAP_CONTENT));
109         return button;
110     }
111 
112     /**
113      * Add a skinny button that takes up just less than half of the screen
114      * horizontally.
115      *
116      * @param root
117      *            The layout to add the button to.
118      * @param label
119      *            The label of the button.
120      * @param atRight
121      *            Which side to put the button on.
122      * @return The newly created button.
123      */
addSkinny(LinearLayout root, String label, boolean atRight)124     private Button addSkinny(LinearLayout root, String label, boolean atRight) {
125         Button button = new MyButton(this);
126         button.setText(label);
127         button.setLayoutParams(new LinearLayout.LayoutParams(0, // width
128                 ViewGroup.LayoutParams.WRAP_CONTENT, 480));
129 
130         TextView filler = new TextView(this);
131         filler.setText("filler");
132         filler.setLayoutParams(new LinearLayout.LayoutParams(0, // width
133                 ViewGroup.LayoutParams.WRAP_CONTENT, 520));
134 
135         LinearLayout ll = new LinearLayout(this);
136         ll.setOrientation(LinearLayout.HORIZONTAL);
137         ll.setLayoutParams(new LinearLayout.LayoutParams(
138                 ViewGroup.LayoutParams.FILL_PARENT,
139                 ViewGroup.LayoutParams.WRAP_CONTENT));
140 
141         if (atRight) {
142             ll.addView(filler);
143             ll.addView(button);
144             root.addView(ll);
145         } else {
146             ll.addView(button);
147             ll.addView(filler);
148             root.addView(ll);
149         }
150         return button;
151     }
152 
153 }
154 
155