GithubHelp home page GithubHelp logo

armcha / space-navigation-view Goto Github PK

View Code? Open in Web Editor NEW
2.0K 57.0 379.0 8.48 MB

Space Navigation is a library allowing easily integrate fully customizable Google Spaces like navigation to your app.

Java 100.00%

space-navigation-view's Introduction

Space-Navigation-View

Android Arsenal Buy Me a Coffee at ko-fi.com

Introduction


Space Navigation is a library allowing easily integrate fully customizable Google [Spaces][1] like navigation to your app. [1]: https://play.google.com/store/apps/details?id=com.google.android.apps.social.spaces

The current minSDK version is API level 14 Android 4.0 (ICE CREAM SANDWICH).

Download sample [apk][7] [7]: https://github.com/armcha/Space-Navigation-View/raw/master/SpaceNavigationView.apk

YouTube demos

Demo 1

Demo 1

Demo 2

Demo 2

Download magic


Gradle:

compile 'com.github.armcha:SpaceNavigationView:1.6.0'

Maven:

<dependency>
  <groupId>com.github.armcha</groupId>
  <artifactId>SpaceNavigationView</artifactId>
  <version>1.6.0</version>
  <type>pom</type>
</dependency>

Setup and usage


Add the Space Navigation view to your layout

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     
      <...View
             ....
             android:layout_marginBottom="@dimen/view_bottom_margin" />
             
      <com.luseen.spacenavigation.SpaceNavigationView
             android:id="@+id/space"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_gravity="bottom"/>
             
 </FrameLayout>

Add Space Navigation items.

   SpaceNavigationView spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space);
   spaceNavigationView.initWithSaveInstanceState(savedInstanceState);
   spaceNavigationView.addSpaceItem(new SpaceItem("HOME", R.drawable.yourDrawable));
   spaceNavigationView.addSpaceItem(new SpaceItem("SEARCH", R.drawable.yourDrawable));

Use initWithSaveInstanceState(savedInstanceState) and override onSaveInstanceState if you want to keep selected item position and badge on device rotation

       @Override
       protected void onSaveInstanceState(Bundle outState) {
           super.onSaveInstanceState(outState);
           spaceNavigationView.onSaveInstanceState(outState);
       }

Set onClick listener

   spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() {
            @Override
            public void onCentreButtonClick() {
               Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemClick(int itemIndex, String itemName) {
               Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show();
            }
            
             @Override
             public void onItemReselected(int itemIndex, String itemName) {
               Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show();           
            }
        });

