android.widget.TabWidget Java Examples

The following examples show how to use android.widget.TabWidget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PdDroidParty.java    From PdDroidPublisher with GNU General Public License v3.0 6 votes vote down vote up
public static TabHost createTabHost(Context context) {
    // Create the TabWidget (the tabs)
    TabWidget tabWidget = new TabWidget(context);
    tabWidget.setId(android.R.id.tabs);

    // Create the FrameLayout (the content area)
    FrameLayout frame = new FrameLayout(context);
    frame.setId(android.R.id.tabcontent);
    LinearLayout.LayoutParams frameLayoutParams = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    frameLayoutParams.setMargins(4, 4, 4, 4);
    frame.setLayoutParams(frameLayoutParams);

    // Create the container for the above widgets
    LinearLayout tabHostLayout = new LinearLayout(context);
    tabHostLayout.setOrientation(LinearLayout.VERTICAL);
    tabHostLayout.addView(tabWidget);
    tabHostLayout.addView(frame);

    // Create the TabHost and add the container to it.
    TabHost tabHost = new TabHost(context, null);
    tabHost.addView(tabHostLayout);
    tabHost.setup();

    return tabHost;
}
 
Example #2
Source File: MainActivity.java    From android_tv_metro with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mTabHost = (TabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabs    = (TabWidget)findViewById(android.R.id.tabs);

    ViewStub vStub = (ViewStub) findViewById(R.id.new_home_menu);
    mMenuContainer = (FrameLayout) vStub.inflate();
    mViewPager = (ViewPager)findViewById(R.id.pager);

    mLoadingView = makeEmptyLoadingView(this, (RelativeLayout)findViewById(R.id.tabs_content));

    setScrollerTime(800);

    albumItem = (DisplayItem) getIntent().getSerializableExtra("item");
    setUserFragmentClass();
    getSupportLoaderManager().initLoader(TabsGsonLoader.LOADER_ID, null, this);

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }
}
 
Example #3
Source File: TabsAdapter.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@Override
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 = tabHost.getTabWidget();
    int oldFocusability = widget.getDescendantFocusability();
    widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    tabHost.setCurrentTab(position);
    widget.setDescendantFocusability(oldFocusability);

    // Scroll the current tab into visibility if needed.
    View tab = widget.getChildTabViewAt(position);
    tempRect.set(tab.getLeft(), tab.getTop(), tab.getRight(), tab.getBottom());
    widget.requestRectangleOnScreen(tempRect, false);

    // Make sure the scrollbars are visible for a moment after selection
    final View contentView = tabs.get(position);
    if (contentView instanceof CaffeinatedScrollView) {
        ((CaffeinatedScrollView) contentView).awakenScrollBars();
    }
}
 
Example #4
Source File: FragmentTabHost.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void a(Context context, AttributeSet attributeset)
{
    TypedArray typedarray = context.obtainStyledAttributes(attributeset, new int[] {
        0x10100f3
    }, 0, 0);
    e = typedarray.getResourceId(0, 0);
    typedarray.recycle();
    super.setOnTabChangedListener(this);
    if (findViewById(0x1020013) == null)
    {
        LinearLayout linearlayout = new LinearLayout(context);
        linearlayout.setOrientation(1);
        addView(linearlayout, new android.widget.FrameLayout.LayoutParams(-1, -1));
        TabWidget tabwidget = new TabWidget(context);
        tabwidget.setId(0x1020013);
        tabwidget.setOrientation(0);
        linearlayout.addView(tabwidget, new android.widget.LinearLayout.LayoutParams(-1, -2, 0.0F));
        FrameLayout framelayout = new FrameLayout(context);
        framelayout.setId(0x1020011);
        linearlayout.addView(framelayout, new android.widget.LinearLayout.LayoutParams(0, 0, 0.0F));
        FrameLayout framelayout1 = new FrameLayout(context);
        b = framelayout1;
        b.setId(e);
        linearlayout.addView(framelayout1, new android.widget.LinearLayout.LayoutParams(-1, 0, 1.0F));
    }
}
 
