예제 #1
0
 private View getNeededView(int position) {
   if (mTabProvider != null && mTabProvider instanceof TitleIconTabProvider) {
     final int imageViewId = ((TitleIconTabProvider) mTabProvider).getTextOrImageViewId();
     return mNiceTabStrip.getChildAt(position).findViewById(imageViewId);
   } else {
     return mNiceTabStrip.getChildAt(position);
   }
 }
예제 #2
0
  private void scrollToTab(int position, int positionOffset) {
    final int tabStripChildCount = mNiceTabStrip.getChildCount();
    if (tabStripChildCount == 0 || position < 0 || position >= tabStripChildCount) {
      return;
    }

    View selectedTab = mNiceTabStrip.getChildAt(position);
    if (selectedTab != null) {
      int targetScrollX = selectedTab.getLeft() + positionOffset;
      if (mNiceTabStrip.isTabSelectedCenter()) {
        targetScrollX -= (mNiceTabStrip.getChildAt(0).getWidth() - selectedTab.getWidth()) / 2;
      } else if (position > 0 || positionOffset > 0) {
        targetScrollX -= mTabOffset;
      }

      scrollTo(targetScrollX, 0);
    }
  }
예제 #3
0
 /**
  * Sets divider show hide.
  *
  * @param showDivider show hide.
  */
 public void setShowDivider(boolean showDivider) {
   mNiceTabStrip.setShowDivider(showDivider);
   postDelayed(
       new Runnable() {
         @Override
         public void run() {
           scrollToTab(mViewPager.getCurrentItem(), 0);
         }
       },
       100);
 }
예제 #4
0
 void changeTabLayoutPadding(boolean tabSelectedCenter, boolean isTabDistributeEvenly) {
   if (tabSelectedCenter) {
     final int paddingLeft, paddingRight;
     if (isTabDistributeEvenly) {
       paddingLeft = (getWidth() - mNiceTabStrip.getTabEvenlyWidth()) / 2;
       paddingRight = (getWidth() - mNiceTabStrip.getTabEvenlyWidth()) / 2;
     } else {
       paddingLeft = (getWidth() - mNiceTabStrip.getFirstTabWidth()) / 2;
       paddingRight = (getWidth() - mNiceTabStrip.getLastTabWidth()) / 2;
     }
     mUserSetPadding = false;
     setPadding(paddingLeft, getPaddingTop(), paddingRight, getPaddingBottom());
     mUserSetPadding = true;
     setClipToPadding(false);
   } else {
     mUserSetPadding = false;
     setPadding(mCachedPaddingLeft, getPaddingTop(), mCachedPaddingRight, getPaddingBottom());
     mUserSetPadding = true;
   }
 }
예제 #5
0
 /**
  * Sets weather tab distribute evenly, if true, every tab width will set to the most wide tab
  * width.
  */
 public void setDistributeEvenly(final boolean distributeEvenly) {
   mNiceTabStrip.setTabDistributeEvenly(distributeEvenly);
   postDelayed(
       new Runnable() {
         @Override
         public void run() {
           scrollToTab(mViewPager.getCurrentItem(), 0);
         }
       },
       100);
 }
예제 #6
0
 /** Sets weather selected tab layout in center. */
 public void setTabSelectedCenter(final boolean tabSelectedCenter) {
   mNiceTabStrip.setTabSelectedCenter(tabSelectedCenter);
   postDelayed(
       new Runnable() {
         @Override
         public void run() {
           scrollToTab(mViewPager.getCurrentItem(), 0);
         }
       },
       100);
 }
예제 #7
0
  /** Populate TabStrip tabs. */
  private void populateTabStrip() {
    mNiceTabStrip.removeAllViews();

    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
      View tabView;

      if (mTabProvider != null) {
        tabView = mTabProvider.createTabView(mNiceTabStrip, i, adapter);
      } else {
        tabView = createDefaultTabView(i);
      }

      tabView.setOnClickListener(tabClickListener);

      mNiceTabStrip.addView(tabView);
    }
  }