Set onLongClick listener

    spaceNavigationView.setSpaceOnLongClickListener(new SpaceOnLongClickListener() {
            @Override
            public void onCentreButtonLongClick() {
                Toast.makeText(MainActivity.this,"onCentreButtonLongClick", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(int itemIndex, String itemName) {
                Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show();
            }
        });

Customize

Customize with xml

 <com.luseen.spacenavigation.SpaceNavigationView
        android:id="@+id/space"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        app:active_item_color="@color/colorAccent"
        app:centre_button_color="@color/centre_button_color"
        app:inactive_item_color="@color/white"
        app:space_background_color="@color/colorPrimary"
        app:centre_button_icon="@drawable/my_drawable"
        app:space_item_icon_size="@dimen/space_item_icon_default_size"
        app:space_item_icon_only_size="@dimen/space_item_icon_only_size"
        app:space_item_text_size="@dimen/space_item_text_default_size" />
Attribute Description
active_item_color item color when selected
inactive_item_color item color when unselected
centre_button_color centre circle button color
space_background_color space view background color
space_item_icon_size item icon size
space_item_icon_only_size item icon size on showIconOnly() mode
space_item_text_size item text size
centre_button_icon allow changing center icon from layout

Change space navigation background

spaceNavigationView.setSpaceBackgroundColor(ContextCompat.getColor(this, R.color.yourColor));

Change centre button icon

spaceNavigationView.setCentreButtonIcon(R.drawable.yourDrawable);

Change centre button background color

spaceNavigationView.setCentreButtonColor(ContextCompat.getColor(this, R.color.yourColor));

Change selected item text and icon color

spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(this, R.color.yourColor));

Change unselected item text and icon color

spaceNavigationView.setInActiveSpaceItemColor(ContextCompat.getColor(this, R.color.yourColor));

Change space item icon size

spaceNavigationView.setSpaceItemIconSize((int) getResources().getDimension(R.dimen.yourDimen));

Change space item icon size when showIconOnly(); mode activated

spaceNavigationView.setSpaceItemIconSizeInOnlyIconMode((int) getResources().getDimension(R.dimen.yourDimen));

Change space item text size

spaceNavigationView.setSpaceItemTextSize((int) getResources().getDimension(R.dimen.yourDimen));

Hide items text and show only icons

spaceNavigationView.showIconOnly();

Hide items icon and show only texts

spaceNavigationView.showTextOnly();

You can change selected item programmatically

spaceNavigationView.changeCurrentItem(int tabIndexToSelect);

Show badge

spaceNavigationView.showBadgeAtIndex(int itemIndexToShowBadge, int badgeCountText, int badgeBackgroundColor);

Hide badge at index

spaceNavigationView.hideBadgeAtIndex(int itemIndexToHideBadge);

Hide all badges

spaceNavigationView.hideAllBadges();

Change badge text

spaceNavigationView.changeBadgeTextAtIndex(int itemIndexToChangeBadge, int badgeCountText);

Set your custom font

spaceNavigationView.setFont(Typeface.createFromAsset(getAssets(), "your_cutom_font.ttf"));

Set centre button pressed state color

spaceNavigationView.setCentreButtonRippleColor(ContextCompat.getColor(this, R.color.yourColor));

Now you can change centre button icon if space navigation view already set up

spaceNavigationView.changeCenterButtonIcon(R.drawable.yourDrawable);

Also you can change item text and icon if space navigation view already set up

spaceNavigationView.changeItemTextAtPosition(0, "NEW TEXT");
spaceNavigationView.changeItemIconAtPosition(1, R.drawable.yourDrawable);

Now you can change space navigation view background color if it already set up

 spaceNavigationView.changeSpaceBackgroundColor(ContextCompat.getColor(context,R.color.yourColor));

If you want to show full badge text or show 9+

spaceNavigationView.shouldShowFullBadgeText(true);

Set centre button icon color

spaceNavigationView.setCentreButtonIconColor(ContextCompat.getColor(context,R.color.yourColor));

If you want to disable default white color filter, just call

spaceNavigationView.setCentreButtonIconColorFilterEnabled(false);

Add recycler view scroll behavior

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.luseen.spacenavigationview.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.luseen.spacenavigation.SpaceNavigationView
        android:id="@+id/space"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior" />
</android.support.design.widget.CoordinatorLayout>

##Versions

##1.6.0

  • Added saving translation height on rotation. Thanks to akiraspeirs
  • Fixed requestLayout being improperly called. Thanks to akiraspeirs
  • Fixed inActiveCentreButtonIconColor not being used initially. Thanks to nextdimension
  • Fixed issue #41

1.5.0

  • Added SpaceNavigationViewBehavior
  • Fixed issue #32

1.4.2

  • Fixed issue #34

1.4.1

1.4.0

  • Added method do disable centre button default color filter
  • Fixed issue #25

1.3.2

  • Added method setCentreButtonIconColor #17

1.3.1

  • Added method shouldShowFullBadgeText
  • Fixed issue #16 , #18

1.3.0

  • Added SpaceOnLongClickListener
  • Added changeSpaceBackgroundColor method
  • Fixed rendering problem when view is in edit mode

1.2.0

  • Fixed centre button issue
  • Added API 14+ support

1.1.0

  • Added changeItemTextAtPosition, changeItemIconAtPosition, changeCenterButtonIcon,setCentreButtonRippleColor methods
  • Now you can set onItemReselect listener

1.0.0

  • Initial release

Apps using the Space Navigation View

Kindly please let me know if you used or planning to use the library in your projects

##Project development Some crazy [pics][8] [8]: https://github.com/armcha/Space-Navigation-View/tree/master/development

Contact

Pull requests are more than welcome. Please fell free to contact me if there is any problem when using the library.

License

  Space Navigation library for Android
  Copyright (c) 2016 Arman Chatikyan (https://github.com/armcha/Space-Navigation-View).
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

space-navigation-view's People

Contributors

akiraspeirs avatar ankitpopli1891 avatar armcha avatar firezenk avatar mseroczynski avatar rvndbalaji avatar subhrajyotisen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

space-navigation-view's Issues

Enable changing the SpaceItems shown in the SpaceNavigationView

There is currently no way to change the items or even the text of the items currently shown in the navigation bar. This would be massively helpful, as I need to change the text of one of the items when the user performs a certain action, without completely rebuilding the layout.

CenterButtonColor

I want to add gradient color on CentreButtonColor from drawable file from java and xml both but its not working.

Centre Button Selectable Conflicts with Custom Icon

@Kogoro
Using spaceNavigationView.setCentreButtonIconColorFilterEnabled(false);
does not work when spaceNavigationView.setCentreButtonSelectable(true); is also used.
You mentioned that you use a custom icon, how are you able to get your custom icon to show?

Manipulating Selection

It would be great to be able to set the selection index manually. Also the centrebutton should be selectable.

Reason:
In my application, the centre button is the representation for the main fragment. But the selection is always on the first item at the startup. So it would be great if I could manipulate the selection.
If you don't have time. but accept pull requests, I could give it a try though it should be easy to implement.

CentreButtonIconColor (#17) breaks custom icon support

I was using a custom icon for the center button icon. The latest update applies a mask to the icon which is undesirable for when you want to use a custom icon. The new masking feature takes away the ability to use anything other than a solid color icon.

I will be reverting back to 1.3.0. Hopefully, there will be an option to have both in a future update. Thank you!

method names?

there is a method named hideBudges? shouldn't this be hideBadges? also Centre -> Center on method names?

Space Navigation View won't show!

I use you library with support library version 24.
when I add it to my xml, I can see the area that is belong to space navigation view, but it seems it is empty! I add spaceItems to it programmatically, but nothing happens!

Make the centerIcon bigger

Hello,

is it possible to make the center icon bigger? I want to fill the whole button with an icon (e.g. a circled profile image)

Thx :-)

Showing a badge throws IndexOutOfBoundsException if called from main Activity lifecycle methods

Hey @armcha, really liking the library!
I set up my SpaceNavigationView in the onCreate of my Activity with the same setup shown in the readme and have added bottomNav.onSaveInstanceState(outState); in my onSaveInstanceState.
Everything looks and works great in the launched activity, SpaceOnClickListener events are returning the correct name and index for my items. But if I try to call

spaceNavigationView.showBadgeAtIndex(0,5, ContextCompat.getColor(this, R.color.cyan));

in any of the main lifecycle methods in my Activity (bottom of onCreate, onResume, onPostResume, etc.) the SpaceNavigationView throws an IndexOutOfBoundsException:
Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.get(ArrayList.java:308) at com.luseen.spacenavigation.SpaceNavigationView.showBadgeAtIndex(SpaceNavigationView.java:822) at com.proto.tangible.tagalong.ExploreActivity$override.onResume(ExploreActivity.java:193) at com.proto.tangible.tagalong.ExploreActivity$override.access$dispatch(ExploreActivity.java) at com.proto.tangible.tagalong.ExploreActivity.onResume(ExploreActivity.java:0) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1326) at android.app.Activity.performResume(Activity.java:6323) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3311) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3359)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2549)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4398)  at android.app.ActivityThread.access$1000(ActivityThread.java:150)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1400)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:168)  at android.app.ActivityThread.main(ActivityThread.java:5845)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 

