Search in sources :

Example 61 with TabHost

use of android.widget.TabHost in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class EmojiPalettesView method addTab.

private void addTab(final TabHost host, final int categoryId) {
    final String tabId = EmojiCategory.getCategoryName(categoryId, 0);
    final TabHost.TabSpec tspec = host.newTabSpec(tabId);
    tspec.setContent(R.id.emoji_keyboard_dummy);
    final ImageView iconView = (ImageView) LayoutInflater.from(getContext()).inflate(R.layout.emoji_keyboard_tab_icon, null);
    // TODO: Replace background color with its own setting rather than using the
    // category page indicator background as a workaround.
    iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
    iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
    iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
    tspec.setIndicator(iconView);
    host.addTab(tspec);
}
Also used : TabHost(android.widget.TabHost) ImageView(android.widget.ImageView)

Example 62 with TabHost

use of android.widget.TabHost in project Fairphone by Kwamecorp.

the class FocusHelper method handlePagedViewGridLayoutWidgetKeyEvent.

/**
 * 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 TabHost tabHost = findTabHostParent(container);
    final TabWidget tabs = tabHost.getTabWidget();
    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();
                } else {
                    tabs.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) {
                // 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) {
                // 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;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) TabWidget(android.widget.TabWidget) View(android.view.View)

Example 63 with TabHost

use of android.widget.TabHost in project Fairphone by Kwamecorp.

the class FocusHelper method handleTabKeyEvent.

/**
 * Handles key events in the tab widget.
 */
static boolean handleTabKeyEvent(AccessibleTabView v, int keyCode, KeyEvent e) {
    if (!LauncherApplication.isScreenLarge())
        return false;
    final FocusOnlyTabWidget parent = (FocusOnlyTabWidget) v.getParent();
    final TabHost tabHost = findTabHostParent(parent);
    final ViewGroup contents = tabHost.getTabContentView();
    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;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup)

Example 64 with TabHost

use of android.widget.TabHost in project Fairphone by Kwamecorp.

the class FocusHelper method handleAppsCustomizeTabKeyEvent.

/**
 * Handles key events in a AppsCustomize tab between the last tab view and the shop button.
 */
