2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.widget.focus;
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;
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.
32 public class GoneParentFocusedChild extends Activity {
33 private LinearLayout mGoneGroup;
34 private Button mButton;
36 private boolean mUnhandledKeyEvent = false;
37 private LinearLayout mLayout;
39 public boolean isUnhandledKeyEvent() {
40 return mUnhandledKeyEvent;
43 public LinearLayout getLayout() {
47 public LinearLayout getGoneGroup() {
51 public Button getButton() {
55 protected void onCreate(Bundle icicle) {
56 super.onCreate(icicle);
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));
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));
71 mButton = new Button(this);
72 mButton.setLayoutParams(new LinearLayout.LayoutParams(
73 ViewGroup.LayoutParams.WRAP_CONTENT,
74 ViewGroup.LayoutParams.WRAP_CONTENT));
77 mGoneGroup.addView(mButton);
78 setContentView(mLayout);
80 mGoneGroup.setVisibility(View.GONE);
81 mButton.requestFocus();
84 public boolean onKeyUp(int keyCode, KeyEvent event) {
85 mUnhandledKeyEvent = true;