From c5a9b4b8c1f21f206518e1b470f8419d9361485b Mon Sep 17 00:00:00 2001 From: Ashok-Varma <8Uv?:frv&,ViXg~> Date: Sat, 30 Apr 2016 09:17:36 +0530 Subject: [PATCH] milestone 1.1.1 push --- README.md | 4 +- app/build.gradle | 18 ++ app/src/main/AndroidManifest.xml | 4 + .../sample/BottomNavigationActivity.java | 58 ++--- .../bottomnavigation/BadgeItem.java | 148 ++++++++---- .../bottomnavigation/BottomNavigationBar.java | 216 +++++++++++------- .../BottomNavigationHelper.java | 23 +- build.gradle | 2 +- gradle.properties | 4 +- 9 files changed, 318 insertions(+), 159 deletions(-) diff --git a/README.md b/README.md index 8400f25..82c32a3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BottomNavigation -get sample apk from [Google Play Store][googlePlayStoreLink] +**get sample apk from [Google Play Store][googlePlayStoreLink]** @@ -76,7 +76,7 @@ bottomNavigationBar public void onTabSelected(int position) { } @Override - public void onTabUnselected(int position) {] + public void onTabUnselected(int position) { } @Override public void onTabReselected(int position) { diff --git a/app/build.gradle b/app/build.gradle index 12c096e..b4e9186 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,15 @@ +buildscript { + repositories { + maven { url 'https://maven.fabric.io/public' } + } + + dependencies { + classpath 'io.fabric.tools:gradle:1.+' + } +} + apply plugin: 'com.android.application' +apply plugin: 'io.fabric' android { compileSdkVersion Integer.parseInt(ANDROID_BUILD_SDK_VERSION) @@ -19,6 +30,10 @@ android { } } +repositories { + maven { url 'https://maven.fabric.io/public' } +} + ext { supportLibraryVersion = project.ANDROID_SUPPORT_LIBRARY_VERSION } @@ -28,4 +43,7 @@ dependencies { compile "com.android.support:appcompat-v7:${supportLibraryVersion}" compile "com.android.support:design:${supportLibraryVersion}" compile project(':bottom-navigation-bar') + compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') { + transitive = true; + } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc8f920..0eb7cf6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,10 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/ashokvarma/bottomnavigation/sample/BottomNavigationActivity.java b/app/src/main/java/com/ashokvarma/bottomnavigation/sample/BottomNavigationActivity.java index 5554eb8..fb89d68 100644 --- a/app/src/main/java/com/ashokvarma/bottomnavigation/sample/BottomNavigationActivity.java +++ b/app/src/main/java/com/ashokvarma/bottomnavigation/sample/BottomNavigationActivity.java @@ -16,6 +16,9 @@ import com.ashokvarma.bottomnavigation.BadgeItem; import com.ashokvarma.bottomnavigation.BottomNavigationBar; import com.ashokvarma.bottomnavigation.BottomNavigationItem; +import com.crashlytics.android.Crashlytics; + +import io.fabric.sdk.android.Fabric; public class BottomNavigationActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, BottomNavigationBar.OnTabSelectedListener { @@ -46,6 +49,7 @@ public class BottomNavigationActivity extends AppCompatActivity implements View. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_bottom_navigation); bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar); @@ -154,6 +158,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { } break; } + if (!items5.isChecked() && !items3.isChecked() && !items4.isChecked()) { + buttonView.setChecked(true); + } refresh(); } @@ -163,27 +170,27 @@ private void refresh() { setScrollableText(lastSelectedPosition); -// BadgeItem badgeItem = new BadgeItem().setText("new !"); -// BadgeItem badgeItem1 = new BadgeItem().setText("damn big"); - numberBadgeItem = new BadgeItem().setBorderWidth(4).setBackgroundColorResource(R.color.blue).setText("" + lastSelectedPosition).setHideOnSelect(autoHide.isChecked()); -// BadgeItem numberBadgeItem1 = new BadgeItem().setBorderWidth(4).setBackgroundColorResource(R.color.blue).setText("12"); -// BadgeItem numberBadgeItem2 = new BadgeItem().setBorderWidth(6).setText("123"); -// BadgeItem badgeItem = null; -// BadgeItem badgeItem1 = null; -// numberBadgeItem = null; -// BadgeItem numberBadgeItem1 = null; -// BadgeItem numberBadgeItem2 = null; + numberBadgeItem = new BadgeItem() + .setBorderWidth(4) + .setBackgroundColorResource(R.color.blue) + .setText("" + lastSelectedPosition) + .setHideOnSelect(autoHide.isChecked()); + if (modeFixed.isChecked()) { - bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED); + bottomNavigationBar + .setMode(BottomNavigationBar.MODE_FIXED); } else if (modeShifting.isChecked()) { - bottomNavigationBar.setMode(BottomNavigationBar.MODE_SHIFTING); + bottomNavigationBar + .setMode(BottomNavigationBar.MODE_SHIFTING); } if (bgStatic.isChecked()) { - bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC); + bottomNavigationBar + .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC); } else if (bgRipple.isChecked()) { - bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE); + bottomNavigationBar + .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE); } if (items3.isChecked()) { @@ -201,8 +208,7 @@ private void refresh() { .addItem(new BottomNavigationItem(R.drawable.ic_tv_white_24dp, "Movies & TV").setActiveColorResource(R.color.brown)) .setFirstSelectedPosition(lastSelectedPosition > 3 ? 3 : lastSelectedPosition) .initialise(); - } else { - items5.setChecked(true); + } else if (items5.isChecked()) { bottomNavigationBar .addItem(new BottomNavigationItem(R.drawable.ic_home_white_24dp, "Home").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem)) .addItem(new BottomNavigationItem(R.drawable.ic_book_white_24dp, "Books").setActiveColorResource(R.color.teal)) @@ -224,6 +230,16 @@ public void onTabSelected(int position) { setScrollableText(position); } + @Override + public void onTabUnselected(int position) { + + } + + @Override + public void onTabReselected(int position) { + message.setText(position + " Tab Reselected"); + } + private void setScrollableText(int position) { switch (position) { case 0: @@ -246,14 +262,4 @@ private void setScrollableText(int position) { break; } } - - @Override - public void onTabUnselected(int position) { - - } - - @Override - public void onTabReselected(int position) { - message.setText(position + " Tab Reselected"); - } } diff --git a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BadgeItem.java b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BadgeItem.java index fb45abe..77a2f7f 100644 --- a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BadgeItem.java +++ b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BadgeItem.java @@ -10,6 +10,7 @@ import android.text.TextUtils; import android.view.Gravity; import android.view.View; +import android.widget.FrameLayout; import android.widget.TextView; import java.lang.ref.WeakReference; @@ -40,22 +41,27 @@ public class BadgeItem { private int mBorderWidth = 0; - private Gravity mGravity; + private int mGravity = Gravity.TOP | Gravity.END; private boolean mHideOnSelect; - private WeakReference mTextView; + private WeakReference mTextViewRef; private boolean mIsHidden = false; private int mAnimationDuration = 200; + /////////////////////////////////////////////////////////////////////////// + // Public setter methods + /////////////////////////////////////////////////////////////////////////// + /** * @param colorResource resource for background color * @return this, to allow builder pattern */ public BadgeItem setBackgroundColorResource(@ColorRes int colorResource) { this.mBackgroundColorResource = colorResource; + refreshDrawable(); return this; } @@ -65,6 +71,7 @@ public BadgeItem setBackgroundColorResource(@ColorRes int colorResource) { */ public BadgeItem setBackgroundColor(@Nullable String colorCode) { this.mBackgroundColorCode = colorCode; + refreshDrawable(); return this; } @@ -74,6 +81,7 @@ public BadgeItem setBackgroundColor(@Nullable String colorCode) { */ public BadgeItem setBackgroundColor(int color) { this.mBackgroundColor = color; + refreshDrawable(); return this; } @@ -83,6 +91,7 @@ public BadgeItem setBackgroundColor(int color) { */ public BadgeItem setTextColorResource(@ColorRes int colorResource) { this.mTextColorResource = colorResource; + setTextColor(); return this; } @@ -92,6 +101,7 @@ public BadgeItem setTextColorResource(@ColorRes int colorResource) { */ public BadgeItem setTextColor(@Nullable String colorCode) { this.mTextColorCode = colorCode; + setTextColor(); return this; } @@ -101,17 +111,18 @@ public BadgeItem setTextColor(@Nullable String colorCode) { */ public BadgeItem setTextColor(int color) { this.mTextColor = color; + setTextColor(); return this; } /** - * @param mText text to be set in badge (this shouldn't be empty text) + * @param text text to be set in badge (this shouldn't be empty text) * @return this, to allow builder pattern */ - public BadgeItem setText(@Nullable CharSequence mText) { - this.mText = mText; - if (mTextView != null && mTextView.get() != null) { -// if (TextUtils.isEmpty(mText)) { + public BadgeItem setText(@Nullable CharSequence text) { + this.mText = text; + if (isWeakReferenceValid()) { +// if (TextUtils.isEmpty(text)) { // if (!mIsHidden) { // hide(); // } @@ -119,10 +130,11 @@ public BadgeItem setText(@Nullable CharSequence mText) { // if (mIsHidden) { // show(); // } -// mTextView.get().setText(mText); +// mTextViewRef.get().setText(text); // } - if (!TextUtils.isEmpty(mText)) { - mTextView.get().setText(mText); + TextView textView = mTextViewRef.get(); + if (!TextUtils.isEmpty(text)) { + textView.setText(text); } } return this; @@ -134,6 +146,7 @@ public BadgeItem setText(@Nullable CharSequence mText) { */ public BadgeItem setBorderColorResource(@ColorRes int colorResource) { this.mBorderColorResource = colorResource; + refreshDrawable(); return this; } @@ -143,6 +156,7 @@ public BadgeItem setBorderColorResource(@ColorRes int colorResource) { */ public BadgeItem setBorderColor(@Nullable String colorCode) { this.mBorderColorCode = colorCode; + refreshDrawable(); return this; } @@ -152,24 +166,32 @@ public BadgeItem setBorderColor(@Nullable String colorCode) { */ public BadgeItem setBorderColor(int color) { this.mBorderColor = color; + refreshDrawable(); return this; } /** - * @param mBorderWidth border width in pixels + * @param borderWidth border width in pixels * @return this, to allow builder pattern */ - public BadgeItem setBorderWidth(int mBorderWidth) { - this.mBorderWidth = mBorderWidth; + public BadgeItem setBorderWidth(int borderWidth) { + this.mBorderWidth = borderWidth; + refreshDrawable(); return this; } /** - * @param mGravity gravity of badge (TOP||LEFT ..etc) + * @param gravity gravity of badge (TOP|LEFT ..etc) * @return this, to allow builder pattern */ - public BadgeItem setGravity(Gravity mGravity) { - this.mGravity = mGravity; + public BadgeItem setGravity(int gravity) { + this.mGravity = gravity; + if (isWeakReferenceValid()) { + TextView textView = mTextViewRef.get(); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) textView.getLayoutParams(); + layoutParams.gravity = gravity; + textView.setLayoutParams(layoutParams); + } return this; } @@ -182,6 +204,19 @@ public BadgeItem setHideOnSelect(boolean hideOnSelect) { return this; } + /** + * @param animationDuration hide and show animation time + * @return this, to allow builder pattern + */ + public BadgeItem setAnimationDuration(int animationDuration) { + this.mAnimationDuration = animationDuration; + return this; + } + + /////////////////////////////////////////////////////////////////////////// + // Library only access method + /////////////////////////////////////////////////////////////////////////// + /** * Internal method used to update view when ever changes are made * @@ -189,7 +224,7 @@ public BadgeItem setHideOnSelect(boolean hideOnSelect) { * @return this, to allow builder pattern */ protected BadgeItem setTextView(TextView mTextView) { - this.mTextView = new WeakReference<>(mTextView); + this.mTextViewRef = new WeakReference<>(mTextView); return this; } @@ -252,7 +287,7 @@ protected int getBorderWidth() { /** * @return gravity of badge */ - protected Gravity getGravity() { + protected int getGravity() { return mGravity; } @@ -267,9 +302,58 @@ protected boolean isHideOnSelect() { * @return reference to text-view */ protected WeakReference getTextView() { - return mTextView; + return mTextViewRef; + } + + + /////////////////////////////////////////////////////////////////////////// + // Internal Methods + /////////////////////////////////////////////////////////////////////////// + + private void refreshDrawable() { + if (isWeakReferenceValid()) { + TextView textView = mTextViewRef.get(); + textView.setBackgroundDrawable(BottomNavigationHelper.getBadgeDrawable(this, textView.getContext())); + } + } + + private void setTextColor() { + if (isWeakReferenceValid()) { + TextView textView = mTextViewRef.get(); + textView.setTextColor(getTextColor(textView.getContext())); + } + } + + private boolean isWeakReferenceValid() { + return mTextViewRef != null && mTextViewRef.get() != null; + } + + /////////////////////////////////////////////////////////////////////////// + // Internal call back methods + /////////////////////////////////////////////////////////////////////////// + + /** + * callback from bottom navigation tab when it is selected + */ + void select() { + if (mHideOnSelect) { + hide(true); + } } + /** + * callback from bottom navigation tab when it is un-selected + */ + void unSelect() { + if (mHideOnSelect) { + show(true); + } + } + + /////////////////////////////////////////////////////////////////////////// + // Public functionality methods + /////////////////////////////////////////////////////////////////////////// + /** * @return this, to allow builder pattern */ @@ -302,8 +386,8 @@ public BadgeItem show() { */ public BadgeItem show(boolean animate) { mIsHidden = false; - if (mTextView != null && mTextView.get() != null) { - TextView textView = mTextView.get(); + if (isWeakReferenceValid()) { + TextView textView = mTextViewRef.get(); if (animate) { textView.setScaleX(0); textView.setScaleY(0); @@ -336,8 +420,8 @@ public BadgeItem hide() { */ public BadgeItem hide(boolean animate) { mIsHidden = true; - if (mTextView != null && mTextView.get() != null) { - TextView textView = mTextView.get(); + if (isWeakReferenceValid()) { + TextView textView = mTextViewRef.get(); if (animate) { ViewPropertyAnimatorCompat animatorCompat = ViewCompat.animate(textView); animatorCompat.cancel(); @@ -373,22 +457,4 @@ public void onAnimationCancel(View view) { public boolean isHidden() { return mIsHidden; } - - /** - * callback from bottom navigation tab when it is selected - */ - void select() { - if (mHideOnSelect) { - hide(true); - } - } - - /** - * callback from bottom navigation tab when it is un-selected - */ - void unSelect() { - if (mHideOnSelect) { - show(true); - } - } } diff --git a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationBar.java b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationBar.java index 26f9e05..5f05c99 100644 --- a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationBar.java +++ b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationBar.java @@ -88,6 +88,10 @@ public class BottomNavigationBar extends FrameLayout { private int mAnimationDuration = 200; private int mRippleAnimationDuration = 500; + /////////////////////////////////////////////////////////////////////////// + // View Default Constructors and Methods + /////////////////////////////////////////////////////////////////////////// + public BottomNavigationBar(Context context) { super(context); init(); @@ -135,6 +139,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + /////////////////////////////////////////////////////////////////////////// + // View Data Setter methods, Called before Initialize method + /////////////////////////////////////////////////////////////////////////// + /** * Used to add a new tab. * @@ -239,18 +247,6 @@ public BottomNavigationBar setFirstSelectedPosition(int firstSelectedPosition) { return this; } - /** - * ripple animation will be 2.5 times this animation duration. - * - * @param animationDuration animation duration for tab animations - * @return this, to allow builder pattern - */ - public BottomNavigationBar setAnimationDuration(int animationDuration) { - this.mAnimationDuration = animationDuration; - this.mRippleAnimationDuration = (int) (animationDuration * 2.5); - return this; - } - /** * will be public once all bugs are ressolved. */ @@ -259,14 +255,9 @@ private BottomNavigationBar setScrollable(boolean scrollable) { return this; } - /** - * @param tabSelectedListener callback listener for tabs - * @return this, to allow builder pattern - */ - public BottomNavigationBar setTabSelectedListener(OnTabSelectedListener tabSelectedListener) { - this.mTabSelectedListener = tabSelectedListener; - return this; - } + /////////////////////////////////////////////////////////////////////////// + // Initialise Method + /////////////////////////////////////////////////////////////////////////// /** * This method should be called at the end of all customisation method. @@ -321,41 +312,36 @@ public void initialise() { } if (mBottomNavigationTabs.size() > mFirstSelectedPosition) { - selectTabInternal(mFirstSelectedPosition, true, true); + selectTabInternal(mFirstSelectedPosition, true, false); } else if (mBottomNavigationTabs.size() > 0) { - selectTabInternal(0, true, true); + selectTabInternal(0, true, false); } } } + //////////////////////////////////////////////////////////////////////////////////////////////// + // Anytime Setter methods that can be called irrespective of whether we call initialise or not + //////////////////////////////////////////////////////////////////////////////////////////////// + /** - * Internal method to setup tabs - * - * @param bottomNavigationTab Tab item - * @param currentItem data structure for tab item - * @param itemWidth tab item in-active width - * @param itemActiveWidth tab item active width + * @param tabSelectedListener callback listener for tabs + * @return this, to allow builder pattern */ - private void setUpTab(BottomNavigationTab bottomNavigationTab, BottomNavigationItem currentItem, int itemWidth, int itemActiveWidth) { - bottomNavigationTab.setInactiveWidth(itemWidth); - bottomNavigationTab.setActiveWidth(itemActiveWidth); - bottomNavigationTab.setPosition(mBottomNavigationItems.indexOf(currentItem)); - - bottomNavigationTab.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - BottomNavigationTab bottomNavigationTabView = (BottomNavigationTab) v; - selectTabInternal(bottomNavigationTabView.getPosition(), false, true); - } - }); - - mBottomNavigationTabs.add(bottomNavigationTab); - - BottomNavigationHelper.bindTabWithData(currentItem, bottomNavigationTab, this); - - bottomNavigationTab.initialise(mBackgroundStyle == BACKGROUND_STYLE_STATIC); + public BottomNavigationBar setTabSelectedListener(OnTabSelectedListener tabSelectedListener) { + this.mTabSelectedListener = tabSelectedListener; + return this; + } - mTabContainer.addView(bottomNavigationTab); + /** + * ripple animation will be 2.5 times this animation duration. + * + * @param animationDuration animation duration for tab animations + * @return this, to allow builder pattern + */ + public BottomNavigationBar setAnimationDuration(int animationDuration) { + this.mAnimationDuration = animationDuration; + this.mRippleAnimationDuration = (int) (animationDuration * 2.5); + return this; } /** @@ -370,7 +356,13 @@ public void clearAll() { mSelectedPosition = DEFAULT_SELECTED_POSITION; } + /////////////////////////////////////////////////////////////////////////// + // Setter methods that should called only after initialise is called + /////////////////////////////////////////////////////////////////////////// + /** + * Should be called only after initialization of BottomBar(i.e after calling initialize method) + * * @param newPosition to select a tab after bottom navigation bar is initialised */ public void selectTab(int newPosition) { @@ -378,6 +370,8 @@ public void selectTab(int newPosition) { } /** + * Should be called only after initialization of BottomBar(i.e after calling initialize method) + * * @param newPosition to select a tab after bottom navigation bar is initialised * @param callListener should this change call listener callbacks */ @@ -385,6 +379,40 @@ public void selectTab(int newPosition, boolean callListener) { selectTabInternal(newPosition, false, callListener); } + /////////////////////////////////////////////////////////////////////////// + // Internal Methods of the class + /////////////////////////////////////////////////////////////////////////// + + /** + * Internal method to setup tabs + * + * @param bottomNavigationTab Tab item + * @param currentItem data structure for tab item + * @param itemWidth tab item in-active width + * @param itemActiveWidth tab item active width + */ + private void setUpTab(BottomNavigationTab bottomNavigationTab, BottomNavigationItem currentItem, int itemWidth, int itemActiveWidth) { + bottomNavigationTab.setInactiveWidth(itemWidth); + bottomNavigationTab.setActiveWidth(itemActiveWidth); + bottomNavigationTab.setPosition(mBottomNavigationItems.indexOf(currentItem)); + + bottomNavigationTab.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + BottomNavigationTab bottomNavigationTabView = (BottomNavigationTab) v; + selectTabInternal(bottomNavigationTabView.getPosition(), false, true); + } + }); + + mBottomNavigationTabs.add(bottomNavigationTab); + + BottomNavigationHelper.bindTabWithData(currentItem, bottomNavigationTab, this); + + bottomNavigationTab.initialise(mBackgroundStyle == BACKGROUND_STYLE_STATIC); + + mTabContainer.addView(bottomNavigationTab); + } + /** * Internal Method to select a tab * @@ -405,11 +433,23 @@ private void selectTabInternal(int newPosition, boolean firstTab, boolean callLi mBottomNavigationTabs.get(mSelectedPosition).unSelect(false, mAnimationDuration); mBottomNavigationTabs.get(newPosition).select(false, mAnimationDuration); - BottomNavigationTab clickedView = mBottomNavigationTabs.get(newPosition); + final BottomNavigationTab clickedView = mBottomNavigationTabs.get(newPosition); if (firstTab) { + // Running a ripple on the opening app won't be good so on firstTab this won't run. mContainer.setBackgroundColor(clickedView.getActiveColor()); + mBackgroundOverlay.setVisibility(View.GONE); } else { - BottomNavigationHelper.setBackgroundWithRipple(clickedView, mContainer, mBackgroundOverlay, clickedView.getActiveColor(), mRippleAnimationDuration); + mBackgroundOverlay.post(new Runnable() { + @Override + public void run() { +// try { + BottomNavigationHelper.setBackgroundWithRipple(clickedView, mContainer, mBackgroundOverlay, clickedView.getActiveColor(), mRippleAnimationDuration); +// } catch (Exception e) { +// mContainer.setBackgroundColor(clickedView.getActiveColor()); +// mBackgroundOverlay.setVisibility(View.GONE); +// } + } + }); } } mSelectedPosition = newPosition; @@ -419,48 +459,23 @@ private void selectTabInternal(int newPosition, boolean firstTab, boolean callLi /** * Internal method used to send callbacks to listener * - * @param oldPosition old selected tab position + * @param oldPosition old selected tab position, -1 if this is first call * @param newPosition newly selected tab position */ private void sendListenerCall(int oldPosition, int newPosition) { - if (mTabSelectedListener != null && oldPosition != -1) { + if (mTabSelectedListener != null) { +// && oldPosition != -1) { if (oldPosition == newPosition) { mTabSelectedListener.onTabReselected(newPosition); } else { mTabSelectedListener.onTabSelected(newPosition); - mTabSelectedListener.onTabUnselected(newPosition); + if (oldPosition != -1) { + mTabSelectedListener.onTabUnselected(oldPosition); + } } } } - /** - * hide with animation - */ - public void hide() { - hide(true); - } - - /** - * @param animate is animation enabled for hide - */ - public void hide(boolean animate) { - setTranslationY(this.getHeight(), animate); - } - - /** - * unHide with animation - */ - public void unHide() { - unHide(true); - } - - /** - * @param animate is animation enabled for unHide - */ - public void unHide(boolean animate) { - setTranslationY(0, animate); - } - /** * @param offset offset needs to be set * @param animate is animation enabled for translation @@ -496,6 +511,43 @@ private void animateOffset(final int offset) { mTranslationAnimator.translationY(offset).start(); } + /////////////////////////////////////////////////////////////////////////// + // Animating methods + /////////////////////////////////////////////////////////////////////////// + + /** + * hide with animation + */ + public void hide() { + hide(true); + } + + /** + * @param animate is animation enabled for hide + */ + public void hide(boolean animate) { + setTranslationY(this.getHeight(), animate); + } + + /** + * unHide with animation + */ + public void unHide() { + unHide(true); + } + + /** + * @param animate is animation enabled for unHide + */ + public void unHide(boolean animate) { + setTranslationY(0, animate); + } + + + /////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////// + /** * @return activeColor */ @@ -531,6 +583,10 @@ public int getAnimationDuration() { return mAnimationDuration; } + /////////////////////////////////////////////////////////////////////////// + // Listener interfaces + /////////////////////////////////////////////////////////////////////////// + /** * Callback interface invoked when a tab's selection state changes. */ diff --git a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationHelper.java b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationHelper.java index 501e6fb..6e16422 100644 --- a/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationHelper.java +++ b/bottom-navigation-bar/src/main/java/com/ashokvarma/bottomnavigation/BottomNavigationHelper.java @@ -8,6 +8,7 @@ import android.os.Build; import android.view.View; import android.view.ViewAnimationUtils; +import android.widget.FrameLayout; /** * Class description : This is utils class specific for this library, most the common code goes here. @@ -145,13 +146,7 @@ private static void setBadgeForTab(BadgeItem badgeItem, BottomNavigationTab bott Context context = bottomNavigationTab.getContext(); - GradientDrawable shape = new GradientDrawable(); - shape.setShape(GradientDrawable.RECTANGLE); - shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius)); -// shape.setCornerRadii(new float[]{8, 8, 8, 8, 0, 0, 0, 0}); - shape.setColor(badgeItem.getBackgroundColor(context)); - shape.setStroke(badgeItem.getBorderWidth(), badgeItem.getBorderColor(context)); - + GradientDrawable shape = getBadgeDrawable(badgeItem, context); bottomNavigationTab.badgeView.setBackgroundDrawable(shape); bottomNavigationTab.setBadgeItem(badgeItem); @@ -161,9 +156,23 @@ private static void setBadgeForTab(BadgeItem badgeItem, BottomNavigationTab bott bottomNavigationTab.badgeView.setTextColor(badgeItem.getTextColor(context)); bottomNavigationTab.badgeView.setText(badgeItem.getText()); + + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) bottomNavigationTab.badgeView.getLayoutParams(); + layoutParams.gravity = badgeItem.getGravity(); + bottomNavigationTab.badgeView.setLayoutParams(layoutParams); } } + static GradientDrawable getBadgeDrawable(BadgeItem badgeItem, Context context) { + GradientDrawable shape = new GradientDrawable(); + shape.setShape(GradientDrawable.RECTANGLE); + shape.setCornerRadius(context.getResources().getDimensionPixelSize(R.dimen.badge_corner_radius)); +// shape.setCornerRadii(new float[]{8, 8, 8, 8, 0, 0, 0, 0}); + shape.setColor(badgeItem.getBackgroundColor(context)); + shape.setStroke(badgeItem.getBorderWidth(), badgeItem.getBorderColor(context)); + return shape; + } + /** * Used to set the ripple animation when a tab is selected * diff --git a/build.gradle b/build.gradle index cdfcc52..9ca9021 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0-alpha5' + classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' diff --git a/gradle.properties b/gradle.properties index 564b639..8b3a72e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,8 +22,8 @@ ANDROID_BUILD_TOOLS_VERSION=23.0.2 ANDROID_BUILD_TARGET_SDK_VERSION=23 ANDROID_BUILD_MIN_SDK_VERSION=14 -APP_VERSION_NAME = 1.1.0 -APP_VERSION_CODE = 1 +APP_VERSION_NAME = 1.1.1 +APP_VERSION_CODE = 2 ANDROID_SUPPORT_LIBRARY_VERSION = 23.3.0 ANDROID_PLAY_SERVICES_VERSION = 8.4.0 \ No newline at end of file