static boolean handleAppsCustomizeTabKeyEvent(View v, int keyCode, KeyEvent e) {
    final TabHost tabHost = findTabHostParent(v);
    final ViewGroup contents = tabHost.getTabContentView();
    final View shop = tabHost.findViewById(R.id.market_button);
    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (handleKeyEvent) {
                // Select the shop button if we aren't on it
                if (v != shop) {
                    shop.requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (handleKeyEvent) {
                // Select the content view (down is handled by the tab key handler otherwise)
                if (v == shop) {
                    contents.requestFocus();
                    wasHandled = true;
                }
            }
            break;
        default:
            break;
    }
    return wasHandled;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 65 with TabHost

use of android.widget.TabHost in project Fairphone by Kwamecorp.

the class FocusHelper method handleAppsCustomizeKeyEvent.

/**
 * Handles key events in a PageViewCellLayout containing PagedViewIcons.
 */
static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
    ViewGroup parentLayout;
    ViewGroup itemContainer;
    int countX;
    int countY;
    if (v.getParent() instanceof PagedViewCellLayoutChildren) {
        itemContainer = (ViewGroup) v.getParent();
        parentLayout = (ViewGroup) itemContainer.getParent();
        countX = ((PagedViewCellLayout) parentLayout).getCellCountX();
        countY = ((PagedViewCellLayout) parentLayout).getCellCountY();
    } else {
        itemContainer = parentLayout = (ViewGroup) v.getParent();
        countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
        countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
    }
    // Note we have an extra parent because of the
    // PagedViewCellLayout/PagedViewCellLayoutChildren relationship
    final PagedView container = (PagedView) parentLayout.getParent();
    final TabHost tabHost = findTabHostParent(container);
    final TabWidget tabs = tabHost.getTabWidget();
    final int iconIndex = itemContainer.indexOfChild(v);
    final int itemCount = itemContainer.getChildCount();
    final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parentLayout));
    final int pageCount = container.getChildCount();
    final int x = iconIndex % countX;
    final int y = iconIndex / countX;
    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    ViewGroup newParent = null;
    // Side pages do not always load synchronously, so check before focusing child siblings
    // willy-nilly
    View child = null;
    boolean wasHandled = false;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (handleKeyEvent) {
                // Select the previous icon or the last icon on the previous page
                if (iconIndex > 0) {
                    itemContainer.getChildAt(iconIndex - 1).requestFocus();
                } else {
                    if (pageIndex > 0) {
                        newParent = getAppsCustomizePage(container, pageIndex - 1);
                        if (newParent != null) {
                            container.snapToPage(pageIndex - 1);
                            child = newParent.getChildAt(newParent.getChildCount() - 1);
                            if (child != null)
                                child.requestFocus();
                        }
                    }
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (handleKeyEvent) {
                // Select the next icon or the first icon on the next page
                if (iconIndex < (itemCount - 1)) {
                    itemContainer.getChildAt(iconIndex + 1).requestFocus();
                } else {
                    if (pageIndex < (pageCount - 1)) {
                        newParent = getAppsCustomizePage(container, pageIndex + 1);
                        if (newParent != null) {
                            container.snapToPage(pageIndex + 1);
                            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 newiconIndex = ((y - 1) * countX) + x;
                    itemContainer.getChildAt(newiconIndex).requestFocus();
                } else {
                    tabs.requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (handleKeyEvent) {
                // Select the closest icon in the previous row, otherwise do nothing
                if (y < (countY - 1)) {
                    int newiconIndex = Math.min(itemCount - 1, ((y + 1) * countX) + x);
                    itemContainer.getChildAt(newiconIndex).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (handleKeyEvent) {
                // Simulate a click on the icon
                View.OnClickListener clickListener = (View.OnClickListener) container;
                clickListener.onClick(v);
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            if (handleKeyEvent) {
                // if there is no previous page
                if (pageIndex > 0) {
                    newParent = getAppsCustomizePage(container, pageIndex - 1);
                    if (newParent != null) {
                        container.snapToPage(pageIndex - 1);
                        child = newParent.getChildAt(0);
                        if (child != null)
                            child.requestFocus();
                    }
                } else {
                    itemContainer.getChildAt(0).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (handleKeyEvent) {
                // if there is no next page
                if (pageIndex < (pageCount - 1)) {
                    newParent = getAppsCustomizePage(container, pageIndex + 1);
                    if (newParent != null) {
                        container.snapToPage(pageIndex + 1);
                        child = newParent.getChildAt(0);
                        if (child != null)
                            child.requestFocus();
                    }
                } else {
                    itemContainer.getChildAt(itemCount - 1).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            if (handleKeyEvent) {
                // Select the first icon on this page
                itemContainer.getChildAt(0).requestFocus();
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            if (handleKeyEvent) {
                // Select the last icon on this page
                itemContainer.getChildAt(itemCount - 1).requestFocus();
            }
            wasHandled = true;
            break;
        default:
            break;
    }
    return wasHandled;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) TabWidget(android.widget.TabWidget) View(android.view.View)

Aggregations

TabHost (android.widget.TabHost)74 View (android.view.View)29 Intent (android.content.Intent)21 ViewGroup (android.view.ViewGroup)19 ListView (android.widget.ListView)18 Test (org.junit.Test)17 TabWidget (android.widget.TabWidget)15 AdapterView (android.widget.AdapterView)13 AbsListView (android.widget.AbsListView)12 ExpandableListView (android.widget.ExpandableListView)12 TextView (android.widget.TextView)12 ActionMenuView (android.widget.ActionMenuView)10 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)10 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)10 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)10 MenuView (com.android.internal.view.menu.MenuView)10 FrameLayout (android.widget.FrameLayout)7 LinearLayout (android.widget.LinearLayout)7 AbsSpinner (android.widget.AbsSpinner)6 QuickContactBadge (android.widget.QuickContactBadge)6