@Override
  public void draw(@NonNull final Canvas canvas) {
    super.draw(canvas);

    // Only recalculate the close bounds if they are dirty
    if (mCloseBoundChanged) {
      mCloseBoundChanged = false;

      mClosableLayoutRect.set(0, 0, getWidth(), getHeight());
      // Create the bounds for our close regions.
      applyCloseRegionBounds(mClosePosition, mClosableLayoutRect, mCloseRegionBounds);

      // The inset rect applies padding around the visible closeButton.
      mInsetCloseRegionBounds.set(mCloseRegionBounds);
      mInsetCloseRegionBounds.inset(mCloseButtonPadding, mCloseButtonPadding);
      // The close button sits inside the close region with padding and gravity
      // in the same way the close region sits inside the whole ClosableLayout
      applyCloseButtonBounds(mClosePosition, mInsetCloseRegionBounds, mCloseButtonBounds);
      mCloseDrawable.setBounds(mCloseButtonBounds);
    }

    // Draw last so that this gets drawn as the top layer. This is also why we override
    // draw instead of onDraw.
    if (mCloseDrawable.isVisible()) {
      mCloseDrawable.draw(canvas);
    }
  }
Beispiel #2
0
  public Drawable createIconDrawable(Drawable src) {
    Bitmap scaled = createIconBitmap(src);

    StateListDrawable result = new StateListDrawable();

    result.addState(
        new int[] {android.R.attr.state_focused},
        new BitmapDrawable(createSelectedBitmap(scaled, false)));
    result.addState(
        new int[] {android.R.attr.state_pressed},
        new BitmapDrawable(createSelectedBitmap(scaled, true)));
    result.addState(new int[0], new BitmapDrawable(scaled));

    result.setBounds(0, 0, mIconTextureWidth, mIconTextureHeight);
    return result;
  }
  private void initTabs(int currentTab) {

    for (int index = 0; index < mTabCount; index++) {
      TextView tvTab = new TextView(mContext);
      tvTab.setId(BASE_ID + index);
      tvTab.setOnClickListener(this);
      tvTab.setGravity(Gravity.CENTER);

      if (null != mViewPager.getAdapter().getPageTitle(index)) {
        tvTab.setTextColor(mTextColor);
        tvTab.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSizeNormal);
        tvTab.setText(mViewPager.getAdapter().getPageTitle(index));
      }

      if (mTabIcons != null && mTabIcons.size() > index) {
        StateListDrawable drawable = mTabIcons.get(index);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvTab.setCompoundDrawables(null, drawable, null, null);
        tvTab.setCompoundDrawablePadding(0);
        tvTab.setPadding(0, 10, 0, 0);
      }

      LayoutParams tabLp = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
      tabLp.gravity = Gravity.CENTER;
      tvTab.setLayoutParams(tabLp);
      tvTab.setPadding(0, mTabPaddingTop, 0, mTabPaddingBottom);
      this.addView(tvTab);

      if (index == 0) {
        resetTab(tvTab, true);
      }

      if (index != mTabCount - 1 && mHasDivider) {
        LayoutParams dividerLp = new LayoutParams(mDividerWidth, LayoutParams.MATCH_PARENT);
        dividerLp.setMargins(0, mDividerVerticalMargin, 0, mDividerVerticalMargin);
        View vLine = new View(getContext());
        vLine.setBackgroundColor(mDividerColor);
        vLine.setLayoutParams(dividerLp);
        this.addView(vLine);
      }
    }
    setCurrentTab(currentTab);
  }
 @Override
 public void setBounds(int left, int top, int right, int bottom) {
   super.setBounds(left, top, right, bottom);
   onBoundsChange(getBounds());
 }