Search in sources :

Example 46 with TabHost

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

the class LaunchpadTabActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Intent tabIntent = new Intent(getIntent());
    tabIntent.setComponent((ComponentName) tabIntent.getParcelableExtra("tab"));
    TabHost th = getTabHost();
    TabHost.TabSpec ts = th.newTabSpec("1");
    ts.setIndicator("One");
    ts.setContent(tabIntent);
    th.addTab(ts);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent)

Example 47 with TabHost

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

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) 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) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Example 48 with TabHost

use of android.widget.TabHost in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) 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) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Example 49 with TabHost

use of android.widget.TabHost in project android_frameworks_base by AOSPA.

the class MediaDump method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // TODO: Read/Write the settings.
    setContentView(R.layout.main);
    TabHost tab = getTabHost();
    // Setup video dumping tab
    TabHost.TabSpec videoDumpTab = tab.newTabSpec("VideoDump");
    videoDumpTab.setIndicator("VideoDump");
    Intent videoDumpIntent = new Intent(this, VideoDumpActivity.class);
    videoDumpTab.setContent(videoDumpIntent);
    tab.addTab(videoDumpTab);
    // Setup rgb player tab
    TabHost.TabSpec rgbPlayerTab = tab.newTabSpec("RgbPlayer");
    rgbPlayerTab.setIndicator("RgbPlayer");
    Intent rgbPlayerIntent = new Intent(this, RgbPlayerActivity.class);
    rgbPlayerTab.setContent(rgbPlayerIntent);
    tab.addTab(rgbPlayerTab);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent)

Example 50 with TabHost

use of android.widget.TabHost in project android_frameworks_base by ResurrectionRemix.

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

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