Skip to content

Commit c97dd86

Browse files
Merge pull request #5 from MuhammadTouseeq/dev_v_1.0.3
add the option to set menu card color
2 parents cc2c596 + 536404b commit c97dd86

10 files changed

Lines changed: 118 additions & 40 deletions

File tree

app/src/main/java/com/pakdev/materialhomemenu/MaterialHomeMenu.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ protected void onCreate(Bundle savedInstanceState) {
1818
//to show /hide icon
1919
setShowMenuIcon(true);
2020
//For List View
21-
// setGridView(false);
21+
setGridView(true);
2222
//For Grid View
23-
setGridView(true, HomeMenu.DRAWABLE_SHAPE.CUSTOM);
24-
setShapeDrawable(R.drawable.shape_rounded_base);
25-
setMenuTextColor(android.R.color.white);
26-
setAnimation(HomeMenu.MENU_ANIMATION.RIGHT_TO_LEFT, 500);
23+
setGridView(true, HomeMenu.DRAWABLE_SHAPE.CIRCLE);
24+
// setShapeDrawable(R.drawable.shape_rounded_base);
25+
// setMenuCardColor(android.R.color.holo_green_dark);
26+
setMenuTextColor(android.R.color.black);
27+
// setAnimation(HomeMenu.MENU_ANIMATION.RIGHT_TO_LEFT, 500);
2728

2829
super.onCreate(savedInstanceState);
2930

@@ -34,12 +35,12 @@ public ArrayList<HomeMenu> getHomeMenuList() {
3435

3536

3637
ArrayList<HomeMenu> arrData = new ArrayList<>();
37-
arrData.add(new HomeMenu().setMenuTitle("Home").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
38-
arrData.add(new HomeMenu().setMenuTitle("About us").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
39-
arrData.add(new HomeMenu().setMenuTitle("Sports").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
40-
arrData.add(new HomeMenu().setMenuTitle("News").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
41-
arrData.add(new HomeMenu().setMenuTitle("Help").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
42-
arrData.add(new HomeMenu().setMenuTitle("Entertainments").setMenuDesc("Description").setMenuIcon(R.drawable.baseline_android_white_24dp));
38+
arrData.add(new HomeMenu().setMenuTitle("Home").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
39+
arrData.add(new HomeMenu().setMenuTitle("About us").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
40+
arrData.add(new HomeMenu().setMenuTitle("Sports").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
41+
arrData.add(new HomeMenu().setMenuTitle("News").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
42+
arrData.add(new HomeMenu().setMenuTitle("Help").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
43+
arrData.add(new HomeMenu().setMenuTitle("Entertainments").setMenuDesc("Description").setMenuIcon(R.drawable.cloth_icon));
4344

4445
return arrData;
4546
}
8.94 KB
Loading

homemenu/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ android {
2828
}
2929

3030
dependencies {
31+
def material_version = '1.3.0-alpha02'
32+
def sdp_version = '1.0.6'
3133
implementation fileTree(dir: 'libs', include: ['*.jar'])
3234

3335
implementation 'androidx.appcompat:appcompat:1.1.0'
3436
testImplementation 'junit:junit:4.12'
3537
androidTestImplementation 'androidx.test:runner:1.2.0'
3638
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3739

40+
implementation "com.google.android.material:material:$material_version"
3841
implementation 'androidx.recyclerview:recyclerview:1.0.0'
42+
implementation "com.intuit.sdp:sdp-android:$sdp_version"
3943
}

homemenu/src/main/java/com/pakdev/homemenu/BaseMenuActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public abstract class BaseMenuActivity extends AppCompatActivity {
2626
private HomeMenu.MENU_ANIMATION MenuAnimation;
2727

2828
private int menuTextColor=android.R.color.black;
29+
private int menuCardColor=-1;
2930
@Override
3031
protected void onCreate(Bundle savedInstanceState) {
3132
super.onCreate(savedInstanceState);
@@ -57,6 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
5758
adapter.setGridMenu(isGridView, MenuShape);
5859
adapter.setShapeDrawable(mShapeDrawable);
5960
adapter.setAnimationType(MenuAnimation, ANIMATION_DURATION);
61+
adapter.setMenuCardColor(menuCardColor);
6062

6163
adapter.setTextColor(menuTextColor);
6264
adapter.setClickListener(new HomeMenuAdapter.ItemClickListener() {
@@ -87,6 +89,10 @@ protected void setMenuTextColor(int menuTextColor) {
8789
this.menuTextColor = menuTextColor;
8890
}
8991

92+
protected void setMenuCardColor(int menuCardColor) {
93+
this.menuCardColor = menuCardColor;
94+
}
95+
9096
//set grid view with default shape
9197
protected void setGridView(boolean gridView) {
9298
isGridView = gridView;
@@ -118,6 +124,7 @@ protected void setShowMenuIcon(boolean showMenuIcon) {
118124
this.showMenuIcon = showMenuIcon;
119125
}
120126

127+
121128
public abstract ArrayList<HomeMenu> getHomeMenuList();
122129

123130
public abstract void onMenuClick(HomeMenu model, int position);

homemenu/src/main/java/com/pakdev/homemenu/HomeMenu.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ public enum DRAWABLE_SHAPE{
99
public enum MENU_ANIMATION{
1010
FADE_IN,LEFT_TO_RIGHT,RIGHT_TO_LEFT
1111
}
12-
12+
public enum HOME_MENU_TYPE{
13+
CIRCLE,GRIDVIEW,LISTVIEW
14+
}
1315
private String mMenuTitle;
1416
private String mMenuDesc;
1517
private int mMenuIcon;

homemenu/src/main/java/com/pakdev/homemenu/HomeMenuAdapter.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.widget.TextView;
1111

1212
import androidx.annotation.NonNull;
13+
import androidx.cardview.widget.CardView;
1314
import androidx.recyclerview.widget.GridLayoutManager;
1415
import androidx.recyclerview.widget.RecyclerView;
1516

@@ -31,6 +32,7 @@ public class HomeMenuAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
3132
public int itemSize;
3233
public int shapeDrawable;
3334
public int textColor;
35+
public int cardColor=-1;
3436
long DURATION = 0;
3537
private boolean on_attach = true;
3638

@@ -51,13 +53,20 @@ public class HomeMenuAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
5153
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
5254
View view=null;
5355

54-
if(isGridMenu) {
55-
view = mInflater.inflate(R.layout.rv_item_grid_menu, parent, false);
56+
if(isGridMenu&&cardColor==-1) {
57+
view = mInflater.inflate(R.layout.rv_item_circle_grid_menu, parent, false);
5658
GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) view.getLayoutParams();
5759
params.height = itemSize;
5860
view.setLayoutParams(params);
5961

6062
}
63+
else if(cardColor!=-1&&isGridMenu)
64+
{
65+
view = mInflater.inflate(R.layout.rv_item_grid_menu, parent, false);
66+
GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) view.getLayoutParams();
67+
params.height = itemSize;
68+
view.setLayoutParams(params);
69+
}
6170
else{
6271
view = mInflater.inflate(R.layout.rv_material_home_menu, parent, false);
6372
}
@@ -80,6 +89,11 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
8089

8190
viewHolder.imgMenuIcon.setVisibility(isMenuIcon?View.VISIBLE:View.GONE);
8291

92+
if(isGridMenu&&cardColor!=-1)
93+
{
94+
viewHolder.cardMenu.setCardBackgroundColor(context.getResources().getColor(cardColor));
95+
}
96+
8397
switch (drawable_shape)
8498
{
8599
case CIRCLE:
@@ -130,7 +144,10 @@ public void setAnimationType(HomeMenu.MENU_ANIMATION animationType,long duration
130144
this.DURATION=duration;
131145
notifyDataSetChanged();
132146
}
133-
147+
public void setMenuCardColor(int mCardcolor) {
148+
this.cardColor = mCardcolor;
149+
notifyDataSetChanged();
150+
}
134151
public void setMenuIcon(boolean menuIcon) {
135152
isMenuIcon = menuIcon;
136153
notifyDataSetChanged();
@@ -171,6 +188,7 @@ static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
171188
LinearLayout rootlayout;
172189
TextView txtMenuDesc;
173190
ImageView imgMenuIcon;
191+
CardView cardMenu;
174192

175193

176194
ViewHolder(View view) {
@@ -179,6 +197,7 @@ static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
179197
rootlayout=view.findViewById(R.id.rootlayout);
180198
txtMenuDesc=view.findViewById(R.id.txtMenuDesc);
181199
imgMenuIcon=view.findViewById(R.id.imgMenuIcon);
200+
cardMenu=view.findViewById(R.id.cardMenu);
182201

183202
view.setOnClickListener(this);
184203
}

homemenu/src/main/res/layout/rv_item_circle_grid_menu.xml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
android:orientation="vertical"
5-
android:layout_width="190dp"
6+
android:layout_width="@dimen/_120sdp"
67
android:gravity="center"
78
android:layout_margin="5dp"
9+
android:layout_height="wrap_content">
10+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
11+
xmlns:tools="http://schemas.android.com/tools"
12+
android:orientation="vertical"
13+
android:layout_width="@dimen/_120sdp"
14+
android:gravity="center"
15+
android:id="@+id/rootlayout"
16+
android:layout_margin="5dp"
817
android:background="@drawable/mhm_shape_circle"
9-
android:layout_height="190dp">
18+
android:layout_height="@dimen/_120sdp">
1019

1120
<ImageView
12-
android:layout_width="50dp"
21+
android:layout_width="@dimen/_60sdp"
1322
android:id="@+id/imgMenuIcon"
14-
android:layout_height="50dp"/>
23+
android:layout_height="@dimen/_60sdp"/>
24+
25+
<TextView
26+
android:layout_width="wrap_content"
27+
android:id="@+id/txtMenuDesc"
28+
android:textColor="@android:color/darker_gray"
29+
tools:text="description"
30+
android:visibility="gone"
31+
android:layout_height="wrap_content"/>
32+
33+
34+
</LinearLayout>
1535

1636

1737
<TextView
@@ -22,12 +42,15 @@
2242
android:id="@+id/txtMenuTitle"
2343
android:layout_height="wrap_content"/>
2444

25-
<TextView
26-
android:layout_width="wrap_content"
27-
android:id="@+id/txtMenuDesc"
28-
android:textColor="@android:color/darker_gray"
29-
tools:text="description"
30-
android:layout_height="wrap_content"/>
45+
<androidx.cardview.widget.CardView
46+
android:layout_width="@dimen/_120sdp"
47+
android:elevation="@dimen/_5sdp"
48+
app:cardBackgroundColor="@android:color/holo_green_dark"
49+
android:layout_margin="@dimen/_8sdp"
50+
android:id="@+id/cardMenu"
51+
android:visibility="gone"
52+
app:cardCornerRadius="@dimen/_15sdp"
53+
android:layout_height="@dimen/_100sdp">
54+
</androidx.cardview.widget.CardView>
55+
</LinearLayout>
3156

32-
33-
</LinearLayout>

homemenu/src/main/res/layout/rv_item_grid_menu.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="@dimen/_120sdp"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
android:elevation="@dimen/_5sdp"
7+
app:cardBackgroundColor="@android:color/holo_green_dark"
8+
android:layout_margin="@dimen/_8sdp"
9+
android:id="@+id/cardMenu"
10+
app:cardCornerRadius="@dimen/_15sdp"
11+
android:layout_height="@dimen/_100sdp">
12+
13+
<LinearLayout
414
android:orientation="vertical"
515
android:layout_width="match_parent"
616
android:gravity="center"
7-
android:layout_margin="5dp"
17+
android:padding="@dimen/_16sdp"
818
android:id="@+id/rootlayout"
9-
android:background="@drawable/mhm_outline_border"
10-
android:layout_height="wrap_content">
19+
android:layout_height="match_parent">
20+
1121

12-
<ImageView
22+
<ImageView
1323
android:layout_width="40dp"
1424
android:id="@+id/imgMenuIcon"
1525
android:layout_height="40dp"/>
@@ -19,6 +29,7 @@
1929
android:layout_width="wrap_content"
2030
tools:text="Title"
2131
android:textSize="16sp"
32+
android:layout_marginTop="@dimen/_5sdp"
2233
android:textColor="@android:color/black"
2334
android:id="@+id/txtMenuTitle"
2435
android:layout_height="wrap_content"/>
@@ -31,3 +42,4 @@
3142

3243

3344
</LinearLayout>
45+
</androidx.cardview.widget.CardView>
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="wrap_content"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
6+
android:elevation="@dimen/_5sdp"
7+
app:cardUseCompatPadding="true"
8+
app:cardCornerRadius="@dimen/_15sdp"
9+
android:layout_height="wrap_content">
10+
11+
<LinearLayout
412
android:orientation="vertical"
5-
android:layout_width="180dp"
13+
android:layout_width="wrap_content"
614
android:gravity="center"
15+
android:padding="@dimen/_15sdp"
716
android:layout_margin="5dp"
8-
android:background="@drawable/mhm_shape_rounded"
9-
android:layout_height="180dp">
17+
android:layout_height="wrap_content">
1018

1119
<ImageView
12-
android:layout_width="60dp"
20+
android:layout_width="@dimen/_60sdp"
1321
android:id="@+id/imgMenuIcon"
14-
android:layout_height="60dp"/>
22+
android:layout_height="@dimen/_60sdp"/>
1523

1624

1725
<TextView
1826
android:layout_width="wrap_content"
1927
tools:text="Title"
2028
android:textSize="16sp"
29+
android:layout_marginTop="@dimen/_5sdp"
2130
android:textColor="@android:color/black"
2231
android:id="@+id/txtMenuTitle"
2332
android:layout_height="wrap_content"/>
@@ -31,3 +40,4 @@
3140

3241

3342
</LinearLayout>
43+
</androidx.cardview.widget.CardView>

homemenu/src/main/res/layout/rv_material_home_menu.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
android:layout_height="wrap_content">
66

77
<ImageView
8-
android:layout_width="40dp"
8+
android:layout_width="@dimen/_30sdp"
99
android:layout_marginRight="8dp"
1010
android:padding="8dp"
1111
android:src="@android:drawable/ic_menu_edit"
1212
android:layout_alignParentLeft="true"
1313
android:layout_centerInParent="true"
1414
android:id="@+id/imgMenuIcon"
15-
android:layout_height="40dp"/>
15+
android:layout_height="@dimen/_30sdp"/>
1616

1717
<LinearLayout
1818
android:layout_width="match_parent"

0 commit comments

Comments
 (0)