Example usage for android.widget TabHost getContext

List of usage examples for android.widget TabHost getContext

Introduction

In this page you can find the example usage for android.widget TabHost getContext.

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:org.agilespain.kitaos.TalksActivity.java

private TabHost.TabSpec createTabSpec(TabHost tabHost, String tag, int labelId) {
    final Context context = tabHost.getContext();

    final TabHost.TabSpec tabSpec = tabHost.newTabSpec(tag);

    final CharSequence label = context.getText(labelId);

    AttributeSet attrs = null;//  www. j a  va2  s  .  co m
    int defStyle = R.attr.kitaosTabViewStyle;
    final TextView view = new TextView(context, attrs, defStyle);
    view.setText(label);

    tabSpec.setIndicator(view);

    return tabSpec;
}

From source file:org.videolan.vlc2.gui.AboutFragment.java

private void addNewTab(TabHost tabHost, String tag, String title) {
    DummyContentFactory dcf = new DummyContentFactory(tabHost.getContext());
    TabSpec tabSpec = tabHost.newTabSpec(tag);
    tabSpec.setIndicator(getNewTabIndicator(tabHost.getContext(), title));
    tabSpec.setContent(dcf);// w w  w.  java 2 s.  c  o m
    tabHost.addTab(tabSpec);
}

From source file:com.hector.invoice.views.TabExportInvoiceOrder.java

/**
 * Add Tab content to the Tabhost/*from w  ww  .  j a  v a 2  s.  co  m*/
 * 
 * @param activity
 * @param tabHost
 * @param tabSpec
 * @param clss
 * @param args
 */
private void AddTab(BaseFragmentActivity activity, TabHost tabHost, String tabName, int type) {
    View tabview = createTabView(tabHost.getContext(), tabName, type);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    lp.weight = 1;
    lp.gravity = Gravity.CENTER;
    lp.setMargins(0, 0, 0, 0);
    tabview.setLayoutParams(lp);

    TabSpec setContent = tabHost.newTabSpec(tabName).setIndicator(tabview).setContent(new TabFactory(activity));
    tabHost.addTab(setContent);
}

From source file:nu.yona.timepicker.time.TimePickerDialog.java

private void setNewTab(TabHost tabHost, String tag, int title, int contentID, int index) {
    TabHost.TabSpec tabSpec = tabHost.newTabSpec(tag);
    tabSpec.setIndicator(getTabIndicator(tabHost.getContext(), title, index)); // new function to inject our own tab layout
    tabSpec.setContent(contentID);//from w  w  w .j a v a 2  s  .  co  m
    tabHost.addTab(tabSpec);
}

From source file:com.momock.outlet.tab.FragmentPagerTabOutlet.java

public void attach(final FragmentTabHolder tabHolder) {
    Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!");
    this.target = tabHolder;
    final TabHost tabHost = target.getTabHost();
    plugs = getPlugs();//w w w.j  a  v a2s .  co m
    Logger.check(target.getTabContent() instanceof ViewPager, "The tab content container must be a ViewPager!");
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    tabContent.setOffscreenPageLimit(plugs.getItemCount());
    tabContent.setAdapter(new FragmentPagerAdapter(target.getFragmentManager()) {

        @Override
        public Fragment getItem(final int position) {
            final ITabPlug plug = (ITabPlug) plugs.getItem(position);
            Fragment f = ((FragmentHolder) plug.getContent()).getFragment();
            if (f instanceof CaseFragment) {
                CaseFragment cf = (CaseFragment) f;
                cf.setActiveCaseIndicator(new IActiveCaseIndicator() {

                    @Override
                    public boolean isActiveCase() {
                        return getActivePlug() == plug;
                    }

                });
            }
            return f;
        }

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        void doFinishUpdate(ViewGroup container) {
            super.finishUpdate(container);
        }

        @Override
        public void finishUpdate(final ViewGroup container) {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    doFinishUpdate(container);
                }

            });
        }

        @Override
        public void setPrimaryItem(ViewGroup container, int position, final Object object) {
            super.setPrimaryItem(container, position, object);
            new Handler().post(new Runnable() {

                @Override
                public void run() {

                    if (object instanceof CaseFragment) {
                        CaseFragment cf = (CaseFragment) object;
                        if (cf.getCase() != null && cf.getCase().getParent() != null)
                            cf.getCase().getParent().setActiveCase(cf.getCase());
                    }
                }

            });
        }
    });
    tabHost.setup();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof FragmentHolder,
                "Plug in PagerTabOutlet must contains a FragmentHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug) {
            tabHost.setCurrentTab(i);
            tabContent.setCurrentItem(i, true);
        }
    }
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}

From source file:com.momock.outlet.tab.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();//from w w w  .  j  a va  2s  .  c  o m

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ITabPlug plug = (ITabPlug) plugs.getItem(position);
            View view = ((ViewHolder) plug.getContent()).getView();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug)
            tabHost.setCurrentTab(i);
    }
}