private void showPress(MotionEvent event, boolean pressed) {
   int touchZone = getTouchZone(event);
   if (touchZone != MIDDLE_ZONE) {
     TextView view = (TextView) getChildAt(mDisplayedPage + getTouchZone(event));
     view.setTextColor(pressed ? mActiveTextColor.getColor() : mInactiveTextColor.getColor());
   }
 }
 public void add(int index, String label) {
   TextView textView = new TextView(mContext);
   textView.setTextColor(mInactiveTextColor.getColor());
   textView.setTextSize(16);
   textView.setText(label);
   addView(textView);
 }
  public PagerHeader(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    Resources resources = context.getResources();
    mDisplayMetrics = resources.getDisplayMetrics();

    // Get attributes from the layout xml
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerHeader, 0, 0);
    //		mActiveTextColor = new ColorSet(
    //				a.getColor(R.styleable.PagerHeader_activeTextColor, Color.GREEN));
    mActiveTextColor = new ColorSet(resources.getColor(R.color.cputuner_green));
    mInactiveTextColor =
        new ColorSet(a.getColor(R.styleable.PagerHeader_inactiveTextColor, Color.LTGRAY));
    mTabColor =
        new ColorSet(a.getColor(R.styleable.PagerHeader_tabColor, mActiveTextColor.getColor()));
    mTabHeight = a.getDimensionPixelSize(R.styleable.PagerHeader_tabHeight, dipToPixels(4));
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerHeader_tabPadding, dipToPixels(10));
    mPaddingPush = a.getDimensionPixelSize(R.styleable.PagerHeader_paddingPush, dipToPixels(50));
    mFadingEdgeLength =
        a.getDimensionPixelSize(R.styleable.PagerHeader_fadingEdgeLength, dipToPixels(30));
    mShowTopShadow = a.getBoolean(R.styleable.PagerHeader_showTopShadow, true);
    mShowBottomBar = a.getBoolean(R.styleable.PagerHeader_showBottomBar, true);
    mShowTab = a.getBoolean(R.styleable.PagerHeader_showTab, true);

    ColorSet fadingEdgeColorHint = new ColorSet(0);
    int backgroundColor = a.getColor(R.styleable.PagerHeader_backgroundColor, Color.DKGRAY);
    setBackgroundColor(backgroundColor);
    fadingEdgeColorHint.setColor(backgroundColor);

    mTabDrawable = new ShapeDrawable(new RectShape());
    mTabDrawable.getPaint().setColor(mTabColor.getColor());

    mBottomBar = new ShapeDrawable(new RectShape());
    mBottomBar.getPaint().setColor(mTabColor.getColor());
    mBottomBarHeight = dipToPixels(2);

    mShadow =
        new GradientDrawable(
            GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0x88000000, 0x00000000});
    mShadowHeight = dipToPixels(3);

    int[] fadingEdgeGradient =
        new int[] {fadingEdgeColorHint.getColor(), fadingEdgeColorHint.getColor(0)};
    mFadingEdgeLeft =
        new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, fadingEdgeGradient);
    mFadingEdgeRight =
        new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, fadingEdgeGradient);

    final ViewConfiguration config = ViewConfiguration.get(context);
    int touchSlop = config.getScaledTouchSlop();
    mTouchSlopSquare = touchSlop * touchSlop;
  }
  public void setPosition(int position, float positionOffset, int positionOffsetPixels) {
    mTouchZonesAccurate = false;
    int width = getWidth();
    int center = width / 2;

    // Move the view at position. This will be the label for the left
    // of the two fragments that may be on the screen
    if (position >= 0 && position < getChildCount()) {
      TextView view = (TextView) getChildAt(position);
      int viewWidth = view.getWidth();
      int leftMin = 0;
      if (position + 1 < getChildCount()) {
        int nextViewWidth = getChildAt(position + 1).getWidth();
        leftMin = Math.min(0, center - (nextViewWidth / 2) - mPaddingPush - viewWidth);
      }
      int leftMax = center - (viewWidth / 2);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mInactiveTextColor.red, mActiveTextColor.red),
              map(positionOffset, 1, 0, mInactiveTextColor.green, mActiveTextColor.green),
              map(positionOffset, 1, 0, mInactiveTextColor.blue, mActiveTextColor.blue)));
    }

    // Move the view at position + 1. This will be the label for the
    // right of the two fragments that may be visible on screen
    if ((position + 1) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 1);
      int viewWidth = view.getWidth();
      int prevViewWidth = getChildAt(position).getWidth();
      int leftMin = center - (viewWidth / 2);
      int leftMax = Math.max(width - viewWidth, center + (prevViewWidth / 2) + mPaddingPush);
      int newLeft = map(positionOffset, 1, 0, leftMin, leftMax);
      view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
      view.setTextColor(
          Color.rgb(
              map(positionOffset, 1, 0, mActiveTextColor.red, mInactiveTextColor.red),
              map(positionOffset, 1, 0, mActiveTextColor.green, mInactiveTextColor.green),
              map(positionOffset, 1, 0, mActiveTextColor.blue, mInactiveTextColor.blue)));
    }

    // Move the view at position - 1. This will be the label for the
    // fragment that is off the screen to the left, if it exists
    if (position > 0) {
      TextView view = (TextView) getChildAt(position - 1);
      int plusOneLeft = getChildAt(position).getLeft();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (plusOneLeft < newLeft + viewWidth + mPaddingPush || newLeft < 0) {
        newLeft = Math.min(0, plusOneLeft - viewWidth - mPaddingPush);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 1, 0, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Move the view at position + 2. This will be the label for the
    // fragment that is off the screen to the right, if it exists
    if ((position + 2) < getChildCount()) {
      TextView view = (TextView) getChildAt(position + 2);
      int minusOneRight = getChildAt(position + 1).getRight();
      int newLeft = view.getLeft();
      int viewWidth = view.getWidth();
      if (minusOneRight > (newLeft - mPaddingPush) || newLeft + viewWidth > width) {
        newLeft = Math.max(minusOneRight + mPaddingPush, width - viewWidth);
        view.layout(newLeft, view.getTop(), newLeft + viewWidth, view.getBottom());
        int alpha = map(positionOffset, 0, 1, 0, 255);
        view.setTextColor(mInactiveTextColor.getColor(alpha));
      }
    }

    // Draw the tab under the active or oncoming TextView based on the
    // positionOffset
    View view = getChildAt(positionOffset < 0.5f ? position : position + 1);
    int viewLeft = view.getLeft();
    int viewRight = view.getRight();
    float percent = (Math.abs(positionOffset - 0.5f) / 0.5f);
    int tabHeight = (int) (mTabHeight * percent);
    int alpha = (int) (255 * percent);
    mTabDrawable.setBounds(
        viewLeft - mTabPadding, getHeight() - tabHeight, viewRight + mTabPadding, getHeight());
    mTabDrawable.setAlpha(alpha);
  }