Skip to content

Commit

Permalink
Update 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
GIGAMOLE committed Apr 19, 2016
1 parent b331fe4 commit 0707967
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 19 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
Or Gradle Maven Central:

```groovy
compile 'com.github.devlight.navigationtabbar:library:1.1.4'
compile 'com.github.devlight.navigationtabbar:library:1.1.5'
```

Or Maven:
Expand All @@ -42,7 +42,7 @@ Or Maven:
<dependency>
<groupId>com.github.devlight.navigationtabbar</groupId>
<artifactId>library</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<type>aar</type>
</dependency>
```
Expand Down Expand Up @@ -81,6 +81,10 @@ For NTB you can set such parameters as:

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

- scale mode:

allows you to handle mode of the model icon and title scale.

- badge position:

allows you to set the badge position in you model. Can be: left(25%), center(50%) and right(75%).
Expand Down Expand Up @@ -187,6 +191,7 @@ And XML init:
app:ntb_inactive_color="#000"
app:ntb_badged="true"
app:ntb_titled="true"
app:ntb_scaled="true"
app:ntb_title_mode="all"
app:ntb_badge_position="right"
app:ntb_badge_gravity="top"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_horizontal_ntb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
app:ntb_badge_gravity="top"
app:ntb_badge_position="right"
app:ntb_badged="true"
app:ntb_scaled="true"
app:ntb_title_mode="all"
app:ntb_titled="true"/>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_samples_ntb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
android:layout_gravity="center"
android:background="#605271"
app:ntb_active_color="#000"
app:ntb_scaled="false"
app:ntb_inactive_color="#fff"
app:ntb_animation_duration="1000"/>

Expand Down Expand Up @@ -108,6 +109,7 @@
app:ntb_animation_duration="400"
app:ntb_preview_colors="@array/red_wine"
app:ntb_corners_radius="50dp"
app:ntb_scaled="false"
app:ntb_active_color="#8d88e4"
app:ntb_inactive_color="#dddfec"/>

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven'

version = "1.1.4"
version = "1.1.5"

android {
compileSdkVersion 23
Expand All @@ -29,7 +29,7 @@ android {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.1.4"
versionName "1.1.5"
}
buildTypes {
release {
Expand Down
63 changes: 48 additions & 15 deletions library/src/main/java/com/gigamole/library/NavigationTabBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
private final static int DEFAULT_ACTIVE_COLOR = Color.WHITE;

private final static float MIN_FRACTION = 0.0f;
private final static float NON_SCALED_FRACTION = 0.35f;
private final static float MAX_FRACTION = 1.0f;

private final static int MIN_ALPHA = 0;
private final static int MAX_ALPHA = 255;

private final static float ACTIVE_ICON_SCALE_BY = 0.35f;
private final static float ICON_SIZE_FRACTION = 0.4f;
private final static float ACTIVE_ICON_SCALE_BY = 0.3f;
private final static float ICON_SIZE_FRACTION = 0.45f;

private final static float TITLE_ACTIVE_ICON_SCALE_BY = 0.25f;
private final static float TITLE_ICON_SIZE_FRACTION = 0.4f;
private final static float TITLE_ACTIVE_ICON_SCALE_BY = 0.2f;
private final static float TITLE_ICON_SIZE_FRACTION = 0.45f;
private final static float TITLE_ACTIVE_SCALE_BY = 0.2f;
private final static float TITLE_SIZE_FRACTION = 0.2f;
private final static float TITLE_MARGIN_FRACTION = 0.15f;
Expand Down Expand Up @@ -227,6 +228,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList
private boolean mIsTitled;
// Detect if model has badge
private boolean mIsBadged;
// Detect if model icon scaled
private boolean mIsScaled;
// Detect if model badge have custom typeface
private boolean mIsBadgeUseTypeface;
// Detect if is bar mode or indicator pager mode
Expand Down Expand Up @@ -274,6 +277,9 @@ public NavigationTabBar(final Context context, final AttributeSet attrs, final i
setIsBadged(
typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)
);
setIsScaled(
typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true)
);
setIsBadgeUseTypeface(
typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)
);
Expand Down Expand Up @@ -395,6 +401,15 @@ public void setIsBadged(final boolean isBadged) {
requestLayout();
}

public boolean isScaled() {
return mIsScaled;
}

public void setIsScaled(final boolean isScaled) {
mIsScaled = isScaled;
requestLayout();
}

public boolean isBadgeUseTypeface() {
return mIsBadgeUseTypeface;
}
Expand Down Expand Up @@ -912,18 +927,26 @@ protected void onDraw(final Canvas canvas) {
// Get interpolated fraction for left last and current models
final float interpolation = mResizeInterpolator.getResizeInterpolation(mFraction, true);
final float lastInterpolation = mResizeInterpolator.getResizeInterpolation(mFraction, false);
// final float interpolation =
// mIsScaled ? mResizeInterpolator.getResizeInterpolation(mFraction, true);
// final float lastInterpolation =
// mIsScaled ? mResizeInterpolator.getResizeInterpolation(mFraction, false) :
// (MAX_FRACTION - NON_SCALED_FRACTION);

// Scale value relative to interpolation
final float matrixScale = model.mActiveIconScaleBy * interpolation;
final float matrixLastScale = model.mActiveIconScaleBy * lastInterpolation;
final float matrixScale = model.mActiveIconScaleBy *
(mIsScaled ? interpolation : NON_SCALED_FRACTION);
final float matrixLastScale = model.mActiveIconScaleBy *
(mIsScaled ? lastInterpolation : (MAX_FRACTION - NON_SCALED_FRACTION));

// Get title alpha relative to interpolation
final int titleAlpha = (int) (MAX_ALPHA * interpolation);
final int titleLastAlpha = MAX_ALPHA - (int) (MAX_ALPHA * lastInterpolation);
// Get title scale relative to interpolation
final float titleScale = MAX_FRACTION + (interpolation * TITLE_ACTIVE_SCALE_BY);
final float titleLastScale = (MAX_FRACTION + TITLE_ACTIVE_SCALE_BY) -
(lastInterpolation * TITLE_ACTIVE_SCALE_BY);
final float titleScale = MAX_FRACTION +
((mIsScaled ? interpolation : NON_SCALED_FRACTION) * TITLE_ACTIVE_SCALE_BY);
final float titleLastScale = mIsScaled ? (MAX_FRACTION + TITLE_ACTIVE_SCALE_BY) -
(lastInterpolation * TITLE_ACTIVE_SCALE_BY) : titleScale;

// Check if we handle models from touch on NTP or from ViewPager
// There is a strange logic of ViewPager onPageScrolled method, so it is
Expand All @@ -940,12 +963,14 @@ else if (mLastIndex == i)
);
else
updateInactiveModel(
model, leftOffset, topOffset, matrixCenterX, matrixCenterY
model, leftOffset, topOffset, titleScale,
matrixScale, matrixCenterX, matrixCenterY
);
} else {
if (i != mIndex && i != mIndex + 1)
updateInactiveModel(
model, leftOffset, topOffset, matrixCenterX, matrixCenterY
model, leftOffset, topOffset, titleScale,
matrixScale, matrixCenterX, matrixCenterY
);
else if (i == mIndex + 1)
updateCurrentModel(
Expand Down Expand Up @@ -1111,17 +1136,25 @@ private void updateInactiveModel(
final Model model,
final float leftOffset,
final float topOffset,
final float textScale,
final float matrixScale,
final float matrixCenterX,
final float matrixCenterY
) {
if (mIsTitled && mTitleMode == TitleMode.ACTIVE)
model.mIconMatrix.setTranslate(leftOffset, topOffset);

model.mIconMatrix.postScale(
model.mInactiveIconScale, model.mInactiveIconScale, matrixCenterX, matrixCenterY
);
if (mIsScaled)
model.mIconMatrix.postScale(
model.mInactiveIconScale, model.mInactiveIconScale, matrixCenterX, matrixCenterY
);
else
model.mIconMatrix.postScale(
model.mInactiveIconScale + matrixScale, model.mInactiveIconScale + matrixScale,
matrixCenterX, matrixCenterY
);

mModelTitlePaint.setTextSize(mModelTitleSize);
mModelTitlePaint.setTextSize(mModelTitleSize * (mIsScaled ? 1.0f : textScale));
if (mTitleMode == TitleMode.ACTIVE) mModelTitlePaint.setAlpha(MIN_ALPHA);
}

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<declare-styleable name="NavigationTabBar">
<attr name="ntb_titled" format="boolean"/>
<attr name="ntb_badged" format="boolean"/>
<attr name="ntb_scaled" format="boolean"/>
<attr name="ntb_badge_use_typeface" format="boolean"/>

<attr name="ntb_title_mode" format="enum">
Expand Down

0 comments on commit 0707967

Please sign in to comment.