@@ -70,16 +70,17 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
70
70
private final static int DEFAULT_ACTIVE_COLOR = Color .WHITE ;
71
71
72
72
private final static float MIN_FRACTION = 0.0f ;
73
+ private final static float NON_SCALED_FRACTION = 0.35f ;
73
74
private final static float MAX_FRACTION = 1.0f ;
74
75
75
76
private final static int MIN_ALPHA = 0 ;
76
77
private final static int MAX_ALPHA = 255 ;
77
78
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 ;
80
81
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 ;
83
84
private final static float TITLE_ACTIVE_SCALE_BY = 0.2f ;
84
85
private final static float TITLE_SIZE_FRACTION = 0.2f ;
85
86
private final static float TITLE_MARGIN_FRACTION = 0.15f ;
@@ -227,6 +228,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
227
228
private boolean mIsTitled ;
228
229
// Detect if model has badge
229
230
private boolean mIsBadged ;
231
+ // Detect if model icon scaled
232
+ private boolean mIsScaled ;
230
233
// Detect if model badge have custom typeface
231
234
private boolean mIsBadgeUseTypeface ;
232
235
// Detect if is bar mode or indicator pager mode
@@ -274,6 +277,9 @@ public NavigationTabBar(final Context context, final AttributeSet attrs, final i
274
277
setIsBadged (
275
278
typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_badged , false )
276
279
);
280
+ setIsScaled (
281
+ typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_scaled , true )
282
+ );
277
283
setIsBadgeUseTypeface (
278
284
typedArray .getBoolean (R .styleable .NavigationTabBar_ntb_badge_use_typeface , false )
279
285
);
@@ -395,6 +401,15 @@ public void setIsBadged(final boolean isBadged) {
395
401
requestLayout ();
396
402
}
397
403
404
+ public boolean isScaled () {
405
+ return mIsScaled ;
406
+ }
407
+
408
+ public void setIsScaled (final boolean isScaled ) {
409
+ mIsScaled = isScaled ;
410
+ requestLayout ();
411
+ }
412
+
398
413
public boolean isBadgeUseTypeface () {
399
414
return mIsBadgeUseTypeface ;
400
415
}
@@ -912,18 +927,26 @@ protected void onDraw(final Canvas canvas) {
912
927
// Get interpolated fraction for left last and current models
913
928
final float interpolation = mResizeInterpolator .getResizeInterpolation (mFraction , true );
914
929
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);
915
935
916
936
// 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 ));
919
941
920
942
// Get title alpha relative to interpolation
921
943
final int titleAlpha = (int ) (MAX_ALPHA * interpolation );
922
944
final int titleLastAlpha = MAX_ALPHA - (int ) (MAX_ALPHA * lastInterpolation );
923
945
// 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 ;
927
950
928
951
// Check if we handle models from touch on NTP or from ViewPager
929
952
// There is a strange logic of ViewPager onPageScrolled method, so it is
@@ -940,12 +963,14 @@ else if (mLastIndex == i)
940
963
);
941
964
else
942
965
updateInactiveModel (
943
- model , leftOffset , topOffset , matrixCenterX , matrixCenterY
966
+ model , leftOffset , topOffset , titleScale ,
967
+ matrixScale , matrixCenterX , matrixCenterY
944
968
);
945
969
} else {
946
970
if (i != mIndex && i != mIndex + 1 )
947
971
updateInactiveModel (
948
- model , leftOffset , topOffset , matrixCenterX , matrixCenterY
972
+ model , leftOffset , topOffset , titleScale ,
973
+ matrixScale , matrixCenterX , matrixCenterY
949
974
);
950
975
else if (i == mIndex + 1 )
951
976
updateCurrentModel (
@@ -1111,17 +1136,25 @@ private void updateInactiveModel(
1111
1136
final Model model ,
1112
1137
final float leftOffset ,
1113
1138
final float topOffset ,
1139
+ final float textScale ,
1140
+ final float matrixScale ,
1114
1141
final float matrixCenterX ,
1115
1142
final float matrixCenterY
1116
1143
) {
1117
1144
if (mIsTitled && mTitleMode == TitleMode .ACTIVE )
1118
1145
model .mIconMatrix .setTranslate (leftOffset , topOffset );
1119
1146
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
+ );
1123
1156
1124
- mModelTitlePaint .setTextSize (mModelTitleSize );
1157
+ mModelTitlePaint .setTextSize (mModelTitleSize * ( mIsScaled ? 1.0f : textScale ) );
1125
1158
if (mTitleMode == TitleMode .ACTIVE ) mModelTitlePaint .setAlpha (MIN_ALPHA );
1126
1159
}
1127
1160
0 commit comments