Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
spaceNavigationView = (SpaceNavigationView) findViewById(R.id.space);
spaceNavigationView.initWithSaveInstanceState(savedInstanceState);
spaceNavigationView.addSpaceItem(new SpaceItem("HOME", R.drawable.account));
spaceNavigationView.addSpaceItem(new SpaceItem("SEARCH", R.drawable.magnify));
spaceNavigationView.addSpaceItem(new SpaceItem("SEARCH", R.drawable.magnify, R.layout.custom_space_item_view));
spaceNavigationView.shouldShowFullBadgeText(true);
spaceNavigationView.setCentreButtonIconColorFilterEnabled(false);

Expand Down
53 changes: 53 additions & 0 deletions Sample/src/main/res/layout/custom_space_item_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/white_ripple"
android:clickable="true">

<LinearLayout
android:id="@+id/main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">

<ImageView
android:id="@+id/space_icon"
android:layout_width="@dimen/space_item_icon_default_size"
android:layout_height="@dimen/space_item_icon_default_size"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/space_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:lines="1"
android:textSize="@dimen/space_item_text_default_size"
tools:text="Label One" />
</LinearLayout>

<RelativeLayout
android:id="@+id/badge_container"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/badge_left_margin"
android:layout_marginRight="2dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="@+id/main_content"
android:visibility="gone">

<TextView
android:id="@+id/badge_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/white"
android:textSize="10sp"
android:textStyle="bold" />
</RelativeLayout>

</RelativeLayout>
16 changes: 16 additions & 0 deletions spacelib/src/main/java/com/luseen/spacenavigation/SpaceItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ public class SpaceItem implements Serializable {

private int itemIcon;

private Integer itemLayout = null;

public SpaceItem(String itemName, int itemIcon) {
this.itemName = itemName;
this.itemIcon = itemIcon;
}

public SpaceItem(String itemName, int itemIcon, int itemLayout) {
this.itemName = itemName;
this.itemIcon = itemIcon;
this.itemLayout = itemLayout;
}

String getItemName() {
return itemName;
}
Expand All @@ -44,4 +52,12 @@ int getItemIcon() {
void setItemIcon(int itemIcon) {
this.itemIcon = itemIcon;
}

Integer getItemLayout() {
return itemLayout;
}

void setItemLayout(int itemLayout) {
this.itemLayout = itemLayout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class SpaceNavigationView extends RelativeLayout {

private int contentWidth;

private int itemLayout = NOT_DEFINED;

private boolean isCentreButtonSelectable = false;

private boolean isCentrePartLinear = false;
Expand Down Expand Up @@ -163,6 +165,7 @@ private void init(AttributeSet attrs) {
activeSpaceItemColor = typedArray.getColor(com.luseen.spacenavigation.R.styleable.SpaceNavigationView_active_item_color, resources.getColor(com.luseen.spacenavigation.R.color.space_white));
inActiveSpaceItemColor = typedArray.getColor(com.luseen.spacenavigation.R.styleable.SpaceNavigationView_inactive_item_color, resources.getColor(com.luseen.spacenavigation.R.color.default_inactive_item_color));
centreButtonIcon = typedArray.getResourceId(R.styleable.SpaceNavigationView_centre_button_icon, R.drawable.near_me);
itemLayout = typedArray.getResourceId(R.styleable.SpaceNavigationView_space_item_layout, R.layout.space_item_view);
isCentrePartLinear = typedArray.getBoolean(R.styleable.SpaceNavigationView_centre_part_linear, false);
activeCentreButtonIconColor = typedArray.getColor(R.styleable.SpaceNavigationView_active_centre_button_icon_color, resources.getColor(R.color.space_white));
inActiveCentreButtonIconColor = typedArray.getColor(R.styleable.SpaceNavigationView_inactive_centre_button_icon_color, resources.getColor(com.luseen.spacenavigation.R.color.default_inactive_item_color));
Expand All @@ -188,6 +191,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (centreButtonIcon == NOT_DEFINED)
centreButtonIcon = R.drawable.near_me;

if (itemLayout == NOT_DEFINED)
itemLayout = R.layout.space_item_view;

if (activeSpaceItemColor == NOT_DEFINED)
activeSpaceItemColor = ContextCompat.getColor(context, com.luseen.spacenavigation.R.color.space_white);

Expand Down Expand Up @@ -429,9 +435,12 @@ private void addSpaceItems(LinearLayout leftContent, LinearLayout rightContent)
targetWidth = contentWidth;
}

Integer itemLayout = spaceItems.get(i).getItemLayout();
if (itemLayout == null) itemLayout = this.itemLayout;

RelativeLayout.LayoutParams textAndIconContainerParams = new RelativeLayout.LayoutParams(
targetWidth, mainContentHeight);
RelativeLayout textAndIconContainer = (RelativeLayout) inflater.inflate(R.layout.space_item_view, this, false);
RelativeLayout textAndIconContainer = (RelativeLayout) inflater.inflate(itemLayout, this, false);
textAndIconContainer.setLayoutParams(textAndIconContainerParams);

ImageView spaceItemIcon = (ImageView) textAndIconContainer.findViewById(R.id.space_icon);
Expand Down Expand Up @@ -768,6 +777,15 @@ public void setCentreButtonIcon(int centreButtonIcon) {
this.centreButtonIcon = centreButtonIcon;
}

/**
* Set space item layout
*
* @param itemLayout target layout
*/
public void setItemLayout(int itemLayout) {
this.itemLayout = itemLayout;
}

/**
* Set active centre button color
*
Expand Down
1 change: 1 addition & 0 deletions spacelib/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<attr name="active_item_color" format="color" />
<attr name="inactive_item_color" format="color" />
<attr name="centre_button_icon" format="reference" />
<attr name="space_item_layout" format="reference" />
<attr name="active_centre_button_icon_color" format="color" />
<attr name="inactive_centre_button_icon_color" format="color" />
<attr name="active_centre_button_background_color" format="color"/>
Expand Down