1 /* 2 * Copyright (C) 2011 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 com.android.browser.view; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.KeyEvent; 22 import android.view.MotionEvent; 23 import android.view.View; 24 import android.widget.FrameLayout; 25 26 public class EventRedirectingFrameLayout extends FrameLayout { 27 28 private int mTargetChild; 29 EventRedirectingFrameLayout(Context context)30 public EventRedirectingFrameLayout(Context context) { 31 super(context); 32 } 33 EventRedirectingFrameLayout(Context context, AttributeSet attrs)34 public EventRedirectingFrameLayout(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 } 37 EventRedirectingFrameLayout( Context context, AttributeSet attrs, int defStyle)38 public EventRedirectingFrameLayout( 39 Context context, AttributeSet attrs, int defStyle) { 40 super(context, attrs, defStyle); 41 } 42 setTargetChild(int index)43 public void setTargetChild(int index) { 44 if (index >= 0 && index < getChildCount()) { 45 mTargetChild = index; 46 getChildAt(mTargetChild).requestFocus(); 47 } 48 } 49 50 @Override dispatchTouchEvent(MotionEvent ev)51 public boolean dispatchTouchEvent(MotionEvent ev) { 52 View child = getChildAt(mTargetChild); 53 if (child != null) 54 return child.dispatchTouchEvent(ev); 55 return false; 56 } 57 58 @Override dispatchKeyEvent(KeyEvent event)59 public boolean dispatchKeyEvent(KeyEvent event) { 60 View child = getChildAt(mTargetChild); 61 if (child != null) 62 return child.dispatchKeyEvent(event); 63 return false; 64 } 65 66 @Override dispatchKeyEventPreIme(KeyEvent event)67 public boolean dispatchKeyEventPreIme(KeyEvent event) { 68 View child = getChildAt(mTargetChild); 69 if (child != null) 70 return child.dispatchKeyEventPreIme(event); 71 return false; 72 } 73 74 } 75