Esempio n. 1
0
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    // HACK: Without this, the onFinishInflate is called twice
    // This issue is due to a bug when Android inflates a layout with a
    // parent. Fixed in Honeycomb
    if (mInflated) return;

    mInflated = true;

    // This should be called before adding any tabs
    // to the TabHost.
    setup();

    mListTouchListener =
        new View.OnTouchListener() {
          public boolean onTouch(View view, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) hideSoftInput(view);
            return false;
          }
        };

    mBackground = (Background) findViewById(R.id.awesomebar_background);

    mTabs =
        new AwesomeBarTab[] {
          new AllPagesTab(mContext), new BookmarksTab(mContext), new HistoryTab(mContext)
        };

    final TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
    // hide the strip since we aren't using the TabHost...
    tabWidget.setStripEnabled(false);

    mViewPager = (ViewPager) findViewById(R.id.tabviewpager);
    mPagerAdapter = new AwesomePagerAdapter();
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(0);
    mViewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          public void onPageScrollStateChanged(int state) {}

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

          public void onPageSelected(int position) {
            tabWidget.setCurrentTab(position);
            styleSelectedTab();
            hideSoftInput(mViewPager);
          }
        });

    for (int i = 0; i < mTabs.length; i++) {
      mTabs[i].setListTouchListener(mListTouchListener);
      addAwesomeTab(mTabs[i].getTag(), mTabs[i].getTitleStringId(), i);
    }

    tabWidget.setCurrentTab(0);

    styleSelectedTab();

    // Initialize "App Pages" list with no filter
    filter("");
  }
Esempio n. 2
0
  public MaterialTabHost(Context context, AttributeSet attrs) {
    super(context, attrs);

    inflater = LayoutInflater.from(context);

    TypedValue outValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    // use ?attr/colorPrimary as background color
    // theme.resolveAttribute(R.attr.colorPrimary, outValue, true);
    // setBackgroundColor(outValue.data);

    // use ?attr/colorControlActivated as default indicator color
    // theme.resolveAttribute(R.attr.colorControlActivated, outValue, true);
    // colorControlActivated = outValue.data;
    setBackgroundColor(0xff0CACF4);
    colorControlActivated = 0xffBEEAFC;

    TypedArray a =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0);
    int indicatorColor =
        a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, colorControlActivated);
    a.recycle();

    // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable
    indicator = new ShapeDrawable();
    indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP);

    Resources res = context.getResources();
    indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height);
    leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset);
    // int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height);

    tabWidget = new TabWidget(context);
    tabWidget.setLayoutParams(
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tabWidget.setId(android.R.id.tabs);
    tabWidget.setStripEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }
    addView(tabWidget);

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

    setup();

    setOnTabChangedListener(
        new TabHost.OnTabChangeListener() {
          @Override
          public void onTabChanged(String tabId) {
            if (listener != null) {
              listener.onTabSelected(Integer.valueOf(tabId));
            }
          }
        });

    float density = getResources().getDisplayMetrics().density;

    // set elevation for App bar
    // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation
    ViewCompat.setElevation(this, APP_TAB_ELEVATION * density);
  }