Example #5
Source File: FragmentTabHost.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #6
Source File: FragmentTabHost.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void a(Context context, AttributeSet attributeset)
{
    TypedArray typedarray = context.obtainStyledAttributes(attributeset, new int[] {
        0x10100f3
    }, 0, 0);
    e = typedarray.getResourceId(0, 0);
    typedarray.recycle();
    super.setOnTabChangedListener(this);
    if (findViewById(0x1020013) == null)
    {
        LinearLayout linearlayout = new LinearLayout(context);
        linearlayout.setOrientation(1);
        addView(linearlayout, new android.widget.FrameLayout.LayoutParams(-1, -1));
        TabWidget tabwidget = new TabWidget(context);
        tabwidget.setId(0x1020013);
        tabwidget.setOrientation(0);
        linearlayout.addView(tabwidget, new android.widget.LinearLayout.LayoutParams(-1, -2, 0.0F));
        FrameLayout framelayout = new FrameLayout(context);
        framelayout.setId(0x1020011);
        linearlayout.addView(framelayout, new android.widget.LinearLayout.LayoutParams(0, 0, 0.0F));
        FrameLayout framelayout1 = new FrameLayout(context);
        b = framelayout1;
        b.setId(e);
        linearlayout.addView(framelayout1, new android.widget.LinearLayout.LayoutParams(-1, 0, 1.0F));
    }
}
 
Example #7
Source File: BadgeView.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void a(View view)
{
    android.view.ViewGroup.LayoutParams layoutparams = view.getLayoutParams();
    android.view.ViewParent viewparent = view.getParent();
    FrameLayout framelayout = new FrameLayout(i);
    if (view instanceof TabWidget)
    {
        View view1 = ((TabWidget)view).getChildTabViewAt(q);
        j = view1;
        ((ViewGroup)view1).addView(framelayout, new android.view.ViewGroup.LayoutParams(-1, -1));
        setVisibility(8);
        framelayout.addView(this);
        return;
    } else
    {
        ViewGroup viewgroup = (ViewGroup)viewparent;
        int i1 = viewgroup.indexOfChild(view);
        viewgroup.removeView(view);
        viewgroup.addView(framelayout, i1, layoutparams);
        framelayout.addView(view);
        setVisibility(8);
        framelayout.addView(this);
        viewgroup.invalidate();
        return;
    }
}
 
Example #8
Source File: BadgeView.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void applyTo(View target) {

    LayoutParams lp = target.getLayoutParams();
    ViewParent parent = target.getParent();
    FrameLayout container = new FrameLayout(context);

    if (target instanceof TabWidget) {

      // set target to the relevant tab child container
      target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
      this.target = target;

      ((ViewGroup) target).addView(container,
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

      this.setVisibility(View.GONE);
      container.addView(this);
    } else {

      // TODO verify that parent is indeed a ViewGroup
      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();
    }
  }
 
Example #9
Source File: HelpFragment.java    From RobotCA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Callback for when a tab is selected.
 * @param position The position of the selected tab
 */
@Override
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);
}
 
Example #10
Source File: IMPopupDialog.java    From opensudoku with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates view with two tabs, first for number in cell selection, second for
 * note editing.
 *
 * @return
 */
private TabHost createTabView() {
    TabHost tabHost = new TabHost(mContext, null);
    tabHost.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    //tabHost.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    //linearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    TabWidget tabWidget = new TabWidget(mContext);
    tabWidget.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    tabWidget.setId(android.R.id.tabs);

    FrameLayout frameLayout = new FrameLayout(mContext);
    frameLayout.setId(android.R.id.tabcontent);

    linearLayout.addView(tabWidget);
    linearLayout.addView(frameLayout);
    tabHost.addView(linearLayout);

    tabHost.setup();

    final View editNumberView = createEditNumberView();
    final View editNoteView = createEditNoteView();

    tabHost.addTab(tabHost.newTabSpec("number")
            .setIndicator(mContext.getString(R.string.select_number))
            .setContent(tag -> editNumberView));
    tabHost.addTab(tabHost.newTabSpec("note")
            .setIndicator(mContext.getString(R.string.edit_note))
            .setContent(tag -> editNoteView));

    return tabHost;
}
 
Example #11
Source File: FragmentTabHost.java    From guideshow with MIT License 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #12
Source File: FragmentTabsPager.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override
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);
}
 
Example #13
Source File: FragmentTabHost.java    From ImitateTaobaoApp with Apache License 2.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    }
}
 
Example #14
Source File: FragmentTabHost.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #15
Source File: FragmentTabHost.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #16
Source File: FragmentTabHost.java    From enjoyshop with Apache License 2.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    }
}
 
Example #17
Source File: FragmentTabHost.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #18
Source File: ManageContactsActivity.java    From DumbphoneAssistant with GNU General Public License v2.0 5 votes vote down vote up
private void update() {
    Collections.sort(simContacts);
    Collections.sort(phoneContacts);
    simAdapter.notifyDataSetChanged();
    phoneAdapter.notifyDataSetChanged();
    TabWidget tabWidget = getTabHost().getTabWidget();
    TextView labelPhone = (TextView) tabWidget.getChildAt(0).findViewById(android.R.id.title);
    TextView labelSim = (TextView) tabWidget.getChildAt(1).findViewById(android.R.id.title);
    labelPhone.setText(getString(R.string.phone_tab_title) + " (" + phoneContacts.size() + ")");
    labelSim.setText(getString(R.string.sim_tab_title) + " (" + simContacts.size() + ")");
}
 
