/**
   * Swap Tab effect(color or cross fade)
   *
   * @param position The page position
   * @param positionOffset The page position offset
   */
  private void swapTabColor(int position, float positionOffset, boolean left) {
    final int colorDefault = mTabColorize.getDefaultTabColor(position);
    final int colorSelected = mTabColorize.getSelectedTabColor(position);
    final int nextColorDefault = mTabColorize.getDefaultTabColor(position + 1);
    final int nextColorSelected = mTabColorize.getSelectedTabColor(position + 1);

    int color = colorDefault;
    int nextColor = nextColorSelected;

    if (mTabColorBlendMode == TabColorBlendMode.DEFAULT_SELECTED) {
      if (colorDefault != colorSelected) {
        color = ColorUtils.blendColors(colorDefault, colorSelected, positionOffset);
      }

      if (nextColorDefault != nextColorSelected) {
        nextColor = ColorUtils.blendColors(nextColorSelected, nextColorDefault, positionOffset);
      }
    } else if (mTabColorBlendMode == TabColorBlendMode.NEXT_SELECTED) {
      if (!left) {
        if (colorDefault != colorSelected) {
          color = ColorUtils.blendColors(colorDefault, colorSelected, positionOffset);
        }

        if (nextColorSelected != colorSelected) {
          nextColor = ColorUtils.blendColors(nextColorSelected, colorSelected, positionOffset);
        }
      } else {
        if (colorSelected != nextColorSelected) {
          color = ColorUtils.blendColors(colorSelected, nextColorSelected, 1 - positionOffset);
        }

        if (nextColorDefault != nextColorSelected) {
          nextColor =
              ColorUtils.blendColors(nextColorDefault, nextColorSelected, 1 - positionOffset);
        }
      }
    }

    setTabColor(getNeededView(position), color);
    setTabColor(getNeededView(position + 1), nextColor);
  }
Beispiel #2
0
  /**
   * Draw indicator
   *
   * @param canvas The canvas
   */
  private void drawIndicator(Canvas canvas) {
    if (mShowIndicator) {
      final int height = getHeight();
      final int childCount = getChildCount();

      if (childCount > 0) {
        View tabView = getChildAt(mSelectedPosition);
        int left = tabView.getLeft();
        int right = tabView.getRight();
        int color = mTabStripColorize.getIndicatorColor(mSelectedPosition);

        if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
          int nextColor = mTabStripColorize.getIndicatorColor(mSelectedPosition + 1);
          if (color != nextColor) {
            color = ColorUtils.blendColors(nextColor, color, mSelectionOffset);
          }

          // Draw the selection partway between the tabs
          View nextTabView = getChildAt(mSelectedPosition + 1);
          left =
              (int) (mSelectionOffset * nextTabView.getLeft() + (1.0f - mSelectionOffset) * left);
          right =
              (int) (mSelectionOffset * nextTabView.getRight() + (1.0f - mSelectionOffset) * right);
        }

        mIndicatorPaint.setColor(color);

        RectF rectF =
            new RectF(
                left,
                height - mIndicatorHeight - mIndicatorPaddingBottom,
                right,
                height - mIndicatorPaddingBottom);
        switch (mIndicatorGravity) {
          case TOP:
            {
              rectF.set(left, mIndicatorPaddingTop, right, mIndicatorHeight + mIndicatorPaddingTop);
              break;
            }
          case CENTER:
            {
              rectF.set(
                  left, (height - mIndicatorHeight) / 2, right, (height + mIndicatorHeight) / 2);
              break;
            }
        }

        if (mIndicatorCornerRadius > 0f) {
          mIndicatorPaint.setAntiAlias(true);
          canvas.drawRoundRect(
              rectF, mIndicatorCornerRadius, mIndicatorCornerRadius, mIndicatorPaint);
        } else {
          mIndicatorPaint.setAntiAlias(false);
          canvas.drawRect(rectF, mIndicatorPaint);
        }

        if (mOnIndicatorColorChangedListener != null) {
          mOnIndicatorColorChangedListener.onIndicatorColorChanged(
              (NiceTabLayout) this.getParent(), color);
        }
      }
    }
  }