Skip to content

Commit e6bbbea

Browse files
committed
BottomBehavior support
Fixes Optimizations Code refactor
1 parent c8a448d commit e6bbbea

18 files changed

+758
-928
lines changed

README.md

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ NavigationTabBar
55

66
Navigation tab bar with colorful interactions.
77

8-
Horizontal NTB|NTB with selected icons |NTB with CoordinatorLayout|Vertical NTB|NTB Samples|
9-
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
10-
![](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)
11-
8+
Horizontal NTB | NTB with bottom behavior | NTB with selected icons | NTB with CoordinatorLayout | Vertical NTB | NTB Samples |
9+
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
10+
![](https://lh6.googleusercontent.com/-Bf7uxUiRvfk/VvpVlkZzsVI/AAAAAAAACPA/Ysg9uuBpaL8UhsXpYPlyNJK6IJssdkMvg/w325-h552-no/hntb.gif)|![](https://lh4.googleusercontent.com/-mF70XCnMpgk/V1NnK34tnhI/AAAAAAAACkY/z0Z15Q_7gg4fMovWiEvo9agJgz7m933cQCL0B/w323-h552-no/btbntb.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)
1211
U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app).
1312

1413
Download
@@ -33,7 +32,7 @@ dependencies {
3332
Or Gradle Maven Central:
3433

3534
```groovy
36-
compile 'com.github.devlight.navigationtabbar:library:1.1.8'
35+
compile 'com.github.devlight.navigationtabbar:library:1.2.0'
3736
```
3837

3938
Or Maven:
@@ -42,7 +41,7 @@ Or Maven:
4241
<dependency>
4342
<groupId>com.github.devlight.navigationtabbar</groupId>
4443
<artifactId>library</artifactId>
45-
<version>1.1.8</version>
44+
<version>1.2.0</version>
4645
<type>aar</type>
4746
</dependency>
4847
```
@@ -63,9 +62,17 @@ For NTB you can set such parameters as:
6362

6463
allows you to set NTB models, where you set icon and color. Can be set up only via code.
6564

65+
- behavior:
66+
67+
allows you to set bottom translation behavior.
68+
6669
- view pager:
6770

68-
allows you to connect NTB with ViewPager. If you want your can also set OnPageChangeListener.
71+
allows you to connect NTB with ViewPager. If you want your can also set OnPageChangeListener.
72+
73+
- background:
74+
75+
allows you to set background to NTB which automatically set with offset relative to badge gravity.
6976

7077
- model selected icon:
7178

@@ -149,6 +156,9 @@ By default badge bg color is the active model color and badge title color is the
149156

150157
If your set ViewPager you can action down on active pointer and do like drag.
151158

159+
If you want to set the background to NTB, just set background via XML or code and its automatically set relative to badge gravity.
160+
161+
152162
<b>Init</b>
153163

154164
Check out in code init:
@@ -211,21 +221,7 @@ navigationTabBar.setBadgeBgColor(Color.RED);
211221
navigationTabBar.setBadgeTitleColor(Color.WHITE);
212222
```
213223

214-
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:
215-
216-
```java
217-
navigationTabBar.post(new Runnable() {
218-
@Override
219-
public void run() {
220-
final View background = findViewById(R.id.background);
221-
background.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
222-
background.requestLayout();
223-
}
224-
});
225-
```
226-
227224
If your models is in badge mode you can set title, hide, show, toggle and update badge title like this:
228-
229225
```java
230226
model.setTitle("Here some title to model");
231227
model.hideBadge();
@@ -234,17 +230,17 @@ model.toggleBadge();
234230
model.updateBadgeTitle("Here some title like NEW or some integer value");
235231
```
236232
237-
To enable translation inside CoordinatorLayout when at bottom of screen:
233+
To enable behavior translation inside CoordinatorLayout when at bottom of screen:
238234
```java
239-
bottomNavigation.setBehaviorTranslationEnabled(true);
235+
bottomNavigation.setBehaviorEnabled(true);
240236
```
241237

242238
Other methods check out in sample.
243239

244240
And XML init:
245241

246242
```xml
247-
<com.gigamole.library.NavigationTabBar
243+
<com.gigamole.library.ntb.NavigationTabBar
248244
android:id="@+id/ntb"
249245
android:layout_width="match_parent"
250246
android:layout_height="50dp"

app/src/main/java/com/gigamole/navigationtabbar/HorizontalCoordinatorNtbActivity.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import android.app.Activity;
44
import android.graphics.Color;
55
import android.os.Bundle;
6+
import android.support.design.widget.CollapsingToolbarLayout;
7+
import android.support.design.widget.CoordinatorLayout;
8+
import android.support.design.widget.Snackbar;
69
import android.support.v4.view.PagerAdapter;
710
import android.support.v4.view.ViewPager;
811
import android.support.v7.widget.LinearLayoutManager;
@@ -12,7 +15,7 @@
1215
import android.view.ViewGroup;
1316
import android.widget.TextView;
1417

15-
import com.gigamole.library.NavigationTabBar;
18+
import com.gigamole.library.ntb.NavigationTabBar;
1619

1720
import java.util.ArrayList;
1821
import java.util.Random;
@@ -104,26 +107,12 @@ public Object instantiateItem(final ViewGroup container, final int position) {
104107
.title("Medal")
105108
.build()
106109
);
107-
//IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT
108-
navigationTabBar.setBehaviorTranslationEnabled(true);
109110

110111
navigationTabBar.setModels(models);
111112
navigationTabBar.setViewPager(viewPager, 2);
112113

113-
final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
114-
//THE FOLLOWING LINE IS IMPORTANT IF YOU WANT THE BACKGROUND VIEW SCROLL BEHAVIOUR TO MATCH
115-
//THE TABBAR SCROLL BEHAVIOR IN THE COORDINATOR LAYOUT
116-
navigationTabBar.setBackgroundView(bgNavigationTabBar);
117-
118-
navigationTabBar.post(new Runnable() {
119-
@Override
120-
public void run() {
121-
final View viewPager = findViewById(R.id.vp_horizontal_ntb);
122-
((ViewGroup.MarginLayoutParams) viewPager.getLayoutParams()).topMargin =
123-
(int) -navigationTabBar.getBadgeMargin();
124-
viewPager.requestLayout();
125-
}
126-
});
114+
//IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT
115+
navigationTabBar.setBehaviorEnabled(true);
127116

128117
navigationTabBar.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() {
129118
@Override
@@ -137,7 +126,8 @@ public void onEndTabSelected(final NavigationTabBar.Model model, final int index
137126
}
138127
});
139128

140-
findViewById(R.id.mask).setOnClickListener(new View.OnClickListener() {
129+
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.parent);
130+
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
141131
@Override
142132
public void onClick(final View v) {
143133
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
@@ -153,8 +143,24 @@ public void run() {
153143
}
154144
}, i * 100);
155145
}
146+
147+
coordinatorLayout.postDelayed(new Runnable() {
148+
@Override
149+
public void run() {
150+
final Snackbar snackbar = Snackbar.make(coordinatorLayout, "Coordinator NTB", Snackbar.LENGTH_SHORT);
151+
snackbar.getView().setBackgroundColor(Color.parseColor("#9b92b3"));
152+
((TextView) snackbar.getView().findViewById(R.id.snackbar_text))
153+
.setTextColor(Color.parseColor("#423752"));
154+
snackbar.show();
155+
}
156+
}, 1000);
156157
}
157158
});
159+
160+
final CollapsingToolbarLayout collapsingToolbarLayout =
161+
(CollapsingToolbarLayout) findViewById(R.id.toolbar);
162+
collapsingToolbarLayout.setExpandedTitleColor(Color.parseColor("#009F90AF"));
163+
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.parseColor("#9f90af"));
158164
}
159165

160166
public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ViewHolder> {

app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import android.view.ViewGroup;
1111
import android.widget.TextView;
1212

13-
import com.gigamole.library.NavigationTabBar;
13+
import com.gigamole.library.ntb.NavigationTabBar;
1414

1515
import java.util.ArrayList;
1616

@@ -26,14 +26,6 @@ protected void onCreate(final Bundle savedInstanceState) {
2626
initUI();
2727
}
2828

29-
@Override
30-
protected void onDestroy() {
31-
super.onDestroy();
32-
System.runFinalization();
33-
Runtime.getRuntime().gc();
34-
System.gc();
35-
}
36-
3729
private void initUI() {
3830
final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
3931
viewPager.setAdapter(new PagerAdapter() {
@@ -134,15 +126,6 @@ public void onPageScrollStateChanged(final int state) {
134126
}
135127
});
136128

137-
navigationTabBar.post(new Runnable() {
138-
@Override
139-
public void run() {
140-
final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
141-
bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
142-
bgNavigationTabBar.requestLayout();
143-
}
144-
});
145-
146129
navigationTabBar.postDelayed(new Runnable() {
147130
@Override
148131
public void run() {

app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import android.support.v4.graphics.ColorUtils;
77
import android.widget.Toast;
88

9-
import com.gigamole.library.NavigationTabBar;
9+
import com.gigamole.library.ntb.NavigationTabBar;
1010

1111
import java.util.ArrayList;
1212

app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import android.view.ViewGroup;
1313
import android.widget.TextView;
1414

15-
import com.gigamole.library.NavigationTabBar;
15+
import com.gigamole.library.ntb.NavigationTabBar;
1616

1717
import java.util.ArrayList;
1818
import java.util.Random;
@@ -110,10 +110,6 @@ public Object instantiateItem(final ViewGroup container, final int position) {
110110
navigationTabBar.post(new Runnable() {
111111
@Override
112112
public void run() {
113-
final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
114-
bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
115-
bgNavigationTabBar.requestLayout();
116-
117113
final View viewPager = findViewById(R.id.vp_horizontal_ntb);
118114
((ViewGroup.MarginLayoutParams) viewPager.getLayoutParams()).topMargin =
119115
(int) -navigationTabBar.getBadgeMargin();

app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import android.view.ViewGroup;
1111
import android.widget.TextView;
1212

13-
import com.gigamole.library.NavigationTabBar;
13+
import com.gigamole.library.ntb.NavigationTabBar;
1414

1515
import java.util.ArrayList;
1616

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

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<android.support.design.widget.CoordinatorLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:id="@+id/parent"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
android:background="#423752"
@@ -10,32 +11,38 @@
1011

1112
<android.support.design.widget.AppBarLayout
1213
android:layout_width="match_parent"
13-
android:layout_height="@dimen/top_app_bar_height"
14+
android:layout_height="180dp"
1415
android:fitsSystemWindows="true"
15-
android:background="#00000000"
1616
android:theme="@style/AppTheme.AppBarOverlay">
1717

1818
<android.support.design.widget.CollapsingToolbarLayout
19+
android:id="@+id/toolbar"
1920
android:layout_width="match_parent"
2021
android:layout_height="match_parent"
2122
android:fitsSystemWindows="true"
22-
app:contentScrim="#423752"
23+
app:title="@string/app_name"
24+
app:expandedTitleTextAppearance="@null"
25+
app:contentScrim="#605271"
2326
app:layout_scrollFlags="scroll|exitUntilCollapsed">
27+
2428
<ImageView
2529
android:id="@+id/backdrop"
2630
android:layout_width="match_parent"
2731
android:layout_height="match_parent"
2832
android:fitsSystemWindows="true"
33+
android:background="#605271"
2934
android:src="@drawable/ic_eighth"
30-
app:layout_collapseMode="pin" />
35+
android:tint="#9f90af"
36+
android:padding="32dp"
37+
app:layout_collapseMode="pin"/>
3138

3239
<android.support.v7.widget.Toolbar
33-
android:fitsSystemWindows="true"
34-
android:id="@+id/toolbar"
3540
android:layout_width="match_parent"
3641
android:layout_height="?attr/actionBarSize"
42+
android:fitsSystemWindows="true"
3743
app:layout_collapseMode="parallax"
38-
app:popupTheme="@style/AppTheme.AppBarOverlay" />
44+
app:title="@string/app_name"
45+
app:popupTheme="@style/AppTheme.AppBarOverlay"/>
3946

4047
</android.support.design.widget.CollapsingToolbarLayout>
4148
</android.support.design.widget.AppBarLayout>
@@ -46,45 +53,30 @@
4653
android:layout_height="match_parent"
4754
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
4855

49-
50-
<View
51-
android:id="@+id/mask"
52-
android:layout_width="match_parent"
53-
android:layout_height="150dp"
54-
android:layout_gravity="bottom"/>
55-
5656
<android.support.design.widget.FloatingActionButton
5757
android:id="@+id/fab"
5858
android:layout_width="wrap_content"
59-
android:layout_height="64dp"
60-
android:src="@android:drawable/ic_dialog_email"
61-
android:layout_gravity="right|bottom"
62-
android:layout_marginBottom="64dp"
59+
android:layout_height="wrap_content"
60+
android:layout_gravity="bottom|end"
61+
android:layout_marginBottom="76dp"
6362
android:layout_marginRight="16dp"
64-
app:backgroundTint="#ffff0000"/>
63+
android:layout_marginEnd="16dp"
64+
android:tint="#9f90af"
65+
android:src="@drawable/ic_first"
66+
app:backgroundTint="#605271"/>
6567

66-
67-
<View
68-
android:id="@+id/bg_ntb_horizontal"
69-
android:layout_width="match_parent"
70-
android:layout_height="52dp"
71-
android:layout_gravity="bottom"
72-
android:background="#605271" />
73-
74-
<com.gigamole.library.NavigationTabBar
75-
android:id="@+id/ntb_horizontal"
76-
android:layout_width="match_parent"
77-
android:layout_height="60dp"
78-
android:layout_gravity="bottom"
79-
app:ntb_badge_bg_color="#ffff0000"
80-
app:ntb_badge_gravity="bottom"
81-
app:ntb_badge_position="left"
82-
app:ntb_badge_title_color="#ffffffff"
83-
app:ntb_badge_use_typeface="true"
84-
app:ntb_badged="true"
85-
app:ntb_scaled="false"
86-
app:ntb_title_mode="active"
87-
app:ntb_titled="true"
88-
app:ntb_typeface="fonts/agency.ttf" />
68+
<com.gigamole.library.ntb.NavigationTabBar
69+
android:id="@+id/ntb_horizontal"
70+
android:layout_width="match_parent"
71+
android:layout_height="60dp"
72+
android:layout_gravity="bottom"
73+
android:background="#605271"
74+
app:ntb_badge_bg_color="#ffff0000"
75+
app:ntb_badge_gravity="top"
76+
app:ntb_badge_position="left"
77+
app:ntb_badge_title_color="#ffffffff"
78+
app:ntb_badge_use_typeface="true"
79+
app:ntb_badged="true"
80+
app:ntb_typeface="fonts/agency.ttf"/>
8981

9082
</android.support.design.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)