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