However, calling the same line some time after the Activity loads (in response to a manual click event or async task with Thread.sleep(400) works just fine for me!

Looking at the library source it seems like the SpaceNavigationView needs to have been laid out before its possible to show badges for your SpaceItems. In most situations the badge quantity to display is calculated almost instantly, so waiting for the draw is a little cumbersome

Provide a way for the SpaceOnClickListener to veto switching to the clicked item

Under certain circumstances I want to do something when one of the items is clicked, but prevent that item from being selected as the current item. Could be implemented as the onItemClick method instead of being void returning a boolean, indicating whether it wants to allow the view to switch to the clicked item or not.

I tried to work around that by setting the currently selected item back to the previous one from the click listener itself, but that doesn't work as the actual switch to the clicked item only occurs after the listener has been called.

changeCurrentItem(0)

When I set the

spaceNavigationView.changeCurrentItem(0);

can't not trigger the onItemClick event.

No reason NullPointer: Your space item count must be greater than 1 , your current items count isa : 0

Currently i am using this:

SpaceNavigationView spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space);
spaceNavigationView.initWithSaveInstanceState(savedInstanceState);spaceNavigationView.setSpaceBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
spaceNavigationView.addSpaceItem(new SpaceItem("HOME", R.drawable.ic_home_white_48dp));
spaceNavigationView.addSpaceItem(new SpaceItem("ANTEPRIMA", R.drawable.ic_web_white_48dp));

