├── .gitignore
├── CodeSample
├── .gitignore
├── Sample.iml
├── build.gradle
├── proguard-rules.txt
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ └── com
│ │ └── dexafree
│ │ └── googlenavigationdrawermenusample
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-hdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_accept.png
│ ├── ic_action_cancel.png
│ ├── ic_drawer.png
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_accept.png
│ ├── ic_action_cancel.png
│ ├── ic_drawer.png
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_accept.png
│ ├── ic_action_cancel.png
│ ├── ic_drawer.png
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_action_accept.png
│ ├── ic_action_cancel.png
│ ├── ic_drawer.png
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_main.xml
│ └── main_content.xml
│ ├── menu
│ └── main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── arrays.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── GoogleNavigationDrawer.jpg
├── GoogleNavigationDrawerMenuLibrary
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.txt
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── org
│ │ └── arasthel
│ │ └── googlenavdrawermenu
│ │ ├── adapters
│ │ └── GoogleNavigationDrawerAdapter.java
│ │ ├── utils
│ │ └── Utils.java
│ │ └── views
│ │ ├── CheckableImageView.java
│ │ ├── CheckableRelativeLayout.java
│ │ ├── CheckedTextView.java
│ │ └── GoogleNavigationDrawer.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── drawable
│ ├── main_section_background.xml
│ └── secondary_section_background.xml
│ ├── layout
│ ├── main_navigation_item.xml
│ ├── navigation_list.xml
│ └── secondary_navigation_item.xml
│ ├── values-v16
│ └── styles.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── README.md
├── aars
└── GoogleNavigationDrawerMenuLibrary.aar
├── build.gradle
├── gradle.properties
├── maven_push.gradle
├── settings.gradle
└── xmlSample
├── .gitignore
├── Sample.iml
├── build.gradle
├── proguard-rules.txt
└── src
└── main
├── AndroidManifest.xml
├── ic_launcher-web.png
├── java
└── com
│ └── dexafree
│ └── googlenavigationdrawermenusample
│ └── MainActivity.java
└── res
├── drawable-hdpi
├── drawer_shadow.9.png
├── ic_action_accept.png
├── ic_action_cancel.png
├── ic_drawer.png
└── ic_launcher.png
├── drawable-mdpi
├── drawer_shadow.9.png
├── ic_action_accept.png
├── ic_action_cancel.png
├── ic_drawer.png
└── ic_launcher.png
├── drawable-xhdpi
├── drawer_shadow.9.png
├── ic_action_accept.png
├── ic_action_cancel.png
├── ic_drawer.png
└── ic_launcher.png
├── drawable-xxhdpi
├── drawer_shadow.9.png
├── ic_action_accept.png
├── ic_action_cancel.png
├── ic_drawer.png
└── ic_launcher.png
├── layout
└── activity_main.xml
├── menu
└── main.xml
├── values-w820dp
└── dimens.xml
└── values
├── arrays.xml
├── dimens.xml
├── strings.xml
└── styles.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | GoogleNavigationDrawerMenu.iml
7 | gradle
8 | gradlew
9 | gradlew.bat
10 |
11 | *.iml
12 |
--------------------------------------------------------------------------------
/CodeSample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/CodeSample/Sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/CodeSample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion '19.1.0'
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:20.0.0'
23 | compile 'com.android.support:support-v4:20.0.0'
24 | compile project(':GoogleNavigationDrawerMenuLibrary')
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | }
27 |
--------------------------------------------------------------------------------
/CodeSample/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Users/Carlos/AppData/Local/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/CodeSample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/CodeSample/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/CodeSample/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/CodeSample/src/main/java/com/dexafree/googlenavigationdrawermenusample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sample project only for demonstration purposes
3 | *
4 | * This project uses the GoogleNavigationDrawerMenu Android library,
5 | * created by Jorge Martín (Arasthel), which is released under a
6 | * GPLv3 license:
7 | * https://github.com/Arasthel/GoogleNavigationDrawerMenu
8 | *
9 | * In this project you can see the library implementation made via Java code
10 | *
11 | * Sample project made by Dexafree
12 | */
13 |
14 | package com.dexafree.googlenavigationdrawermenusample;
15 |
16 | import android.content.Context;
17 | import android.content.res.TypedArray;
18 | import android.graphics.Color;
19 | import android.graphics.Typeface;
20 | import android.support.v4.app.ActionBarDrawerToggle;
21 | import android.support.v4.widget.DrawerLayout.LayoutParams;
22 | import android.support.v7.app.ActionBarActivity;
23 | import android.os.Bundle;
24 | import android.util.DisplayMetrics;
25 | import android.view.*;
26 | import android.widget.TextView;
27 | import android.widget.Toast;
28 |
29 | import org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer;
30 |
31 | public class MainActivity extends ActionBarActivity {
32 |
33 | private Context mContext;
34 | private ActionBarDrawerToggle drawerToggle;
35 | private GoogleNavigationDrawer mDrawer;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | mContext = this;
41 |
42 |
43 | //First of all we need to prepare the LayoutParams
44 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
45 |
46 | //Instance the GoogleNavigationDrawer and set the LayoutParams
47 | mDrawer = new GoogleNavigationDrawer(mContext);
48 | mDrawer.setLayoutParams(params);
49 |
50 |
51 |
52 | // Here we are providing data to the adapter of the ListView
53 | String[] mainSections = getResources().getStringArray(R.array.navigation_main_sections);
54 | String[] secondarySections = getResources().getStringArray(R.array.navigation_secondary_sections);
55 | int[] mainSectionDrawables = getDrawables();
56 |
57 |
58 | mDrawer.setListViewSections(mainSections, // Main sections
59 | secondarySections, // Secondary sections
60 | mainSectionDrawables, // Main sections icon ids
61 | null); // Secondary sections icon ids
62 |
63 |
64 | // Now we add the content to the drawer since the menu is already there
65 | LayoutInflater inflater = getLayoutInflater();
66 | View contentView = inflater.inflate(R.layout.main_content, null);
67 | mDrawer.addView(contentView, 0);
68 |
69 | float density = getResources().getDisplayMetrics().density;
70 | int padding = (int) (8*density);
71 |
72 | // Now we add a clickable header and an unclickable footer to the menu
73 | TextView header = new TextView(this);
74 | header.setTextColor(Color.WHITE);
75 | header.setGravity(Gravity.CENTER_HORIZONTAL);
76 | header.setBackgroundResource(R.drawable.abc_list_selector_background_transition_holo_dark);
77 | header.setText("The clickable header");
78 | header.setPadding(padding, padding, padding, padding);
79 |
80 | TextView footer = new TextView(this);
81 | footer.setText("The footer");
82 | footer.setTextColor(Color.WHITE);
83 | footer.setPadding(padding, padding, padding, padding);
84 | footer.setGravity(Gravity.CENTER_HORIZONTAL);
85 | footer.setBackgroundColor(Color.DKGRAY);
86 | mDrawer.setMenuHeaderAndFooter(header,footer,true,false);
87 | setContentView(mDrawer);
88 |
89 | mDrawer.setOnNavigationSectionSelected(new GoogleNavigationDrawer.OnNavigationSectionSelected() {
90 | @Override
91 | public void onSectionSelected(View v, int i, long l) {
92 | Toast.makeText(getBaseContext(), "Selected section: "+i, Toast.LENGTH_SHORT).show();
93 | }
94 | });
95 |
96 | //Prepare the drawerToggle in order to be able to open/close the drawer
97 | drawerToggle = new ActionBarDrawerToggle(this,
98 | mDrawer,
99 | R.drawable.ic_drawer,
100 | R.string.app_name,
101 | R.string.app_name);
102 |
103 |
104 | //Attach the DrawerListener
105 | mDrawer.setDrawerListener(drawerToggle);
106 |
107 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
108 | getSupportActionBar().setHomeButtonEnabled(true);
109 | }
110 |
111 | @Override
112 | protected void onPostCreate(Bundle savedInstanceState) {
113 | super.onPostCreate(savedInstanceState);
114 | drawerToggle.syncState();
115 | }
116 |
117 |
118 | @Override
119 | public boolean onCreateOptionsMenu(Menu menu) {
120 | getMenuInflater().inflate(R.menu.main, menu);
121 | return true;
122 | }
123 |
124 | @Override
125 | public boolean onOptionsItemSelected(MenuItem item) {
126 | /*
127 | * Declare the behaviour of clicking at the
128 | * application icon, opening and closing the drawer
129 | */
130 | if(item.getItemId() == android.R.id.home) {
131 | if(mDrawer != null) {
132 | if(mDrawer.isDrawerMenuOpen()) {
133 | mDrawer.closeDrawerMenu();
134 | } else {
135 | mDrawer.openDrawerMenu();
136 | }
137 | }
138 | }
139 | return super.onOptionsItemSelected(item);
140 | }
141 |
142 | private int[] getDrawables(){
143 | TypedArray imgs = getResources().obtainTypedArray(R.array.drawable_ids);
144 |
145 | int[] mainSectionDrawables = new int[imgs.length()];
146 |
147 | for(int i=0;i
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/layout/main_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - Home
6 | - Some Other
7 |
8 |
9 |
10 | - Settings
11 | - Info
12 |
13 |
14 |
15 | - @drawable/ic_action_accept
16 | - @drawable/ic_action_cancel
17 |
18 |
19 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | GoogleNavigationDrawerMenuSample
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/CodeSample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawer.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/GoogleNavigationDrawer.jpg
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android-library'
2 |
3 | android {
4 | compileSdkVersion 18
5 | buildToolsVersion "19.1.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:support-v4:20.0.0'
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | }
25 |
26 | sourceSets {
27 | main {
28 | java {
29 | srcDir 'src/main/java'
30 | }
31 | }
32 | }
33 | task jar(type: Jar) {
34 | from sourceSets.main.java
35 | }
36 |
37 | // Script to upload plugin to Maven
38 | apply from: '../maven_push.gradle'
39 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=GoogleNavigationDrawerMenuLibrary
2 | POM_ARTIFACT_ID=gnavdrawer-library
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/adapters/GoogleNavigationDrawerAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.arasthel.googlenavdrawermenu.adapters;
16 |
17 | import android.annotation.TargetApi;
18 | import android.content.Context;
19 | import android.graphics.Typeface;
20 | import android.graphics.drawable.Drawable;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 | import android.widget.BaseAdapter;
24 | import android.widget.ImageView;
25 | import android.widget.RelativeLayout;
26 |
27 | import org.arasthel.googlenavdrawermenu.R;
28 | import org.arasthel.googlenavdrawermenu.views.CheckableRelativeLayout;
29 | import org.arasthel.googlenavdrawermenu.views.CheckedTextView;
30 |
31 | /**
32 | * Created by Arasthel on 14/04/14.
33 | */
34 | public class GoogleNavigationDrawerAdapter extends BaseAdapter {
35 |
36 | public static final int TYPE_MAIN = 0;
37 | private static final int TYPE_SECONDARY = 1;
38 |
39 | private String[] mMainSections;
40 | private String[] mSecondarySections;
41 | private int[] mMainSectionsDrawableIds;
42 | private int[] mSecondarySectionsDrawableIds;
43 |
44 | private int mainDividerHeight = -1;
45 | private int secondaryDividerHeight = -1;
46 |
47 | private int mainDividerColor = -1;
48 | private int secondaryDividerColor = -1;
49 |
50 | private Drawable mainDividerDrawable = null;
51 | private Drawable secondaryDividerDrawable = null;
52 |
53 | private int mMainBackResId = R.drawable.main_section_background;
54 | private int mSecondaryBackResId = R.drawable.secondary_section_background;
55 |
56 | private Context mContext;
57 |
58 | public GoogleNavigationDrawerAdapter(Context context) {
59 | mContext = context;
60 | }
61 |
62 | public GoogleNavigationDrawerAdapter(Context context, String[] mainSections, String[] secondarySections, int[] mainSectionsDrawableIds, int[] secondarySectionsDrawableIds) {
63 | this(context);
64 | mMainSections = mainSections;
65 | mSecondarySections = secondarySections;
66 | mMainSectionsDrawableIds = mainSectionsDrawableIds;
67 | mSecondarySectionsDrawableIds = secondarySectionsDrawableIds;
68 | }
69 |
70 | public GoogleNavigationDrawerAdapter(Context context, String[] mainSections, String[] secondarySections, int[] mainSectionsDrawableIds, int[] secondarySectionsDrawableIds, int mainBackResId, int secondaryBackResId) {
71 | this(context, mainSections, secondarySections, mainSectionsDrawableIds, secondarySectionsDrawableIds);
72 | mMainBackResId = mainBackResId;
73 | mSecondaryBackResId = secondaryBackResId;
74 | }
75 |
76 | @Override
77 | public int getItemViewType(int position) {
78 | return (position >= mMainSections.length) ? TYPE_SECONDARY : TYPE_MAIN;
79 | }
80 |
81 | @Override
82 | public int getViewTypeCount() {
83 | return 2;
84 | }
85 |
86 | @Override
87 | public int getCount() {
88 | int count = 0;
89 | if(mMainSections != null) {
90 | count += mMainSections.length;
91 | }
92 | if(mSecondarySections != null) {
93 | count += mSecondarySections.length;
94 | }
95 | return count;
96 | }
97 |
98 | @Override
99 | public Object getItem(int i) {
100 | if(i >= mMainSections.length && mSecondarySections != null) {
101 | return mSecondarySections[i - mMainSections.length];
102 | } else {
103 | return mMainSections[i];
104 | }
105 | }
106 |
107 | @Override
108 | public long getItemId(int i) {
109 | return i;
110 | }
111 |
112 | @TargetApi(16)
113 | @Override
114 | public View getView(int i, View view, ViewGroup viewGroup) {
115 | int icon = -1;
116 | switch (getItemViewType(i)) {
117 | case TYPE_MAIN:
118 | PrimaryHolder primaryHolder;
119 | if(view == null) {
120 | view = View.inflate(mContext, R.layout.main_navigation_item, null);
121 | view.setBackgroundResource(mMainBackResId);
122 | primaryHolder = new PrimaryHolder();
123 | primaryHolder.primaryTextView = (CheckedTextView) view.findViewById(android.R.id.text1);
124 | primaryHolder.primaryImageView = (ImageView) view.findViewById(android.R.id.icon);
125 | primaryHolder.bottomDivider = view.findViewById(R.id.google_nav_drawer_divider_bottom);
126 | if(mainDividerHeight != -1) {
127 | ((RelativeLayout.LayoutParams) primaryHolder.bottomDivider.getLayoutParams()).height = mainDividerHeight;
128 | }
129 |
130 | if(mainDividerColor != -1) {
131 | primaryHolder.bottomDivider.setBackgroundColor(mainDividerColor);
132 | }
133 |
134 | if(mainDividerDrawable != null) {
135 | int sdk = android.os.Build.VERSION.SDK_INT;
136 | if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
137 | primaryHolder.bottomDivider.setBackgroundDrawable(mainDividerDrawable);
138 | } else {
139 | primaryHolder.bottomDivider.setBackground(mainDividerDrawable);
140 | }
141 | }
142 | view.setTag(primaryHolder);
143 | } else {
144 | primaryHolder = (PrimaryHolder) view.getTag();
145 | }
146 |
147 | if(i == mMainSections.length-1) {
148 | primaryHolder.bottomDivider.setVisibility(View.GONE);
149 | } else {
150 | primaryHolder.bottomDivider.setVisibility(View.VISIBLE);
151 | }
152 |
153 | primaryHolder.primaryTextView.setText((CharSequence) getItem(i));
154 | if(((CheckableRelativeLayout) view).isChecked()) {
155 | primaryHolder.primaryTextView.setTypeface(null, Typeface.BOLD);
156 | } else {
157 | primaryHolder.primaryTextView.setTypeface(null, Typeface.NORMAL);
158 | }
159 | icon = getPrimaryDrawableId(i);
160 | if(icon != -1) {
161 | primaryHolder.primaryImageView.setImageResource(icon);
162 | primaryHolder.primaryImageView.setVisibility(View.VISIBLE);
163 | } else {
164 | primaryHolder.primaryImageView.setVisibility(View.GONE);
165 | }
166 | break;
167 | case TYPE_SECONDARY:
168 | SecondaryHolder holder;
169 | if(view == null) {
170 | view = View.inflate(mContext, R.layout.secondary_navigation_item, null);
171 | holder = new SecondaryHolder();
172 | view.setBackgroundResource(mSecondaryBackResId);
173 | holder.secondaryTextView = (CheckedTextView) view.findViewById(android.R.id.text1);
174 | holder.secondaryImageView = (ImageView) view.findViewById(android.R.id.icon);
175 | holder.topDivider = view.findViewById(R.id.google_nav_drawer_divider_top);
176 | holder.bottomDivider = view.findViewById(R.id.google_nav_drawer_divider_bottom);
177 | if(secondaryDividerHeight != -1) {
178 | ((RelativeLayout.LayoutParams) holder.topDivider.getLayoutParams()).height = secondaryDividerHeight;
179 | ((RelativeLayout.LayoutParams) holder.bottomDivider.getLayoutParams()).height = secondaryDividerHeight;
180 | }
181 |
182 | if(secondaryDividerColor != -1) {
183 | holder.topDivider.setBackgroundColor(secondaryDividerColor);
184 | holder.bottomDivider.setBackgroundColor(secondaryDividerColor);
185 | }
186 |
187 | if(secondaryDividerDrawable != null) {
188 | int sdk = android.os.Build.VERSION.SDK_INT;
189 | if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
190 | holder.topDivider.setBackgroundDrawable(secondaryDividerDrawable);
191 | holder.bottomDivider.setBackgroundDrawable(secondaryDividerDrawable);
192 | } else {
193 | holder.topDivider.setBackground(secondaryDividerDrawable);
194 | holder.bottomDivider.setBackground(secondaryDividerDrawable);
195 | }
196 | }
197 | view.setTag(holder);
198 | } else {
199 | holder = (SecondaryHolder) view.getTag();
200 | }
201 | if(i != mMainSections.length) {
202 | holder.topDivider.setVisibility(View.GONE);
203 | } else {
204 | holder.topDivider.setVisibility(View.VISIBLE);
205 | }
206 | holder.secondaryTextView.setText((CharSequence) getItem(i));
207 |
208 | if(((CheckableRelativeLayout) view).isChecked()) {
209 | holder.secondaryTextView.setTypeface(null, Typeface.BOLD);
210 | } else {
211 | holder.secondaryTextView.setTypeface(null, Typeface.NORMAL);
212 | }
213 |
214 | icon = getSecondaryDrawableId(i);
215 | if(icon != -1) {
216 | holder.secondaryImageView.setImageResource(icon);
217 | holder.secondaryImageView.setVisibility(View.VISIBLE);
218 | } else {
219 | holder.secondaryImageView.setVisibility(View.GONE);
220 | }
221 |
222 | break;
223 | }
224 | return view;
225 | }
226 |
227 | private int getPrimaryDrawableId(int position) {
228 | if(mMainSectionsDrawableIds == null) {
229 | return -1;
230 | }
231 |
232 | if(mMainSectionsDrawableIds.length <= position) {
233 | return -1;
234 | }
235 |
236 | return mMainSectionsDrawableIds[position];
237 | }
238 |
239 | private int getSecondaryDrawableId(int position) {
240 | position = position - mMainSections.length;
241 | if(mSecondarySectionsDrawableIds == null) {
242 | return -1;
243 | }
244 |
245 | if(mSecondarySectionsDrawableIds.length <= position) {
246 | return -1;
247 | }
248 |
249 | return mSecondarySectionsDrawableIds[position];
250 | }
251 |
252 | public void setSecondaryDividerHeight(int height) {
253 | this.secondaryDividerHeight = height;
254 | }
255 |
256 | private class PrimaryHolder {
257 | public CheckedTextView primaryTextView;
258 | public ImageView primaryImageView;
259 | public View bottomDivider;
260 | }
261 |
262 | private class SecondaryHolder {
263 | public CheckedTextView secondaryTextView;
264 | public ImageView secondaryImageView;
265 | public View topDivider;
266 | public View bottomDivider;
267 | }
268 |
269 | public String[] getMainSections() {
270 | return mMainSections;
271 | }
272 |
273 | public void setMainSections(String[] mMainSections) {
274 | this.mMainSections = mMainSections;
275 | }
276 |
277 | public String[] getSecondarySections() {
278 | return mSecondarySections;
279 | }
280 |
281 | public void setSecondarySections(String[] mSecondarySections) {
282 | this.mSecondarySections = mSecondarySections;
283 | }
284 |
285 | public int[] getMainSectionsDrawableIds() {
286 | return mMainSectionsDrawableIds;
287 | }
288 |
289 | public void setMainSectionsDrawableIds(int[] mMainSectionsDrawableIds) {
290 | this.mMainSectionsDrawableIds = mMainSectionsDrawableIds;
291 | }
292 |
293 | public int[] getSecondarySectionsDrawableIds() {
294 | return mSecondarySectionsDrawableIds;
295 | }
296 |
297 | public void setSecondarySectionsDrawableIds(int[] mSecondarySectionsDrawableIds) {
298 | this.mSecondarySectionsDrawableIds = mSecondarySectionsDrawableIds;
299 | }
300 |
301 | public int getMainBackResId() {
302 | return mMainBackResId;
303 | }
304 |
305 | public void setMainBackResId(int mMainBackResId) {
306 | this.mMainBackResId = mMainBackResId;
307 | }
308 |
309 | public int getSecondaryBackResId() {
310 | return mSecondaryBackResId;
311 | }
312 |
313 | public void setSecondaryBackResId(int mSecondaryBackResId) {
314 | this.mSecondaryBackResId = mSecondaryBackResId;
315 | }
316 |
317 | public Drawable getSecondaryDividerDrawable() {
318 | return secondaryDividerDrawable;
319 | }
320 |
321 | public void setSecondaryDividerDrawable(Drawable secondaryDividerDrawable) {
322 | this.secondaryDividerDrawable = secondaryDividerDrawable;
323 | }
324 |
325 | public int getMainDividerHeight() {
326 | return mainDividerHeight;
327 | }
328 |
329 | public void setMainDividerHeight(int mainDividerHeight) {
330 | this.mainDividerHeight = mainDividerHeight;
331 | }
332 |
333 | public Drawable getMainDividerDrawable() {
334 | return mainDividerDrawable;
335 | }
336 |
337 | public void setMainDividerDrawable(Drawable mainDividerDrawable) {
338 | this.mainDividerDrawable = mainDividerDrawable;
339 | }
340 |
341 | public int getMainDividerColor() {
342 | return mainDividerColor;
343 | }
344 |
345 | public void setMainDividerColor(int mainDividerColor) {
346 | this.mainDividerColor = mainDividerColor;
347 | }
348 |
349 | public int getSecondaryDividerColor() {
350 | return secondaryDividerColor;
351 | }
352 |
353 | public void setSecondaryDividerColor(int secondaryDividerColor) {
354 | this.secondaryDividerColor = secondaryDividerColor;
355 | }
356 | }
357 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package org.arasthel.googlenavdrawermenu.utils;
2 |
3 | /**
4 | * Created by Arasthel on 15/04/14.
5 | */
6 | public class Utils {
7 |
8 | public static String[] convertToStringArray(CharSequence[] charSequences) {
9 | if(charSequences == null) {
10 | return null;
11 | }
12 |
13 | if (charSequences instanceof String[]) {
14 | return (String[]) charSequences;
15 | }
16 |
17 | String[] strings = new String[charSequences.length];
18 | for (int index = 0; index < charSequences.length; index++) {
19 | strings[index] = charSequences[index].toString();
20 | }
21 |
22 | return strings;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/views/CheckableImageView.java:
--------------------------------------------------------------------------------
1 | package org.arasthel.googlenavdrawermenu.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.Checkable;
6 | import android.widget.ImageView;
7 |
8 | /**
9 | * Created by Arasthel on 15/04/14.
10 | */
11 | public class CheckableImageView extends ImageView implements Checkable {
12 |
13 | private boolean checked = false;
14 | private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
15 |
16 | public CheckableImageView(Context context) {
17 | super(context);
18 | }
19 |
20 | public CheckableImageView(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | }
23 |
24 | public CheckableImageView(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | }
27 |
28 | @Override
29 | public int[] onCreateDrawableState(int extraSpace) {
30 | final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
31 | if (isChecked())
32 | mergeDrawableStates(drawableState, CHECKED_STATE_SET);
33 | return drawableState;
34 | }
35 |
36 | @Override
37 | public void setChecked(boolean b) {
38 | checked = b;
39 | refreshDrawableState();
40 | }
41 |
42 | @Override
43 | public boolean isChecked() {
44 | return checked;
45 | }
46 |
47 | @Override
48 | public void toggle() {
49 | setChecked(!isChecked());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/views/CheckableRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package org.arasthel.googlenavdrawermenu.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.Checkable;
6 | import android.widget.RelativeLayout;
7 |
8 | /**
9 | * Created by Arasthel on 15/04/14.
10 | */
11 | public class CheckableRelativeLayout extends RelativeLayout implements Checkable {
12 |
13 | private boolean checked = false;
14 | private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked };
15 |
16 | public CheckableRelativeLayout(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | @Override
21 | protected int[] onCreateDrawableState(int extraSpace) {
22 | final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
23 | if (isChecked())
24 | mergeDrawableStates(drawableState, CHECKED_STATE_SET);
25 | return drawableState;
26 | }
27 |
28 | @Override
29 | public void setChecked(boolean b) {
30 | ((CheckedTextView) findViewById(android.R.id.text1)).setChecked(b);
31 | ((CheckableImageView) findViewById(android.R.id.icon)).setChecked(b);
32 | checked = b;
33 | refreshDrawableState();
34 | }
35 |
36 | @Override
37 | public boolean isChecked() {
38 | return checked;
39 | }
40 |
41 | @Override
42 | public void toggle() {
43 | setChecked(!isChecked());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/views/CheckedTextView.java:
--------------------------------------------------------------------------------
1 | package org.arasthel.googlenavdrawermenu.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Typeface;
5 | import android.util.AttributeSet;
6 | import android.widget.Checkable;
7 | import android.widget.TextView;
8 |
9 | /**
10 | * Created by Arasthel on 15/04/14.
11 | */
12 | public class CheckedTextView extends TextView implements Checkable {
13 |
14 | private boolean checked = false;
15 |
16 | public CheckedTextView(Context context) {
17 | super(context);
18 | }
19 |
20 | public CheckedTextView(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | }
23 |
24 | public CheckedTextView(Context context, AttributeSet attrs, int defStyle) {
25 | super(context, attrs, defStyle);
26 | }
27 |
28 |
29 | @Override
30 | public void setChecked(boolean b) {
31 | checked = b;
32 | if(isChecked()) {
33 | setTypeface(null, Typeface.BOLD);
34 | } else {
35 | setTypeface(null, Typeface.NORMAL);
36 | }
37 | }
38 |
39 | @Override
40 | public boolean isChecked() {
41 | return checked;
42 | }
43 |
44 | @Override
45 | public void toggle() {
46 | setChecked(!isChecked());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/java/org/arasthel/googlenavdrawermenu/views/GoogleNavigationDrawer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.arasthel.googlenavdrawermenu.views;
16 |
17 | import android.annotation.TargetApi;
18 | import android.app.Activity;
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.drawable.Drawable;
22 | import android.os.Bundle;
23 | import android.os.Parcelable;
24 | import android.support.v4.widget.DrawerLayout;
25 | import android.util.AttributeSet;
26 | import android.support.v4.view.GravityCompat;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.widget.AdapterView;
30 | import android.widget.ListAdapter;
31 | import android.widget.ListView;
32 |
33 | import org.arasthel.googlenavdrawermenu.R;
34 | import org.arasthel.googlenavdrawermenu.adapters.GoogleNavigationDrawerAdapter;
35 | import org.arasthel.googlenavdrawermenu.utils.Utils;
36 |
37 | public class GoogleNavigationDrawer extends DrawerLayout {
38 |
39 | private ListView mListView;
40 |
41 | private int mListPaddingTop = 0;
42 | private int mListPaddingBottom = 0;
43 | private int mListPaddingLeft = 0;
44 | private int mListPaddingRight = 0;
45 |
46 | private int mDrawerGravity = GravityCompat.START;
47 |
48 | private int mListBackgroundColor = -1;
49 | private Drawable mListBackground = null;
50 | private int mListPrimarySectionsBackgroundId = -1;
51 | private int mListSecondarySectionsBackgroundId = -1;
52 |
53 | private Drawable mListMainDividerDrawable = null;
54 | private Drawable mListSecondaryDividerDrawable = null;
55 |
56 | private float mListWidth = -1;
57 | private int mListMainDividerHeight = -1;
58 | private int mListSecondaryDividerHeight = -1;
59 | private int mListMainDivider = -1;
60 | private int mListSecondaryDivider = -1;
61 |
62 | private OnNavigationSectionSelected mSelectionListener;
63 |
64 | private String[] mMainSections;
65 | private String[] mSecondarySections;
66 |
67 | private int[] mMainSectionsDrawableIds;
68 | private int[] mSecondarySectionsDrawableIds;
69 |
70 | private View mHeaderView;
71 | private View mFooterView;
72 |
73 | private boolean mHeaderClickable = true;
74 | private boolean mFooterClickable = true;
75 | private boolean mSecondarySectionsClickable = true;
76 |
77 | private int checkPosition;
78 |
79 | private Activity mActivity;
80 |
81 | private boolean mShouldChangeTitle = false;
82 |
83 | public GoogleNavigationDrawer(Context context) {
84 | super(context);
85 | }
86 |
87 | public GoogleNavigationDrawer(Context context, AttributeSet attrs) {
88 | super(context, attrs);
89 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GoogleNavigationDrawer, 0, 0);
90 |
91 | configureWithTypedArray(a);
92 | }
93 |
94 | public GoogleNavigationDrawer(Context context, AttributeSet attrs, int defStyle) {
95 | super(context, attrs, defStyle);
96 |
97 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GoogleNavigationDrawer, defStyle, 0);
98 |
99 | configureWithTypedArray(a);
100 | }
101 |
102 | /**
103 | * We need to override onFinishInflate so that it adds the ListView when it has finished inflating itself
104 | */
105 | @Override
106 | protected void onFinishInflate() {
107 | super.onFinishInflate();
108 | setListViewSections(mMainSections, mSecondarySections, mMainSectionsDrawableIds, mSecondarySectionsDrawableIds);
109 | }
110 |
111 | /**
112 | * Add the feature to set the titles automatically to the section's names
113 | * @param activity The activity whose title will change or not
114 | * @param shouldChangeTitle True if it should change
115 | */
116 | public void setShouldChangeTitle(Activity activity, boolean shouldChangeTitle) {
117 | if (shouldChangeTitle)
118 | mActivity = activity;
119 | else
120 | mActivity = null;
121 | mShouldChangeTitle = shouldChangeTitle;
122 | }
123 |
124 | /**
125 | * Change list background to the drawable.
126 | * @param d Drawable to set as background
127 | */
128 | @TargetApi(16)
129 | public void setListBackground(Drawable d) {
130 | mListBackground = d;
131 | int sdk = android.os.Build.VERSION.SDK_INT;
132 | if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
133 | mListView.setBackgroundDrawable(mListBackground);
134 | } else {
135 | mListView.setBackground(mListBackground);
136 | }
137 | }
138 |
139 | /**
140 | * Set list background to the resource with this id
141 | * @param backgroundId Id of the background
142 | */
143 | @TargetApi(16)
144 | public void setListBackground(int backgroundId) {
145 | Drawable d = getResources().getDrawable(backgroundId);
146 | setBackground(d);
147 | }
148 |
149 | /**
150 | * Set list backround to the provided color
151 | * @param color
152 | */
153 | public void setListBackgroundColor(int color) {
154 | mListView.setBackgroundColor(color);
155 | }
156 |
157 | /**
158 | * Change list width
159 | * @param width
160 | */
161 | public void setWidth(int width) {
162 | mListWidth = width;
163 | ((LayoutParams) mListView.getLayoutParams()).width = width;
164 | mListView.requestLayout();
165 | }
166 |
167 | /**
168 | * Set the main list divider drawable to the provided one
169 | * @param listDivider
170 | */
171 | public void setMainListDivider(Drawable listDivider) {
172 | this.mListMainDividerDrawable = listDivider;
173 | mListView.setDivider(listDivider);
174 | }
175 |
176 | public void setMainListDividerHeight(int height) {
177 | this.mListMainDividerHeight = height;
178 | mListView.setDividerHeight(height);
179 | }
180 |
181 | /**
182 | * Set the main list divider drawable to the provided one
183 | * @param listDivider
184 | */
185 | public void setSecondaryListDivider(Drawable listDivider) {
186 | this.mListSecondaryDividerDrawable = listDivider;
187 | }
188 |
189 | public void setSecondaryListDividerHeight(int height) {
190 | this.mListSecondaryDividerHeight = height;
191 | }
192 | /**
193 | * Set the behavior of the secondary sections
194 | * @param isSecondarySectionsClickable
195 | */
196 | public void setIsSecondarySectionsClickable(boolean isSecondarySectionsClickable) {
197 | this.mSecondarySectionsClickable = isSecondarySectionsClickable;
198 | }
199 |
200 | /**
201 | * Configure View with custom attrs
202 | * @param typedArray - A TypedArray
203 | */
204 | public void configureWithTypedArray(TypedArray typedArray) {
205 | mListBackground = typedArray.getDrawable(R.styleable.GoogleNavigationDrawer_list_background);
206 |
207 | mListWidth = typedArray.getDimension(R.styleable.GoogleNavigationDrawer_list_width, -1);
208 |
209 | mListMainDividerHeight = (int) typedArray.getDimension(R.styleable.GoogleNavigationDrawer_list_main_divider_height, -1);
210 | mListSecondaryDividerHeight = (int) typedArray.getDimension(R.styleable.GoogleNavigationDrawer_list_secondary_divider_height, -1);
211 |
212 | mListMainDividerDrawable = typedArray.getDrawable(R.styleable.GoogleNavigationDrawer_list_main_divider);
213 | mListSecondaryDividerDrawable = typedArray.getDrawable(R.styleable.GoogleNavigationDrawer_list_secondary_divider);
214 |
215 | if(mListMainDividerDrawable == null) {
216 | mListMainDivider = typedArray.getColor(R.styleable.GoogleNavigationDrawer_list_main_divider, -1);
217 | }
218 |
219 | if(mListSecondaryDividerDrawable == null) {
220 | mListSecondaryDivider = typedArray.getColor(R.styleable.GoogleNavigationDrawer_list_secondary_divider, -1);
221 | }
222 |
223 | mListPaddingTop = typedArray.getDimensionPixelSize(R.styleable.GoogleNavigationDrawer_list_paddingTop, mListPaddingTop);
224 | mListPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.GoogleNavigationDrawer_list_paddingBottom, mListPaddingBottom);
225 | mListPaddingRight = typedArray.getDimensionPixelSize(R.styleable.GoogleNavigationDrawer_list_paddingRight, mListPaddingRight);
226 | mListPaddingLeft = typedArray.getDimensionPixelSize(R.styleable.GoogleNavigationDrawer_list_paddingLeft, mListPaddingLeft);
227 |
228 | mDrawerGravity = typedArray.getInt(R.styleable.GoogleNavigationDrawer_drawer_gravity, mDrawerGravity);
229 |
230 | mMainSections = Utils.convertToStringArray(typedArray.getTextArray(R.styleable.GoogleNavigationDrawer_list_mainSectionsEntries));
231 | mSecondarySections = Utils.convertToStringArray(typedArray.getTextArray(R.styleable.GoogleNavigationDrawer_list_secondarySectionsEntries));
232 |
233 | mListPrimarySectionsBackgroundId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_mainSectionsBackground, -1);
234 | mListSecondarySectionsBackgroundId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_secondarySectionsBackground, -1);
235 |
236 | int mainSectDrawableId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_mainSectionsDrawables, -1);
237 |
238 | if(!isInEditMode()) {
239 |
240 | if (mMainSections != null) {
241 | mMainSectionsDrawableIds = new int[mMainSections.length];
242 |
243 | if (mainSectDrawableId != -1) {
244 | TypedArray mainSectTypedArray = getResources().obtainTypedArray(mainSectDrawableId);
245 | for (int i = 0; i < mMainSections.length; i++) {
246 | mMainSectionsDrawableIds[i] = mainSectTypedArray.getResourceId(i, 0);
247 | }
248 | mainSectTypedArray.recycle();
249 | }
250 | }
251 |
252 | int secondarySectDrawableId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_secondarySectionsDrawables, -1);
253 |
254 | if (mSecondarySections != null) {
255 | mSecondarySectionsDrawableIds = new int[mSecondarySections.length];
256 |
257 | if (secondarySectDrawableId != -1) {
258 | TypedArray secondarySectTypedArray = getResources().obtainTypedArray(secondarySectDrawableId);
259 | for (int i = 0; i < mSecondarySections.length; i++) {
260 | mSecondarySectionsDrawableIds[i] = secondarySectTypedArray.getResourceId(i, 0);
261 | }
262 | secondarySectTypedArray.recycle();
263 | }
264 | }
265 |
266 | LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
267 |
268 | int headerViewId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_headerView, -1);
269 | if (headerViewId != -1) {
270 | mHeaderView = inflater.inflate(headerViewId, null);
271 | mHeaderClickable = typedArray.getBoolean(R.styleable.GoogleNavigationDrawer_list_headerClickable, true);
272 | }
273 |
274 | int footerViewId = typedArray.getResourceId(R.styleable.GoogleNavigationDrawer_list_footerView, -1);
275 | if (footerViewId != -1) {
276 | mFooterView = inflater.inflate(footerViewId, null);
277 | mFooterClickable = typedArray.getBoolean(R.styleable.GoogleNavigationDrawer_list_footerClickable, true);
278 | }
279 |
280 | mSecondarySectionsClickable = typedArray.getBoolean(R.styleable.GoogleNavigationDrawer_list_secondarySectionsCheckable, true);
281 | }
282 |
283 | typedArray.recycle();
284 |
285 | }
286 |
287 | /**
288 | * The ListView menu is inflated and added to de DrawerLayout
289 | */
290 | private void configureList() {
291 | LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
292 | mListView = (ListView) inflater.inflate(R.layout.navigation_list, this, false);
293 | if(mListWidth >= 0) {
294 | ((LayoutParams) mListView.getLayoutParams()).width = (int) mListWidth;
295 | }
296 |
297 | if(mListBackgroundColor != -1) {
298 | setListBackgroundColor(mListBackgroundColor);
299 | }
300 |
301 | if(mListBackground != null) {
302 | setListBackground(mListBackground);
303 | }
304 |
305 | mListView.setPadding(mListPaddingLeft, mListPaddingTop, mListPaddingRight, mListPaddingBottom);
306 | ((DrawerLayout.LayoutParams) mListView.getLayoutParams()).gravity = mDrawerGravity;
307 | if(mHeaderView != null) {
308 | setMenuHeader(mHeaderView,mHeaderClickable);
309 | }
310 | if(mFooterView != null) {
311 | setMenuFooter(mFooterView,mFooterClickable);
312 | }
313 | addView(mListView);
314 |
315 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
316 | @Override
317 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
318 |
319 | if(mHeaderView != null && i == 0 && !mHeaderClickable) {
320 | return;
321 | }
322 |
323 | if(mFooterView != null && i == mListView.getCount()-1 && !mFooterClickable) {
324 | return;
325 | }
326 | if (mSecondarySectionsClickable || mListView.getAdapter().getItemViewType(i) == GoogleNavigationDrawerAdapter.TYPE_MAIN)
327 | check(i);
328 |
329 | if(mSelectionListener != null) {
330 | mSelectionListener.onSectionSelected(view, i, l);
331 | }
332 |
333 | if (mShouldChangeTitle && i != 0 && i != mListView.getCount() - 1) {
334 | CharSequence title = (CharSequence) mListView.getAdapter().getItem(i);
335 | mActivity.setTitle(title);
336 | }
337 |
338 | closeDrawerMenu();
339 | }
340 | });
341 | }
342 |
343 | /**
344 | * The way to set the ListView adapter items
345 | * @param mainSections A String array with the main section titles. Cannot be null.
346 | * @param secondarySections A String array with the secondary section titles. May be null.
347 | * @param mainDrawableIds An integer array with the ids of the main sections icons. Must have the same length as mainSections. May be null.
348 | * @param secondaryDrawableIds An integer array with the ids of the secondary sections icons. Must have the same length as secondarySections. May be null.
349 | */
350 | public void setListViewSections(String[] mainSections, String[] secondarySections, int[] mainDrawableIds, int[] secondaryDrawableIds) {
351 | if(!isInEditMode()) {
352 | if(mListView == null) {
353 | configureList();
354 | }
355 | GoogleNavigationDrawerAdapter adapter = new GoogleNavigationDrawerAdapter(getContext(), mainSections, secondarySections, mainDrawableIds, secondaryDrawableIds);
356 |
357 | if(mListMainDividerHeight != -1) {
358 | adapter.setMainDividerHeight(mListMainDividerHeight);
359 | }
360 |
361 | if(mListMainDivider != -1) {
362 | adapter.setMainDividerColor(mListMainDivider);
363 | }
364 |
365 | if(mListMainDividerDrawable != null) {
366 | adapter.setMainDividerDrawable(mListMainDividerDrawable);
367 | }
368 |
369 | if(mListSecondaryDividerHeight != -1) {
370 | adapter.setSecondaryDividerHeight(mListSecondaryDividerHeight);
371 | }
372 |
373 | if(mListSecondaryDivider != -1) {
374 | adapter.setSecondaryDividerColor(mListSecondaryDivider);
375 | }
376 |
377 | if(mListSecondaryDividerDrawable != null) {
378 | adapter.setSecondaryDividerDrawable(mListSecondaryDividerDrawable);
379 | }
380 |
381 | if(mListPrimarySectionsBackgroundId >= 0) {
382 | adapter.setMainBackResId(mListPrimarySectionsBackgroundId);
383 | }
384 |
385 | if(mListSecondarySectionsBackgroundId >= 0) {
386 | adapter.setSecondaryBackResId(mListSecondarySectionsBackgroundId);
387 | }
388 |
389 | mListView.setAdapter(adapter);
390 | if(mHeaderView != null && !isHeaderClickable()) {
391 | check(1);
392 | } else {
393 | check(0);
394 | }
395 | }
396 | }
397 |
398 | /**
399 | * Check an item on the ListView
400 | * @param position The position to check
401 | */
402 | public void check(int position) {
403 | mListView.setItemChecked(checkPosition, false);
404 | mListView.setItemChecked(position, true);
405 | checkPosition = position;
406 | }
407 |
408 |
409 | /**
410 | * Helper to access the isDrawerOpen method of the ListView menu.
411 | * @return whether it's opened or not
412 | */
413 | public boolean isDrawerMenuOpen() {
414 | return super.isDrawerOpen(mListView);
415 | }
416 |
417 | /**
418 | * Helper to open the ListView menu.
419 | */
420 | public void openDrawerMenu() {
421 | super.openDrawer(mListView);
422 | }
423 |
424 | /**
425 | * Helper to close the ListView menu.
426 | */
427 | public void closeDrawerMenu() {
428 | super.closeDrawer(mListView);
429 | }
430 |
431 | /**
432 | * Set custom listener so when a ListView item is clicked, it's also checked
433 | * @param listener The OnNavigationSectionSelected listener. Use null to disable.
434 | */
435 | public void setOnNavigationSectionSelected(OnNavigationSectionSelected listener) {
436 | mSelectionListener = listener;
437 | }
438 |
439 | /**
440 | * Set a custom header view
441 | * @param v The header view
442 | */
443 | public void setMenuHeader(View v) {
444 | if(mListView != null) {
445 | if(mListView.getAdapter() != null) {
446 | ListAdapter adapter = (ListAdapter) mListView.getAdapter();
447 | removeView(mListView);
448 | configureList();
449 | mListView.addHeaderView(v, null, isHeaderClickable());
450 | mListView.setAdapter(adapter);
451 | } else {
452 | mListView.addHeaderView(v, null, isHeaderClickable());
453 | }
454 | mHeaderView = v;
455 | }
456 | }
457 |
458 | /**
459 | * Set a custom header view
460 | * @param v The header view
461 | */
462 | public void setMenuHeader(View v, boolean clickable) {
463 | if(mListView != null) {
464 | setHeaderClickable(clickable);
465 | if(mListView.getAdapter() != null) {
466 | ListAdapter adapter = (ListAdapter) mListView.getAdapter();
467 | removeView(mListView);
468 | configureList();
469 | mListView.addHeaderView(v, null, isHeaderClickable());
470 | mListView.setAdapter(adapter);
471 | } else {
472 | mListView.addHeaderView(v, null, isHeaderClickable());
473 | }
474 | mHeaderView = v;
475 | }
476 | }
477 |
478 | /**
479 | * Returns the header of the ListView
480 | * @return The header of the ListView
481 | */
482 | public View getMenuHeader() {
483 | return mHeaderView;
484 | }
485 |
486 | /**
487 | * Set a custom footer view
488 | * @param v The footer view
489 | */
490 | public void setMenuFooter(View v, boolean clickable) {
491 | if(mListView != null) {
492 | setFooterClickable(clickable);
493 | if(mListView.getAdapter() != null) {
494 | ListAdapter adapter = mListView.getAdapter();
495 | removeView(mListView);
496 | configureList();
497 | mListView.addFooterView(v, null, isFooterClickable());
498 | mListView.setAdapter(adapter);
499 | } else {
500 | mListView.addFooterView(v, null, isFooterClickable());
501 | }
502 | mFooterView = v;
503 | }
504 | }
505 |
506 | /**
507 | * Adding a header and a footer to an already populated ListView is quite inefficient.
508 | * To make it less messy, please use this method if you are going to add both of them.
509 | * @param header The header View
510 | * @param footer The footer View
511 | */
512 | public void setMenuHeaderAndFooter(View header, View footer, boolean headerClickable, boolean footerClickable) {
513 | if(mListView != null) {
514 | setHeaderClickable(headerClickable);
515 | setFooterClickable(footerClickable);
516 | if(mListView.getAdapter() != null) {
517 | ListAdapter adapter = mListView.getAdapter();
518 | removeView(mListView);
519 | configureList();
520 | mListView.addHeaderView(header, null, isHeaderClickable());
521 | mListView.addFooterView(footer, null, isFooterClickable());
522 | mListView.setAdapter(adapter);
523 | } else {
524 | mListView.addFooterView(header, null, isHeaderClickable());
525 | mListView.addFooterView(footer, null, isFooterClickable());
526 | }
527 | mHeaderView = header;
528 | mFooterView = footer;
529 | }
530 | }
531 |
532 | public boolean isHeaderClickable() {
533 | return mHeaderClickable;
534 | }
535 |
536 | public void setHeaderClickable(boolean mHeaderClickable) {
537 | this.mHeaderClickable = mHeaderClickable;
538 | }
539 |
540 | public boolean isFooterClickable() {
541 | return mFooterClickable;
542 | }
543 |
544 | public void setFooterClickable(boolean mFooterClickable) {
545 | this.mFooterClickable = mFooterClickable;
546 | }
547 |
548 | /**
549 | * Returns the footer of the ListView
550 | * @return The footer of the ListView
551 | */
552 | public View getMenuFooter() {
553 | return mFooterView;
554 | }
555 |
556 | public interface OnNavigationSectionSelected {
557 |
558 | public void onSectionSelected(View v, int i, long l);
559 |
560 | }
561 |
562 | @Override
563 | protected Parcelable onSaveInstanceState() {
564 | Parcelable superState = super.onSaveInstanceState();
565 | Bundle bundle = new Bundle();
566 | bundle.putParcelable("view", superState);
567 | bundle.putInt("position", checkPosition);
568 | bundle.putBoolean("isdraweropen", isDrawerMenuOpen());
569 | bundle.putBoolean("shouldchangetitle", mShouldChangeTitle);
570 | return bundle;
571 | }
572 |
573 | @Override
574 | public void onRestoreInstanceState(Parcelable state) {
575 | Bundle bundle = (Bundle)state;
576 | super.onRestoreInstanceState(bundle.getParcelable("view"));
577 | check(bundle.getInt("position"));
578 | mShouldChangeTitle = bundle.getBoolean("shouldchangetitle", false);
579 | if (mShouldChangeTitle && checkPosition != 0 && checkPosition != mListView.getCount() - 1) {
580 | CharSequence title = (CharSequence) mListView.getAdapter().getItem(checkPosition);
581 | mActivity.setTitle(title);
582 | }
583 | if (bundle.getBoolean("isdraweropen", false))
584 | openDrawerMenu();
585 | }
586 | }
587 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable/main_section_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/drawable/secondary_section_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/layout/main_navigation_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
18 |
19 |
27 |
28 |
29 |
30 |
34 |
35 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/layout/navigation_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/layout/secondary_navigation_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
12 |
13 |
23 |
24 |
32 |
33 |
34 |
35 |
40 |
41 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values-v16/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @android:color/transparent
4 | #ccc
5 | #ccc
6 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 64dp
4 | 46dp
5 |
6 | 48dp
7 | 32dp
8 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GoogleNavigationDrawerMenu
3 |
4 |
--------------------------------------------------------------------------------
/GoogleNavigationDrawerMenuLibrary/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GoogleNavigationDrawerMenu
2 |
3 | This project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without having to do any extra effort. Sorry for the long name, though.
4 |
5 | 
6 |
7 | ## Index
8 | * [Features](#features)
9 | * [How to use](#how-to-use)
10 | 1. [Include the library](#1-include-the-library)
11 | 2. [Use class in XML or code](#2-use-class-in-xml-or-code)
12 | 3. [Handling selection](#3-handling-selection-opening-and-closing-of-the-menu)
13 | 4. [Customizing the inner ListView](#4-customizing-the-inner-listview)
14 | * [License](#license)
15 |
16 | ## Features
17 |
18 | With GoogleNavigationDrawerMenu you can:
19 |
20 | * Set a GoogleApp-styled DrawerLayout menu and only have to specify the main content for your app, you no longer have set the ListView and its styles. Everything is handled by the **GoogleNavigationDrawer** class.
21 | * Set main and secondary sections to the menu.
22 | * Set a list of icons for those sections (optional).
23 | * Both text and icons remain selected when you click on them.
24 | * Set an *OnNavigationSectionSelected* listener so you can handle section selection events.
25 | * Change the background of the list items.
26 | * Set a header and footer to the inner ListView.
27 |
28 | ## How to use
29 |
30 | ### 1. Include the library:
31 |
32 | **Manually (Option A):**
33 |
34 | Download the source code and import ```GoogleNavigationDrawerMenuLibrary``` folder as a Library Module in Android Studio or as a Project in Eclipse (still not tested).
35 |
36 | **Manually (Option B):**
37 |
38 | * Download the [AAR](aars/GoogleNavigationDrawerMenuLibrary.aar?raw=true).
39 | * Put it in the ```aars``` folder of your Android Studio project.
40 | * Add a File Dependency or add it to the ```build.gradle``` of your main Module, like this:
41 |
42 | repositories {
43 | mavenCentral()
44 | flatDir {
45 | dirs 'aars'
46 | }
47 | }
48 |
49 | Notice the ```flatDir``` local maven repository created. Now you will have to add the aar file to the *dependencies* list, as if you were adding it from Maven Central Repository:
50 |
51 | compile 'com.arasthel:gnavdrawer-library:+'
52 |
53 |
54 | **Automatic (Gradle):**
55 |
56 | Add it to your Application Module's `build.gradle`:
57 |
58 | Declare it into your build.gradle
59 |
60 | dependencies{
61 | compile 'com.arasthel:gnavdrawer-library:+'
62 | }
63 |
64 | ### 2. Use class in XML or code:
65 |
66 | #### Example of how to use it on an XML code:
67 |
68 | ```xml
69 |
81 |
82 |
86 |
87 |
88 | ```
89 |
90 | You may think *'Ok, so where's the menu?'*. Well, the GoogleNavigationDrawer class itself contains it and handles it so you don't have to manually modify it. You can customize it, though, you can find that info in [**Customizing Section**](#4-customizing-the-inner-listview).
91 |
92 | All the `drawer:*` attributes are optional, but if you don't provide any entries you will have to do it later in code with `drawer.setListViewSections(...)`.
93 |
94 | #### Using GoogleNavigationDrawer in Java Code:
95 |
96 | ```java
97 | ViewGroup container = (ViewGroup) findViewById(R.id.container);
98 | GoogleNavigationDrawer drawer = new GoogleNavigationDrawer(context);
99 | // Here we are providing data to the adapter of the ListView
100 | drawer.setListViewSections(new String[]{"Section A", "Section B"}, // Main sections
101 | new String[]{"Settings"}, // Secondary sections
102 | new int[]{R.drawable.ic_launcher}, // Main sections icon ids
103 | null); // Secondary sections icon ids
104 | // To work correctly, a DrawerLayout must be the only View in a ViewGroup
105 | container.removeAllViews();
106 | container.addView(drawer);
107 | // Now we add the content to the drawer since the menu is already there.
108 | // Also, DrawerLayout forces the contentView to be the first item. Otherwise, you can't click on the menu.
109 | drawer.addView(contentView, 0);
110 | ```
111 |
112 |
113 | GoogleNavigationDrawer extends DrawerLayout. This means you can use DrawerLayout methods and set a DrawerListener to it.
114 |
115 | ### 3. Handling selection, opening and closing of the menu:
116 |
117 | As you cannot access the inner ListView to ensure encapsulation, additional methods have been provided so you can do it by code. This methods are:
118 |
119 | ```java
120 | public boolean isDrawerMenuOpen();
121 |
122 | public void openDrawerMenu();
123 |
124 | public void closeDrawerMenu();
125 | ```
126 |
127 | Also, to handle section selections, a listener has been provided:
128 |
129 | ```java
130 | public void setOnNavigationSectionSelected(OnNavigationSectionSelected listener);
131 | ```
132 | You can also easily tell the drawer to change your Activity title based on the selected section via this method:
133 |
134 | ```java
135 | public void setShouldChangeTitle(Activity activity, boolean shouldChangeTitle);
136 | ```
137 |
138 | ### 4. Customizing the inner ListView:
139 |
140 | Finally, customization. The main XML attributes of the class are the following:
141 |
142 | ```xml
143 | drawer:list_padding[Top, Bottom, Left, Right]="dimen"
144 | drawer:drawer_gravity="start"
145 | drawer:list_mainSectionsEntries="array"
146 | drawer:list_secondarySectionsEntries="array"
147 | drawer:list_mainSectionsDrawables="array"
148 | drawer:list_secondarySectionsDrawables="array"
149 | drawer:list_headerView="layout"
150 | drawer:list_footerView="layout"
151 | drawer:list_headerClickable="boolean" (default is true)
152 | drawer:list_footerClickable="boolean" (default is true)
153 | drawer:list_secondarySectionsCheckable="boolean" (default is true)
154 | drawer:list_mainSectionsBackground="drawable"
155 | drawer:list_secondarySectionsBackground="drawable"
156 | drawer:list_width="dimension"
157 | drawer:list_background="drawable|color"
158 | drawer:list_[main|secondary]_divider="drawable|color"
159 | drawer:list_[main|secondary]_divider_height="dimension"
160 | ```
161 |
162 |
163 | Example of *arrays* in ```arrays.xml```:
164 |
165 | ```xml
166 |
167 |
168 |
169 |
170 | - Home
171 | - Some Other
172 |
173 |
174 |
175 | - Settings
176 | - Info
177 |
178 |
179 |
180 | - @drawable/ic_home
181 | - @drawable/ic_other
182 |
183 |
184 |
185 | ```
186 |
187 | Also, both icon drawables and backgrounds **should have checked states** to keep them consistent with the rest of the library:
188 |
189 | ```xml
190 |
191 |
192 |
193 |
194 |
195 |
196 | ```
197 |
198 | All these attributes can also be set by code.
199 |
200 | ## License:
201 |
202 | This library is licensed under Apachev2:
203 |
204 | >Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
205 | >You may obtain a copy of the License at
206 |
207 | > http://www.apache.org/licenses/LICENSE-2.0
208 |
209 | >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.
210 | >See the License for the specific language governing permissions and limitations under the License.
211 |
212 | This means you can use the library in whatever way you want and also I take no responsibility of what it could do (thermo-nuclear explosions and such).
213 |
214 | Anyway, it would be really nice of you if you could give this library a line in some "About" section in your app.
215 |
--------------------------------------------------------------------------------
/aars/GoogleNavigationDrawerMenuLibrary.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/aars/GoogleNavigationDrawerMenuLibrary.aar
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:0.11.+'
9 | }
10 | }
11 |
12 | def isReleaseBuild() {
13 | return version.contains("SNAPSHOT") == false
14 | }
15 |
16 | allprojects {
17 | version = VERSION_NAME
18 | group = GROUP
19 |
20 | repositories {
21 | mavenCentral()
22 | }
23 | }
24 |
25 | apply plugin: 'android-reporting'
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | VERSION_NAME=1.1.4
21 | VERSION_CODE=12
22 | GROUP=com.arasthel
23 |
24 | POM_DESCRIPTION=Android library to get the style of the menu of the Google Apps
25 | POM_URL=https://github.com/Arasthel/GoogleNavigationDrawerMenu
26 | POM_SCM_URL=https://github.com/Arasthel/GoogleNavigationDrawerMenu
27 | POM_SCM_CONNECTION=scm:git@github.com:Arasthel/GoogleNavigationDrawerMenu.git
28 | POM_SCM_DEV_CONNECTION=scm:git@github.com:Arasthel/GoogleNavigationDrawerMenu.git
29 | POM_LICENCE_NAME=Apache v2
30 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0
31 | POM_LICENCE_DIST=repo
32 | POM_DEVELOPER_ID=arasthel
33 | POM_DEVELOPER_NAME=Jorge Martín
34 |
--------------------------------------------------------------------------------
/maven_push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven'
2 | apply plugin: 'signing'
3 |
4 | def sonatypeRepositoryUrl
5 | if (isReleaseBuild()) {
6 | println 'RELEASE BUILD'
7 | sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
8 | } else {
9 | println 'DEBUG BUILD'
10 | sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
11 | }
12 |
13 | def getRepositoryUsername() {
14 | return hasProperty('nexusUsername') ? nexusUsername : ""
15 | }
16 |
17 | def getRepositoryPassword() {
18 | return hasProperty('nexusPassword') ? nexusPassword : ""
19 | }
20 |
21 | afterEvaluate { project ->
22 | uploadArchives {
23 | repositories {
24 | mavenDeployer {
25 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
26 |
27 | pom.artifactId = POM_ARTIFACT_ID
28 |
29 | repository(url: sonatypeRepositoryUrl) {
30 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
31 | }
32 |
33 | pom.project {
34 | name POM_NAME
35 | packaging POM_PACKAGING
36 | description POM_DESCRIPTION
37 | url POM_URL
38 |
39 | scm {
40 | url POM_SCM_URL
41 | connection POM_SCM_CONNECTION
42 | developerConnection POM_SCM_DEV_CONNECTION
43 | }
44 |
45 | licenses {
46 | license {
47 | name POM_LICENCE_NAME
48 | url POM_LICENCE_URL
49 | distribution POM_LICENCE_DIST
50 | }
51 | }
52 |
53 | developers {
54 | developer {
55 | id POM_DEVELOPER_ID
56 | name POM_DEVELOPER_NAME
57 | }
58 | }
59 | }
60 | }
61 | }
62 | }
63 |
64 | signing {
65 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
66 | sign configurations.archives
67 | }
68 |
69 | task androidJavadocs(type: Javadoc) {
70 | //source = android.sourceSets.main.allJava
71 | }
72 |
73 | task androidJavadocsJar(type: Jar) {
74 | classifier = 'javadoc'
75 | //basename = artifact_id
76 | from androidJavadocs.destinationDir
77 | }
78 |
79 | task androidSourcesJar(type: Jar) {
80 | classifier = 'sources'
81 | //basename = artifact_id
82 | //from android.sourceSets.main.allSource
83 | }
84 |
85 | artifacts {
86 | //archives packageReleaseJar
87 | archives androidSourcesJar
88 | archives androidJavadocsJar
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'GoogleNavigationDrawerMenuLibrary', ':XMLSample', ':CodeSample'
--------------------------------------------------------------------------------
/xmlSample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/xmlSample/Sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/xmlSample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion "19.1.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:20.0.0'
23 | compile project(':GoogleNavigationDrawerMenuLibrary')
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | }
26 |
--------------------------------------------------------------------------------
/xmlSample/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Users/Carlos/AppData/Local/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/xmlSample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/xmlSample/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/xmlSample/src/main/java/com/dexafree/googlenavigationdrawermenusample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Sample project only for demonstration purposes
3 | *
4 | * This project uses the GoogleNavigationDrawerMenu Android library,
5 | * created by Jorge Martín (Arasthel), which is released under a
6 | * GPLv3 license:
7 | * https://github.com/Arasthel/GoogleNavigationDrawerMenu
8 | *
9 | * In this project you can see the library implementation made via XML code
10 | *
11 | * Sample project made by Dexafree
12 | */
13 |
14 | package com.dexafree.googlenavigationdrawermenusample;
15 |
16 | import android.content.Context;
17 | import android.support.v4.app.ActionBarDrawerToggle;
18 | import android.support.v7.app.ActionBarActivity;
19 | import android.os.Bundle;
20 | import android.view.*;
21 | import org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer;
22 |
23 | public class MainActivity extends ActionBarActivity {
24 |
25 | private ActionBarDrawerToggle drawerToggle;
26 | private GoogleNavigationDrawer mDrawer;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 |
33 | /*
34 | * We get the GoogleNavigationDrawer object
35 | * in order to allow further method usage
36 | */
37 | mDrawer = (GoogleNavigationDrawer) findViewById(R.id.navigation_drawer_container);
38 |
39 | /*
40 | * We get the drawerToggle object order to
41 | * allow showing the NavigationDrawer icon
42 | */
43 | drawerToggle = new ActionBarDrawerToggle(this,
44 | mDrawer,
45 | R.drawable.ic_drawer,
46 | R.string.app_name,
47 | R.string.app_name);
48 |
49 |
50 | mDrawer.setDrawerListener(drawerToggle); //Attach the DrawerListener
51 |
52 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
53 | getSupportActionBar().setHomeButtonEnabled(true);
54 | }
55 |
56 | @Override
57 | protected void onPostCreate(Bundle savedInstanceState) {
58 | super.onPostCreate(savedInstanceState);
59 | drawerToggle.syncState();
60 | }
61 |
62 |
63 | @Override
64 | public boolean onCreateOptionsMenu(Menu menu) {
65 | getMenuInflater().inflate(R.menu.main, menu);
66 | return true;
67 | }
68 |
69 | @Override
70 | public boolean onOptionsItemSelected(MenuItem item) {
71 | /*
72 | * Declare the behaviour of clicking at the
73 | * application icon, opening and closing the drawer
74 | */
75 | if(item.getItemId() == android.R.id.home) {
76 | if(mDrawer != null) {
77 | if(mDrawer.isDrawerMenuOpen()) {
78 | mDrawer.closeDrawerMenu();
79 | } else {
80 | mDrawer.openDrawerMenu();
81 | }
82 | }
83 | }
84 | return super.onOptionsItemSelected(item);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-hdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-hdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-hdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-hdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-hdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-hdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-hdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-hdpi/ic_drawer.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-mdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-mdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-mdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-mdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-mdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-mdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-mdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-mdpi/ic_drawer.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xhdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xhdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xxhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xxhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xxhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xxhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xxhdpi/ic_action_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xxhdpi/ic_action_cancel.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xxhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xxhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jmartinesp/GoogleNavigationDrawerMenu/8a4d020842eea1f53ea61b581ed4ca0cc5501b71/xmlSample/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/xmlSample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
17 |
18 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | - Home
6 | - Some Other
7 |
8 |
9 |
10 | - Settings
11 | - Info
12 |
13 |
14 |
15 | - @drawable/ic_action_accept
16 | - @drawable/ic_action_cancel
17 |
18 |
19 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | GoogleNavigationDrawerMenuSample
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/xmlSample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------