Skip to content

Commit 0707967

Browse files
committed
Update 1.1.5
1 parent b331fe4 commit 0707967

File tree

6 files changed

+61
-19
lines changed

6 files changed

+61
-19
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333
Or Gradle Maven Central:
3434

3535
```groovy
36-
compile 'com.github.devlight.navigationtabbar:library:1.1.4'
36+
compile 'com.github.devlight.navigationtabbar:library:1.1.5'
3737
```
3838

3939
Or Maven:
@@ -42,7 +42,7 @@ Or Maven:
4242
<dependency>
4343
<groupId>com.github.devlight.navigationtabbar</groupId>
4444
<artifactId>library</artifactId>
45-
<version>1.1.4</version>
45+
<version>1.1.5</version>
4646
<type>aar</type>
4747
</dependency>
4848
```
@@ -81,6 +81,10 @@ For NTB you can set such parameters as:
8181

8282
allows you to handle mode of the model title show. Can show all or only active.
8383

84+
- scale mode:
85+
86+
allows you to handle mode of the model icon and title scale.
87+
8488
- badge position:
8589

8690
allows you to set the badge position in you model. Can be: left(25%), center(50%) and right(75%).
@@ -187,6 +191,7 @@ And XML init:
187191
app:ntb_inactive_color="#000"
188192
app:ntb_badged="true"
189193
app:ntb_titled="true"
194+
app:ntb_scaled="true"
190195
app:ntb_title_mode="all"
191196
app:ntb_badge_position="right"
192197
app:ntb_badge_gravity="top"

app/src/main/res/layout/activity_horizontal_ntb.xml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
app:ntb_badge_gravity="top"
3434
app:ntb_badge_position="right"
3535
app:ntb_badged="true"
36+
app:ntb_scaled="true"
3637
app:ntb_title_mode="all"
3738
app:ntb_titled="true"/>
3839

app/src/main/res/layout/activity_samples_ntb.xml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
android:layout_gravity="center"
2929
android:background="#605271"
3030
app:ntb_active_color="#000"
31+
app:ntb_scaled="false"
3132
app:ntb_inactive_color="#fff"
3233
app:ntb_animation_duration="1000"/>
3334

@@ -108,6 +109,7 @@
108109
app:ntb_animation_duration="400"
109110
app:ntb_preview_colors="@array/red_wine"
110111
app:ntb_corners_radius="50dp"
112+
app:ntb_scaled="false"
111113
app:ntb_active_color="#8d88e4"
112114
app:ntb_inactive_color="#dddfec"/>
113115

library/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray"
1919
apply plugin: 'com.github.dcendents.android-maven'
2020
apply plugin: 'maven'
2121

22-
version = "1.1.4"
22+
version = "1.1.5"
2323

2424
android {
2525
compileSdkVersion 23
@@ -29,7 +29,7 @@ android {
2929
minSdkVersion 11
3030
targetSdkVersion 23
3131
versionCode 1
32-
versionName "1.1.4"
32+
versionName "1.1.5"
3333
}
3434
buildTypes {
3535
release {

library/src/main/java/com/gigamole/library/NavigationTabBar.java

+48-15
Original file line numberDiff line numberDiff line change
@@ -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

library/src/main/res/values/attrs.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<declare-styleable name="NavigationTabBar">
55
<attr name="ntb_titled" format="boolean"/>
66
<attr name="ntb_badged" format="boolean"/>
7+
<attr name="ntb_scaled" format="boolean"/>
78
<attr name="ntb_badge_use_typeface" format="boolean"/>
89

910
<attr name="ntb_title_mode" format="enum">

0 commit comments

Comments
 (0)