예제 #8
0
  /**
   * Sets blurred view.
   *
   * @param blurredView the view to be blurred. (Set null to cancel blur)
   * @param blurredBackgroundColor the view's background color. (if blurredView's background is
   *     color, give the color to me, if is not color, give 0{@link
   *     android.graphics.Color#TRANSPARENT} to me, if blurredView's background is null, give a
   *     proper color to me, i.e blurredView's parent background color or window's background color.
   */
  public void setBlurredView(View blurredView, int blurredBackgroundColor) {
    if (blurredView != null) {
      mUserSetBackground = false;
      setBackgroundDrawable(null);
      mUserSetBackground = true;
    } else {
      mUserSetBackground = false;
      setBackgroundDrawable(mCachedBackground);
      mUserSetBackground = true;
    }

    mNiceTabStrip.setBlurredView(blurredView, blurredBackgroundColor);
  }
예제 #9
0
 /**
  * Gets tab badge text.
  *
  * @param position tab position.
  * @return null(small badge, or tab has no badge with given position) or badge text.
  */
 public String getBadgeText(int position) {
   return mNiceTabStrip.getBadgeText(position);
 }
예제 #10
0
 /**
  * Remove tab badge with given position.
  *
  * @param position tab position.
  * @return the badge or null(no position or no badges).
  */
 public Badge removeBadge(int position) {
   return mNiceTabStrip.removeBadge(position);
 }
예제 #11
0
 /**
  * Sets tab badge(small size).
  *
  * @param position tab position.
  */
 public void setBadgeSmall(int position) {
   mNiceTabStrip.setBadgeSmall(position);
 }
예제 #12
0
 /**
  * Sets the colors to be used for indicating the selected tab. These colors are treated as a
  * circular array. Providing one color will mean that all tabs are indicated with the same color.
  */
 public void setIndicatorColors(int... colors) {
   mNiceTabStrip.setIndicatorColors(colors);
 }
예제 #13
0
 /** Sets indicator underline divider draw order. */
 public void setDrawOrder(NiceTabStrip.DrawOrder drawOrder) {
   mNiceTabStrip.setDrawOrder(drawOrder);
 }
예제 #14
0
 public void invalidateBlur() {
   mNiceTabStrip.invalidate();
 }
예제 #15
0
 /**
  * Sets the blur overlay color.
  *
  * @param color the blur overlay color.
  */
 public void setOverlayColor(int color) {
   mNiceTabStrip.setOverlayColor(color);
 }
예제 #16
0
 /**
  * Sets the blur down sample factor.
  *
  * @param factor the blur down sample factor.
  */
 public void setDownSampleFactor(int factor) {
   mNiceTabStrip.setDownSampleFactor(factor);
 }
예제 #17
0
 /**
  * Sets the blur radius.
  *
  * @param radius the blur radius.
  */
 public void setBlurRadius(int radius) {
   mNiceTabStrip.setBlurRadius(radius);
 }
예제 #18
0
 /** Clears all tab badges. */
 public void clearBadge() {
   mNiceTabStrip.clearBadge();
 }
예제 #19
0
 /**
  * Sets underline show hide.
  *
  * @param showUnderline show hide.
  */
 public void setShowUnderline(boolean showUnderline) {
   mNiceTabStrip.setShowUnderline(showUnderline);
 }
예제 #20
0
 /**
  * Register a callback to be invoked when indicator color changed.
  *
  * @param listener The callback that will run
  */
 public void setOnIndicatorColorChangedListener(
     NiceTabStrip.OnIndicatorColorChangedListener listener) {
   mNiceTabStrip.setOnIndicatorColorChangedListener(listener);
 }
예제 #21
0
 /**
  * Set the custom {@link NiceTabStrip.TabStripColorize} to be used, if set to null, then uses
  * default TabColorize
  *
  * <p>If you only require simple customisation then you can use {@link
  * #setIndicatorColors(int...)} and {@link #setDividerColors(int...)} to achieve similar effects.
  */
 public void setTabStripColorize(NiceTabStrip.TabStripColorize tabColorize) {
   mNiceTabStrip.setTabStripColorize(tabColorize);
 }
