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.focus;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.util.InternalSelectionView;
22 import android.view.ViewGroup;
23 import android.widget.LinearLayout;
24 
25 /**
26  * {@link android.view.FocusFinder#findNextFocus(android.view.ViewGroup, android.view.View, int)}
27  * and
28  * {@link android.view.View#requestFocus(int, android.graphics.Rect)}
29  * work together to give a newly focused item a hint about the most interesting
30  * rectangle of the previously focused view.  The view taking focus can use this
31  * to set an internal selection more appropriate using this rect.
32  *
33  * This Activity excercises that behavior using three adjacent {@link android.util.InternalSelectionView}
34  * that report interesting rects when giving up focus, and use interesting rects
35  * when taking focus to best select the internal row to show as selected.
36  */
37 public class AdjacentVerticalRectLists extends Activity {
38 
39     private LinearLayout mLayout;
40     private InternalSelectionView mLeftColumn;
41     private InternalSelectionView mMiddleColumn;
42     private InternalSelectionView mRightColumn;
43 
44 
getLayout()45     public LinearLayout getLayout() {
46         return mLayout;
47     }
48 
getLeftColumn()49     public InternalSelectionView getLeftColumn() {
50         return mLeftColumn;
51     }
52 
getMiddleColumn()53     public InternalSelectionView getMiddleColumn() {
54         return mMiddleColumn;
55     }
56 
getRightColumn()57     public InternalSelectionView getRightColumn() {
58         return mRightColumn;
59     }
60 
61     @Override
onCreate(Bundle icicle)62     protected void onCreate(Bundle icicle) {
63         super.onCreate(icicle);
64 
65         mLayout = new LinearLayout(this);
66         mLayout.setOrientation(LinearLayout.HORIZONTAL);
67         mLayout.setLayoutParams(new ViewGroup.LayoutParams(
68                 ViewGroup.LayoutParams.MATCH_PARENT,
69                 ViewGroup.LayoutParams.MATCH_PARENT));
70 
71         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,
72                 ViewGroup.LayoutParams.MATCH_PARENT, 1);
73 
74         mLeftColumn = new InternalSelectionView(this, 5, "left column");
75         mLeftColumn.setLayoutParams(params);
76         mLeftColumn.setPadding(10, 10, 10, 10);
77         mLayout.addView(mLeftColumn);
78 
79         mMiddleColumn = new InternalSelectionView(this, 5, "middle column");
80         mMiddleColumn.setLayoutParams(params);
81         mMiddleColumn.setPadding(10, 10, 10, 10);
82         mLayout.addView(mMiddleColumn);
83 
84         mRightColumn = new InternalSelectionView(this, 5, "right column");
85         mRightColumn.setLayoutParams(params);
86         mRightColumn.setPadding(10, 10, 10, 10);
87         mLayout.addView(mRightColumn);
88 
89         setContentView(mLayout);
90     }
91 
92 
93 }
94