From 2cad8477b6c66f312d466d8c8ea6d3c550c0dede Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Thu, 7 Apr 2016 18:14:40 +0300 Subject: [PATCH 01/64] Fixes Release 1.1.2 --- library/build.gradle | 4 ++-- .../src/main/java/com/gigamole/library/NavigationTabBar.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 7ad9b86..0d73c12 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.1.1" +version = "1.1.2" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.1" + versionName "1.1.2" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 8711fb8..a08e281 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -548,13 +548,13 @@ public void setOnTabBarSelectedIndexListener(final OnTabBarSelectedIndexListener mAnimatorListener = new Animator.AnimatorListener() { @Override public void onAnimationStart(final Animator animation) { - if (mOnTabBarSelectedIndexListener != null && !mIsViewPagerMode) + if (mOnTabBarSelectedIndexListener != null) mOnTabBarSelectedIndexListener.onStartTabSelected(mModels.get(mIndex), mIndex); } @Override public void onAnimationEnd(final Animator animation) { - if (mOnTabBarSelectedIndexListener != null && !mIsViewPagerMode) + if (mOnTabBarSelectedIndexListener != null) mOnTabBarSelectedIndexListener.onEndTabSelected(mModels.get(mIndex), mIndex); } From 186517a46acdf52d2182ac040a56f237fef7913b Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Thu, 7 Apr 2016 18:15:35 +0300 Subject: [PATCH 02/64] Fixes Release 1.1.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b6a35f6..c8e4299 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.1' +compile 'com.github.devlight.navigationtabbar:library:1.1.2' ``` Or Maven: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.1 + 1.1.2 aar ``` From bc6101d49ed305cfb290910d0038446ad84f72b3 Mon Sep 17 00:00:00 2001 From: A-Ar Concepcion Date: Fri, 8 Apr 2016 17:40:33 +0800 Subject: [PATCH 03/64] Add support for Vector Drawables --- .../com/gigamole/library/NavigationTabBar.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index a08e281..3e5d508 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -1240,9 +1240,18 @@ public static class Model { public Model(final Drawable icon, final int color) { mColor = color; - mIcon = icon != null ? ((BitmapDrawable) icon).getBitmap() : - Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); - + if (icon != null) { + if(icon instanceof BitmapDrawable) { + mIcon = ((BitmapDrawable) icon).getBitmap(); + } else { + mIcon = Bitmap.createBitmap(icon.getIntrinsicWidth(),icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(mIcon); + icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + icon.draw(canvas); + } + } else { + mIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); + } mBadgeAnimator.addListener(new Animator.AnimatorListener() { @Override From ab389091ee7ba352f7e4a95f5b4fdf0a5e06accb Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Mon, 11 Apr 2016 10:06:20 +0300 Subject: [PATCH 04/64] Update 1.1.3 --- README.md | 4 ++-- library/build.gradle | 4 ++-- .../gigamole/library/NavigationTabBar.java | 23 +++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c8e4299..9922b0a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.2' +compile 'com.github.devlight.navigationtabbar:library:1.1.3' ``` Or Maven: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.2 + 1.1.3 aar ``` diff --git a/library/build.gradle b/library/build.gradle index 0d73c12..e77a152 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.1.2" +version = "1.1.3" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.2" + versionName "1.1.3" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 3e5d508..0bd73b7 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -969,12 +969,13 @@ else if (i == mIndex) // Draw pointer with active color to wrap out active icon if (mCornersRadius == 0) mIconsCanvas.drawRect(mPointerBounds, mIconPointerPaint); - else mIconsCanvas.drawRoundRect(mPointerBounds, mCornersRadius, mCornersRadius, mIconPointerPaint); + else + mIconsCanvas.drawRoundRect(mPointerBounds, mCornersRadius, mCornersRadius, mIconPointerPaint); // Draw general bitmap canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null); // Draw icons bitmap on top - canvas.drawBitmap( mIconsBitmap, 0.0f, pointerBadgeMargin, null); + canvas.drawBitmap(mIconsBitmap, 0.0f, pointerBadgeMargin, null); // If is not badged, exit if (!mIsBadged) return; @@ -1068,7 +1069,7 @@ private void updateCurrentModel( model.mIconMatrix.postScale( model.mInactiveIconScale + matrixScale, model.mInactiveIconScale + matrixScale, matrixCenterX, matrixCenterY + (mIsTitled && mTitleMode == TitleMode.ACTIVE ? - mTitleMargin * 0.5f * interpolation : 0.0f) + mTitleMargin * 0.5f * interpolation : 0.0f) ); mModelTitlePaint.setTextSize(mModelTitleSize * textScale); @@ -1097,7 +1098,7 @@ private void updateLastModel( model.mInactiveIconScale + model.mActiveIconScaleBy - matrixLastScale, model.mInactiveIconScale + model.mActiveIconScaleBy - matrixLastScale, matrixCenterX, matrixCenterY + (mIsTitled && mTitleMode == TitleMode.ACTIVE ? - mTitleMargin * 0.5f - (mTitleMargin * 0.5f * lastInterpolation) : 0.0f) + mTitleMargin * 0.5f - (mTitleMargin * 0.5f * lastInterpolation) : 0.0f) ); mModelTitlePaint.setTextSize(mModelTitleSize * textLastScale); @@ -1241,17 +1242,21 @@ public static class Model { public Model(final Drawable icon, final int color) { mColor = color; if (icon != null) { - if(icon instanceof BitmapDrawable) { - mIcon = ((BitmapDrawable) icon).getBitmap(); - } else { - mIcon = Bitmap.createBitmap(icon.getIntrinsicWidth(),icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(mIcon); + if (icon instanceof BitmapDrawable) mIcon = ((BitmapDrawable) icon).getBitmap(); + else { + mIcon = Bitmap.createBitmap( + icon.getIntrinsicWidth(), + icon.getIntrinsicHeight(), + Bitmap.Config.ARGB_8888 + ); + final Canvas canvas = new Canvas(mIcon); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.draw(canvas); } } else { mIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); } + mBadgeAnimator.addListener(new Animator.AnimatorListener() { @Override From b331fe45b9de08571ed53aaf0c23783bd48c0422 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Mon, 18 Apr 2016 11:14:17 +0300 Subject: [PATCH 05/64] Update 1.1.4 --- README.md | 4 ++-- app/src/main/AndroidManifest.xml | 3 ++- .../HorizontalNtbActivity.java | 14 ++++++++----- library/build.gradle | 4 ++-- .../gigamole/library/NavigationTabBar.java | 20 ++++++++++++++++++- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9922b0a..8c79917 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.3' +compile 'com.github.devlight.navigationtabbar:library:1.1.4' ``` Or Maven: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.3 + 1.1.4 aar ``` diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f18db43..8bfe1ea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,8 @@ - + diff --git a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java index 5bdc2ea..d01bf39 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java @@ -81,16 +81,20 @@ public Object instantiateItem(final ViewGroup container, final int position) { getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4]), "Medal")); navigationTabBar.setModels(models); navigationTabBar.setViewPager(viewPager, 2); - - navigationTabBar.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() { + navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override - public void onStartTabSelected(final NavigationTabBar.Model model, final int index) { + public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) { } @Override - public void onEndTabSelected(final NavigationTabBar.Model model, final int index) { - model.hideBadge(); + public void onPageSelected(final int position) { + navigationTabBar.getModels().get(position).hideBadge(); + } + + @Override + public void onPageScrollStateChanged(final int state) { + } }); diff --git a/library/build.gradle b/library/build.gradle index e77a152..224e105 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.1.3" +version = "1.1.4" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.3" + versionName "1.1.4" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 0bd73b7..df75632 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -19,6 +19,7 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -1186,7 +1187,7 @@ public Parcelable onSaveInstanceState() { return savedState; } - static class SavedState extends BaseSavedState { + private static class SavedState extends BaseSavedState { int index; public SavedState(Parcelable superState) { @@ -1218,6 +1219,23 @@ public SavedState[] newArray(int size) { }; } + @Override + protected void onConfigurationChanged(final Configuration newConfig) { + // Config view on rotate etc. + super.onConfigurationChanged(newConfig); + requestLayout(); + + // Refresh pointer and state after config changed to current + final int tempIndex = mIndex; + setModelIndex(INVALID_INDEX, true); + post(new Runnable() { + @Override + public void run() { + setModelIndex(tempIndex, true); + } + }); + } + // Model class public static class Model { From 070796707768e1291b79f7e2ba2b7670a4c80b59 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Tue, 19 Apr 2016 23:24:26 +0300 Subject: [PATCH 06/64] Update 1.1.5 --- README.md | 9 ++- .../res/layout/activity_horizontal_ntb.xml | 1 + .../main/res/layout/activity_samples_ntb.xml | 2 + library/build.gradle | 4 +- .../gigamole/library/NavigationTabBar.java | 63 ++++++++++++++----- library/src/main/res/values/attrs.xml | 1 + 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 8c79917..92e7700 100644 --- a/README.md +++ b/README.md @@ -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: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.4 + 1.1.5 aar ``` @@ -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%). @@ -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" diff --git a/app/src/main/res/layout/activity_horizontal_ntb.xml b/app/src/main/res/layout/activity_horizontal_ntb.xml index 5832815..701b0f8 100644 --- a/app/src/main/res/layout/activity_horizontal_ntb.xml +++ b/app/src/main/res/layout/activity_horizontal_ntb.xml @@ -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"/> diff --git a/app/src/main/res/layout/activity_samples_ntb.xml b/app/src/main/res/layout/activity_samples_ntb.xml index 2e3f036..fc654e4 100644 --- a/app/src/main/res/layout/activity_samples_ntb.xml +++ b/app/src/main/res/layout/activity_samples_ntb.xml @@ -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"/> @@ -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"/> diff --git a/library/build.gradle b/library/build.gradle index 224e105..9e9c365 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.4" + versionName "1.1.5" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index df75632..90a71ea 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -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; @@ -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 @@ -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) ); @@ -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; } @@ -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 @@ -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( @@ -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); } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 47ec2da..c3dc53d 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -4,6 +4,7 @@ + From 84ad75fed989f4281b6e81ee23cf28f67d99c0af Mon Sep 17 00:00:00 2001 From: Mohamed Ezzat Date: Fri, 29 Apr 2016 00:45:06 +0200 Subject: [PATCH 07/64] Multiple quality improvements --- .../navigationtabbar/HorizontalNtbActivity.java | 2 ++ .../gigamole/navigationtabbar/MainActivity.java | 2 ++ .../com/gigamole/library/NavigationTabBar.java | 17 +++++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java index d01bf39..5acc3d3 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java @@ -128,6 +128,8 @@ public void run() { case 4: model.setBadgeTitle("777"); break; + default: + break; } navigationTabBar.postDelayed(new Runnable() { @Override diff --git a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java index d549f35..21e46e3 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java @@ -63,6 +63,8 @@ public void onAnimationEnd(final View view) { new Intent(MainActivity.this, SamplesNtbActivity.class) ); break; + default: + break; } } diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 90a71ea..718adba 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -51,6 +51,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.List; import java.util.Random; /** @@ -110,8 +111,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList private RectF mBounds = new RectF(); private RectF mPointerBounds = new RectF(); // Badge bounds and bg badge bounds - final Rect mBadgeBounds = new Rect(); - final RectF mBgBadgeBounds = new RectF(); + private final Rect mBadgeBounds = new Rect(); + private final RectF mBgBadgeBounds = new RectF(); // Canvas, where all of other canvas will be merged private Bitmap mBitmap; @@ -149,7 +150,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Paint for icon mask pointer - final Paint mIconPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mIconPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { { setStyle(Style.FILL); setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); @@ -157,7 +158,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Paint for model title - final Paint mModelTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mModelTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG) { { setDither(true); setColor(Color.WHITE); @@ -166,7 +167,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Paint for badge - final Paint mBadgePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mBadgePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG) { { setDither(true); setTextAlign(Align.CENTER); @@ -180,7 +181,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList private int mAnimationDuration; // NTP models - private ArrayList mModels = new ArrayList<>(); + private List mModels = new ArrayList<>(); // Variables for ViewPager private ViewPager mViewPager; @@ -361,11 +362,11 @@ public void setAnimationDuration(final int animationDuration) { resetScroller(); } - public ArrayList getModels() { + public List getModels() { return mModels; } - public void setModels(final ArrayList models) { + public void setModels(final List models) { //Set update listeners to badge model animation for (final Model model : models) { model.mBadgeAnimator.removeAllUpdateListeners(); From baed5beb92b178d026f935e266f4046f202fd56b Mon Sep 17 00:00:00 2001 From: Mohamed Ezzat Date: Thu, 5 May 2016 04:49:55 +0200 Subject: [PATCH 08/64] pmd:ImmutableField - Immutable Field --- .../com/gigamole/library/NavigationTabBar.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 718adba..3e9d01d 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -108,8 +108,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList private final static Interpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator(); // NTP and pointer bounds - private RectF mBounds = new RectF(); - private RectF mPointerBounds = new RectF(); + private final RectF mBounds = new RectF(); + private final RectF mPointerBounds = new RectF(); // Badge bounds and bg badge bounds private final Rect mBadgeBounds = new Rect(); private final RectF mBgBadgeBounds = new RectF(); @@ -127,7 +127,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList private Canvas mPointerCanvas; // Main paint - private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { { setDither(true); setStyle(Style.FILL); @@ -135,7 +135,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Pointer paint - private Paint mPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { { setDither(true); setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); @@ -143,7 +143,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Icons paint - private Paint mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { + private final Paint mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { { setDither(true); } @@ -176,8 +176,8 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList }; // Variables for animator - private ValueAnimator mAnimator = new ValueAnimator(); - private ResizeInterpolator mResizeInterpolator = new ResizeInterpolator(); + private final ValueAnimator mAnimator = new ValueAnimator(); + private final ResizeInterpolator mResizeInterpolator = new ResizeInterpolator(); private int mAnimationDuration; // NTP models @@ -1277,7 +1277,7 @@ public static class Model { private int mColor; private Bitmap mIcon; - private Matrix mIconMatrix = new Matrix(); + private final Matrix mIconMatrix = new Matrix(); private String mBadgeTitle = ""; private String mTempBadgeTitle = ""; @@ -1286,7 +1286,7 @@ public static class Model { private boolean mIsBadgeShowed; private boolean mIsBadgeUpdated; - private ValueAnimator mBadgeAnimator = new ValueAnimator(); + private final ValueAnimator mBadgeAnimator = new ValueAnimator(); private float mInactiveIconScale; private float mActiveIconScaleBy; From 8667f004aadf22a93f82560b69cc6d39dac86d0a Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Sat, 7 May 2016 14:35:02 +0300 Subject: [PATCH 09/64] Update 1.1.6 --- README.md | 48 +++++++----- .../HorizontalNtbActivity.java | 2 +- .../TopHorizontalNtbActivity.java | 2 +- .../navigationtabbar/VerticalNtbActivity.java | 2 +- .../layout/activity_horizontal_top_ntb.xml | 2 + .../res/layout/{vp_item.xml => item_vp.xml} | 0 build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- library/build.gradle | 4 +- .../gigamole/library/NavigationTabBar.java | 75 +++++++++++++------ library/src/main/res/values/attrs.xml | 2 + 11 files changed, 93 insertions(+), 50 deletions(-) rename app/src/main/res/layout/{vp_item.xml => item_vp.xml} (100%) diff --git a/README.md b/README.md index 92e7700..628a6fa 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ NavigationTabBar Navigation tab bar with colorful interactions. -Horizontal NTB|NTB bottom, badge, all title |NTB top, badge, typeface, active title|Vertical NTB|NTB Samples| +Horizontal NTB|NTB bottom, badge, all title |NTB top, colored badge, typeface, active title|Vertical NTB|NTB Samples| :-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------: ![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh5.googleusercontent.com/-3RKqh-MquqA/VwLWxHKv2jI/AAAAAAAACQg/WjmW9OravjIAzinLVFXEditNN4DFfRt6A/w322-h552-no/ttbntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) @@ -33,7 +33,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.5' +compile 'com.github.devlight.navigationtabbar:library:1.1.6' ``` Or Maven: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.5 + 1.1.6 aar ``` @@ -59,23 +59,23 @@ For NTB you can set such parameters as: - models: - allows you to set NTB models, where you set icon color. Can be set up only via code. + allows you to set NTB models, where you set icon color. Can be set up only via code. - view pager: - allows you to connect NTB with ViewPager. If you want your can also set OnPageChangeListener. + allows you to connect NTB with ViewPager. If you want your can also set OnPageChangeListener. - model title: - allows you to enable title in you model. + allows you to enable title in you model. - model badge: - allows you to enable badge in you model. + allows you to enable badge in you model. - use custom typeface on badge: - allows you to handle set of custom typeface in your badge. + allows you to handle set of custom typeface in your badge. - title mode: @@ -87,42 +87,48 @@ For NTB you can set such parameters as: - badge position: - allows you to set the badge position in you model. Can be: left(25%), center(50%) and right(75%). + allows you to set the badge position in you model. Can be: left(25%), center(50%) and right(75%). - badge gravity: - allows you to set the badge gravity in NTB. Can be top or bottom. + allows you to set the badge gravity in NTB. Can be top or bottom. + + - badge colors: + + allows you to set the badge bg and title colors. - typeface: - allows you to set custom typeface to your title. + allows you to set custom typeface to your title. - corners radius: - allows you to set corners radius of pointer. + allows you to set corners radius of pointer. - animation duration: - allows you to set animation duration. + allows you to set animation duration. - inactive color: - allows you to set inactive icon color. + allows you to set inactive icon color. - active color: - allows you to set active icon color. + allows you to set active icon color. - tab bar listener: - allows you to set listener which triggering on start or on end when you set model index. + allows you to set listener which triggering on start or on end when you set model index. - preview colors: - allows you to set preview colors, which generate count of models equals to count of colors. + allows you to set preview colors, which generate count of models equals to count of colors. Orientation automatically detected according to view size. +By default badge bg color is the active model color and badge title color is the model bg color. To reset colors just set badge bg and title color to 0. + If your set ViewPager you can action down on active pointer and do like drag. Check out in code init: @@ -150,6 +156,8 @@ navigationTabBar.setTypeface("fonts/custom_font.ttf"); navigationTabBar.setIsBadged(true); navigationTabBar.setIsTitled(true); navigationTabBar.setIsBadgeUseTypeface(true); +navigationTabBar.setBadgeBgColor(Color.RED); +navigationTabBar.setBadgeTitleColor(Color.WHITE); ``` If you want to set the background to NTB, you need to create some view at he bottom of NTB in layout and then set height of your background view like this: @@ -195,6 +203,8 @@ And XML init: app:ntb_title_mode="all" app:ntb_badge_position="right" app:ntb_badge_gravity="top" + app:ntb_badge_bg_color="#ffff0000" + app:ntb_badge_title_color="#ffffffff" app:ntb_typeface="fonts/custom_typeface.ttf" app:ntb_badge_use_typeface="true"/> ``` @@ -214,7 +224,7 @@ Inspiration Tapbar interactions| Circle interactions | Title interactions :-------------------------:|:-------------------------:|:-------------------------: -![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)|![](https://s-media-cache-ak0.pinimg.com/564x/f4/0d/a9/f40da9e5b73eb5e0e46681eba38f1347.jpg)|![](https://s-media-cache-ak0.pinimg.com/564x/14/eb/dd/14ebddfc0d92f02be3d61ede48a9da6e.jpg) +![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)|![](https://s-media-cache-ak0.pinimg.com/564x/f4/0d/a9/f40da9e5b73eb5e0e46681eba38f1347.jpg)|![](https://lh4.googleusercontent.com/-SLKBsDGJW-o/Vy3SOiBZN3I/AAAAAAAACbQ/bD2a8m4tAbsmAN5UCcco69sMgya8eCs0ACL0B/w321-h552-no/ttbbntb.gif) Thanks to [Valery Nuzhniy](https://www.pinterest.com/hevbolt/) for NTB badge design. @@ -223,4 +233,4 @@ Author Made in [DevLight Mobile Agency](https://github.com/DevLight-Mobile-Agency) -Created by [Basil Miller](https://github.com/GIGAMOLE) - [@gigamole](mailto:http://gigamole53@gmail.com) \ No newline at end of file +Created by [Basil Miller](https://github.com/GIGAMOLE) - [@gigamole](mailto:gigamole53@gmail.com) \ No newline at end of file diff --git a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java index d01bf39..d3b1c32 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java @@ -55,7 +55,7 @@ public void destroyItem(final View container, final int position, final Object o @Override public Object instantiateItem(final ViewGroup container, final int position) { final View view = LayoutInflater.from( - getBaseContext()).inflate(R.layout.vp_item, null, false); + getBaseContext()).inflate(R.layout.item_vp, null, false); final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); txtPage.setText(String.format("Page #%d", position)); diff --git a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java index 1834bc2..5ace335 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java @@ -56,7 +56,7 @@ public void destroyItem(final View container, final int position, final Object o @Override public Object instantiateItem(final ViewGroup container, final int position) { final View view = LayoutInflater.from( - getBaseContext()).inflate(R.layout.vp_item, null, false); + getBaseContext()).inflate(R.layout.item_vp, null, false); final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); txtPage.setText(String.format("Page #%d", position)); diff --git a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java index 6e3b7c3..9654297 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java @@ -55,7 +55,7 @@ public void destroyItem(final View container, final int position, final Object o @Override public Object instantiateItem(final ViewGroup container, final int position) { final View view = LayoutInflater.from( - getBaseContext()).inflate(R.layout.vp_item, null, false); + getBaseContext()).inflate(R.layout.item_vp, null, false); final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); txtPage.setText(String.format("Page #%d", position)); diff --git a/app/src/main/res/layout/activity_horizontal_top_ntb.xml b/app/src/main/res/layout/activity_horizontal_top_ntb.xml index 520622c..7c5077d 100644 --- a/app/src/main/res/layout/activity_horizontal_top_ntb.xml +++ b/app/src/main/res/layout/activity_horizontal_top_ntb.xml @@ -38,6 +38,8 @@ app:ntb_badge_gravity="bottom" app:ntb_badge_position="left" app:ntb_badge_use_typeface="true" + app:ntb_badge_bg_color="#ffff0000" + app:ntb_badge_title_color="#ffffffff" app:ntb_badged="true" app:ntb_title_mode="active" app:ntb_titled="true" diff --git a/app/src/main/res/layout/vp_item.xml b/app/src/main/res/layout/item_vp.xml similarity index 100% rename from app/src/main/res/layout/vp_item.xml rename to app/src/main/res/layout/item_vp.xml diff --git a/build.gradle b/build.gradle index ba818b7..cd70ee5 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1" - classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.android.tools.build:gradle:2.1.0' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ec41c8e..05ac656 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Mar 28 17:22:59 EEST 2016 +#Sat May 07 12:59:05 EEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/library/build.gradle b/library/build.gradle index 9e9c365..bdd95ee 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.1.5" +version = "1.1.6" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.5" + versionName "1.1.6" } buildTypes { release { diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 90a71ea..195dee7 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -19,6 +19,7 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -49,8 +50,10 @@ import android.view.animation.LinearInterpolator; import android.widget.Scroller; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.Random; /** @@ -87,7 +90,7 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList private final static float BADGE_HORIZONTAL_FRACTION = 0.5f; private final static float BADGE_VERTICAL_FRACTION = 0.75f; - private final static float BADGE_TITLE_SIZE_FRACTION = 0.85f; + private final static float BADGE_TITLE_SIZE_FRACTION = 0.9f; private final static int ALL_INDEX = 0; private final static int ACTIVE_INDEX = 1; @@ -212,6 +215,12 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList // Model badge gravity: top or bottom private BadgeGravity mBadgeGravity; + // Model badge bg and title color. + // By default badge bg color is the active model color and badge title color is the model bg color + // To reset colors just set bg and title color to 0 + private int mBadgeTitleColor; + private int mBadgeBgColor; + // Indexes private int mLastIndex = INVALID_INDEX; private int mIndex = INVALID_INDEX; @@ -271,30 +280,24 @@ public NavigationTabBar(final Context context, final AttributeSet attrs, final i final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { - setIsTitled( - typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false) - ); - setIsBadged( - typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false) - ); - setIsScaled( - typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true) - ); + setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); + 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) ); - setTitleMode( - typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX) - ); + + setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, ALL_INDEX)); setBadgePosition( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, RIGHT_INDEX) ); setBadgeGravity( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, TOP_INDEX) ); - setTypeface( - typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface) - ); + setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, 0)); + setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, 0)); + + setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor( R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR @@ -483,11 +486,29 @@ public void setBadgeGravity(final BadgeGravity badgeGravity) { requestLayout(); } + public int getBadgeBgColor() { + return mBadgeBgColor; + } + + public void setBadgeBgColor(final int badgeBgColor) { + mBadgeBgColor = badgeBgColor; + } + + public int getBadgeTitleColor() { + return mBadgeTitleColor; + } + + public void setBadgeTitleColor(final int badgeTitleColor) { + mBadgeTitleColor = badgeTitleColor; + } + public Typeface getTypeface() { return mTypeface; } public void setTypeface(final String typeface) { + if (TextUtils.isEmpty(typeface)) return; + Typeface tempTypeface; try { tempTypeface = Typeface.createFromAsset(getContext().getAssets(), typeface); @@ -566,10 +587,18 @@ public void setOnTabBarSelectedIndexListener(final OnTabBarSelectedIndexListener public void onAnimationStart(final Animator animation) { if (mOnTabBarSelectedIndexListener != null) mOnTabBarSelectedIndexListener.onStartTabSelected(mModels.get(mIndex), mIndex); + + animation.removeListener(this); + animation.addListener(this); } @Override public void onAnimationEnd(final Animator animation) { + if (mIsViewPagerMode) return; + + animation.removeListener(this); + animation.addListener(this); + if (mOnTabBarSelectedIndexListener != null) mOnTabBarSelectedIndexListener.onEndTabSelected(mModels.get(mIndex), mIndex); } @@ -927,11 +956,6 @@ 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 * @@ -1050,7 +1074,7 @@ else if (i == mIndex) // Set color and alpha for badge bg if (model.mBadgeFraction == MIN_FRACTION) mBadgePaint.setColor(Color.TRANSPARENT); - else mBadgePaint.setColor(mActiveColor); + else mBadgePaint.setColor(mBadgeBgColor == 0 ? mActiveColor : mBadgeBgColor); mBadgePaint.setAlpha((int) (MAX_ALPHA * model.mBadgeFraction)); // Set corners to round rect for badge bg and draw @@ -1059,7 +1083,7 @@ else if (i == mIndex) // Set color and alpha for badge title if (model.mBadgeFraction == MIN_FRACTION) mBadgePaint.setColor(Color.TRANSPARENT); - else mBadgePaint.setColor(model.getColor()); + else mBadgePaint.setColor(mBadgeTitleColor == 0 ? model.getColor() : mBadgeTitleColor); mBadgePaint.setAlpha((int) (MAX_ALPHA * model.mBadgeFraction)); // Set badge title center position and draw title @@ -1312,10 +1336,15 @@ public Model(final Drawable icon, final int color) { @Override public void onAnimationStart(final Animator animation) { + animation.removeListener(this); + animation.addListener(this); } @Override public void onAnimationEnd(final Animator animation) { + animation.removeListener(this); + animation.addListener(this); + // Detect whether we just update text and don`t reset show state if (!mIsBadgeUpdated) mIsBadgeShowed = !mIsBadgeShowed; else mIsBadgeUpdated = false; diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index c3dc53d..f12c014 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -20,6 +20,8 @@ + + From 5121a33e8298be2dedd030ec878dc091e25fc25e Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Sat, 7 May 2016 14:39:29 +0300 Subject: [PATCH 10/64] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 628a6fa..bc558cc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Navigation tab bar with colorful interactions. Horizontal NTB|NTB bottom, badge, all title |NTB top, colored badge, typeface, active title|Vertical NTB|NTB Samples| :-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------: -![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh5.googleusercontent.com/-3RKqh-MquqA/VwLWxHKv2jI/AAAAAAAACQg/WjmW9OravjIAzinLVFXEditNN4DFfRt6A/w322-h552-no/ttbntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) +![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh4.googleusercontent.com/-SLKBsDGJW-o/Vy3SOiBZN3I/AAAAAAAACbQ/bD2a8m4tAbsmAN5UCcco69sMgya8eCs0ACL0B/w321-h552-no/ttbbntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app). From b18338419a36af5207a57d3f915e007031af7202 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Sat, 14 May 2016 14:37:38 +0300 Subject: [PATCH 11/64] CoordinatorLayout usage update --- app/build.gradle | 4 +- .../TopHorizontalNtbActivity.java | 47 +++++++++++- .../layout/activity_horizontal_top_ntb.xml | 72 ++++++++++--------- app/src/main/res/layout/item_list.xml | 23 ++++++ app/src/main/res/layout/item_vp_list.xml | 19 +++++ 5 files changed, 129 insertions(+), 36 deletions(-) create mode 100644 app/src/main/res/layout/item_list.xml create mode 100644 app/src/main/res/layout/item_vp_list.xml diff --git a/app/build.gradle b/app/build.gradle index a3466fc..8a8c4af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,5 +22,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':library') - compile 'com.android.support:appcompat-v7:23.2.1' + compile 'com.android.support:appcompat-v7:23.3.0' + compile 'com.android.support:design:23.3.0' + compile 'com.android.support:support-v4:24.0.0-alpha2' } diff --git a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java index 5ace335..da5ce89 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java @@ -5,6 +5,8 @@ import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -56,10 +58,15 @@ public void destroyItem(final View container, final int position, final Object o @Override public Object instantiateItem(final ViewGroup container, final int position) { final View view = LayoutInflater.from( - getBaseContext()).inflate(R.layout.item_vp, null, false); + getBaseContext()).inflate(R.layout.item_vp_list, null, false); - final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); - txtPage.setText(String.format("Page #%d", position)); + final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager( + getBaseContext(), LinearLayoutManager.VERTICAL, false + ) + ); + recyclerView.setAdapter(new RecycleAdapter()); container.addView(view); return view; @@ -89,6 +96,11 @@ public void run() { final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal); bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight(); bgNavigationTabBar.requestLayout(); + + final View viewPager = findViewById(R.id.vp_horizontal_ntb); + ((ViewGroup.MarginLayoutParams) viewPager.getLayoutParams()).topMargin = + (int) -navigationTabBar.getBadgeMargin(); + viewPager.requestLayout(); } }); @@ -123,4 +135,33 @@ public void run() { } }); } + + public class RecycleAdapter extends RecyclerView.Adapter { + + @Override + public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) { + final View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.item_list, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, final int position) { + holder.txt.setText(String.format("Navigation Item #%d", position)); + } + + @Override + public int getItemCount() { + return 20; + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + public TextView txt; + + public ViewHolder(final View itemView) { + super(itemView); + txt = (TextView) itemView.findViewById(R.id.txt_vp_item_list); + } + } + } } diff --git a/app/src/main/res/layout/activity_horizontal_top_ntb.xml b/app/src/main/res/layout/activity_horizontal_top_ntb.xml index 7c5077d..e8861f1 100644 --- a/app/src/main/res/layout/activity_horizontal_top_ntb.xml +++ b/app/src/main/res/layout/activity_horizontal_top_ntb.xml @@ -1,5 +1,5 @@ - + app:layout_behavior="@string/appbar_scrolling_view_behavior"/> + + + + + + + + + + + + - - + android:layout_gravity="bottom"/> - - - - - - - + diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml new file mode 100644 index 0000000..95fd221 --- /dev/null +++ b/app/src/main/res/layout/item_list.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_vp_list.xml b/app/src/main/res/layout/item_vp_list.xml new file mode 100644 index 0000000..9474696 --- /dev/null +++ b/app/src/main/res/layout/item_vp_list.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file From bab43dd5fafae5acffa68f6ace7fe7a4fd4c34a1 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Sat, 14 May 2016 14:46:37 +0300 Subject: [PATCH 12/64] CoordinatorLayout usage update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc558cc..06a1e8e 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ NavigationTabBar Navigation tab bar with colorful interactions. -Horizontal NTB|NTB bottom, badge, all title |NTB top, colored badge, typeface, active title|Vertical NTB|NTB Samples| +Horizontal NTB|NTB bottom, badge, all title |NTB with CoordinatorLayout|Vertical NTB|NTB Samples| :-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------: -![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh4.googleusercontent.com/-SLKBsDGJW-o/Vy3SOiBZN3I/AAAAAAAACbQ/bD2a8m4tAbsmAN5UCcco69sMgya8eCs0ACL0B/w321-h552-no/ttbbntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) +![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh6.googleusercontent.com/-hMvLn-jzY3k/VzcPrGAmr4I/AAAAAAAACc0/US0yokfG23kQJEAPxFoPp-8lOUNRSPV9QCL0B/w321-h552-no/cltntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app). From ea05fd6aa086c161846ee5e23b86e4823cea9c7e Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Fri, 20 May 2016 15:34:20 +0300 Subject: [PATCH 13/64] Update 1.1.8 --- README.md | 74 +++++-- .../HorizontalNtbActivity.java | 75 ++++--- .../navigationtabbar/SamplesNtbActivity.java | 185 +++++++++++------ .../TopHorizontalNtbActivity.java | 53 +++-- .../navigationtabbar/VerticalNtbActivity.java | 80 +++++--- .../layout/activity_horizontal_top_ntb.xml | 1 + .../gigamole/library/NavigationTabBar.java | 194 +++++++++++++++--- 7 files changed, 481 insertions(+), 181 deletions(-) diff --git a/README.md b/README.md index 06a1e8e..6307917 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ NavigationTabBar Navigation tab bar with colorful interactions. -Horizontal NTB|NTB bottom, badge, all title |NTB with CoordinatorLayout|Vertical NTB|NTB Samples| +Horizontal NTB|NTB with selected icons |NTB with CoordinatorLayout|Vertical NTB|NTB Samples| :-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------: -![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-hxXHKG4zMOU/VwLWxDdhxQI/AAAAAAAACQg/gErfodzZlpINFmlWllvuFs6dlRnp_rG9w/w322-h551-no/tbntb.gif)|![](https://lh6.googleusercontent.com/-hMvLn-jzY3k/VzcPrGAmr4I/AAAAAAAACc0/US0yokfG23kQJEAPxFoPp-8lOUNRSPV9QCL0B/w321-h552-no/cltntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) +![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh5.googleusercontent.com/-LcHHajuKNzw/Vz77El2lHsI/AAAAAAAACiQ/I0CjrMUP6R4ioH9h8nEe37LCqXmb3GJKACL0B/w317-h552-no/ntbsi.gif)|![](https://lh6.googleusercontent.com/-hMvLn-jzY3k/VzcPrGAmr4I/AAAAAAAACc0/US0yokfG23kQJEAPxFoPp-8lOUNRSPV9QCL0B/w321-h552-no/cltntb.gif)|![](https://lh4.googleusercontent.com/-k4Ac7-c2m8E/VvpVlk3ZmLI/AAAAAAAACPA/21ISoAYGZzUlvGPmIauXwfYZOKdCYIRGg/w323-h552-no/vntb.gif)|![](https://lh5.googleusercontent.com/-hmELfZQvexU/VvpVlooaPvI/AAAAAAAACPA/5HA5ic7dASwBUYqpqcfxAmfLzPPDXejqQ/w322-h552-no/ntbs.gif) U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app). @@ -33,7 +33,7 @@ dependencies { Or Gradle Maven Central: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.6' +compile 'com.github.devlight.navigationtabbar:library:1.1.8' ``` Or Maven: @@ -42,7 +42,7 @@ Or Maven: com.github.devlight.navigationtabbar library - 1.1.6 + 1.1.8 aar ``` @@ -50,7 +50,7 @@ Or Maven: Android SDK Version ========= -NavigationTabBar requires a minimum sdk version of 11. +NavigationTabBar requires a minimum SDK version of 11. Sample ======== @@ -59,12 +59,16 @@ For NTB you can set such parameters as: - models: - allows you to set NTB models, where you set icon color. Can be set up only via code. + allows you to set NTB models, where you set icon and color. Can be set up only via code. - view pager: allows you to connect NTB with ViewPager. If you want your can also set OnPageChangeListener. + - model selected icon: + + allows you to set selected icon when current model is active. + - model title: allows you to enable title in you model. @@ -125,6 +129,12 @@ For NTB you can set such parameters as: allows you to set preview colors, which generate count of models equals to count of colors. +Creation of models occurs through Builder pattern. + +ModelBuilder requires two fields: icon and color. Title, badge title and selected icon is optional. + +You can set selected icon. Resize and scale of selected icon equals to original icon. + Orientation automatically detected according to view size. By default badge bg color is the active model color and badge title color is the model bg color. To reset colors just set badge bg and title color to 0. @@ -136,16 +146,46 @@ Check out in code init: ```java final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb); final ArrayList models = new ArrayList<>(); -models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), colors[0])); -models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), colors[1])); -models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), colors[2])); -models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), colors[3])); -models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), colors[4])); +models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0]) + ).title("Heart") + .badgeTitle("NTB") + .build() +); +models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), + Color.parseColor(colors[1]) + ).title("Cup") + .badgeTitle("with") + .build() +); +models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2]) + ).title("Diploma") + .badgeTitle("state") + .build() +); +models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), + Color.parseColor(colors[3]) + ).title("Flag") + .badgeTitle("icon") + .build() +); +models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), + Color.parseColor(colors[4]) + ).title("Medal") + .badgeTitle("777") + .build() +); navigationTabBar.setModels(models); navigationTabBar.setViewPager(viewPager, 2); @@ -222,7 +262,7 @@ Apache 2.0 and MIT. See [LICENSE](https://github.com/DevLight-Mobile-Agency/Navi Inspiration ====== -Tapbar interactions| Circle interactions | Title interactions +TapBar interactions| Circle interactions | Title interactions :-------------------------:|:-------------------------:|:-------------------------: ![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)|![](https://s-media-cache-ak0.pinimg.com/564x/f4/0d/a9/f40da9e5b73eb5e0e46681eba38f1347.jpg)|![](https://lh4.googleusercontent.com/-SLKBsDGJW-o/Vy3SOiBZN3I/AAAAAAAACbQ/bD2a8m4tAbsmAN5UCcco69sMgya8eCs0ACL0B/w321-h552-no/ttbbntb.gif) diff --git a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java index a0aa96f..bd91aa0 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java @@ -69,16 +69,52 @@ public Object instantiateItem(final ViewGroup container, final int position) { final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal); final ArrayList models = new ArrayList<>(); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), Color.parseColor(colors[0]), "Heart")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), Color.parseColor(colors[1]), "Cup")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), Color.parseColor(colors[2]), "Diploma")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), Color.parseColor(colors[3]), "Flag")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4]), "Medal")); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_sixth)) + .title("Heart") + .badgeTitle("NTB") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), + Color.parseColor(colors[1])) +// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("Cup") + .badgeTitle("with") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_seventh)) + .title("Diploma") + .badgeTitle("state") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), + Color.parseColor(colors[3])) +// .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("Flag") + .badgeTitle("icon") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), + Color.parseColor(colors[4])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("Medal") + .badgeTitle("777") + .build() + ); + navigationTabBar.setModels(models); navigationTabBar.setViewPager(viewPager, 2); navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @@ -112,25 +148,6 @@ public void run() { public void run() { for (int i = 0; i < navigationTabBar.getModels().size(); i++) { final NavigationTabBar.Model model = navigationTabBar.getModels().get(i); - switch (i) { - case 0: - model.setBadgeTitle("NTB"); - break; - case 1: - model.setBadgeTitle("with"); - break; - case 2: - model.setBadgeTitle("title"); - break; - case 3: - model.setBadgeTitle("badge"); - break; - case 4: - model.setBadgeTitle("777"); - break; - default: - break; - } navigationTabBar.postDelayed(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java index ac9a6c0..097263f 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java @@ -22,79 +22,134 @@ protected void onCreate(final Bundle savedInstanceState) { initUI(); } - @Override - protected void onDestroy() { - super.onDestroy(); - System.runFinalization(); - Runtime.getRuntime().gc(); - System.gc(); - } - private void initUI() { final NavigationTabBar ntbSample1 = (NavigationTabBar) findViewById(R.id.ntb_sample_1); final ArrayList models1 = new ArrayList<>(); - models1.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), Color.WHITE)); - models1.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), Color.LTGRAY)); - models1.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), Color.GRAY)); - models1.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), Color.DKGRAY)); + models1.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), Color.WHITE + ).build() + ); + models1.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), Color.LTGRAY + ).build() + ); + models1.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), Color.GRAY + ).build() + ); + models1.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), Color.DKGRAY + ).build() + ); ntbSample1.setModels(models1); final NavigationTabBar ntbSample2 = (NavigationTabBar) findViewById(R.id.ntb_sample_2); final ArrayList models2 = new ArrayList<>(); - models2.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_seventh), Color.YELLOW)); - models2.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_sixth), Color.YELLOW)); - models2.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), Color.YELLOW)); - models2.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_eighth), Color.YELLOW)); - models2.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), Color.YELLOW)); + models2.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), Color.YELLOW + ).build() + ); + models2.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), Color.YELLOW + ).build() + ); + models2.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), Color.YELLOW + ).build() + ); + models2.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_eighth), Color.YELLOW + ).build() + ); + models2.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), Color.YELLOW + ).build() + ); ntbSample2.setModels(models2); ntbSample2.setModelIndex(3, true); final NavigationTabBar ntbSample3 = (NavigationTabBar) findViewById(R.id.ntb_sample_3); final ArrayList models3 = new ArrayList<>(); - models3.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_seventh), Color.RED)); - models3.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_seventh), Color.RED)); - models3.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_seventh), Color.RED)); + models3.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), Color.RED + ).build() + ); + models3.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), Color.RED + ).build() + ); + models3.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), Color.RED + ).build() + ); ntbSample3.setModels(models3); ntbSample3.setModelIndex(1, true); final NavigationTabBar ntbSample4 = (NavigationTabBar) findViewById(R.id.ntb_sample_4); final int bgColor = Color.parseColor("#423752"); final ArrayList models4 = new ArrayList<>(); - models4.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), bgColor)); - models4.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), bgColor)); - models4.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), bgColor)); - models4.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_sixth), bgColor)); - models4.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), bgColor)); + models4.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), bgColor + ).build() + ); + models4.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), bgColor + ).build() + ); + models4.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), bgColor + ).build() + ); + models4.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), bgColor + ).build() + ); + models4.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), bgColor + ).build() + ); ntbSample4.setModels(models4); ntbSample4.setModelIndex(2, true); final NavigationTabBar ntbSample5 = (NavigationTabBar) findViewById(R.id.ntb_sample_5); final ArrayList models5 = new ArrayList<>(); - models5.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), Color.WHITE)); - models5.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), Color.WHITE)); - models5.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), Color.WHITE)); - models5.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_sixth), Color.WHITE)); + models5.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), Color.WHITE + ).build() + ); + models5.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), Color.WHITE + ).build() + ); + models5.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), Color.WHITE + ).build() + ); + models5.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), Color.WHITE + ).build() + ); ntbSample5.setModels(models5); ntbSample5.setModelIndex(2, true); ntbSample5.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() { @@ -111,18 +166,30 @@ public void onEndTabSelected(final NavigationTabBar.Model model, final int index final NavigationTabBar ntbSample6 = (NavigationTabBar) findViewById(R.id.ntb_sample_6); final ArrayList models6 = new ArrayList<>(); - models6.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), randomColor())); - models6.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), randomColor())); - models6.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), randomColor())); - models6.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_sixth), randomColor())); + models6.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), randomColor() + ).build() + ); + models6.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), randomColor() + ).build() + ); + models6.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), randomColor() + ).build() + ); + models6.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), randomColor() + ).build() + ); ntbSample6.setModels(models6); } - private int randomColor(){ + private int randomColor() { float[] TEMP_HSL = new float[]{0, 0, 0}; float[] hsl = TEMP_HSL; hsl[0] = (float) (Math.random() * 360); diff --git a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java index da5ce89..6f32fc8 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java @@ -29,14 +29,6 @@ protected void onCreate(final Bundle savedInstanceState) { initUI(); } - @Override - protected void onDestroy() { - super.onDestroy(); - System.runFinalization(); - Runtime.getRuntime().gc(); - System.gc(); - } - private void initUI() { final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb); viewPager.setAdapter(new PagerAdapter() { @@ -77,16 +69,41 @@ public Object instantiateItem(final ViewGroup container, final int position) { final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal); final ArrayList models = new ArrayList<>(); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), Color.parseColor(colors[0]), "Heart")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), Color.parseColor(colors[1]), "Cup")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), Color.parseColor(colors[2]), "Diploma")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), Color.parseColor(colors[3]), "Flag")); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4]), "Medal")); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0])) + .title("Heart") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), + Color.parseColor(colors[1])) + .title("Cup") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2])) + .title("Diploma") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), + Color.parseColor(colors[3])) + .title("Flag") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), + Color.parseColor(colors[4])) + .title("Medal") + .build() + ); navigationTabBar.setModels(models); navigationTabBar.setViewPager(viewPager, 2); diff --git a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java index 9654297..53275a7 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java @@ -26,14 +26,6 @@ protected void onCreate(final Bundle savedInstanceState) { initUI(); } - @Override - protected void onDestroy() { - super.onDestroy(); - System.runFinalization(); - Runtime.getRuntime().gc(); - System.gc(); - } - private void initUI() { final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_vertical_ntb); viewPager.setAdapter(new PagerAdapter() { @@ -69,22 +61,62 @@ public Object instantiateItem(final ViewGroup container, final int position) { final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_vertical); final ArrayList models = new ArrayList<>(); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_first), Color.parseColor(colors[0]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_second), Color.parseColor(colors[1]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_third), Color.parseColor(colors[2]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fourth), Color.parseColor(colors[3]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_sixth), Color.parseColor(colors[5]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_seventh), Color.parseColor(colors[6]))); - models.add(new NavigationTabBar.Model( - getResources().getDrawable(R.drawable.ic_eighth), Color.parseColor(colors[7]))); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), + Color.parseColor(colors[1])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), + Color.parseColor(colors[3])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), + Color.parseColor(colors[4])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), + Color.parseColor(colors[5])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), + Color.parseColor(colors[6])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_eighth), + Color.parseColor(colors[7])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .build() + ); navigationTabBar.setModels(models); navigationTabBar.setViewPager(viewPager, 4); diff --git a/app/src/main/res/layout/activity_horizontal_top_ntb.xml b/app/src/main/res/layout/activity_horizontal_top_ntb.xml index e8861f1..ef221b7 100644 --- a/app/src/main/res/layout/activity_horizontal_top_ntb.xml +++ b/app/src/main/res/layout/activity_horizontal_top_ntb.xml @@ -43,6 +43,7 @@ app:ntb_badged="true" app:ntb_title_mode="active" app:ntb_titled="true" + app:ntb_scaled="false" app:ntb_typeface="fonts/agency.ttf"/> diff --git a/library/src/main/java/com/gigamole/library/NavigationTabBar.java b/library/src/main/java/com/gigamole/library/NavigationTabBar.java index 5c1af67..3da5054 100644 --- a/library/src/main/java/com/gigamole/library/NavigationTabBar.java +++ b/library/src/main/java/com/gigamole/library/NavigationTabBar.java @@ -19,7 +19,6 @@ import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; -import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Bitmap; @@ -50,10 +49,8 @@ import android.view.animation.LinearInterpolator; import android.widget.Scroller; -import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Random; @@ -151,6 +148,11 @@ public class NavigationTabBar extends View implements ViewPager.OnPageChangeList setDither(true); } }; + private final Paint mSelectedIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { + { + setDither(true); + } + }; // Paint for icon mask pointer private final Paint mIconPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG) { @@ -346,7 +348,7 @@ public void onAnimationUpdate(final ValueAnimator animation) { previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) - mModels.add(new Model(null, Color.parseColor(previewColor))); + mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build()); requestLayout(); } } @@ -553,6 +555,7 @@ public void setInactiveColor(final int inactiveColor) { // Set color filter to wrap icons with inactive color mIconPaint.setColorFilter(new PorterDuffColorFilter(inactiveColor, PorterDuff.Mode.SRC_IN)); + mSelectedIconPaint.setColorFilter(new PorterDuffColorFilter(inactiveColor, PorterDuff.Mode.SRC_IN)); mModelTitlePaint.setColor(mInactiveColor); postInvalidate(); } @@ -973,6 +976,9 @@ protected void onDraw(final Canvas canvas) { final float titleLastScale = mIsScaled ? (MAX_FRACTION + TITLE_ACTIVE_SCALE_BY) - (lastInterpolation * TITLE_ACTIVE_SCALE_BY) : titleScale; + mIconPaint.setAlpha(MAX_ALPHA); + if (model.mSelectedIcon != null) mSelectedIconPaint.setAlpha(MAX_ALPHA); + // Check if we handle models from touch on NTP or from ViewPager // There is a strange logic of ViewPager onPageScrolled method, so it is if (mIsSetIndexFromTabBar) { @@ -1009,8 +1015,18 @@ else if (i == mIndex) ); } - // Draw model icon - mIconsCanvas.drawBitmap(model.mIcon, model.mIconMatrix, mIconPaint); + // Draw original model icon + if (model.mSelectedIcon == null) { + mIconsCanvas.drawBitmap(model.mIcon, model.mIconMatrix, mIconPaint); + } else { + if (mIconPaint.getAlpha() != MIN_ALPHA) + // Draw original icon when is visible + mIconsCanvas.drawBitmap(model.mIcon, model.mIconMatrix, mIconPaint); + } + // Draw selected icon when exist and visible + if (model.mSelectedIcon != null && mSelectedIconPaint.getAlpha() != MIN_ALPHA) + mIconsCanvas.drawBitmap(model.mSelectedIcon, model.mIconMatrix, mSelectedIconPaint); + if (mIsTitled) mIconsCanvas.drawText( isInEditMode() ? PREVIEW_TITLE : model.getTitle(), @@ -1125,6 +1141,33 @@ private void updateCurrentModel( mModelTitlePaint.setTextSize(mModelTitleSize * textScale); if (mTitleMode == TitleMode.ACTIVE) mModelTitlePaint.setAlpha(textAlpha); + + if (model.mSelectedIcon == null) { + mIconPaint.setAlpha(MAX_ALPHA); + return; + } + + // Calculate cross fade alpha between icon and selected icon + final float iconAlpha; + final float selectedIconAlpha; + if (interpolation <= 0.475F) { + iconAlpha = MAX_FRACTION - interpolation * 2.1F; + selectedIconAlpha = MIN_FRACTION; + } else if (interpolation >= 0.525F) { + iconAlpha = MIN_FRACTION; + selectedIconAlpha = (interpolation - 0.55F) * 1.9F; + } else { + iconAlpha = MIN_FRACTION; + selectedIconAlpha = MIN_FRACTION; + } + + mIconPaint.setAlpha( + (int) (MAX_ALPHA * clampValue(iconAlpha, MIN_FRACTION, MAX_FRACTION)) + ); + mSelectedIconPaint.setAlpha( + (int) (MAX_ALPHA * clampValue(selectedIconAlpha, MIN_FRACTION, MAX_FRACTION)) + ); + } // Method to transform last fraction of NTB and position @@ -1154,6 +1197,32 @@ private void updateLastModel( mModelTitlePaint.setTextSize(mModelTitleSize * textLastScale); if (mTitleMode == TitleMode.ACTIVE) mModelTitlePaint.setAlpha(textLastAlpha); + + if (model.mSelectedIcon == null) { + mIconPaint.setAlpha(MAX_ALPHA); + return; + } + + // Calculate cross fade alpha between icon and selected icon + final float iconAlpha; + final float selectedIconAlpha; + if (lastInterpolation <= 0.475F) { + iconAlpha = MIN_FRACTION; + selectedIconAlpha = MAX_FRACTION - lastInterpolation * 2.1F; + } else if (lastInterpolation >= 0.525F) { + iconAlpha = (lastInterpolation - 0.55F) * 1.9F; + selectedIconAlpha = MIN_FRACTION; + } else { + iconAlpha = MIN_FRACTION; + selectedIconAlpha = MIN_FRACTION; + } + + mIconPaint.setAlpha( + (int) (MAX_ALPHA * clampValue(iconAlpha, MIN_FRACTION, MAX_FRACTION)) + ); + mSelectedIconPaint.setAlpha( + (int) (MAX_ALPHA * clampValue(selectedIconAlpha, MIN_FRACTION, MAX_FRACTION)) + ); } // Method to transform others fraction of NTB and position @@ -1181,6 +1250,14 @@ private void updateInactiveModel( mModelTitlePaint.setTextSize(mModelTitleSize * (mIsScaled ? 1.0f : textScale)); if (mTitleMode == TitleMode.ACTIVE) mModelTitlePaint.setAlpha(MIN_ALPHA); + + // Reset icons alpha + if (model.mSelectedIcon == null) { + mIconPaint.setAlpha(MAX_ALPHA); + return; + } + + mSelectedIconPaint.setAlpha(MIN_ALPHA); } @Override @@ -1294,15 +1371,21 @@ public void run() { }); } + // Clamp value to max and min bounds + private float clampValue(final float value, final float max, final float min) { + return Math.max(Math.min(value, min), max); + } + // Model class public static class Model { - private String mTitle = ""; private int mColor; private Bitmap mIcon; + private Bitmap mSelectedIcon; private final Matrix mIconMatrix = new Matrix(); + private String mTitle = ""; private String mBadgeTitle = ""; private String mTempBadgeTitle = ""; private float mBadgeFraction; @@ -1315,23 +1398,12 @@ public static class Model { private float mInactiveIconScale; private float mActiveIconScaleBy; - public Model(final Drawable icon, final int color) { - mColor = color; - if (icon != null) { - if (icon instanceof BitmapDrawable) mIcon = ((BitmapDrawable) icon).getBitmap(); - else { - mIcon = Bitmap.createBitmap( - icon.getIntrinsicWidth(), - icon.getIntrinsicHeight(), - Bitmap.Config.ARGB_8888 - ); - final Canvas canvas = new Canvas(mIcon); - icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - icon.draw(canvas); - } - } else { - mIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); - } + public Model(final Builder builder) { + mColor = builder.mColor; + mIcon = builder.mIcon; + mSelectedIcon = builder.mSelectedIcon; + mTitle = builder.mTitle; + mBadgeTitle = builder.mBadgeTitle; mBadgeAnimator.addListener(new Animator.AnimatorListener() { @@ -1364,16 +1436,6 @@ public void onAnimationRepeat(final Animator animation) { }); } - public Model(final Drawable icon, final int color, final String title) { - this(icon, color); - mTitle = title; - } - - public Model(final Drawable icon, final int color, final String title, final String badgeTitle) { - this(icon, color, title); - mBadgeTitle = badgeTitle; - } - public String getTitle() { return mTitle; } @@ -1450,6 +1512,70 @@ public void hideBadge() { mBadgeAnimator.setRepeatCount(0); mBadgeAnimator.start(); } + + public static class Builder { + + private int mColor; + + private Bitmap mIcon; + private Bitmap mSelectedIcon; + + private String mTitle; + private String mBadgeTitle; + + public Builder(final Drawable icon, final int color) { + mColor = color; + + if (icon != null) { + if (icon instanceof BitmapDrawable) mIcon = ((BitmapDrawable) icon).getBitmap(); + else { + mIcon = Bitmap.createBitmap( + icon.getIntrinsicWidth(), + icon.getIntrinsicHeight(), + Bitmap.Config.ARGB_8888 + ); + final Canvas canvas = new Canvas(mIcon); + icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + icon.draw(canvas); + } + } else { + mIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); + } + } + + public Builder selectedIcon(final Drawable selectedIcon) { + if (selectedIcon != null) { + if (selectedIcon instanceof BitmapDrawable) + mSelectedIcon = ((BitmapDrawable) selectedIcon).getBitmap(); + else { + mSelectedIcon = Bitmap.createBitmap( + selectedIcon.getIntrinsicWidth(), + selectedIcon.getIntrinsicHeight(), + Bitmap.Config.ARGB_8888 + ); + final Canvas canvas = new Canvas(mSelectedIcon); + selectedIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + selectedIcon.draw(canvas); + } + } else mSelectedIcon = null; + + return this; + } + + public Builder title(final String title) { + mTitle = title; + return this; + } + + public Builder badgeTitle(final String title) { + mBadgeTitle = title; + return this; + } + + public Model build() { + return new Model(this); + } + } } // Custom scroller with custom scroll duration From d98332af7bfc83d3a65ae4de86b27dd370964adf Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Fri, 20 May 2016 15:36:40 +0300 Subject: [PATCH 14/64] Update 1.1.8 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 6307917..ab94d99 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ NavigationTabBar requires a minimum SDK version of 11. Sample ======== +Parameters + For NTB you can set such parameters as: - models: @@ -129,6 +131,8 @@ For NTB you can set such parameters as: allows you to set preview colors, which generate count of models equals to count of colors. +Tips + Creation of models occurs through Builder pattern. ModelBuilder requires two fields: icon and color. Title, badge title and selected icon is optional. @@ -141,6 +145,8 @@ By default badge bg color is the active model color and badge title color is the If your set ViewPager you can action down on active pointer and do like drag. +Init + Check out in code init: ```java From 98ec195cd02aa90e85d6be245d6e73b7bae17cd7 Mon Sep 17 00:00:00 2001 From: GIGAMOLE Date: Fri, 20 May 2016 15:39:17 +0300 Subject: [PATCH 15/64] Update 1.1.8 --- library/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index bdd95ee..1a2fc21 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray" apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'maven' -version = "1.1.6" +version = "1.1.8" android { compileSdkVersion 23 @@ -29,7 +29,7 @@ android { minSdkVersion 11 targetSdkVersion 23 versionCode 1 - versionName "1.1.6" + versionName "1.1.8" } buildTypes { release { From 1775a0a8a5f71bf0f622949783a6cfe5f4da384b Mon Sep 17 00:00:00 2001 From: daely Date: Thu, 2 Jun 2016 12:59:27 +0300 Subject: [PATCH 16/64] added support for autoscroll of NavigationTabBar at bottom of coordinator layout. See new demo: Horizontal(Coordinator Layout) NavigationTabBar. The code was adapted from --- README.md | 7 +- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 + .../HorizontalCoordinatorNtbActivity.java | 188 ++++++++ .../navigationtabbar/MainActivity.java | 7 + .../activity_horizontal_coordinator_ntb.xml | 90 ++++ app/src/main/res/layout/activity_main.xml | 18 +- app/src/main/res/values/dimens.xml | 4 + app/src/main/res/values/styles.xml | 2 +- library/build.gradle | 4 +- .../BottomNavigationTabBarBehavior.java | 406 ++++++++++++++++++ .../gigamole/library/NavigationTabBar.java | 146 +++++++ .../library/VerticalScrollingBehavior.java | 146 +++++++ 13 files changed, 1014 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/gigamole/navigationtabbar/HorizontalCoordinatorNtbActivity.java create mode 100644 app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 library/src/main/java/com/gigamole/library/BottomNavigationTabBarBehavior.java create mode 100644 library/src/main/java/com/gigamole/library/VerticalScrollingBehavior.java diff --git a/README.md b/README.md index ab94d99..9164a48 100644 --- a/README.md +++ b/README.md @@ -228,7 +228,12 @@ model.showBadge(); model.toggleBadge(); model.updateBadgeTitle("Here some title like NEW or some integer value"); ``` - + +To enable translation inside CoordinatorLayout when at bottom of screen: +```java +bottomNavigation.setBehaviorTranslationEnabled(true); +``` + Other methods check out in sample. And XML init: diff --git a/app/build.gradle b/app/build.gradle index 8a8c4af..7a55400 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,5 +24,5 @@ dependencies { compile project(':library') compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0' - compile 'com.android.support:support-v4:24.0.0-alpha2' + compile 'com.android.support:support-v4:23.3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8bfe1ea..36bb73b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,7 @@ + diff --git a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalCoordinatorNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalCoordinatorNtbActivity.java new file mode 100644 index 0000000..ecbc49b --- /dev/null +++ b/app/src/main/java/com/gigamole/navigationtabbar/HorizontalCoordinatorNtbActivity.java @@ -0,0 +1,188 @@ +package com.gigamole.navigationtabbar; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.gigamole.library.NavigationTabBar; + +import java.util.ArrayList; +import java.util.Random; + +/** + * Created by GIGAMOLE on 28.03.2016. + */ +public class HorizontalCoordinatorNtbActivity extends Activity { + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_horizontal_coordinator_ntb); + initUI(); + } + + private void initUI() { + final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb); + viewPager.setAdapter(new PagerAdapter() { + @Override + public int getCount() { + return 5; + } + + @Override + public boolean isViewFromObject(final View view, final Object object) { + return view.equals(object); + } + + @Override + public void destroyItem(final View container, final int position, final Object object) { + ((ViewPager) container).removeView((View) object); + } + + @Override + public Object instantiateItem(final ViewGroup container, final int position) { + final View view = LayoutInflater.from( + getBaseContext()).inflate(R.layout.item_vp_list, null, false); + + final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(new LinearLayoutManager( + getBaseContext(), LinearLayoutManager.VERTICAL, false + ) + ); + recyclerView.setAdapter(new RecycleAdapter()); + + container.addView(view); + return view; + } + }); + + final String[] colors = getResources().getStringArray(R.array.default_preview); + + final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal); + final ArrayList models = new ArrayList<>(); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0])) + .title("Heart") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_second), + Color.parseColor(colors[1])) + .title("Cup") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2])) + .title("Diploma") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fourth), + Color.parseColor(colors[3])) + .title("Flag") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_fifth), + Color.parseColor(colors[4])) + .title("Medal") + .build() + ); + //IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT + navigationTabBar.setBehaviorTranslationEnabled(true); + + navigationTabBar.setModels(models); + navigationTabBar.setViewPager(viewPager, 2); + + final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal); + //THE FOLLOWING LINE IS IMPORTANT IF YOU WANT THE BACKGROUND VIEW SCROLL BEHAVIOUR TO MATCH + //THE TABBAR SCROLL BEHAVIOR IN THE COORDINATOR LAYOUT + navigationTabBar.setBackgroundView(bgNavigationTabBar); + + navigationTabBar.post(new Runnable() { + @Override + public void run() { + final View viewPager = findViewById(R.id.vp_horizontal_ntb); + ((ViewGroup.MarginLayoutParams) viewPager.getLayoutParams()).topMargin = + (int) -navigationTabBar.getBadgeMargin(); + viewPager.requestLayout(); + } + }); + + navigationTabBar.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() { + @Override + public void onStartTabSelected(final NavigationTabBar.Model model, final int index) { + + } + + @Override + public void onEndTabSelected(final NavigationTabBar.Model model, final int index) { + model.hideBadge(); + } + }); + + findViewById(R.id.mask).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + for (int i = 0; i < navigationTabBar.getModels().size(); i++) { + final NavigationTabBar.Model model = navigationTabBar.getModels().get(i); + navigationTabBar.postDelayed(new Runnable() { + @Override + public void run() { + final String title = String.valueOf(new Random().nextInt(15)); + if (!model.isBadgeShowed()) { + model.setBadgeTitle(title); + model.showBadge(); + } else model.updateBadgeTitle(title); + } + }, i * 100); + } + } + }); + } + + public class RecycleAdapter extends RecyclerView.Adapter { + + @Override + public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) { + final View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.item_list, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, final int position) { + holder.txt.setText(String.format("Navigation Item #%d", position)); + } + + @Override + public int getItemCount() { + return 20; + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + public TextView txt; + + public ViewHolder(final View itemView) { + super(itemView); + txt = (TextView) itemView.findViewById(R.id.txt_vp_item_list); + } + } + } +} diff --git a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java index 21e46e3..d0fc224 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java +++ b/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java @@ -19,6 +19,8 @@ protected void onCreate(Bundle savedInstanceState) { private void initUI() { final View btnHorizontalNtb = findViewById(R.id.btn_horizontal_ntb); btnHorizontalNtb.setOnClickListener(this); + final View btnHorizontalCoordinatorNtb = findViewById(R.id.btn_horizontal_coordinator_ntb); + btnHorizontalCoordinatorNtb.setOnClickListener(this); final View btnTopHorizontalNtb = findViewById(R.id.btn_horizontal_top_ntb); btnTopHorizontalNtb.setOnClickListener(this); final View btnVerticalNtb = findViewById(R.id.btn_vertical_ntb); @@ -53,6 +55,11 @@ public void onAnimationEnd(final View view) { new Intent(MainActivity.this, TopHorizontalNtbActivity.class) ); break; + case R.id.btn_horizontal_coordinator_ntb: + startActivity( + new Intent(MainActivity.this, HorizontalCoordinatorNtbActivity.class) + ); + break; case R.id.btn_vertical_ntb: startActivity( new Intent(MainActivity.this, VerticalNtbActivity.class) diff --git a/app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml b/app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml new file mode 100644 index 0000000..4894b16 --- /dev/null +++ b/app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7b92cf2..42818b7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:weightSum="4" + android:weightSum="5" android:background="#423752"> - + + + 180dp + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 52071e1..6c5d7ef 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -2,5 +2,5 @@