136225e975c22b79c14fd7a058dc7a01252738ce5John Reck/* 236225e975c22b79c14fd7a058dc7a01252738ce5John Reck * Copyright (C) 2011 The Android Open Source Project 336225e975c22b79c14fd7a058dc7a01252738ce5John Reck * 436225e975c22b79c14fd7a058dc7a01252738ce5John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 536225e975c22b79c14fd7a058dc7a01252738ce5John Reck * you may not use this file except in compliance with the License. 636225e975c22b79c14fd7a058dc7a01252738ce5John Reck * You may obtain a copy of the License at 736225e975c22b79c14fd7a058dc7a01252738ce5John Reck * 836225e975c22b79c14fd7a058dc7a01252738ce5John Reck * http://www.apache.org/licenses/LICENSE-2.0 936225e975c22b79c14fd7a058dc7a01252738ce5John Reck * 1036225e975c22b79c14fd7a058dc7a01252738ce5John Reck * Unless required by applicable law or agreed to in writing, software 1136225e975c22b79c14fd7a058dc7a01252738ce5John Reck * distributed under the License is distributed on an "AS IS" BASIS, 1236225e975c22b79c14fd7a058dc7a01252738ce5John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1336225e975c22b79c14fd7a058dc7a01252738ce5John Reck * See the License for the specific language governing permissions and 1436225e975c22b79c14fd7a058dc7a01252738ce5John Reck * limitations under the License 1536225e975c22b79c14fd7a058dc7a01252738ce5John Reck */ 1636225e975c22b79c14fd7a058dc7a01252738ce5John Reck 1736225e975c22b79c14fd7a058dc7a01252738ce5John Reckpackage com.android.browser.view; 1836225e975c22b79c14fd7a058dc7a01252738ce5John Reck 1936225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.content.Context; 2036225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.util.AttributeSet; 2136225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.view.KeyEvent; 2236225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.view.MotionEvent; 2336225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.view.View; 2436225e975c22b79c14fd7a058dc7a01252738ce5John Reckimport android.widget.FrameLayout; 2536225e975c22b79c14fd7a058dc7a01252738ce5John Reck 2636225e975c22b79c14fd7a058dc7a01252738ce5John Reckpublic class EventRedirectingFrameLayout extends FrameLayout { 2736225e975c22b79c14fd7a058dc7a01252738ce5John Reck 2836225e975c22b79c14fd7a058dc7a01252738ce5John Reck private int mTargetChild; 2936225e975c22b79c14fd7a058dc7a01252738ce5John Reck 3036225e975c22b79c14fd7a058dc7a01252738ce5John Reck public EventRedirectingFrameLayout(Context context) { 3136225e975c22b79c14fd7a058dc7a01252738ce5John Reck super(context); 3236225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 3336225e975c22b79c14fd7a058dc7a01252738ce5John Reck 3436225e975c22b79c14fd7a058dc7a01252738ce5John Reck public EventRedirectingFrameLayout(Context context, AttributeSet attrs) { 3536225e975c22b79c14fd7a058dc7a01252738ce5John Reck super(context, attrs); 3636225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 3736225e975c22b79c14fd7a058dc7a01252738ce5John Reck 3836225e975c22b79c14fd7a058dc7a01252738ce5John Reck public EventRedirectingFrameLayout( 3936225e975c22b79c14fd7a058dc7a01252738ce5John Reck Context context, AttributeSet attrs, int defStyle) { 4036225e975c22b79c14fd7a058dc7a01252738ce5John Reck super(context, attrs, defStyle); 4136225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 4236225e975c22b79c14fd7a058dc7a01252738ce5John Reck 4336225e975c22b79c14fd7a058dc7a01252738ce5John Reck public void setTargetChild(int index) { 4436225e975c22b79c14fd7a058dc7a01252738ce5John Reck if (index >= 0 && index < getChildCount()) { 4536225e975c22b79c14fd7a058dc7a01252738ce5John Reck mTargetChild = index; 4636225e975c22b79c14fd7a058dc7a01252738ce5John Reck getChildAt(mTargetChild).requestFocus(); 4736225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 4836225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 4936225e975c22b79c14fd7a058dc7a01252738ce5John Reck 5036225e975c22b79c14fd7a058dc7a01252738ce5John Reck @Override 5136225e975c22b79c14fd7a058dc7a01252738ce5John Reck public boolean dispatchTouchEvent(MotionEvent ev) { 5236225e975c22b79c14fd7a058dc7a01252738ce5John Reck View child = getChildAt(mTargetChild); 5336225e975c22b79c14fd7a058dc7a01252738ce5John Reck if (child != null) 5436225e975c22b79c14fd7a058dc7a01252738ce5John Reck return child.dispatchTouchEvent(ev); 5536225e975c22b79c14fd7a058dc7a01252738ce5John Reck return false; 5636225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 5736225e975c22b79c14fd7a058dc7a01252738ce5John Reck 5836225e975c22b79c14fd7a058dc7a01252738ce5John Reck @Override 5936225e975c22b79c14fd7a058dc7a01252738ce5John Reck public boolean dispatchKeyEvent(KeyEvent event) { 6036225e975c22b79c14fd7a058dc7a01252738ce5John Reck View child = getChildAt(mTargetChild); 6136225e975c22b79c14fd7a058dc7a01252738ce5John Reck if (child != null) 6236225e975c22b79c14fd7a058dc7a01252738ce5John Reck return child.dispatchKeyEvent(event); 6336225e975c22b79c14fd7a058dc7a01252738ce5John Reck return false; 6436225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 6536225e975c22b79c14fd7a058dc7a01252738ce5John Reck 6636225e975c22b79c14fd7a058dc7a01252738ce5John Reck @Override 6736225e975c22b79c14fd7a058dc7a01252738ce5John Reck public boolean dispatchKeyEventPreIme(KeyEvent event) { 6836225e975c22b79c14fd7a058dc7a01252738ce5John Reck View child = getChildAt(mTargetChild); 6936225e975c22b79c14fd7a058dc7a01252738ce5John Reck if (child != null) 7036225e975c22b79c14fd7a058dc7a01252738ce5John Reck return child.dispatchKeyEventPreIme(event); 7136225e975c22b79c14fd7a058dc7a01252738ce5John Reck return false; 7236225e975c22b79c14fd7a058dc7a01252738ce5John Reck } 7336225e975c22b79c14fd7a058dc7a01252738ce5John Reck 7436225e975c22b79c14fd7a058dc7a01252738ce5John Reck} 75