Example #1
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (getChildCount() == 0) {
      return;
    }

    final Drawable d = indicator;

    View tabView = tabWidget.getChildTabViewAt(position);
    if (tabView == null) {
      return;
    }

    View nextTabView =
        position + 1 < tabWidget.getTabCount() ? tabWidget.getChildTabViewAt(position + 1) : null;

    int tabWidth = tabView.getWidth();
    int nextTabWidth = nextTabView == null ? tabWidth : nextTabView.getWidth();

    int indicatorWidth = (int) (nextTabWidth * positionOffset + tabWidth * (1 - positionOffset));
    int indicatorLeft = (int) (getPaddingLeft() + tabView.getLeft() + positionOffset * tabWidth);

    int height = getHeight();
    d.setBounds(indicatorLeft, height - indicatorHeight, indicatorLeft + indicatorWidth, height);
    d.draw(canvas);
  }
Example #2
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (type == Type.Centered) {
      if (maxTabWidth == Integer.MIN_VALUE) {
        for (int i = 0; i < tabWidget.getTabCount(); i++) {
          View tabView = tabWidget.getChildTabViewAt(i);
          if (tabView.getMeasuredWidth() > maxTabWidth) {
            maxTabWidth = tabView.getMeasuredWidth();
          }
        }

        if (maxTabWidth > 0) {
          for (int i = 0; i < tabWidget.getTabCount(); i++) {
            View tabView = tabWidget.getChildTabViewAt(i);
            LinearLayout.LayoutParams params =
                (LinearLayout.LayoutParams) tabView.getLayoutParams();
            params.width = maxTabWidth;
            tabView.setLayoutParams(params);
          }
        }
      }
    }

    super.onLayout(changed, left, top, right, bottom);
  }
Example #3
0
  private void styleSelectedTab() {
    int selIndex = mViewPager.getCurrentItem();
    TabWidget tabWidget = getTabWidget();
    boolean isPrivate = false;

    if (mTarget != null && mTarget.equals(AwesomeBar.Target.CURRENT_TAB.name())) {
      Tab tab = Tabs.getInstance().getSelectedTab();
      if (tab != null) isPrivate = tab.isPrivate();
    }

    for (int i = 0; i < tabWidget.getTabCount(); i++) {
      GeckoTextView view = (GeckoTextView) tabWidget.getChildTabViewAt(i);
      if (isPrivate) {
        view.setPrivateMode((i == selIndex) ? false : true);
      } else {
        if (i == selIndex) view.resetTheme();
        else if (mActivity.getLightweightTheme().isEnabled())
          view.setTheme(mActivity.getLightweightTheme().isLightTheme());
        else view.resetTheme();
      }

      if (i == selIndex) continue;

      if (i == (selIndex - 1)) view.getBackground().setLevel(1);
      else if (i == (selIndex + 1)) view.getBackground().setLevel(2);
      else view.getBackground().setLevel(0);
    }

    if (selIndex == 0) findViewById(R.id.tab_widget_left).getBackground().setLevel(1);
    else findViewById(R.id.tab_widget_left).getBackground().setLevel(0);

    if (selIndex == (tabWidget.getTabCount() - 1))
      findViewById(R.id.tab_widget_right).getBackground().setLevel(2);
    else findViewById(R.id.tab_widget_right).getBackground().setLevel(0);
  }