Example #19
Source File: TabsAdapter.java    From callerid-for-android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #20
Source File: FragmentTabHost.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #21
Source File: FragmentTabHost.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();

    super.setOnTabChangedListener(this);

    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
 
Example #22
Source File: BadgeView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void applyTo(View target) {

		LayoutParams lp = target.getLayoutParams();
		ViewParent parent = target.getParent();
		FrameLayout container = new FrameLayout(context);

		if (target instanceof TabWidget) {
			// set target to the relevant tab child container
			target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
			this.target = target;
			((ViewGroup) target).addView(container, new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

			this.setVisibility(View.GONE);
			container.addView(this);
		} else {
			// verify that parent is indeed a ViewGroup
			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();
		}
	}
 
Example #23
Source File: BaseFragmentTabHost.java    From FragmentMixViewPager with Apache License 2.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
	// If owner hasn't made its own view hierarchy, then as a convenience
	// we will construct a standard one here.
	if (findViewById(android.R.id.tabs) == null) {
		LinearLayout ll = new LinearLayout(context);
		ll.setOrientation(LinearLayout.VERTICAL);
		addView(ll, new FrameLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.MATCH_PARENT));

		TabWidget tw = new TabWidget(context);
		tw.setId(android.R.id.tabs);
		tw.setOrientation(TabWidget.HORIZONTAL);
		ll.addView(tw, new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT, 0));

		FrameLayout fl = new FrameLayout(context);
		fl.setId(android.R.id.tabcontent);
		ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

		mRealTabContent = fl = new FrameLayout(context);
		mRealTabContent.setId(mContainerId);
		ll.addView(fl, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
	}
}
 
Example #24
Source File: TabsAdapter.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
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 tabWidget = tabHost.getTabWidget();
  int oldFocusability = tabWidget.getDescendantFocusability();
  tabWidget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
  tabHost.setCurrentTab(position);
  tabWidget.setDescendantFocusability(oldFocusability);
}
 
Example #25
Source File: OpenTabHost.java    From AndroidTVWidget with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
	this.mContext = context;
	LayoutInflater.from(context).inflate(R.layout.tabhost_title_head, this, true);
	mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
	setup();
	mTabWidget.setStripEnabled(false);
	initViewEvents();
	this.setBackgroundColor(Color.TRANSPARENT);
}
 
Example #26
Source File: OpenTabHost.java    From AndroidTVWidget with Apache License 2.0 5 votes vote down vote up
private void initViewEvents() {
	setOnTabChangedListener(new OnTabChangeListener() {
		@Override
		public void onTabChanged(String tabId) {
			int position = getCurrentTab();
			OnTabSelectListener cb = mOnTabSelectListener;
			if (cb != null) {
				TabWidget tw = getTabWidget();
				View titleWidget = tw.getChildTabViewAt(position);
				cb.onTabSelect(OpenTabHost.this, titleWidget, position);
			}
		}
	});
}
 
Example #27
Source File: FragmentTabHost.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
private void ensureHierarchy(Context context) {
    // If owner hasn't made its own view hierarchy, then as a convenience
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0));

        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));

        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    }
}
 
Example #28
Source File: BadgeView.java    From umeng_community_android with MIT License 5 votes vote down vote up
private void applyTo(View target) {

        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);

        if (target instanceof TabWidget) {
            // set target to the relevant tab child container
            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();

        }

    }
 
Example #29
Source File: OpenTabHost.java    From Android-tv-widget with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
	this.mContext = context;
	LayoutInflater.from(context).inflate(R.layout.tabhost_title_head, this, true);
	mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
	setup();
	mTabWidget.setStripEnabled(false);
	initViewEvents();
	this.setBackgroundColor(Color.TRANSPARENT);
}
 
Example #30
Source File: OpenTabHost.java    From Android-tv-widget with Apache License 2.0 5 votes vote down vote up
private void initViewEvents() {
	setOnTabChangedListener(new OnTabChangeListener() {
		@Override
		public void onTabChanged(String tabId) {
			int position = getCurrentTab();
			OnTabSelectListener cb = mOnTabSelectListener;
			if (cb != null) {
				TabWidget tw = getTabWidget();
				View titleWidget = tw.getChildTabViewAt(position);
				cb.onTabSelect(OpenTabHost.this, titleWidget, position);
			}
		}
	});
}