Search in sources :

Example 31 with TabHost

use of android.widget.TabHost in project Ushahidi_Android by ushahidi.

the class ReportTabFragment method addTab.

private void addTab(String indicator, int drawableId, Class<?> c) {
    TabHost tabHost = mTabHost;
    TabHost.TabSpec spec = tabHost.newTabSpec(indicator);
    Intent intent = new Intent(getActivity(), c);
    View tabIndicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab_indicator, tabHost.getTabWidget(), false);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);
    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

Example 32 with TabHost

use of android.widget.TabHost in project spring-data-document-examples by spring-projects.

the class MainTabWidget method onCreate.

//***************************************
// Activity methods
//***************************************
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Resources res = getResources();
    TabHost tabHost = getTabHost();
    TabHost.TabSpec tabSpec;
    Intent intent;
    // add events tab
    intent = new Intent();
    intent.setClass(this, RestListingActivity.class);
    tabSpec = tabHost.newTabSpec("restaurants");
    tabSpec.setIndicator("Restaurants", res.getDrawable(R.drawable.ic_tab_events));
    tabSpec.setContent(intent);
    tabHost.addTab(tabSpec);
    // add profile tab
    intent = new Intent();
    intent.setClass(this, FavoritesListingActivity.class);
    tabSpec = tabHost.newTabSpec("favorites");
    tabSpec.setIndicator("Favorites", res.getDrawable(R.drawable.ic_tab_profile));
    tabSpec.setContent(intent);
    tabHost.addTab(tabSpec);
    // add info tab
    intent = new Intent();
    intent.setClass(this, InfoActivity.class);
    tabSpec = tabHost.newTabSpec("info");
    tabSpec.setIndicator("Info", res.getDrawable(R.drawable.ic_tab_info));
    tabSpec.setContent(intent);
    tabHost.addTab(tabSpec);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent) Resources(android.content.res.Resources)

Example 33 with TabHost

use of android.widget.TabHost in project pictureapp by EyeSeeTea.

the class DashboardActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    handler = new Handler(Looper.getMainLooper());
    mDashboardActivityStrategy = new DashboardActivityStrategy();
    dashboardActivity = this;
    setContentView(R.layout.tab_dashboard);
    Survey.removeInProgress();
    if (savedInstanceState == null) {
        initImprove();
        initMonitor();
        if (GradleVariantConfig.isStockFragmentActive()) {
            initStock();
        }
        initAssess();
    }
    initTabHost(savedInstanceState);
    /* set tabs in order */
    LayoutUtils.setTabHosts(this);
    LayoutUtils.setTabDivider(this);
    //set the tabs background as transparent
    setTabsBackgroundColor(R.color.tab_unpressed_background);
    //set first tab as selected:
    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.tab_pressed_background));
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            /** If current tab is android */
            //set the tabs background as transparent
            setTabsBackgroundColor(R.color.tab_unpressed_background);
            //If change of tab from surveyFragment or FeedbackFragment they could be closed.
            if (isSurveyFragmentActive()) {
                onSurveyBackPressed();
            }
            if (isReviewFragmentActive()) {
                exitReviewOnChangeTab(null);
            }
            if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_assess))) {
                if (!isReadOnly) {
                    unsentFragment.reloadData();
                }
                unsentFragment.reloadHeader(dashboardActivity);
            } else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_improve))) {
                sentFragment.reloadData();
                sentFragment.reloadHeader(dashboardActivity);
            } else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_stock))) {
                mDashboardActivityStrategy.reloadStockFragment(dashboardActivity);
            } else if (tabId.equalsIgnoreCase(getResources().getString(R.string.tab_tag_monitor))) {
                monitorFragment.reloadData();
                monitorFragment.reloadHeader(dashboardActivity);
            }
            tabHost.getCurrentTabView().setBackgroundColor(getResources().getColor(R.color.tab_pressed_background));
        }
    });
    // init tabHost
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
        tabHost.getTabWidget().getChildAt(i).setFocusable(false);
    }
    getSurveysFromService();
}
Also used : TabHost(android.widget.TabHost) Handler(android.os.Handler) DashboardActivityStrategy(org.eyeseetea.malariacare.strategies.DashboardActivityStrategy)

Example 34 with TabHost

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

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 35 with TabHost

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

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)

Aggregations

TabHost (android.widget.TabHost)73 View (android.view.View)30 Intent (android.content.Intent)21 ViewGroup (android.view.ViewGroup)18 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)11 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