From 6f0669310664c7cc8ea0643e544d3490e19e142e Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Sat, 25 May 2019 23:56:57 +0500 Subject: [PATCH 1/7] Fixed Bugs { be aware written in kotlin } fixed rotation bug now on screen rotation no crash or {Null Pointer Exception} Now TypeFaces can be applied fixed Save Restore State. Removed unused code fixed Click listener bug.. -> click listener was not being called for default active view... :) --- .../BubbleNavigationLinearView | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView new file mode 100644 index 0000000..1b82bdb --- /dev/null +++ b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView @@ -0,0 +1,148 @@ +package com.superTasker.frameworkdrivers.customWidgets + +import android.content.Context +import android.graphics.Typeface +import android.os.Bundle +import android.util.AttributeSet +import android.util.Log +import android.view.Gravity +import android.view.View +import android.widget.LinearLayout +import androidx.core.view.get +import com.gauravk.bubblenavigation.BubbleToggleView +import com.gauravk.bubblenavigation.listener.BubbleNavigationChangeListener +import java.lang.IllegalStateException + +class BubbleNavigationLinearView :LinearLayout,View.OnClickListener{ + + + private val CURRENT_ACTIVE_VIEW:String ="x.f" + private var currentActiveItemPosition: Int = 0 + private val TAG = "BNLView" + private var navigationChangeListener: BubbleNavigationChangeListener? = null + + constructor(context:Context,attrs:AttributeSet?):super(context,attrs) { + init() + } + constructor(context:Context):super(context) { + init() + } + constructor(context:Context,attrs:AttributeSet?,defStyleAttr:Int):super(context,attrs,defStyleAttr) { + init() + } + private fun init() { + orientation = HORIZONTAL + gravity = Gravity.CENTER + } + + override fun onFinishInflate() { + super.onFinishInflate() + checkViewsAreAllBubble() + setClickListenerForItems() + refreshActiveState() + updateMeasurementForItems() + } + private fun refreshActiveState() { + var foundActiveElement = false + for ( i:Int in 0 until childCount) { + val btv = this[i] as BubbleToggleView + if (btv.isActive && !foundActiveElement) { + foundActiveElement = true + this.currentActiveItemPosition = i + } else { + btv.setInitialState(false) + } + } + if (!foundActiveElement) { + (this[this.currentActiveItemPosition] as BubbleToggleView).setInitialState(true) + } + } + + private fun updateMeasurementForItems() { + val numChildViews = childCount + if(numChildViews > 0) { + val calculatedEachItemWidth = (measuredWidth - (paddingRight + paddingLeft)) / numChildViews + for(i:Int in 0 until numChildViews) { + (this[i] as BubbleToggleView).updateMeasurements(calculatedEachItemWidth) + } + } + + } + + private fun checkViewsAreAllBubble() { + println("zzbc: $childCount" ) + for( i:Int in 0 until childCount) { + val view:View = this[i] + val wrongView:Boolean = view !is BubbleToggleView + if(wrongView) { + throw IllegalStateException("only BubbleToggles are allowed") + } + } + } + + private fun setClickListenerForItems() { + for(i:Int in 0 until childCount) { + (this[i] as BubbleToggleView).setOnClickListener(this) + } + } + + private fun getItemPositionById(id: Int): Int { + for(i:Int in 0 until childCount) { + if(id == (this[i] as BubbleToggleView).id) { + return i + } + } + return -1 + } + + fun setNavigationChangeListener(navigationChangeListener: BubbleNavigationChangeListener) { + this.navigationChangeListener = navigationChangeListener + this.navigationChangeListener?.onNavigationChanged(this[currentActiveItemPosition],this.currentActiveItemPosition) + } + + fun setTypeface(typeface: Typeface) { + for(i:Int in 0 until childCount) { + (this[i] as BubbleToggleView).setTitleTypeface(typeface) + } + } + + + fun getCurrentActiveItemPosition(): Int { + return currentActiveItemPosition + } + + fun setCurrentActiveItem(position: Int) { + if (currentActiveItemPosition == position) return + if (position < 0 || position >= this.childCount) + return + val btv:BubbleToggleView =( this[(position)] as BubbleToggleView) + btv.performClick() + } + + override fun onClick(view:View?) { + println("clicked ") + val changedPosition = getItemPositionById(view?.id!!) + if (changedPosition >= 0) { + if (changedPosition == currentActiveItemPosition) { + return + } + val currentActiveToggleView:BubbleToggleView = this[(currentActiveItemPosition)] as BubbleToggleView + val newActiveToggleView = this[(changedPosition)] as BubbleToggleView + currentActiveToggleView.toggle() + newActiveToggleView.toggle() + //changed the current active position + currentActiveItemPosition = changedPosition + navigationChangeListener?.onNavigationChanged(view, currentActiveItemPosition) + } else { + Log.w(TAG, "Selected id not found! Cannot toggle") + } + } + + fun onSaveInstanceState(bundle: Bundle) { + bundle.putInt(CURRENT_ACTIVE_VIEW,currentActiveItemPosition) + } + + fun onRestoreInstanceState(bundle: Bundle) { + val currentActiveView = bundle.getInt(CURRENT_ACTIVE_VIEW,0) + setCurrentActiveItem(currentActiveView) + } From b22c79d49a6bf42eb78ca7ef8365b0b49e4c57a9 Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Sun, 26 May 2019 11:51:34 +0500 Subject: [PATCH 2/7] Rename BubbleNavigationLinearView to BubbleNavigationLinearView,kt --- .../{BubbleNavigationLinearView => BubbleNavigationLinearView,kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bubblenavigation/src/main/java/com/gauravk/bubblenavigation/{BubbleNavigationLinearView => BubbleNavigationLinearView,kt} (100%) diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView,kt similarity index 100% rename from bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView rename to bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView,kt From 6d9fd8b5de304952091368158e022cdf0b3c2549 Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Sun, 26 May 2019 11:52:49 +0500 Subject: [PATCH 3/7] Rename BubbleNavigationLinearView,kt to BubbleNavigationLinearView.kt --- ...ubbleNavigationLinearView,kt => BubbleNavigationLinearView.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bubblenavigation/src/main/java/com/gauravk/bubblenavigation/{BubbleNavigationLinearView,kt => BubbleNavigationLinearView.kt} (100%) diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView,kt b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt similarity index 100% rename from bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView,kt rename to bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt From 7036a21101ad2fd2d17eb66d74c2398e8fe5f1fd Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Sun, 26 May 2019 11:55:12 +0500 Subject: [PATCH 4/7] Update BubbleNavigationLinearView.kt --- .../com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt index 1b82bdb..c6fe8ba 100644 --- a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt +++ b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt @@ -1,4 +1,4 @@ -package com.superTasker.frameworkdrivers.customWidgets +package com.gauravk.bubblenavigation; import android.content.Context import android.graphics.Typeface From b97eaacdb394f46c0e1089f8d6aa9338a6f08e01 Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Wed, 19 Jun 2019 23:50:57 +0500 Subject: [PATCH 5/7] Update BubbleNavigationLinearView.java --- .../BubbleNavigationLinearView.java | 229 ++++++------------ 1 file changed, 75 insertions(+), 154 deletions(-) diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.java b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.java index 0392a72..3d1742c 100644 --- a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.java +++ b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.java @@ -37,198 +37,115 @@ @SuppressWarnings("unused") public class BubbleNavigationLinearView extends LinearLayout implements View.OnClickListener { - //constants - private static final String TAG = "BNLView"; - private static final int MIN_ITEMS = 2; - private static final int MAX_ITEMS = 5; - - private ArrayList bubbleNavItems; - private BubbleNavigationChangeListener navigationChangeListener; - + private String CURRENT_ACTIVE_VIEW = "x.f"; private int currentActiveItemPosition = 0; + private static final String TAG = "bnlview"; + private BubbleNavigationChangeListener navigationChangeListener = null; - /** - * Constructors - */ - public BubbleNavigationLinearView(@NonNull Context context) { - super(context); - init(context, null); - } + public BubbleNavigationLinearView(Context context, AttributeSet attrs) { + super(context,attrs); + init(); - public BubbleNavigationLinearView(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - init(context, attrs); } - - public BubbleNavigationLinearView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context, attrs); - } - - @Override - protected Parcelable onSaveInstanceState() { - Bundle bundle = new Bundle(); - bundle.putParcelable("superState", super.onSaveInstanceState()); - bundle.putInt("current_item", currentActiveItemPosition); - return bundle; + public BubbleNavigationLinearView(Context context) { + super(context); + init(); } - @Override - protected void onRestoreInstanceState(Parcelable state) { - if (state instanceof Bundle) { - Bundle bundle = (Bundle) state; - currentActiveItemPosition = bundle.getInt("current_item"); - state = bundle.getParcelable("superState"); - } - super.onRestoreInstanceState(state); + public BubbleNavigationLinearView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); } - ///////////////////////////////////////// - // PRIVATE METHODS - ///////////////////////////////////////// - - /** - * Initialize - * - * @param context current context - * @param attrs custom attributes - */ - private void init(Context context, AttributeSet attrs) { - + public void init() { setOrientation(HORIZONTAL); setGravity(Gravity.CENTER); + } - post(new Runnable() { - @Override - public void run() { - updateChildNavItems(); - } - }); - } - - /** - * Finds Child Elements of type {@link BubbleToggleView} and adds them to {@link #bubbleNavItems} - */ - private void updateChildNavItems() { - bubbleNavItems = new ArrayList<>(); - for (int index = 0; index < getChildCount(); ++index) { - View view = getChildAt(index); - if (view instanceof BubbleToggleView) - bubbleNavItems.add((BubbleToggleView) view); - else { - Log.w(TAG, "Cannot have child bubbleNavItems other than BubbleToggleView"); - return; - } - } - - if (bubbleNavItems.size() < MIN_ITEMS) { - Log.w(TAG, "The bubbleNavItems list should have at least 2 bubbleNavItems of BubbleToggleView"); - } else if (bubbleNavItems.size() > MAX_ITEMS) { - Log.w(TAG, "The bubbleNavItems list should not have more than 5 bubbleNavItems of BubbleToggleView"); - } - + protected void onFinishInflate() { + super.onFinishInflate(); + checkViewsAreAllBubble(); setClickListenerForItems(); - setInitialActiveState(); + refreshActiveState(); updateMeasurementForItems(); } - /** - * Makes sure that ONLY ONE child {@link #bubbleNavItems} is active - */ - private void setInitialActiveState() { + private void refreshActiveState() { boolean foundActiveElement = false; - for (int i = 0; i < bubbleNavItems.size(); i++) { - if (bubbleNavItems.get(i).isActive() && !foundActiveElement) { + for (int i=0;i 0) { - int calculatedEachItemWidth = (getMeasuredWidth() - (getPaddingRight() + getPaddingLeft())) / numChildElements; - for (BubbleToggleView btv : bubbleNavItems) - btv.updateMeasurements(calculatedEachItemWidth); + int numChildViews = getChildCount(); + if(numChildViews > 0) { + int calculatedEachItemWidth = (getMeasuredWidth() - (getPaddingRight() + getPaddingLeft())) / numChildViews; + for(int i=0;i= bubbleNavItems.size()) - return; - BubbleToggleView btv = bubbleNavItems.get(position); + if(currentActiveItemPosition == position) return; + if(position < 0 || position >= this.getChildCount()) { + return ; + } + BubbleToggleView btv = (BubbleToggleView)this.getChildAt(position); btv.performClick(); } - @Override public void onClick(View v) { int changedPosition = getItemPositionById(v.getId()); @@ -236,20 +153,24 @@ public void onClick(View v) { if (changedPosition == currentActiveItemPosition) { return; } - BubbleToggleView currentActiveToggleView = bubbleNavItems.get(currentActiveItemPosition); - BubbleToggleView newActiveToggleView = bubbleNavItems.get(changedPosition); - if (currentActiveToggleView != null) - currentActiveToggleView.toggle(); - if (newActiveToggleView != null) - newActiveToggleView.toggle(); - + BubbleToggleView currentActiveToggleView = (BubbleToggleView)this.getChildAt(currentActiveItemPosition); + BubbleToggleView newActiveToggleView = (BubbleToggleView)this.getChildAt(changedPosition); + currentActiveToggleView.toggle(); + newActiveToggleView.toggle(); //changed the current active position currentActiveItemPosition = changedPosition; - - if (navigationChangeListener != null) - navigationChangeListener.onNavigationChanged(v, currentActiveItemPosition); + navigationChangeListener.onNavigationChanged(v, currentActiveItemPosition); } else { Log.w(TAG, "Selected id not found! Cannot toggle"); } } + + public void onSaveInstanceState(Bundle bundle) { + bundle.putInt(CURRENT_ACTIVE_VIEW,currentActiveItemPosition); + } + + public void onRestoreInstanceState(Bundle bundle) { + int currentActiveView = bundle.getInt(CURRENT_ACTIVE_VIEW,0); + setCurrentActiveItem(currentActiveView); + } } From bbed98331d87e8ccbdd1343ac366773cfd579057 Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Wed, 19 Jun 2019 23:53:23 +0500 Subject: [PATCH 6/7] Delete BubbleNavigationLinearView.kt already updated *.java file --- .../BubbleNavigationLinearView.kt | 148 ------------------ 1 file changed, 148 deletions(-) delete mode 100644 bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt diff --git a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt b/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt deleted file mode 100644 index c6fe8ba..0000000 --- a/bubblenavigation/src/main/java/com/gauravk/bubblenavigation/BubbleNavigationLinearView.kt +++ /dev/null @@ -1,148 +0,0 @@ -package com.gauravk.bubblenavigation; - -import android.content.Context -import android.graphics.Typeface -import android.os.Bundle -import android.util.AttributeSet -import android.util.Log -import android.view.Gravity -import android.view.View -import android.widget.LinearLayout -import androidx.core.view.get -import com.gauravk.bubblenavigation.BubbleToggleView -import com.gauravk.bubblenavigation.listener.BubbleNavigationChangeListener -import java.lang.IllegalStateException - -class BubbleNavigationLinearView :LinearLayout,View.OnClickListener{ - - - private val CURRENT_ACTIVE_VIEW:String ="x.f" - private var currentActiveItemPosition: Int = 0 - private val TAG = "BNLView" - private var navigationChangeListener: BubbleNavigationChangeListener? = null - - constructor(context:Context,attrs:AttributeSet?):super(context,attrs) { - init() - } - constructor(context:Context):super(context) { - init() - } - constructor(context:Context,attrs:AttributeSet?,defStyleAttr:Int):super(context,attrs,defStyleAttr) { - init() - } - private fun init() { - orientation = HORIZONTAL - gravity = Gravity.CENTER - } - - override fun onFinishInflate() { - super.onFinishInflate() - checkViewsAreAllBubble() - setClickListenerForItems() - refreshActiveState() - updateMeasurementForItems() - } - private fun refreshActiveState() { - var foundActiveElement = false - for ( i:Int in 0 until childCount) { - val btv = this[i] as BubbleToggleView - if (btv.isActive && !foundActiveElement) { - foundActiveElement = true - this.currentActiveItemPosition = i - } else { - btv.setInitialState(false) - } - } - if (!foundActiveElement) { - (this[this.currentActiveItemPosition] as BubbleToggleView).setInitialState(true) - } - } - - private fun updateMeasurementForItems() { - val numChildViews = childCount - if(numChildViews > 0) { - val calculatedEachItemWidth = (measuredWidth - (paddingRight + paddingLeft)) / numChildViews - for(i:Int in 0 until numChildViews) { - (this[i] as BubbleToggleView).updateMeasurements(calculatedEachItemWidth) - } - } - - } - - private fun checkViewsAreAllBubble() { - println("zzbc: $childCount" ) - for( i:Int in 0 until childCount) { - val view:View = this[i] - val wrongView:Boolean = view !is BubbleToggleView - if(wrongView) { - throw IllegalStateException("only BubbleToggles are allowed") - } - } - } - - private fun setClickListenerForItems() { - for(i:Int in 0 until childCount) { - (this[i] as BubbleToggleView).setOnClickListener(this) - } - } - - private fun getItemPositionById(id: Int): Int { - for(i:Int in 0 until childCount) { - if(id == (this[i] as BubbleToggleView).id) { - return i - } - } - return -1 - } - - fun setNavigationChangeListener(navigationChangeListener: BubbleNavigationChangeListener) { - this.navigationChangeListener = navigationChangeListener - this.navigationChangeListener?.onNavigationChanged(this[currentActiveItemPosition],this.currentActiveItemPosition) - } - - fun setTypeface(typeface: Typeface) { - for(i:Int in 0 until childCount) { - (this[i] as BubbleToggleView).setTitleTypeface(typeface) - } - } - - - fun getCurrentActiveItemPosition(): Int { - return currentActiveItemPosition - } - - fun setCurrentActiveItem(position: Int) { - if (currentActiveItemPosition == position) return - if (position < 0 || position >= this.childCount) - return - val btv:BubbleToggleView =( this[(position)] as BubbleToggleView) - btv.performClick() - } - - override fun onClick(view:View?) { - println("clicked ") - val changedPosition = getItemPositionById(view?.id!!) - if (changedPosition >= 0) { - if (changedPosition == currentActiveItemPosition) { - return - } - val currentActiveToggleView:BubbleToggleView = this[(currentActiveItemPosition)] as BubbleToggleView - val newActiveToggleView = this[(changedPosition)] as BubbleToggleView - currentActiveToggleView.toggle() - newActiveToggleView.toggle() - //changed the current active position - currentActiveItemPosition = changedPosition - navigationChangeListener?.onNavigationChanged(view, currentActiveItemPosition) - } else { - Log.w(TAG, "Selected id not found! Cannot toggle") - } - } - - fun onSaveInstanceState(bundle: Bundle) { - bundle.putInt(CURRENT_ACTIVE_VIEW,currentActiveItemPosition) - } - - fun onRestoreInstanceState(bundle: Bundle) { - val currentActiveView = bundle.getInt(CURRENT_ACTIVE_VIEW,0) - setCurrentActiveItem(currentActiveView) - } From e9abfe31e4051332bbb9994d26eb7f00bd1acdf0 Mon Sep 17 00:00:00 2001 From: S Tanveer Hussain Date: Thu, 25 Mar 2021 22:34:21 +0500 Subject: [PATCH 7/7] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d92ef4..76fa2ce 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ [![AwesomeAndroid](https://img.shields.io/badge/Awesome_Android-BubbleNavigation-purple.svg?style=flat)](https://android.libhunt.com/bubble-navigation-alternatives) 🎉 A light-weight library to make beautiful Navigation Bar easily with ton of 🎨 customization option. - +
+**orientation,and first item selected bug and other bugs fixed** ## Demos | FloatingTopBarActivity | TopBarActivity |