diff --git a/src/com/android/launcher3/AccessibleTabView.java b/src/com/android/launcher3/AccessibleTabView.java deleted file mode 100644 index 90a78656ed..0000000000 --- a/src/com/android/launcher3/AccessibleTabView.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.KeyEvent; -import android.widget.TextView; - -/** - * We use a custom tab view to process our own focus traversals. - */ -public class AccessibleTabView extends TextView { - public AccessibleTabView(Context context) { - super(context); - } - - public AccessibleTabView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AccessibleTabView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - return FocusHelper.handleTabKeyEvent(this, keyCode, event) - || super.onKeyDown(keyCode, event); - } - - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - return FocusHelper.handleTabKeyEvent(this, keyCode, event) - || super.onKeyUp(keyCode, event); - } -} diff --git a/src/com/android/launcher3/FocusHelper.java b/src/com/android/launcher3/FocusHelper.java index d529b39016..e607047188 100644 --- a/src/com/android/launcher3/FocusHelper.java +++ b/src/com/android/launcher3/FocusHelper.java @@ -17,12 +17,10 @@ package com.android.launcher3; import android.content.res.Configuration; -import android.util.Log; import android.view.KeyEvent; import android.view.SoundEffectConstants; import android.view.View; import android.view.ViewGroup; -import android.view.ViewParent; import android.widget.ScrollView; import java.util.ArrayList; @@ -58,16 +56,6 @@ class HotseatIconKeyEventListener implements View.OnKeyListener { } public class FocusHelper { - /** - * Private helper to get the parent TabHost in the view hiearchy. - */ - private static AppsCustomizeTabHost findTabHostParent(View v) { - ViewParent p = v.getParent(); - while (p != null && !(p instanceof AppsCustomizeTabHost)) { - p = p.getParent(); - } - return (AppsCustomizeTabHost) p; - } /** * Returns the Viewgroup containing page contents for the page at the index specified. @@ -81,148 +69,6 @@ public class FocusHelper { return page; } - /** - * Handles key events in a PageViewExtendedLayout containing PagedViewWidgets. - */ - static boolean handlePagedViewGridLayoutWidgetKeyEvent(PagedViewWidget w, int keyCode, - KeyEvent e) { - - final PagedViewGridLayout parent = (PagedViewGridLayout) w.getParent(); - final PagedView container = (PagedView) parent.getParent(); - final int widgetIndex = parent.indexOfChild(w); - final int widgetCount = parent.getChildCount(); - final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parent)); - final int pageCount = container.getChildCount(); - final int cellCountX = parent.getCellCountX(); - final int cellCountY = parent.getCellCountY(); - final int x = widgetIndex % cellCountX; - final int y = widgetIndex / cellCountX; - - final int action = e.getAction(); - final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP); - ViewGroup newParent = null; - // Now that we load items in the bg asynchronously, we can't just focus - // child siblings willy-nilly - View child = null; - boolean wasHandled = false; - switch (keyCode) { - case KeyEvent.KEYCODE_DPAD_LEFT: - if (handleKeyEvent) { - // Select the previous widget or the last widget on the previous page - if (widgetIndex > 0) { - parent.getChildAt(widgetIndex - 1).requestFocus(); - } else { - if (pageIndex > 0) { - newParent = getAppsCustomizePage(container, pageIndex - 1); - if (newParent != null) { - child = newParent.getChildAt(newParent.getChildCount() - 1); - if (child != null) child.requestFocus(); - } - } - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_RIGHT: - if (handleKeyEvent) { - // Select the next widget or the first widget on the next page - if (widgetIndex < (widgetCount - 1)) { - parent.getChildAt(widgetIndex + 1).requestFocus(); - } else { - if (pageIndex < (pageCount - 1)) { - newParent = getAppsCustomizePage(container, pageIndex + 1); - if (newParent != null) { - child = newParent.getChildAt(0); - if (child != null) child.requestFocus(); - } - } - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_UP: - if (handleKeyEvent) { - // Select the closest icon in the previous row, otherwise select the tab bar - if (y > 0) { - int newWidgetIndex = ((y - 1) * cellCountX) + x; - child = parent.getChildAt(newWidgetIndex); - if (child != null) child.requestFocus(); - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_DOWN: - if (handleKeyEvent) { - // Select the closest icon in the previous row, otherwise do nothing - if (y < (cellCountY - 1)) { - int newWidgetIndex = Math.min(widgetCount - 1, ((y + 1) * cellCountX) + x); - child = parent.getChildAt(newWidgetIndex); - if (child != null) child.requestFocus(); - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_ENTER: - case KeyEvent.KEYCODE_DPAD_CENTER: - if (handleKeyEvent) { - // Simulate a click on the widget - View.OnClickListener clickListener = (View.OnClickListener) container; - clickListener.onClick(w); - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_PAGE_UP: - if (handleKeyEvent) { - // Select the first item on the previous page, or the first item on this page - // if there is no previous page - if (pageIndex > 0) { - newParent = getAppsCustomizePage(container, pageIndex - 1); - if (newParent != null) { - child = newParent.getChildAt(0); - } - } else { - child = parent.getChildAt(0); - } - if (child != null) child.requestFocus(); - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_PAGE_DOWN: - if (handleKeyEvent) { - // Select the first item on the next page, or the last item on this page - // if there is no next page - if (pageIndex < (pageCount - 1)) { - newParent = getAppsCustomizePage(container, pageIndex + 1); - if (newParent != null) { - child = newParent.getChildAt(0); - } - } else { - child = parent.getChildAt(widgetCount - 1); - } - if (child != null) child.requestFocus(); - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_MOVE_HOME: - if (handleKeyEvent) { - // Select the first item on this page - child = parent.getChildAt(0); - if (child != null) child.requestFocus(); - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_MOVE_END: - if (handleKeyEvent) { - // Select the last item on this page - parent.getChildAt(widgetCount - 1).requestFocus(); - } - wasHandled = true; - break; - default: break; - } - return wasHandled; - } - /** * Handles key events in a PageViewCellLayout containing PagedViewIcons. */ @@ -393,60 +239,6 @@ public class FocusHelper { return wasHandled; } - /** - * Handles key events in the tab widget. - */ - static boolean handleTabKeyEvent(AccessibleTabView v, int keyCode, KeyEvent e) { - if (!LauncherAppState.getInstance().isScreenLarge()) return false; - - final FocusOnlyTabWidget parent = (FocusOnlyTabWidget) v.getParent(); - final AppsCustomizeTabHost tabHost = findTabHostParent(parent); - final ViewGroup contents = tabHost.getContent(); - final int tabCount = parent.getTabCount(); - final int tabIndex = parent.getChildTabIndex(v); - - final int action = e.getAction(); - final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP); - boolean wasHandled = false; - switch (keyCode) { - case KeyEvent.KEYCODE_DPAD_LEFT: - if (handleKeyEvent) { - // Select the previous tab - if (tabIndex > 0) { - parent.getChildTabViewAt(tabIndex - 1).requestFocus(); - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_RIGHT: - if (handleKeyEvent) { - // Select the next tab, or if the last tab has a focus right id, select that - if (tabIndex < (tabCount - 1)) { - parent.getChildTabViewAt(tabIndex + 1).requestFocus(); - } else { - if (v.getNextFocusRightId() != View.NO_ID) { - tabHost.findViewById(v.getNextFocusRightId()).requestFocus(); - } - } - } - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_UP: - // Do nothing - wasHandled = true; - break; - case KeyEvent.KEYCODE_DPAD_DOWN: - if (handleKeyEvent) { - // Select the content view - contents.requestFocus(); - } - wasHandled = true; - break; - default: break; - } - return wasHandled; - } - /** * Handles key events in the workspace hotseat (bottom of the screen). */