@@ -70,16 +70,17 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
7070 private final static int DEFAULT_ACTIVE_COLOR = Color .WHITE ;
7171
7272 private final static float MIN_FRACTION = 0.0f ;
73+ private final static float NON_SCALED_FRACTION = 0.35f ;
7374 private final static float MAX_FRACTION = 1.0f ;
7475
7576 private final static int MIN_ALPHA = 0 ;
7677 private final static int MAX_ALPHA = 255 ;
7778
78- private final static float ACTIVE_ICON_SCALE_BY = 0.35f ;
79- private final static float ICON_SIZE_FRACTION = 0.4f ;
79+ private final static float ACTIVE_ICON_SCALE_BY = 0.3f ;
80+ private final static float ICON_SIZE_FRACTION = 0.45f ;
8081
81- private final static float TITLE_ACTIVE_ICON_SCALE_BY = 0.25f ;
82- private final static float TITLE_ICON_SIZE_FRACTION = 0.4f ;
82+ private final static float TITLE_ACTIVE_ICON_SCALE_BY = 0.2f ;
83+ private final static float TITLE_ICON_SIZE_FRACTION = 0.45f ;
8384 private final static float TITLE_ACTIVE_SCALE_BY = 0.2f ;
8485 private final static float TITLE_SIZE_FRACTION = 0.2f ;
8586 private final static float TITLE_MARGIN_FRACTION = 0.15f ;
@@ -227,6 +228,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
227228 private boolean mIsTitled ;
228229 // Detect if model has badge
229230 private boolean mIsBadged ;
231+ // Detect if model icon scaled
232+ private boolean mIsScaled ;
230233 // Detect if model badge have custom typeface
231234 private boolean mIsBadgeUseTypeface ;
232235 // Detect if is bar mode or indicator pager mode
@@ -274,6 +277,9 @@ public NavigationTabBar(final Context context, final AttributeSet attrs, final i
274277 setIsBadged (
275278 typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_badged , false )
276279 );
280+ setIsScaled (
281+ typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_scaled , true )
282+ );
277283 setIsBadgeUseTypeface (
278284 typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_badge_use_typeface , false )
279285 );
@@ -395,6 +401,15 @@ public void setIsBadged(final boolean isBadged) {
395401 requestLayout ();
396402 }
397403
404+ public boolean isScaled () {
405+ return mIsScaled ;
406+ }
407+
408+ public void setIsScaled (final boolean isScaled ) {
409+ mIsScaled = isScaled ;
410+ requestLayout ();
411+ }
412+
398413 public boolean isBadgeUseTypeface () {
399414 return mIsBadgeUseTypeface ;
400415 }
@@ -912,18 +927,26 @@ protected void onDraw(final Canvas canvas) {
912927 // Get interpolated fraction for left last and current models
913928 final float interpolation = mResizeInterpolator .getResizeInterpolation (mFraction , true );
914929 final float lastInterpolation = mResizeInterpolator .getResizeInterpolation (mFraction , false );
930+ // final float interpolation =
931+ // mIsScaled ? mResizeInterpolator.getResizeInterpolation(mFraction, true);
932+ // final float lastInterpolation =
933+ // mIsScaled ? mResizeInterpolator.getResizeInterpolation(mFraction, false) :
934+ // (MAX_FRACTION - NON_SCALED_FRACTION);
915935
916936 // Scale value relative to interpolation
917- final float matrixScale = model .mActiveIconScaleBy * interpolation ;
918- final float matrixLastScale = model .mActiveIconScaleBy * lastInterpolation ;
937+ final float matrixScale = model .mActiveIconScaleBy *
938+ (mIsScaled ? interpolation : NON_SCALED_FRACTION );
939+ final float matrixLastScale = model .mActiveIconScaleBy *
940+ (mIsScaled ? lastInterpolation : (MAX_FRACTION - NON_SCALED_FRACTION ));
919941
920942 // Get title alpha relative to interpolation
921943 final int titleAlpha = (int ) (MAX_ALPHA * interpolation );
922944 final int titleLastAlpha = MAX_ALPHA - (int ) (MAX_ALPHA * lastInterpolation );
923945 // Get title scale relative to interpolation
924- final float titleScale = MAX_FRACTION + (interpolation * TITLE_ACTIVE_SCALE_BY );
925- final float titleLastScale = (MAX_FRACTION + TITLE_ACTIVE_SCALE_BY ) -
926- (lastInterpolation * TITLE_ACTIVE_SCALE_BY );
946+ final float titleScale = MAX_FRACTION +
947+ ((mIsScaled ? interpolation : NON_SCALED_FRACTION ) * TITLE_ACTIVE_SCALE_BY );
948+ final float titleLastScale = mIsScaled ? (MAX_FRACTION + TITLE_ACTIVE_SCALE_BY ) -
949+ (lastInterpolation * TITLE_ACTIVE_SCALE_BY ) : titleScale ;
927950
928951 // Check if we handle models from touch on NTP or from ViewPager
929952 // There is a strange logic of ViewPager onPageScrolled method, so it is
@@ -940,12 +963,14 @@ else if (mLastIndex == i)
940963 );
941964 else
942965 updateInactiveModel (
943- model , leftOffset , topOffset , matrixCenterX , matrixCenterY
966+ model , leftOffset , topOffset , titleScale ,
967+ matrixScale , matrixCenterX , matrixCenterY
944968 );
945969 } else {
946970 if (i != mIndex && i != mIndex + 1 )
947971 updateInactiveModel (
948- model , leftOffset , topOffset , matrixCenterX , matrixCenterY
972+ model , leftOffset , topOffset , titleScale ,
973+ matrixScale , matrixCenterX , matrixCenterY
949974 );
950975 else if (i == mIndex + 1 )
951976 updateCurrentModel (
@@ -1111,17 +1136,25 @@ private void updateInactiveModel(
11111136 final Model model ,
11121137 final float leftOffset ,
11131138 final float topOffset ,
1139+ final float textScale ,
1140+ final float matrixScale ,
11141141 final float matrixCenterX ,
11151142 final float matrixCenterY
11161143 ) {
11171144 if (mIsTitled && mTitleMode == TitleMode .ACTIVE )
11181145 model .mIconMatrix .setTranslate (leftOffset , topOffset );
11191146
1120- model .mIconMatrix .postScale (
1121- model .mInactiveIconScale , model .mInactiveIconScale , matrixCenterX , matrixCenterY
1122- );
1147+ if (mIsScaled )
1148+ model .mIconMatrix .postScale (
1149+ model .mInactiveIconScale , model .mInactiveIconScale , matrixCenterX , matrixCenterY
1150+ );
1151+ else
1152+ model .mIconMatrix .postScale (
1153+ model .mInactiveIconScale + matrixScale , model .mInactiveIconScale + matrixScale ,
1154+ matrixCenterX , matrixCenterY
1155+ );
11231156
1124- mModelTitlePaint .setTextSize (mModelTitleSize );
1157+ mModelTitlePaint .setTextSize (mModelTitleSize * ( mIsScaled ? 1.0f : textScale ) );
11251158 if (mTitleMode == TitleMode .ACTIVE ) mModelTitlePaint .setAlpha (MIN_ALPHA );
11261159 }
11271160
0 commit comments