Example #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    TAG = "TabHost2";
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.tab2);

    addTabView(getString(R.string.view1), null, View1.class);
    addTabView(getString(R.string.view2), null, View2.class);

    // TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    TabHost tabHost = getTabHost();
    TabWidget tw = tabHost.getTabWidget();
    tw.setBackgroundResource(R.drawable.tab_bg);

    for (int i = 0, n = tw.getChildCount(); i < n; i++) {
      View view = (View) tw.getChildTabViewAt(i);
      view.setBackgroundResource(R.drawable.none);

      TextView tv = (TextView) view.findViewById(android.R.id.title);
      tv.setTextSize(10);
      tv.setGravity(Gravity.CENTER_HORIZONTAL);
      tv.setText("Label" + (i + 1));

      ImageView img = (ImageView) view.findViewById(android.R.id.icon);
      img.setBackgroundResource(R.drawable.none);
      img.setImageResource(R.drawable.tab_button);
    }

    tabHost.setOnTabChangedListener(this);
    onTabChanged(getString(R.string.view1));
  }
  /** Setup the tab host and create all necessary tabs. */
  @Override
  protected void onFinishInflate() {
    // Setup the tab host
    setup();

    final ViewGroup tabsContainer = (ViewGroup) findViewById(R.id.tabs_container);
    final TabWidget tabs = getTabWidget();
    final AppsCustomizePagedView appsCustomizePane =
        (AppsCustomizePagedView) findViewById(R.id.apps_customize_pane_content);
    mTabs = tabs;
    mTabsContainer = tabsContainer;
    mAppsCustomizePane = appsCustomizePane;
    mAnimationBuffer = (FrameLayout) findViewById(R.id.animation_buffer);
    mContent = (LinearLayout) findViewById(R.id.apps_customize_content);
    LayoutParams params = (LayoutParams) mContent.getLayoutParams();
    params.topMargin += Utils.getStatusBarSize(getResources());
    mContent.setLayoutParams(params);
    if (tabs == null || mAppsCustomizePane == null) throw new Resources.NotFoundException();

    // Configure the tabs content factory to return the same paged view (that we change the
    // content filter on)
    TabContentFactory contentFactory =
        new TabContentFactory() {
          public View createTabContent(String tag) {
            return appsCustomizePane;
          }
        };

    // Create the tabs
    TextView tabView;
    String label;
    label = getContext().getString(R.string.all_apps_button_label);
    tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
    tabView.setText(label);
    tabView.setContentDescription(label);
    addTab(newTabSpec(APPS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
    label = getContext().getString(R.string.widgets_tab_label);
    tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
    tabView.setText(label);
    tabView.setContentDescription(label);
    addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
    setOnTabChangedListener(this);

    // Setup the key listener to jump between the last tab view and the market icon
    AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
    View lastTab = tabs.getChildTabViewAt(tabs.getTabCount() - 1);
    lastTab.setOnKeyListener(keyListener);
    View shopButton = findViewById(R.id.market_button);
    shopButton.setOnKeyListener(keyListener);

    // Hide the tab bar until we measure
    mTabsContainer.setAlpha(0f);
  }
Example #6
0
  private void initTabHost(Bundle args) {
    mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);
    mTabHost.setup();
    TabInfo tabInfo = null;

    // Create Child Tab1

    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab1").setIndicator(createTabView(mContext, "登入")),
        (tabInfo = new TabInfo("Tab1", PersonalLogin.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);

    // Create Child Tab2
    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab2").setIndicator(createTabView(mContext, "悠遊卡登入")),
        (tabInfo = new TabInfo("Tab2", PersonalLoginEasyCard.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);
    mTabHost.setCurrentTab(0);

    // Create Child Tab3
    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab3").setIndicator(createTabView(mContext, "註冊")),
        (tabInfo = new TabInfo("Tab3", PersonalRegister.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);
    mTabHost.setCurrentTab(0);

    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenWidth = dm.widthPixels;

    TabWidget tabWidget = mTabHost.getTabWidget();
    int count = tabWidget.getChildCount();
    if (count > 1) {
      for (int i = 0; i < count; i++) {
        tabWidget.getChildTabViewAt(i).setMinimumWidth((screenWidth) / 1);
      }
    }

    mTabHost.setOnTabChangedListener(this);
  }
Example #7
0
 /*
  * Attach the BadgeView to the TabWidget
  *
  * @param target the TabWidget to attach the BadgeView
  *
  * @param tabIndex index of the tab
  */
 public void setTargetView(TabWidget target, int tabIndex) {
   View tabView = target.getChildTabViewAt(tabIndex);
   setTargetView(tabView);
 }