diff --git a/README.md b/README.md index b6a35f6..86fdb58 100644 --- a/README.md +++ b/README.md @@ -1,141 +1,222 @@ -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-NavigationTabBar-blue.svg?style=flat-square)](http://android-arsenal.com/details/1/3382) +
+

+ + Devlight + +

+
NavigationTabBar -=================== +================ Navigation tab bar with colorful interactions. -Horizontal NTB|NTB bottom, badge, all title |NTB top, 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) - -U can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app). +[![Android Arsenal](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScbFFTYko2dlc2d28)](http://android-arsenal.com/details/1/3382) +      +[![Android](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wSccEZaclNGN0R5OWc)](https://github.com/DevLight-Mobile-Agency) +      +[![Download](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScZE8wb0xKbC1RT0U)](https://bintray.com/gigamole/maven/navigationtabbar/_latestVersion) +      +[![License](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScU0tmeFpGMHVWNWs)](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/blob/master/LICENSE.txt) +      +[![Codacy](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScSHhmckZyeGJDcXc)](https://www.codacy.com/app/gigamole53/NavigationTabBar?utm_source=github.com&utm_medium=referral&utm_content=DevLight-Mobile-Agency/NavigationTabBar&utm_campaign=Badge_Grade) + + + + + + + + + + + +
+ +You can check the sample app [here](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/tree/master/app). + +Warn +==== +``` +This library is not more supported. +If you want to add new feature or fix a bug, grab source code and do it. +If you think your fix or feature would be useful to other developers, +I can add link of your repository to this README file. +Thank you for using our libraries. +``` Download ------------- - -You can download a .aar` from GitHub's [releases page](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/releases). - -Or use Gradle jCenter: - -```groovy -dependencies { - repositories { - mavenCentral() - maven { - url 'http://dl.bintray.com/gigamole/maven/' - } - } - compile 'com.github.devlight.navigationtabbar:library:+' -} -``` +======== -Or Gradle Maven Central: +You can download a `.aar` from GitHub's [releases page](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/releases). +You can use Gradle: ```groovy -compile 'com.github.devlight.navigationtabbar:library:1.1.1' +compile 'devlight.io:navigationtabbar:1.2.5' ``` Or Maven: - ```groovy - com.github.devlight.navigationtabbar - library - 1.1.1 + devlight.io + navigationtabbar + 1.2.5 aar ``` +Or Ivy: +```groovy + + + +``` + Android SDK Version -========= +=================== -NavigationTabBar requires a minimum sdk version of 11. +`NavigationTabBar` requires a minimum SDK version of 11. Sample -======== +====== + +Parameters -For NTB you can set such parameters as: +For `NTB` you can set such parameters as: - - models: + - models: + allows you to set `NTB` models, where you set icon and 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. + - 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. + - view pager: + allows you to connect `NTB` with `ViewPager`. If you want your can also set `OnPageChangeListener`. + + - background color: + allows you to set background to `NTB` which automatically set with offset relative to badge gravity and corners radius. + + - model selected icon: + allows you to set selected icon when current model is active. - - model title: + - 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. + + - use custom typeface on badge: + allows you to handle set of custom typeface in your badge. - - model badge: + - title mode: + allows you to handle mode of the model title show. Can show all or only active. - allows you to enable badge in you model. + - title size: + allows you to set titles size. - - use custom typeface on badge: + - scale mode: + allows you to handle mode of the model icon and title scale. - allows you to handle set of custom typeface in your badge. - - - title mode: - - allows you to handle mode of the model title show. Can show all or only active. + - tint mode: + allows you to enable or disable icon tinting. + + - badge size: + allows you to set badges size. - - badge position: - - allows you to set the badge position in you model. Can be: left(25%), center(50%) and right(75%). + - badge position: + 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. + - badge gravity: + 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. + - typeface: + allows you to set custom typeface to your title. - - corners radius: - - allows you to set corners radius of pointer. + - corners radius: + allows you to set corners radius of pointer. - - animation duration: - - allows you to set animation duration. - - - inactive color: + - icon size fraction: + allows you to set icon size fraction relative to smaller model side. - allows you to set inactive icon color. + - animation duration: + allows you to set animation duration. + + - inactive color: + allows you to set inactive icon color. - - active color: - - allows you to set active icon color. + - active 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. + - tab bar listener: + 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. + - preview colors: + allows you to set preview colors, which generate count of models equals to count of colors. + +Tips -Orientation automatically detected according to view size. +Creation of models occurs through `Builder` pattern. +`ModelBuilder` requires two fields: icon and color. Title, badge title and selected icon is optional. -If your set ViewPager you can action down on active pointer and do like drag. +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 `AUTO_COLOR` value to badge bg and title color. +By default badge sizes and title sizes is auto fit. To reset calculation just set `AUTO_SIZE` value to badge size and title size. +By default icon size fraction is `0.5F` (half of smaller side of `NTB` model). To reset scale fraction of icon to automatic just put in method `AUTO_SCALE` value. + +If your set `ViewPager` and enable swipe you can action down on active pointer and do like drag. + +Init 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); @@ -145,24 +226,18 @@ navigationTabBar.setBadgePosition(NavigationTabBar.BadgePosition.CENTER); navigationTabBar.setTypeface("fonts/custom_font.ttf"); navigationTabBar.setIsBadged(true); navigationTabBar.setIsTitled(true); +navigationTabBar.setIsTinted(true); navigationTabBar.setIsBadgeUseTypeface(true); -``` - -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(); - } -}); +navigationTabBar.setBadgeBgColor(Color.RED); +navigationTabBar.setBadgeTitleColor(Color.WHITE); +navigationTabBar.setIsSwiped(true); +navigationTabBar.setBgColor(Color.BLACK); +navigationTabBar.setBadgeSize(10); +navigationTabBar.setTitleSize(10); +navigationTabBar.setIconSizeFraction(0.5); ``` 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(); @@ -170,13 +245,23 @@ model.showBadge(); model.toggleBadge(); model.updateBadgeTitle("Here some title like NEW or some integer value"); ``` - + +To enable behavior translation inside `CoordinatorLayout` when at bottom of screen: +```java +navigationTabBar.setBehaviorEnabled(true); +``` + +To deselect active index and reset pointer: +```java +navigationTabBar.deselect(); +``` + Other methods check out in sample. And XML init: ```xml - + app:ntb_badge_use_typeface="true" + app:ntb_swiped="true" + app:ntb_bg_color="#000" + app:ntb_icon_size_fraction="https://github.com/0.5" + app:ntb_badge_size="10sp" + app:ntb_title_size="10sp"/> +``` + +XML属性中文详解: +```xml + ``` Getting Help -====== +============ To report a specific problem or feature request, [open a new issue on Github](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/issues/new). -License -====== +Xamarin +======= -Apache 2.0 and MIT. See [LICENSE](https://github.com/DevLight-Mobile-Agency/NavigationTabBar/blob/master/LICENSE.txt) file for details. +Thanks to [Martijn van Dijk](https://github.com/martijn00) for developing Xamarin bindings library for [NavigationTabBar](https://github.com/martijn00/NavigationTabBarXamarin). +Plugin is available on [Nuget](https://www.nuget.org/packages/Xam.Plugins.Android.NavigationTabBar/). -Inspiration -====== +## use navbar using materialize css +navbar using materialize css is really easy and would take just assigning right classes to the html tags and it would create a navigation tab bar using its prewritten css and js files. This can be easily used in html pages using downloaded files or cdn links... +https://materializecss.com/navbar.html + +Credits +======= + +Sincere thanks, to portal [FAnDroid.info](http://www.fandroid.info) [(StartAndroid)](https://www.youtube.com/channel/UCzE7HcbvyEiS5ea1rVRbPLQ) who released the review of this library in detail. If you understand the Russian language, then feel free to see the video or read the [text version](http://www.fandroid.info/obzor-biblioteki-navigationtabbar-dlya-android-ot-komandy-devlight/) of its great post. +

+ + + +

-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) +Inspired by: + +|[Sergey Valiukh](https://dribbble.com/SergeyValiukh)| +|:--------------------------------------------------:| +|[![](https://s-media-cache-ak0.pinimg.com/originals/39/ee/33/39ee330f3460bd638284f0576bc95b65.gif)](https://dribbble.com/shots/2071319-GIF-of-the-Tapbar-Interactions)| Thanks to [Valery Nuzhniy](https://www.pinterest.com/hevbolt/) for NTB badge design. Author +====== + +Created by [Basil Miller](https://github.com/GIGAMOLE) - [@gigamole](mailto:gigamole53@gmail.com) + +Company ======= -Made in [DevLight Mobile Agency](https://github.com/DevLight-Mobile-Agency) +[![Facebook](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScaGhGVFNKU0VxMnc)](https://www.facebook.com/devlightagency)     [![Twitter](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wScZ1ExQWh5cHF5cVE)](https://twitter.com/DevLightIO)     [![LinkedIn](https://drive.google.com/uc?export=download&id=0BxPO_UeS7wSccGZINzEycE1nVFE)](https://www.linkedin.com/company/devlight) + +[Here](https://github.com/DevLight-Mobile-Agency) you can see open source work developed by Devlight LLC. +This and another works is an exclusive property of Devlight LLC. + +If you want to use this library in applications which will be available on Google Play, please report us about it or author of the library. + +Whether you're searching for a new partner or trusted team for creating your new great product we are always ready to start work with you. + +You can contact us via info@devlight.io or opensource@devlight.io. +Thanks in advance. -Created by [Basil Miller](https://github.com/GIGAMOLE) - [@gigamole](mailto:http://gigamole53@gmail.com) \ No newline at end of file +Devlight LLC, 2016 +[devlight.io](http://devlight.io) diff --git a/app/build.gradle b/app/build.gradle index a3466fc..146f017 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - applicationId "com.gigamole.navigationtabbar" - minSdkVersion 11 - targetSdkVersion 23 + applicationId "devlight.io.navigationtabbar" + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -17,10 +17,18 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + targetCompatibility 1.7 + sourceCompatibility 1.7 + } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':library') - compile 'com.android.support:appcompat-v7:23.2.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':navigationtabbar') +// compile 'com.github.devlight.navigationtabbar:navigationtabbar:1.2.3' + + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:design:27.1.1' + implementation 'com.android.support:support-v4:27.1.1' } diff --git a/library/src/androidTest/java/com/gigamole/library/ApplicationTest.java b/app/src/androidTest/java/devlight/io/sample/ApplicationTest.java similarity index 91% rename from library/src/androidTest/java/com/gigamole/library/ApplicationTest.java rename to app/src/androidTest/java/devlight/io/sample/ApplicationTest.java index 35e36d7..3d59832 100644 --- a/library/src/androidTest/java/com/gigamole/library/ApplicationTest.java +++ b/app/src/androidTest/java/devlight/io/sample/ApplicationTest.java @@ -1,4 +1,4 @@ -package com.gigamole.library; +package devlight.io.sample; import android.app.Application; import android.test.ApplicationTestCase; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f18db43..68997ed 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + @@ -17,9 +18,15 @@ - + + + + + + diff --git a/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java deleted file mode 100644 index ac9a6c0..0000000 --- a/app/src/main/java/com/gigamole/navigationtabbar/SamplesNtbActivity.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.gigamole.navigationtabbar; - -import android.app.Activity; -import android.graphics.Color; -import android.os.Bundle; -import android.support.v4.graphics.ColorUtils; -import android.widget.Toast; - -import com.gigamole.library.NavigationTabBar; - -import java.util.ArrayList; - -/** - * Created by GIGAMOLE on 28.03.2016. - */ -public class SamplesNtbActivity extends Activity { - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_samples_ntb); - 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)); - 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)); - 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)); - 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)); - 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)); - ntbSample5.setModels(models5); - ntbSample5.setModelIndex(2, true); - ntbSample5.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) { - Toast.makeText(SamplesNtbActivity.this, String.format("onEndTabSelected #%d", index), Toast.LENGTH_SHORT).show(); - } - }); - - 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())); - ntbSample6.setModels(models6); - } - - private int randomColor(){ - float[] TEMP_HSL = new float[]{0, 0, 0}; - float[] hsl = TEMP_HSL; - hsl[0] = (float) (Math.random() * 360); - hsl[1] = (float) (40 + (Math.random() * 60)); - hsl[2] = (float) (40 + (Math.random() * 60)); - return ColorUtils.HSLToColor(hsl); - } -} diff --git a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java b/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java deleted file mode 100644 index 6e3b7c3..0000000 --- a/app/src/main/java/com/gigamole/navigationtabbar/VerticalNtbActivity.java +++ /dev/null @@ -1,92 +0,0 @@ -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.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.gigamole.library.NavigationTabBar; - -import java.util.ArrayList; - -/** - * Created by GIGAMOLE on 28.03.2016. - */ -public class VerticalNtbActivity extends Activity { - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_vertical_ntb); - 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() { - @Override - public int getCount() { - return 8; - } - - @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.vp_item, null, false); - - final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); - txtPage.setText(String.format("Page #%d", position)); - - container.addView(view); - return view; - } - }); - - final String[] colors = getResources().getStringArray(R.array.vertical_ntb); - - 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]))); - - navigationTabBar.setModels(models); - navigationTabBar.setViewPager(viewPager, 4); - } -} diff --git a/app/src/main/java/devlight/io/sample/HorizontalCoordinatorNtbActivity.java b/app/src/main/java/devlight/io/sample/HorizontalCoordinatorNtbActivity.java new file mode 100644 index 0000000..50fbc83 --- /dev/null +++ b/app/src/main/java/devlight/io/sample/HorizontalCoordinatorNtbActivity.java @@ -0,0 +1,209 @@ +package devlight.io.sample; + +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; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import devlight.io.library.ntb.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() + ); + + navigationTabBar.setModels(models); + navigationTabBar.setViewPager(viewPager, 2); + + //IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT + navigationTabBar.setBehaviorEnabled(true); + + 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(); + } + }); + navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(final int position) { + + } + + @Override + public void onPageScrollStateChanged(final int state) { + + } + }); + + 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++) { + 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); + } + + coordinatorLayout.postDelayed(new Runnable() { + @Override + public void run() { + final Snackbar snackbar = Snackbar.make(navigationTabBar, "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 { + + @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/HorizontalNtbActivity.java b/app/src/main/java/devlight/io/sample/HorizontalNtbActivity.java similarity index 51% rename from app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java rename to app/src/main/java/devlight/io/sample/HorizontalNtbActivity.java index 5bdc2ea..5d72919 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/HorizontalNtbActivity.java +++ b/app/src/main/java/devlight/io/sample/HorizontalNtbActivity.java @@ -1,4 +1,4 @@ -package com.gigamole.navigationtabbar; +package devlight.io.sample; import android.app.Activity; import android.graphics.Color; @@ -10,7 +10,7 @@ import android.view.ViewGroup; import android.widget.TextView; -import com.gigamole.library.NavigationTabBar; +import devlight.io.library.ntb.NavigationTabBar; import java.util.ArrayList; @@ -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() { @@ -55,7 +47,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)); @@ -69,37 +61,68 @@ 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.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(); } - }); - 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(); + public void onPageScrollStateChanged(final int state) { + } }); @@ -108,23 +131,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; - } navigationTabBar.postDelayed(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java b/app/src/main/java/devlight/io/sample/MainActivity.java similarity index 85% rename from app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java rename to app/src/main/java/devlight/io/sample/MainActivity.java index d549f35..927295d 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/MainActivity.java +++ b/app/src/main/java/devlight/io/sample/MainActivity.java @@ -1,4 +1,4 @@ -package com.gigamole.navigationtabbar; +package devlight.io.sample; import android.app.Activity; import android.content.Intent; @@ -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) @@ -63,6 +70,8 @@ public void onAnimationEnd(final View view) { new Intent(MainActivity.this, SamplesNtbActivity.class) ); break; + default: + break; } } diff --git a/app/src/main/java/devlight/io/sample/SamplesNtbActivity.java b/app/src/main/java/devlight/io/sample/SamplesNtbActivity.java new file mode 100644 index 0000000..9e16a66 --- /dev/null +++ b/app/src/main/java/devlight/io/sample/SamplesNtbActivity.java @@ -0,0 +1,200 @@ +package devlight.io.sample; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.graphics.ColorUtils; +import android.widget.Toast; + +import devlight.io.library.ntb.NavigationTabBar; + +import java.util.ArrayList; + +/** + * Created by GIGAMOLE on 28.03.2016. + */ +public class SamplesNtbActivity extends Activity { + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_samples_ntb); + initUI(); + } + + private void initUI() { + final NavigationTabBar ntbSample1 = (NavigationTabBar) findViewById(R.id.ntb_sample_1); + final ArrayList models1 = new ArrayList<>(); + 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.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.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.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.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() { + @Override + public void onStartTabSelected(final NavigationTabBar.Model model, final int index) { + + } + + @Override + public void onEndTabSelected(final NavigationTabBar.Model model, final int index) { + Toast.makeText(SamplesNtbActivity.this, String.format("onEndTabSelected #%d", index), Toast.LENGTH_SHORT).show(); + } + }); + + final NavigationTabBar ntbSample6 = (NavigationTabBar) findViewById(R.id.ntb_sample_6); + final ArrayList models6 = new ArrayList<>(); + 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() { + float[] TEMP_HSL = new float[]{0, 0, 0}; + float[] hsl = TEMP_HSL; + hsl[0] = (float) (Math.random() * 360); + hsl[1] = (float) (40 + (Math.random() * 60)); + hsl[2] = (float) (40 + (Math.random() * 60)); + return ColorUtils.HSLToColor(hsl); + } +} diff --git a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java b/app/src/main/java/devlight/io/sample/TopHorizontalNtbActivity.java similarity index 50% rename from app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java rename to app/src/main/java/devlight/io/sample/TopHorizontalNtbActivity.java index 1834bc2..c12ca21 100644 --- a/app/src/main/java/com/gigamole/navigationtabbar/TopHorizontalNtbActivity.java +++ b/app/src/main/java/devlight/io/sample/TopHorizontalNtbActivity.java @@ -1,16 +1,18 @@ -package com.gigamole.navigationtabbar; +package devlight.io.sample; 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 devlight.io.library.ntb.NavigationTabBar; import java.util.ArrayList; import java.util.Random; @@ -27,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() { @@ -56,10 +50,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.vp_item, 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; @@ -70,25 +69,51 @@ 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); 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(); + viewPager.requestLayout(); } }); @@ -123,4 +148,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/java/devlight/io/sample/VerticalNtbActivity.java b/app/src/main/java/devlight/io/sample/VerticalNtbActivity.java new file mode 100644 index 0000000..29f3fb5 --- /dev/null +++ b/app/src/main/java/devlight/io/sample/VerticalNtbActivity.java @@ -0,0 +1,132 @@ +package devlight.io.sample; + +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.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import devlight.io.library.ntb.NavigationTabBar; + +import java.util.ArrayList; + +/** + * Created by GIGAMOLE on 28.03.2016. + */ +public class VerticalNtbActivity extends Activity { + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_vertical_ntb); + initUI(); + } + + private void initUI() { + final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_vertical_ntb); + viewPager.setAdapter(new PagerAdapter() { + @Override + public int getCount() { + return 8; + } + + @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, null, false); + + final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page); + txtPage.setText(String.format("Page #%d", position)); + + container.addView(view); + return view; + } + }); + + final String[] colors = getResources().getStringArray(R.array.vertical_ntb); + + final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_vertical); + final ArrayList models = new ArrayList<>(); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_first), + Color.parseColor(colors[0])) + .title("ic_first") + .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)) + .title("ic_second") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_third), + Color.parseColor(colors[2])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("ic_third") + .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("ic_fourth") + .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("ic_fifth") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_sixth), + Color.parseColor(colors[5])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("ic_sixth") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_seventh), + Color.parseColor(colors[6])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("ic_seventh") + .build() + ); + models.add( + new NavigationTabBar.Model.Builder( + getResources().getDrawable(R.drawable.ic_eighth), + Color.parseColor(colors[7])) + .selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)) + .title("ic_eighth") + .build() + ); + + navigationTabBar.setModels(models); + navigationTabBar.setViewPager(viewPager, 4); + } +} diff --git a/app/src/main/res/drawable/bg_round_circle.xml b/app/src/main/res/drawable/bg_round_circle.xml deleted file mode 100644 index 5e40942..0000000 --- a/app/src/main/res/drawable/bg_round_circle.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file 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..3655967 --- /dev/null +++ b/app/src/main/res/layout/activity_horizontal_coordinator_ntb.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_horizontal_ntb.xml b/app/src/main/res/layout/activity_horizontal_ntb.xml index 5832815..e3392b1 100644 --- a/app/src/main/res/layout/activity_horizontal_ntb.xml +++ b/app/src/main/res/layout/activity_horizontal_ntb.xml @@ -1,41 +1,30 @@ - + android:layout_height="0dp" + android:layout_weight="1"/> - + android:layout_height="60dp" + app:ntb_badge_gravity="top" + app:ntb_badge_position="right" + app:ntb_badged="true" + app:ntb_scaled="true" + app:ntb_tinted="true" + app:ntb_title_mode="all" + app:ntb_titled="true" + app:ntb_swiped="true"/> - - - - - - - + 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..e9eb923 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/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"> - + - @@ -39,12 +40,12 @@ android:layout_weight="1" android:padding="10dp"> - @@ -56,11 +57,12 @@ android:layout_weight="1" android:padding="10dp"> - @@ -82,11 +84,12 @@ android:layout_weight="1" android:padding="10dp"> - @@ -99,17 +102,18 @@ android:layout_weight="1" android:padding="10dp"> - + app:ntb_inactive_color="#dddfec" + app:ntb_bg_color="#8d88e4"/> @@ -119,12 +123,12 @@ android:layout_weight="1" android:padding="10dp"> - diff --git a/app/src/main/res/layout/activity_vertical_ntb.xml b/app/src/main/res/layout/activity_vertical_ntb.xml index da6a74d..d6187b7 100644 --- a/app/src/main/res/layout/activity_vertical_ntb.xml +++ b/app/src/main/res/layout/activity_vertical_ntb.xml @@ -7,10 +7,12 @@ android:orientation="horizontal" android:background="#423752"> - 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/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/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 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 @@