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.os.Bundle;
21import android.view.KeyEvent;
22import android.view.View;
23import android.view.ViewGroup;
24import android.widget.Button;
25import 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 */
32public class GoneParentFocusedChild extends Activity {
33    private LinearLayout mGoneGroup;
34    private Button mButton;
35
36    private boolean mUnhandledKeyEvent = false;
37    private LinearLayout mLayout;
38
39    public boolean isUnhandledKeyEvent() {
40        return mUnhandledKeyEvent;
41    }
42
43    public LinearLayout getLayout() {
44        return mLayout;
45    }
46
47    public LinearLayout getGoneGroup() {
48        return mGoneGroup;
49    }
50
51    public Button getButton() {
52        return mButton;
53    }
54
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
84    public boolean onKeyUp(int keyCode, KeyEvent event) {
85        mUnhandledKeyEvent = true;
86        return true;
87    }
88}
89