But when i call

spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() {
@OverRide
public void onCentreButtonClick() {
startActivity(new Intent(MainActivity.this, FormActivity.class));
}
...

I get the error message even if i added two working items:

java.lang.NullPointerException: Your space item count must be greater than 1 , your current items count isa : 0

Rendering Error in Preview

Rendering error caused by Line 213-221 in SpaceNavigationView.java
untitled20160901113656

Fix by removing or overriding for preview. Thanks for making the Space Navigation View. It is AMAZING! 🎆

TextView layout_gravity="center"

if one changed the icon size, via app:space_item_icon_size="24dp" the Text will be not be centered veritcally with the icon. i guess you might need to center the TextView layout gravity instead of aligning it top.

Recyclerview scroll behaviour

Nice work,I so love your library. Please how can I add a FAB behaviour to the space navigation bar? I mean I want the space navigation view to autohide when recyclerview is scrolled up and down. Thanks and thumbs up for an awesome library.

Change Selected Item Color Not Updating

This is probably my error so please forgive me. I notice that spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(this, R.color.yourColor)); does not actually update the currently selected item color. That means the following code does not work properly because the color that is set will be applied to the next selected icon. Example, Item 1 selected and Item 1's icon is Red. When Item 2 is selected, Item 2's icon is Red. When Item 3 is selected, Item 3's icon is Blue.

    spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() {
        @Override
        public void onCentreButtonClick() {
        }

        @Override
        public void onItemClick(int itemIndex, String itemName) {
            Log.d("Click", Integer.toString(itemIndex));
            switch (itemIndex)
            {
                case 0:
                    spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(getApplicationContext(), R.color.RED));
                    break;
                case 1:
                    spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(getApplicationContext(), R.color.BLUE));
                    break;
                case 2:
                    spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(getApplicationContext(), R.color.YELLOW));
                    break;
                case 3:
                    spaceNavigationView.setActiveSpaceItemColor(ContextCompat.getColor(getApplicationContext(), R.color.GREEN));
                    break;
                default: break;
            }
        }

        @Override
        public void onItemReselected(int itemIndex, String itemName) {
        }
    });

Is there a proper way to set the icon color so it updates the currently selected item color? Something like changeSpaceBackgroundColor(). Thank you for taking a look!

Remove space item

Currently you can add space items, but you cannot remove them?
I am working on an activity which has two fragments, each fragment would have different nav icons and one has more icons than the other. I can add icons when moving to the second frag, but cannot remove nav icons when moving back to the first fragment.

Control Centre FloatingActionButton

More functionalities like disable FAB or hide, or something like this.

Also something like getFab() or getFabView() to control the View like RotationAnimation.

Elevation and Shadow support

Per the material design spec this component should have a default elevation of 8dp and cast a shadow upwards on to the content above it - it doesn't seem to do that currently regardless of elevation being set in the layout or in code.

Unable to change center button icon

Attempting to change the center button icon results in a null exception error. The error says that the FAB has not been initiated yet. However, Space Navigation View has been initiated. Might this be a bug?

SpaceNavigationView spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space);
spaceNavigationView.initWithSaveInstanceState(savedInstanceState);
spaceNavigationView.changeCenterButtonIcon(R.drawable.company_icon);
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blankicon/com.blankicon.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setImageResource(int)' on a null object reference
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setImageResource(int)' on a null object reference

Thank you for taking a look!

Exception in XML layout preview when using the space navigation

When I use the space navigation in a layout file the preview window will throw an Exception:

java.lang.NullPointerException: Your space item count must be greater than 1 , your current items count is : 0

This makes the preview basically unsuable. Is there a way you could just show dummy items when in the preview, or can you provide items directly in the xml?

Vector icons with colors and custom bar height

Hi, I try to put a colored icon in the bar, but I only see a white silhouette, its posible to show the colored version? And how can i change the height of the icons bar? Thanks a lot!

Support Drawable icons

spaceNavigationView.addSpaceItem(new SpaceItem("HOME", R.drawable.yourDrawable)); should support Drawables as well

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.