* commit 'f1b995f9d049cb5c7225b3b17f09369237a83ca2': TabHost key handling corrected
This commit is contained in:
committed by
Android Git Automerger
commit
0dc70504cb
@@ -48,6 +48,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class TabHost extends FrameLayout implements ViewTreeObserver.OnTouchModeChangeListener {
|
public class TabHost extends FrameLayout implements ViewTreeObserver.OnTouchModeChangeListener {
|
||||||
|
|
||||||
|
private static final int TABWIDGET_LOCATION_LEFT = 0;
|
||||||
|
private static final int TABWIDGET_LOCATION_TOP = 1;
|
||||||
|
private static final int TABWIDGET_LOCATION_RIGHT = 2;
|
||||||
|
private static final int TABWIDGET_LOCATION_BOTTOM = 3;
|
||||||
private TabWidget mTabWidget;
|
private TabWidget mTabWidget;
|
||||||
private FrameLayout mTabContent;
|
private FrameLayout mTabContent;
|
||||||
private List<TabSpec> mTabSpecs = new ArrayList<TabSpec>(2);
|
private List<TabSpec> mTabSpecs = new ArrayList<TabSpec>(2);
|
||||||
@@ -293,22 +297,73 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
|
|||||||
return mTabContent;
|
return mTabContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the location of the TabWidget.
|
||||||
|
*
|
||||||
|
* @return The TabWidget location.
|
||||||
|
*/
|
||||||
|
private int getTabWidgetLocation() {
|
||||||
|
int location = TABWIDGET_LOCATION_TOP;
|
||||||
|
|
||||||
|
switch (mTabWidget.getOrientation()) {
|
||||||
|
case LinearLayout.VERTICAL:
|
||||||
|
location = (mTabContent.getLeft() < mTabWidget.getLeft()) ? TABWIDGET_LOCATION_RIGHT
|
||||||
|
: TABWIDGET_LOCATION_LEFT;
|
||||||
|
break;
|
||||||
|
case LinearLayout.HORIZONTAL:
|
||||||
|
default:
|
||||||
|
location = (mTabContent.getTop() < mTabWidget.getTop()) ? TABWIDGET_LOCATION_BOTTOM
|
||||||
|
: TABWIDGET_LOCATION_TOP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
final boolean handled = super.dispatchKeyEvent(event);
|
final boolean handled = super.dispatchKeyEvent(event);
|
||||||
|
|
||||||
// unhandled key ups change focus to tab indicator for embedded activities
|
// unhandled key events change focus to tab indicator for embedded
|
||||||
// when there is nothing that will take focus from default focus searching
|
// activities when there is nothing that will take focus from default
|
||||||
|
// focus searching
|
||||||
if (!handled
|
if (!handled
|
||||||
&& (event.getAction() == KeyEvent.ACTION_DOWN)
|
&& (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||||
&& (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP)
|
|
||||||
&& (mCurrentView != null)
|
&& (mCurrentView != null)
|
||||||
&& (mCurrentView.isRootNamespace())
|
&& (mCurrentView.isRootNamespace())
|
||||||
&& (mCurrentView.hasFocus())
|
&& (mCurrentView.hasFocus())) {
|
||||||
&& (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) {
|
int keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP;
|
||||||
mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus();
|
int directionShouldChangeFocus = View.FOCUS_UP;
|
||||||
playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
|
int soundEffect = SoundEffectConstants.NAVIGATION_UP;
|
||||||
return true;
|
|
||||||
|
switch (getTabWidgetLocation()) {
|
||||||
|
case TABWIDGET_LOCATION_LEFT:
|
||||||
|
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_LEFT;
|
||||||
|
directionShouldChangeFocus = View.FOCUS_LEFT;
|
||||||
|
soundEffect = SoundEffectConstants.NAVIGATION_LEFT;
|
||||||
|
break;
|
||||||
|
case TABWIDGET_LOCATION_RIGHT:
|
||||||
|
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||||
|
directionShouldChangeFocus = View.FOCUS_RIGHT;
|
||||||
|
soundEffect = SoundEffectConstants.NAVIGATION_RIGHT;
|
||||||
|
break;
|
||||||
|
case TABWIDGET_LOCATION_BOTTOM:
|
||||||
|
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_DOWN;
|
||||||
|
directionShouldChangeFocus = View.FOCUS_DOWN;
|
||||||
|
soundEffect = SoundEffectConstants.NAVIGATION_DOWN;
|
||||||
|
break;
|
||||||
|
case TABWIDGET_LOCATION_TOP:
|
||||||
|
default:
|
||||||
|
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP;
|
||||||
|
directionShouldChangeFocus = View.FOCUS_UP;
|
||||||
|
soundEffect = SoundEffectConstants.NAVIGATION_UP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (event.getKeyCode() == keyCodeShouldChangeFocus
|
||||||
|
&& mCurrentView.findFocus().focusSearch(directionShouldChangeFocus) == null) {
|
||||||
|
mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus();
|
||||||
|
playSoundEffect(soundEffect);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user