Skip to content

Commit

Permalink
BottomBehavior support
Browse files Browse the repository at this point in the history
Fixes
Optimizations
Code refactor
  • Loading branch information
GIGAMOLE committed Jun 4, 2016
1 parent c8a448d commit e6bbbea
Show file tree
Hide file tree
Showing 18 changed files with 758 additions and 928 deletions.
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ NavigationTabBar

Navigation tab bar with colorful interactions.

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://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)

Horizontal NTB | NTB with bottom behavior | 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/-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)
U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app).

Download
Expand All @@ -33,7 +32,7 @@ dependencies {
Or Gradle Maven Central:

```groovy
compile 'com.github.devlight.navigationtabbar:library:1.1.8'
compile 'com.github.devlight.navigationtabbar:library:1.2.0'
```

Or Maven:
Expand All @@ -42,7 +41,7 @@ Or Maven:
<dependency>
<groupId>com.github.devlight.navigationtabbar</groupId>
<artifactId>library</artifactId>
<version>1.1.8</version>
<version>1.2.0</version>
<type>aar</type>
</dependency>
```
Expand All @@ -63,9 +62,17 @@ For NTB you can set such parameters as:

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

- behavior:

allows you to set bottom translation behavior.

- 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.

- background:

allows you to set background to NTB which automatically set with offset relative to badge gravity.

- model selected icon:

Expand Down Expand Up @@ -149,6 +156,9 @@ 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.

If you want to set the background to NTB, just set background via XML or code and its automatically set relative to badge gravity.


<b>Init</b>

Check out in code init:
Expand Down Expand Up @@ -211,21 +221,7 @@ 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:

```java
navigationTabBar.post(new Runnable() {
@Override
public void run() {
final View background = findViewById(R.id.background);
background.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
background.requestLayout();
}
});
```

If your models is in badge mode you can set title, hide, show, toggle and update badge title like this:

```java
model.setTitle("Here some title to model");
model.hideBadge();
Expand All @@ -234,17 +230,17 @@ model.toggleBadge();
model.updateBadgeTitle("Here some title like NEW or some integer value");
```
To enable translation inside CoordinatorLayout when at bottom of screen:
To enable behavior translation inside CoordinatorLayout when at bottom of screen:
```java
bottomNavigation.setBehaviorTranslationEnabled(true);
bottomNavigation.setBehaviorEnabled(true);
```

Other methods check out in sample.

And XML init:

```xml
<com.gigamole.library.NavigationTabBar
<com.gigamole.library.ntb.NavigationTabBar
android:id="@+id/ntb"
android:layout_width="match_parent"
android:layout_height="50dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -12,7 +15,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.gigamole.library.NavigationTabBar;
import com.gigamole.library.ntb.NavigationTabBar;

import java.util.ArrayList;
import java.util.Random;
Expand Down Expand Up @@ -104,26 +107,12 @@ public Object instantiateItem(final ViewGroup container, final int position) {
.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();
}
});
//IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT
navigationTabBar.setBehaviorEnabled(true);

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

findViewById(R.id.mask).setOnClickListener(new View.OnClickListener() {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.parent);
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
Expand All @@ -153,8 +143,24 @@ public void run() {
}
}, i * 100);
}

coordinatorLayout.postDelayed(new Runnable() {
@Override
public void run() {
final Snackbar snackbar = Snackbar.make(coordinatorLayout, "Coordinator NTB", Snackbar.LENGTH_SHORT);
snackbar.getView().setBackgroundColor(Color.parseColor("#9b92b3"));
((TextView) snackbar.getView().findViewById(R.id.snackbar_text))
.setTextColor(Color.parseColor("#423752"));
snackbar.show();
}
}, 1000);
}
});

final CollapsingToolbarLayout collapsingToolbarLayout =
(CollapsingToolbarLayout) findViewById(R.id.toolbar);
collapsingToolbarLayout.setExpandedTitleColor(Color.parseColor("#009F90AF"));
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.parseColor("#9f90af"));
}

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ViewHolder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.gigamole.library.NavigationTabBar;
import com.gigamole.library.ntb.NavigationTabBar;

import java.util.ArrayList;

Expand All @@ -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_horizontal_ntb);
viewPager.setAdapter(new PagerAdapter() {
Expand Down Expand Up @@ -134,15 +126,6 @@ public void onPageScrollStateChanged(final int state) {
}
});

navigationTabBar.post(new Runnable() {
@Override
public void run() {
final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
bgNavigationTabBar.requestLayout();
}
});

navigationTabBar.postDelayed(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.support.v4.graphics.ColorUtils;
import android.widget.Toast;

import com.gigamole.library.NavigationTabBar;
import com.gigamole.library.ntb.NavigationTabBar;

import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.gigamole.library.NavigationTabBar;
import com.gigamole.library.ntb.NavigationTabBar;

import java.util.ArrayList;
import java.util.Random;
Expand Down Expand Up @@ -110,10 +110,6 @@ public Object instantiateItem(final ViewGroup container, final int position) {
navigationTabBar.post(new Runnable() {
@Override
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.gigamole.library.NavigationTabBar;
import com.gigamole.library.ntb.NavigationTabBar;

import java.util.ArrayList;

Expand Down
76 changes: 34 additions & 42 deletions app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#423752"
Expand All @@ -10,32 +11,38 @@

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="@dimen/top_app_bar_height"
android:layout_height="180dp"
android:fitsSystemWindows="true"
android:background="#00000000"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#423752"
app:title="@string/app_name"
app:expandedTitleTextAppearance="@null"
app:contentScrim="#605271"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#605271"
android:src="@drawable/ic_eighth"
app:layout_collapseMode="pin" />
android:tint="#9f90af"
android:padding="32dp"
app:layout_collapseMode="pin"/>

<android.support.v7.widget.Toolbar
android:fitsSystemWindows="true"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:popupTheme="@style/AppTheme.AppBarOverlay" />
app:title="@string/app_name"
app:popupTheme="@style/AppTheme.AppBarOverlay"/>

</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Expand All @@ -46,45 +53,30 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


<View
android:id="@+id/mask"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="bottom"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="64dp"
android:src="@android:drawable/ic_dialog_email"
android:layout_gravity="right|bottom"
android:layout_marginBottom="64dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="76dp"
android:layout_marginRight="16dp"
app:backgroundTint="#ffff0000"/>
android:layout_marginEnd="16dp"
android:tint="#9f90af"
android:src="@drawable/ic_first"
app:backgroundTint="#605271"/>


<View
android:id="@+id/bg_ntb_horizontal"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_gravity="bottom"
android:background="#605271" />

<com.gigamole.library.NavigationTabBar
android:id="@+id/ntb_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
app:ntb_badge_bg_color="#ffff0000"
app:ntb_badge_gravity="bottom"
app:ntb_badge_position="left"
app:ntb_badge_title_color="#ffffffff"
app:ntb_badge_use_typeface="true"
app:ntb_badged="true"
app:ntb_scaled="false"
app:ntb_title_mode="active"
app:ntb_titled="true"
app:ntb_typeface="fonts/agency.ttf" />
<com.gigamole.library.ntb.NavigationTabBar
android:id="@+id/ntb_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:background="#605271"
app:ntb_badge_bg_color="#ffff0000"
app:ntb_badge_gravity="top"
app:ntb_badge_position="left"
app:ntb_badge_title_color="#ffffffff"
app:ntb_badge_use_typeface="true"
app:ntb_badged="true"
app:ntb_typeface="fonts/agency.ttf"/>

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

0 comments on commit e6bbbea

Please sign in to comment.