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.view.KeyEvent;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.Button;
25 import android.widget.LinearLayout;
26 
27 /**
28  * An activity that helps test the scenario where a parent is
29  * GONE and one of its children has focus; the activity should get
30  * the key event.  see bug 945150.
31  */
32 public class GoneParentFocusedChild extends Activity {
33     private LinearLayout mGoneGroup;
34     private Button mButton;
35 
36     private boolean mUnhandledKeyEvent = false;
37     private LinearLayout mLayout;
38 
isUnhandledKeyEvent()39     public boolean isUnhandledKeyEvent() {
40         return mUnhandledKeyEvent;
41     }
42 
getLayout()43     public LinearLayout getLayout() {
44         return mLayout;
45     }
46 
getGoneGroup()47     public LinearLayout getGoneGroup() {
48         return mGoneGroup;
49     }
50 
getButton()51     public Button getButton() {
52         return mButton;
53     }
54 
onCreate(Bundle icicle)55     protected void onCreate(Bundle icicle) {
56         super.onCreate(icicle);
57 
58         mLayout = new LinearLayout(this);
59         mLayout.setOrientation(LinearLayout.HORIZONTAL);
60         mLayout.setLayoutParams(new ViewGroup.LayoutParams(
61                 ViewGroup.LayoutParams.MATCH_PARENT,
62                 ViewGroup.LayoutParams.MATCH_PARENT));
63 
64 
65         mGoneGroup = new LinearLayout(this);
66         mGoneGroup.setOrientation(LinearLayout.HORIZONTAL);
67         mGoneGroup.setLayoutParams(new ViewGroup.LayoutParams(
68                 ViewGroup.LayoutParams.MATCH_PARENT,
69                 ViewGroup.LayoutParams.MATCH_PARENT));
70 
71         mButton = new Button(this);
72         mButton.setLayoutParams(new LinearLayout.LayoutParams(
73                 ViewGroup.LayoutParams.WRAP_CONTENT,
74                 ViewGroup.LayoutParams.WRAP_CONTENT));
75 
76 
77         mGoneGroup.addView(mButton);
78         setContentView(mLayout);
79 
80         mGoneGroup.setVisibility(View.GONE);
81         mButton.requestFocus();
82     }
83 
onKeyUp(int keyCode, KeyEvent event)84     public boolean onKeyUp(int keyCode, KeyEvent event) {
85         mUnhandledKeyEvent = true;
86         return true;
87     }
88 }
89