Search in sources :

Example 1 with TabWidget

use of android.widget.TabWidget in project Launcher3 by chislon.

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) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 2 with TabWidget

use of android.widget.TabWidget in project AndroidDevelop by 7449.

the class BadgeView method applyTo.

private void applyTo(View target) {
    LayoutParams lp = target.getLayoutParams();
    ViewParent parent = target.getParent();
    FrameLayout container = new FrameLayout(context);
    if (target instanceof TabWidget) {
        target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
        this.target = target;
        ((ViewGroup) target).addView(container, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        this.setVisibility(View.GONE);
        container.addView(this);
    } else {
        ViewGroup group = (ViewGroup) parent;
        int index = group.indexOfChild(target);
        group.removeView(target);
        group.addView(container, index, lp);
        container.addView(target);
        this.setVisibility(View.GONE);
        container.addView(this);
        group.invalidate();
    }
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) TabWidget(android.widget.TabWidget) SuppressLint(android.annotation.SuppressLint)

Example 3 with TabWidget

use of android.widget.TabWidget in project android_frameworks_base by DirtyUnicorns.

the class RenderSessionImpl method setupTabHost.

/**
     * Sets up a {@link TabHost} object.
     * @param tabHost the TabHost to setup.
     * @param layoutlibCallback The project callback object to access the project R class.
     * @throws PostInflateException
     */
private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException {
    // look for the TabWidget, and the FrameLayout. They have their own specific names
    View v = tabHost.findViewById(android.R.id.tabs);
    if (v == null) {
        throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
    }
    if (!(v instanceof TabWidget)) {
        throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
    }
    v = tabHost.findViewById(android.R.id.tabcontent);
    if (v == null) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
    }
    if (!(v instanceof FrameLayout)) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
    }
    FrameLayout content = (FrameLayout) v;
    // now process the content of the frameLayout and dynamically create tabs for it.
    final int count = content.getChildCount();
    // this must be called before addTab() so that the TabHost searches its TabWidget
    // and FrameLayout.
    tabHost.setup();
    if (count == 0) {
        // Create a dummy child to get a single tab
        TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details, null)).setContent(new TabHost.TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new LinearLayout(getContext());
            }
        });
        tabHost.addTab(spec);
    } else {
        // for each child of the frameLayout, add a new TabSpec
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            String tabSpec = String.format("tab_spec%d", i + 1);
            // child cannot be null.
            @SuppressWarnings("ConstantConditions") int id = child.getId();
            @SuppressWarnings("deprecation") Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id);
            String name;
            if (resource != null) {
                name = resource.getSecond();
            } else {
                // default name if id is unresolved.
                name = String.format("Tab %d", i + 1);
            }
            tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
        }
    }
}
Also used : TabHost(android.widget.TabHost) ResourceType(com.android.resources.ResourceType) TabWidget(android.widget.TabWidget) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) TabSpec(android.widget.TabHost.TabSpec) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Example 4 with TabWidget

use of android.widget.TabWidget in project Cangol-uiframe by Cangol.

the class TabPageManager method onPageSelected.

public void onPageSelected(int position) {
    // Unfortunately when TabHost changes the current tab, it kindly
    // also takes care of putting focus on it when not in touch mode.
    // The jerk.
    // This hack tries to prevent this from pulling focus out of our
    // ViewPager.
    TabWidget widget = mTabHost.getTabWidget();
    int oldFocusability = widget.getDescendantFocusability();
    widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    mTabHost.setCurrentTab(position);
    widget.setDescendantFocusability(oldFocusability);
}
Also used : TabWidget(android.widget.TabWidget)

Example 5 with TabWidget

use of android.widget.TabWidget in project platform_frameworks_base by android.

the class RenderSessionImpl method setupTabHost.

/**
     * Sets up a {@link TabHost} object.
     * @param tabHost the TabHost to setup.
     * @param layoutlibCallback The project callback object to access the project R class.
     * @throws PostInflateException
     */
private void setupTabHost(TabHost tabHost, LayoutlibCallback layoutlibCallback) throws PostInflateException {
    // look for the TabWidget, and the FrameLayout. They have their own specific names
    View v = tabHost.findViewById(android.R.id.tabs);
    if (v == null) {
        throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
    }
    if (!(v instanceof TabWidget)) {
        throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
    }
    v = tabHost.findViewById(android.R.id.tabcontent);
    if (v == null) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
    }
    if (!(v instanceof FrameLayout)) {
        //noinspection SpellCheckingInspection
        throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
    }
    FrameLayout content = (FrameLayout) v;
    // now process the content of the frameLayout and dynamically create tabs for it.
    final int count = content.getChildCount();
    // this must be called before addTab() so that the TabHost searches its TabWidget
    // and FrameLayout.
    tabHost.setup();
    if (count == 0) {
        // Create a dummy child to get a single tab
        TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details, null)).setContent(new TabHost.TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new LinearLayout(getContext());
            }
        });
        tabHost.addTab(spec);
    } else {
        // for each child of the frameLayout, add a new TabSpec
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            String tabSpec = String.format("tab_spec%d", i + 1);
            // child cannot be null.
            @SuppressWarnings("ConstantConditions") int id = child.getId();
            @SuppressWarnings("deprecation") Pair<ResourceType, String> resource = layoutlibCallback.resolveResourceId(id);
            String name;
            if (resource != null) {
                name = resource.getSecond();
            } else {
                // default name if id is unresolved.
                name = String.format("Tab %d", i + 1);
            }
            tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
        }
    }
}
Also used : TabHost(android.widget.TabHost) ResourceType(com.android.resources.ResourceType) TabWidget(android.widget.TabWidget) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) TabSpec(android.widget.TabHost.TabSpec) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

TabWidget (android.widget.TabWidget)37 View (android.view.View)21 FrameLayout (android.widget.FrameLayout)16 TabHost (android.widget.TabHost)15 LinearLayout (android.widget.LinearLayout)14 ViewGroup (android.view.ViewGroup)13 ListView (android.widget.ListView)12 TextView (android.widget.TextView)12 AdapterView (android.widget.AdapterView)9 AbsListView (android.widget.AbsListView)7 ExpandableListView (android.widget.ExpandableListView)6 ImageView (android.widget.ImageView)6 TabSpec (android.widget.TabHost.TabSpec)6 ResourceType (com.android.resources.ResourceType)6 ActionMenuView (android.widget.ActionMenuView)5 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)5 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)5 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)5 MenuView (com.android.internal.view.menu.MenuView)5 SuppressLint (android.annotation.SuppressLint)3