예제 #22
0
  /** Reset all tab to defaults and select current page tab. */
  private void resetTabStrip() {
    int childCount = mNiceTabStrip.getChildCount();
    int selectedPosition = mViewPager.getCurrentItem();
    for (int i = 0; i < childCount; i++) {
      View view = getNeededView(i);

      switch (mTabMode) {
        case TITLE_ONLY:
          {
            ((TextView) view)
                .setTextColor(
                    i == selectedPosition
                        ? mTabColorize.getSelectedTabColor(i)
                        : mTabColorize.getDefaultTabColor(i));
            break;
          }
        case ICON_ONLY:
          {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (mIconCrossFade && drawable instanceof CrossFadeDrawable) {
              //                        tintDrawable(((CrossFadeDrawable)
              // drawable).getFading().mutate(), mTabColorize.getSelectedTabColor(i));
              tintDrawable(
                  ((CrossFadeDrawable) drawable).getFading(), mTabColorize.getSelectedTabColor(i));
              //                        tintDrawable(((CrossFadeDrawable)
              // drawable).getBase().mutate(), mTabColorize.getDefaultTabColor(i));
              tintDrawable(
                  ((CrossFadeDrawable) drawable).getBase(), mTabColorize.getDefaultTabColor(i));
              crossFadeDrawable(drawable, i == selectedPosition ? 1f : 0f);
            }
            break;
          }
        case BOTH:
          {
            final int color =
                i == selectedPosition
                    ? mTabColorize.getSelectedTabColor(i)
                    : mTabColorize.getDefaultTabColor(i);
            ((TextView) view).setTextColor(color);

            Drawable drawable = ((TextView) view).getCompoundDrawables()[1];
            if (mIconCrossFade && drawable instanceof CrossFadeDrawable) {
              //                        tintDrawable(((CrossFadeDrawable)
              // drawable).getFading().mutate(), mTabColorize.getSelectedTabColor(i));
              tintDrawable(
                  ((CrossFadeDrawable) drawable).getFading(), mTabColorize.getSelectedTabColor(i));
              //                        tintDrawable(((CrossFadeDrawable)
              // drawable).getBase().mutate(), mTabColorize.getDefaultTabColor(i));
              tintDrawable(
                  ((CrossFadeDrawable) drawable).getBase(), mTabColorize.getDefaultTabColor(i));
              crossFadeDrawable(drawable, i == selectedPosition ? 1f : 0f);
            } else {
              //                        tintDrawable(drawable.mutate(), color);
              tintDrawable(drawable, color);
            }
            break;
          }
      }

      view.setSelected(i == selectedPosition);
    }
  }
예제 #23
0
 /**
  * Sets indicator show hide.
  *
  * @param showIndicator show hide.
  */
 public void setShowIndicator(boolean showIndicator) {
   mNiceTabStrip.setShowIndicator(showIndicator);
 }
예제 #24
0
 @Override
 protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
   super.onSizeChanged(width, height, oldWidth, oldHeight);
   changeTabLayoutPadding(
       mNiceTabStrip.isTabSelectedCenter(), mNiceTabStrip.isTabDistributeEvenly());
 }
예제 #25
0
 /**
  * Sets tab badge(normal size).
  *
  * @param position tab position.
  * @param text tab badge text, if text is null, do nothing.
  */
 public void setBadge(int position, String text) {
   mNiceTabStrip.setBadge(position, text);
 }
예제 #26
0
 @Override
 protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
   mNiceTabStrip.invalidate();
 }
예제 #27
0
 /**
  * Sets the colors to be used for tab dividers. These colors are treated as a circular array.
  * Providing one color will mean that all tabs are indicated with the same color.
  */
 public void setDividerColors(int... colors) {
   mNiceTabStrip.setDividerColors(colors);
 }