extends ActionBarDrawerToggle {
12 |
13 | private String titleRequested;
14 | private Fragment fragmentRequested;
15 | private Fragment oldFragment;
16 | private boolean request;
17 |
18 | public MaterialActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) {
19 | super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes);
20 | }
21 |
22 | public void addFragmentRequest(Fragment fragment, String title,Fragment oldFragment) {
23 | request = true;
24 |
25 | titleRequested = title;
26 | fragmentRequested = fragment;
27 | this.oldFragment = oldFragment;
28 | }
29 |
30 | public boolean isFragmentRequested() {
31 | return request;
32 | }
33 |
34 | public Fragment getFragmentRequested() {
35 | return fragmentRequested;
36 | }
37 |
38 | public String getTitleRequested() {
39 | return titleRequested;
40 | }
41 |
42 | public Fragment getOldFragment() {
43 | return oldFragment;
44 | }
45 |
46 | public void removeFragmentRequest() {
47 | request = false;
48 |
49 | titleRequested = null;
50 | fragmentRequested = null;
51 | oldFragment = null;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
27 |
28 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
29 |
30 |
46 |
47 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section_icon_large.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
29 |
30 |
46 |
47 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/test/Test.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.test;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 |
6 | import it.neokree.example.R;
7 | import it.neokree.example.mockedFragments.FragmentButton;
8 | import it.neokree.example.mockedFragments.FragmentIndex;
9 | import it.neokree.example.mockedFragments.FragmentList;
10 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
11 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
12 |
13 | /**
14 | * Created by neokree on 22/01/15.
15 | */
16 | public class Test extends MaterialNavigationDrawer {
17 |
18 | @Override
19 | public void init(Bundle savedInstanceState) {
20 |
21 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com",R.drawable.photo, R.drawable.bamboo);
22 | this.addAccount(account);
23 |
24 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
25 | this.addAccount(account2);
26 |
27 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
28 | this.addAccount(account3);
29 |
30 | MaterialAccount account4 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
31 | this.addAccount(account4);
32 |
33 | // create sections
34 | this.addSection(newSection("Section 1", new TestFragment()));
35 | this.addSection(newSection("Section 2",new FragmentList()));
36 | this.addSection(newSection("Section 3", R.drawable.ic_mic_white_24dp,new TestFragment()).setSectionColor(Color.parseColor("#9c27b0")));
37 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new TestFragment()).setSectionColor(Color.parseColor("#03a9f4")));
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/functionalities/MultiPane.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.functionalities;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 |
7 | import it.neokree.example.R;
8 | import it.neokree.example.mockedActivity.Settings;
9 | import it.neokree.example.mockedFragments.FragmentButton;
10 | import it.neokree.example.mockedFragments.FragmentIndex;
11 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
12 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
13 |
14 | /**
15 | * Created by neokree on 20/01/15.
16 | */
17 | public class MultiPane extends MaterialNavigationDrawer {
18 |
19 | @Override
20 | public void init(Bundle savedInstanceState) {
21 | // add accounts
22 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com", R.drawable.photo, R.drawable.bamboo);
23 | this.addAccount(account);
24 |
25 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
26 | this.addAccount(account2);
27 |
28 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
29 | this.addAccount(account3);
30 |
31 | // create sections
32 | this.addSection(newSection("Section 1", new FragmentIndex()));
33 | this.addSection(newSection("Section 2",new FragmentIndex()));
34 | this.addSection(newSection("Section 3",R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
35 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
36 |
37 | // create bottom section
38 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/functionalities/KitkatStatusBar.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.functionalities;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 |
7 | import it.neokree.example.R;
8 | import it.neokree.example.mockedActivity.Settings;
9 | import it.neokree.example.mockedFragments.FragmentButton;
10 | import it.neokree.example.mockedFragments.FragmentIndex;
11 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
12 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
13 |
14 | /**
15 | * Created by neokree on 20/01/15.
16 | */
17 | public class KitkatStatusBar extends MaterialNavigationDrawer {
18 |
19 | @Override
20 | public void init(Bundle savedInstanceState) {
21 | // add accounts
22 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com", R.drawable.photo, R.drawable.bamboo);
23 | this.addAccount(account);
24 |
25 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
26 | this.addAccount(account2);
27 |
28 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
29 | this.addAccount(account3);
30 |
31 | // create sections
32 | this.addSection(newSection("Section 1", new FragmentIndex()));
33 | this.addSection(newSection("Section 2",new FragmentIndex()));
34 | this.addSection(newSection("Section 3",R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
35 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
36 |
37 | // create bottom section
38 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/java/it/neokree/materialnavigationdrawer/util/MaterialDrawerLayout.java:
--------------------------------------------------------------------------------
1 | package it.neokree.materialnavigationdrawer.util;
2 |
3 | import android.content.Context;
4 | import android.support.v4.widget.DrawerLayout;
5 | import android.util.AttributeSet;
6 | import android.view.KeyEvent;
7 | import android.view.MotionEvent;
8 |
9 | /**
10 | * An improved version of DrawerLayout that will ensure that a locked open DrawerLayout can be used without capturing all touches into the client
11 | * area.
12 | *
13 | * To activate, call {@link #requestDisallowInterceptTouchEvent(boolean)} on the layout. Note that this should only ever be done in case when
14 | * the drawer is to be locked open.
15 | *
16 | *
17 | * Created by neokree on 04/01/15.
18 | *
19 | * Original source code by Rainer Burgstaller
20 | */
21 | public class MaterialDrawerLayout extends DrawerLayout {
22 | private boolean multipaneSupport = false;
23 |
24 | public MaterialDrawerLayout(Context context) {
25 | super(context);
26 | }
27 |
28 | public MaterialDrawerLayout(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | public MaterialDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
33 | super(context, attrs, defStyle);
34 | }
35 |
36 | @Override
37 | public boolean onInterceptTouchEvent(final MotionEvent ev) {
38 | if (multipaneSupport) {
39 | return false;
40 | }
41 | return super.onInterceptTouchEvent(ev);
42 | }
43 |
44 | public void setMultipaneSupport(boolean support) {
45 | if(Utils.isTablet(this.getResources())) {
46 | // custom implementation only for tablets
47 | multipaneSupport = support;
48 | }
49 | }
50 |
51 | @Override
52 | public boolean onKeyUp(int keyCode, KeyEvent event) {
53 |
54 | if(multipaneSupport) {
55 | return false;
56 | }
57 | else {
58 | return super.onKeyUp(keyCode, event);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section_ripple.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
30 |
31 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/dark/Accounts.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.dark;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 |
7 | import it.neokree.example.R;
8 | import it.neokree.example.mockedActivity.Settings;
9 | import it.neokree.example.mockedFragments.FragmentButton;
10 | import it.neokree.example.mockedFragments.FragmentIndex;
11 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
12 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
13 | import it.neokree.materialnavigationdrawer.elements.listeners.MaterialAccountListener;
14 |
15 | /**
16 | * Created by neokree on 18/01/15.
17 | */
18 | public class Accounts extends MaterialNavigationDrawer implements MaterialAccountListener{
19 |
20 | @Override
21 | public void init(Bundle savedInstanceState) {
22 |
23 | // add accounts
24 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com",R.drawable.photo, R.drawable.bamboo);
25 | this.addAccount(account);
26 |
27 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
28 | this.addAccount(account2);
29 |
30 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
31 | this.addAccount(account3);
32 |
33 | // set listener
34 | this.setAccountListener(this);
35 |
36 | // create sections
37 | this.addSection(newSection("Section 1", new FragmentIndex()));
38 | this.addSection(newSection("Section 2",new FragmentIndex()));
39 | this.addSection(newSection("Section 3",R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
40 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
41 |
42 | // create bottom section
43 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
44 | }
45 |
46 | @Override
47 | public void onAccountOpening(MaterialAccount account) {
48 |
49 | }
50 |
51 | @Override
52 | public void onChangeAccount(MaterialAccount newAccount) {
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/light/Accounts.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.light;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 |
7 | import it.neokree.example.R;
8 | import it.neokree.example.mockedActivity.Settings;
9 | import it.neokree.example.mockedFragments.FragmentButton;
10 | import it.neokree.example.mockedFragments.FragmentIndex;
11 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
12 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
13 | import it.neokree.materialnavigationdrawer.elements.listeners.MaterialAccountListener;
14 |
15 | /**
16 | * Created by neokree on 18/01/15.
17 | */
18 | public class Accounts extends MaterialNavigationDrawer implements MaterialAccountListener {
19 |
20 | @Override
21 | public void init(Bundle savedInstanceState) {
22 |
23 | // add accounts
24 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com",R.drawable.photo, R.drawable.bamboo);
25 | this.addAccount(account);
26 |
27 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
28 | this.addAccount(account2);
29 |
30 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
31 | this.addAccount(account3);
32 |
33 | // set listener
34 | this.setAccountListener(this);
35 |
36 | // create sections
37 | this.addSection(newSection("Section 1", new FragmentIndex()));
38 | this.addSection(newSection("Section 2",new FragmentIndex()));
39 | this.addSection(newSection("Section 3",R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
40 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
41 |
42 | // create bottom section
43 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
44 |
45 | }
46 |
47 | @Override
48 | public void onAccountOpening(MaterialAccount account) {
49 |
50 | }
51 |
52 | @Override
53 | public void onChangeAccount(MaterialAccount newAccount) {
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section_icon_large_ripple.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
23 |
24 |
38 |
39 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_material_section_icon_ripple.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
39 |
40 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/backpattern/BackPatternCustom.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.backpattern;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 |
7 | import it.neokree.example.R;
8 | import it.neokree.example.mockedActivity.Settings;
9 | import it.neokree.example.mockedFragments.FragmentButton;
10 | import it.neokree.example.mockedFragments.FragmentIndex;
11 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
12 | import it.neokree.materialnavigationdrawer.elements.MaterialSection;
13 |
14 | /**
15 | * Created by neokree on 14/02/15.
16 | */
17 | public class BackPatternCustom extends MaterialNavigationDrawer {
18 |
19 | @Override
20 | public void init(Bundle savedInstanceState) {
21 | this.addSection(newSection("Section 1", new FragmentIndex()));
22 | this.addSection(newSection("Section 2",new FragmentIndex()));
23 | this.addSection(newSection("Section 3", R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
24 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
25 |
26 | // create bottom section
27 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
28 |
29 | // add pattern
30 | this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_CUSTOM);
31 | }
32 |
33 | @Override
34 | protected MaterialSection backToSection(MaterialSection currentSection) {
35 | MaterialSection section;
36 | switch(currentSection.getPosition()) {
37 | case 3:
38 | section =this.getSectionAtCurrentPosition(2);
39 | this.changeToolbarColor(section); // remember to change the toolbar color
40 | break;
41 | case 2:
42 | section = this.getSectionAtCurrentPosition(1);
43 | this.changeToolbarColor(section); // remember to change the toolbar color
44 | break;
45 | case 1:
46 | section = this.getSectionAtCurrentPosition(0);
47 | this.changeToolbarColor(section); // remember to change the toolbar color
48 | break;
49 | default:
50 | section = super.backToSection(currentSection); // exit from activity
51 | break;
52 | }
53 |
54 | return section;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_drawer_customheader.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
25 |
26 |
36 |
37 |
38 |
39 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/functionalities/CustomAccountSection.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example.functionalities;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.widget.Toast;
7 |
8 | import it.neokree.example.R;
9 | import it.neokree.example.mockedActivity.Settings;
10 | import it.neokree.example.mockedFragments.FragmentButton;
11 | import it.neokree.example.mockedFragments.FragmentIndex;
12 | import it.neokree.materialnavigationdrawer.MaterialNavigationDrawer;
13 | import it.neokree.materialnavigationdrawer.elements.MaterialAccount;
14 | import it.neokree.materialnavigationdrawer.elements.MaterialSection;
15 | import it.neokree.materialnavigationdrawer.elements.listeners.MaterialSectionListener;
16 |
17 | /**
18 | * Created by neokree on 20/01/15.
19 | */
20 | public class CustomAccountSection extends MaterialNavigationDrawer {
21 |
22 | @Override
23 | public void init(Bundle savedInstanceState) {
24 |
25 | // add accounts
26 | MaterialAccount account = new MaterialAccount(this.getResources(),"NeoKree","neokree@gmail.com", R.drawable.photo, R.drawable.bamboo);
27 | this.addAccount(account);
28 |
29 | MaterialAccount account2 = new MaterialAccount(this.getResources(),"Hatsune Miky","hatsune.miku@example.com",R.drawable.photo2,R.drawable.mat2);
30 | this.addAccount(account2);
31 |
32 | MaterialAccount account3 = new MaterialAccount(this.getResources(),"Example","example@example.com",R.drawable.photo,R.drawable.mat3);
33 | this.addAccount(account3);
34 |
35 | // add account sections
36 | this.addAccountSection(newSection("Account settings",R.drawable.ic_settings_black_24dp,new MaterialSectionListener() {
37 | @Override
38 | public void onClick(MaterialSection section) {
39 | Toast.makeText(CustomAccountSection.this,"Account settings clicked",Toast.LENGTH_SHORT).show();
40 |
41 | // for default section is selected when you click on it
42 | section.unSelect(); // so deselect the section if you want
43 | }
44 | }));
45 |
46 |
47 | // create sections
48 | this.addSection(newSection("Section 1", new FragmentIndex()));
49 | this.addSection(newSection("Section 2",new FragmentIndex()));
50 | this.addSection(newSection("Section 3",R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
51 | this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));
52 |
53 | // create bottom section
54 | this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MaterialNavigationDrawer
2 | ========================
3 |
4 | Navigation Drawer Activity with material design style and simplified methods
5 | [](https://android-arsenal.com/details/1/1114) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K4GJELZKNEF68)
6 |
7 | It requires 10+ API and android support v7 (Toolbar)
8 |
9 | [Download example apk](https://raw.github.com/neokree/MaterialNavigationDrawer/master/example.apk)
10 |
11 | If you are using MaterialNavigationDrawer in your app and would like to be listed here, please let me know via [email](mailto:neokree@gmail.com)!
12 |
13 | ## Set up a Navigation Drawer
14 | check the [wiki page](https://github.com/neokree/MaterialNavigationDrawer/wiki/Set-Up-a-Navigation-Drawer-Activity)
15 |
16 | ## How to import
17 | Add this to your build.gradle:
18 | ```java
19 | repositories {
20 | mavenCentral()
21 | }
22 |
23 | dependencies {
24 | compile 'it.neokree:MaterialNavigationDrawer:1.3'
25 | }
26 | ```
27 |
28 | You don't know how to do something? Visit the [wiki](https://github.com/neokree/MaterialNavigationDrawer/wiki)!
29 | You need some examples? See the [example project](https://github.com/neokree/MaterialNavigationDrawer/tree/master/MaterialNavigationDrawer)!
30 |
31 | ### Useful issues
32 | For open a useful issue, please follow this little guide:
33 |
34 | 1. Check if your issue is not opened yet. This prevent to have different questions to the same problem.
35 | 2. When you open an issue, please add the library version used, devices tested and related api.
36 |
37 | ### External libraries used
38 | [Android-UI](https://github.com/markushi/android-ui)
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/values-v21/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
29 |
30 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/values-v19/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
27 |
28 |
41 |
42 |
46 |
47 |
51 |
52 |
56 |
57 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
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 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/java/it/neokree/materialnavigationdrawer/elements/MaterialSubheader.java:
--------------------------------------------------------------------------------
1 | package it.neokree.materialnavigationdrawer.elements;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Color;
7 | import android.graphics.Typeface;
8 | import android.util.TypedValue;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 |
14 | import it.neokree.materialnavigationdrawer.R;
15 | import it.neokree.materialnavigationdrawer.util.Utils;
16 |
17 | /**
18 | * Created by neokree on 17/01/15.
19 | */
20 | public class MaterialSubheader {
21 |
22 | private CharSequence title;
23 | private int titleColor;
24 |
25 | private TextView text;
26 | private View view;
27 |
28 | public MaterialSubheader(Context ctx) {
29 | float density = ctx.getResources().getDisplayMetrics().density;
30 |
31 | // create layout
32 | LinearLayout layout = new LinearLayout(ctx);
33 | layout.setOrientation(LinearLayout.VERTICAL);
34 |
35 | // inflate the line
36 | View view = new View(ctx);
37 | view.setBackgroundColor(Color.parseColor("#e0e0e0"));
38 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,1);
39 | params.setMargins(0,(int) (8 * density), 0 , (int) (8 * density));
40 | layout.addView(view,params);
41 |
42 | // inflate the text
43 | text = new TextView(ctx);
44 | Utils.setAlpha(text,0.54f);
45 | text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
46 | text.setGravity(Gravity.START);
47 | LinearLayout.LayoutParams paramsText = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
48 | paramsText.setMargins((int) (16 * density),0, (int) (16 * density) , (int) (4 * density));
49 |
50 | layout.addView(text,paramsText);
51 | this.view = layout;
52 |
53 | // get attributes from current theme
54 | Resources.Theme theme = ctx.getTheme();
55 | TypedValue typedValue = new TypedValue();
56 | theme.resolveAttribute(R.attr.sectionStyle,typedValue,true);
57 | TypedArray values = theme.obtainStyledAttributes(typedValue.resourceId,R.styleable.MaterialSection);
58 | try {
59 | titleColor = values.getColor(R.styleable.MaterialSubheader_subheaderTitleColor,0x000);
60 |
61 |
62 | }
63 | finally {
64 | values.recycle();
65 | }
66 |
67 | // set attributes to the view
68 | text.setTextColor(Color.BLACK);
69 |
70 | }
71 |
72 | public void setTitleFont(Typeface font) {
73 | text.setTypeface(font);
74 | }
75 |
76 | public void setTitle(CharSequence title) {
77 | this.title = title;
78 | text.setText(title);
79 | }
80 |
81 | public void setTitleColor(int color) {
82 | titleColor = color;
83 | text.setTextColor(color);
84 | }
85 |
86 | public int getTitleColor() {
87 | return titleColor;
88 | }
89 |
90 | public CharSequence getTitle() {
91 | return title;
92 | }
93 |
94 | public View getView() {
95 | return view;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
27 |
28 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
56 |
57 |
65 |
66 |
69 |
70 |
73 |
74 |
78 |
79 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/java/it/neokree/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package it.neokree.example;
2 |
3 | import android.app.ListActivity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.AdapterView;
8 | import android.widget.ArrayAdapter;
9 |
10 | import java.util.ArrayList;
11 |
12 | import it.neokree.example.backpattern.BackAnywhere;
13 | import it.neokree.example.backpattern.BackPatternCustom;
14 | import it.neokree.example.backpattern.BackToFirst;
15 | import it.neokree.example.functionalities.CustomAccountSection;
16 | import it.neokree.example.functionalities.KitkatStatusBar;
17 | import it.neokree.example.functionalities.MultiPane;
18 | import it.neokree.example.functionalities.RealColorSections;
19 | import it.neokree.example.functionalities.RippleBackport;
20 | import it.neokree.example.functionalities.UniqueToolbarColor;
21 | import it.neokree.example.functionalities.master_child.MasterChildActivity;
22 | import it.neokree.example.light.Accounts;
23 | import it.neokree.example.light.CustomDrawerHeader;
24 | import it.neokree.example.light.ImageDrawerHeader;
25 | import it.neokree.example.light.MockedAccount;
26 | import it.neokree.example.light.NoDrawerHeader;
27 | import it.neokree.example.test.Test;
28 |
29 | /**
30 | * Created by neokree on 30/12/14.
31 | */
32 | public class MainActivity extends ListActivity implements AdapterView.OnItemClickListener {
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | ArrayList list = new ArrayList();
38 |
39 | list.add("Light - Mocked Account");
40 | list.add("Dark - Mocked Account");
41 |
42 | list.add("Light - Accounts");
43 | list.add("Dark - Accounts");
44 |
45 | list.add("Light - Drawer Header Image");
46 | list.add("Dark - Drawer Header Image");
47 |
48 | list.add("Light - No Drawer Header");
49 | list.add("Dark - No Drawer Header");
50 |
51 | list.add("Light - Custom Drawer Header");
52 | list.add("Dark - Custom Drawer Header");
53 |
54 | list.add("Functionality: unique Toolbar Color");
55 | list.add("Functionality: ripple backport support");
56 | list.add("Functionality: multi pane support for tablet");
57 | list.add("Functionality: custom section under account list");
58 | list.add("Functionality: Kitkat trasluncent status bar");
59 | list.add("Functionality: Master/Child example");
60 | list.add("Functionality: section not pre-rendered");
61 |
62 | list.add("Back Pattern: Back To first");
63 | list.add("Back Pattern: Back Anywhere");
64 | list.add("Back Pattern: Custom");
65 |
66 | //list.add("Test");
67 |
68 | this.setListAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,list));
69 | this.getListView().setOnItemClickListener(this);
70 | }
71 |
72 | @Override
73 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
74 | Intent intent;
75 | switch(position) {
76 | case 0:
77 | intent = new Intent(this,MockedAccount.class);
78 | break;
79 | case 1:
80 | intent = new Intent(this, it.neokree.example.dark.MockedAccount.class);
81 | break;
82 | case 2:
83 | intent = new Intent(this,Accounts.class);
84 | break;
85 | case 3:
86 | intent = new Intent(this, it.neokree.example.dark.Accounts.class);
87 | break;
88 | case 4:
89 | intent = new Intent(this,ImageDrawerHeader.class);
90 | break;
91 | case 5:
92 | intent = new Intent(this, it.neokree.example.dark.ImageDrawerHeader.class);
93 | break;
94 | case 6:
95 | intent = new Intent(this,NoDrawerHeader.class);
96 | break;
97 | case 7:
98 | intent = new Intent(this, it.neokree.example.dark.NoDrawerHeader.class);
99 | break;
100 | case 8:
101 | intent = new Intent(this, CustomDrawerHeader.class);
102 | break;
103 | case 9:
104 | intent = new Intent(this, it.neokree.example.dark.CustomDrawerHeader.class);
105 | break;
106 | case 10:
107 | intent = new Intent(this, UniqueToolbarColor.class);
108 | break;
109 | case 11:
110 | intent = new Intent(this, RippleBackport.class);
111 | break;
112 | case 12:
113 | intent = new Intent(this, MultiPane.class);
114 | break;
115 | case 13:
116 | intent = new Intent(this, CustomAccountSection.class);
117 | break;
118 | case 14:
119 | intent = new Intent(this, KitkatStatusBar.class);
120 | break;
121 | case 15:
122 | intent = new Intent(this, MasterChildActivity.class);
123 | break;
124 | case 16:
125 | intent = new Intent(this, RealColorSections.class);
126 | break;
127 | case 17:
128 | intent = new Intent(this, BackToFirst.class);
129 | break;
130 | case 18:
131 | intent = new Intent(this, BackAnywhere.class);
132 | break;
133 | case 19:
134 | intent = new Intent(this, BackPatternCustom.class);
135 | break;
136 | case 20:
137 | intent = new Intent(this, Test.class);
138 | break;
139 | default:
140 | intent = null;
141 | }
142 | startActivity(intent);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/res/layout/layout_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
22 |
23 |
27 |
28 |
39 |
40 |
51 |
52 |
62 |
63 |
72 |
73 |
82 |
83 |
93 |
94 |
95 |
96 |
108 |
109 |
117 |
118 |
126 |
127 |
128 |
129 |
138 |
139 |
140 |
141 |
142 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/java/it/neokree/materialnavigationdrawer/util/Utils.java:
--------------------------------------------------------------------------------
1 | package it.neokree.materialnavigationdrawer.util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.res.Configuration;
7 | import android.content.res.Resources;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.graphics.Canvas;
11 | import android.graphics.Color;
12 | import android.graphics.Paint;
13 | import android.graphics.Point;
14 | import android.graphics.PorterDuff;
15 | import android.graphics.PorterDuffXfermode;
16 | import android.graphics.Rect;
17 | import android.graphics.drawable.BitmapDrawable;
18 | import android.graphics.drawable.Drawable;
19 | import android.graphics.drawable.GradientDrawable;
20 | import android.os.Build;
21 | import android.util.DisplayMetrics;
22 | import android.view.Display;
23 | import android.view.View;
24 | import android.view.animation.AlphaAnimation;
25 | import android.widget.ImageView;
26 |
27 | import java.util.Locale;
28 |
29 | /**
30 | * Class containing some static utility methods.
31 | *
32 | * Created by neokree on 06/01/15.
33 | */
34 | public class Utils {
35 | private Utils() {}
36 |
37 | public static int getDrawerWidth(Resources res) {
38 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
39 |
40 | if (res.getConfiguration().smallestScreenWidthDp >= 600 || res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
41 | // device is a tablet
42 | return (int) (320 * res.getDisplayMetrics().density);
43 | } else {
44 | return (int) (res.getDisplayMetrics().widthPixels - (56 * res.getDisplayMetrics().density));
45 | }
46 | }
47 | else { // for devices without smallestScreenWidthDp reference calculate if device screen is over 600 dp
48 | if((res.getDisplayMetrics().widthPixels/res.getDisplayMetrics().density) >= 600 || res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
49 | return (int) (320 * res.getDisplayMetrics().density);
50 | else
51 | return (int) (res.getDisplayMetrics().widthPixels - (56 * res.getDisplayMetrics().density));
52 | }
53 | }
54 |
55 | public static boolean isTablet(Resources res) {
56 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
57 | return res.getConfiguration().smallestScreenWidthDp >= 600;
58 | }
59 | else { // for devices without smallestScreenWidthDp reference calculate if device screen is over 600
60 | return (res.getDisplayMetrics().widthPixels/res.getDisplayMetrics().density) >= 600;
61 |
62 | }
63 | }
64 |
65 | public static int getScreenHeight(Activity act) {
66 | int height = 0;
67 | Display display = act.getWindowManager().getDefaultDisplay();
68 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
69 | Point size = new Point();
70 | display.getSize(size);
71 | height = size.y;
72 | } else {
73 | height = display.getHeight(); // deprecated
74 | }
75 | return height;
76 | }
77 |
78 | public static Point getUserPhotoSize(Resources res) {
79 | int size = (int) (64 * res.getDisplayMetrics().density);
80 |
81 | return new Point(size,size);
82 | }
83 |
84 | public static Point getBackgroundSize(Resources res) {
85 | int width = getDrawerWidth(res);
86 |
87 | int height = (9 * width) / 16;
88 |
89 | return new Point(width,height);
90 | }
91 |
92 | public static Bitmap getCroppedBitmapDrawable(Bitmap bitmap) {
93 | Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
94 | bitmap.getHeight(), Bitmap.Config.ARGB_8888);
95 | Canvas canvas = new Canvas(output);
96 |
97 | final int color = 0xff424242;
98 | final Paint paint = new Paint();
99 | final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
100 |
101 | paint.setAntiAlias(true);
102 | canvas.drawARGB(0, 0, 0, 0);
103 | paint.setColor(color);
104 | // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
105 | canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
106 | bitmap.getWidth() / 2, paint);
107 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
108 | canvas.drawBitmap(bitmap, rect, rect, paint);
109 | //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
110 | //return _bmp;
111 | return output;
112 | }
113 |
114 | public static Bitmap resizeBitmapFromResource(Resources res, int resId,int reqWidth, int reqHeight) {
115 |
116 | // First decode with inJustDecodeBounds=true to check dimensions
117 | final BitmapFactory.Options options = new BitmapFactory.Options();
118 | options.inJustDecodeBounds = true;
119 | BitmapFactory.decodeResource(res, resId, options);
120 |
121 | // Calculate inSampleSize
122 | options.inSampleSize = calculateSize(options, reqWidth, reqHeight);
123 |
124 | // Decode bitmap with inSampleSize set
125 | options.inJustDecodeBounds = false;
126 | return BitmapFactory.decodeResource(res, resId, options);
127 | }
128 |
129 | public static Bitmap resizeBitmap(Bitmap bitmap, int reqWidth,int reqHeight) {
130 | return Bitmap.createScaledBitmap(bitmap,reqWidth,reqHeight,true);
131 |
132 | }
133 |
134 | public static int calculateSize(
135 | BitmapFactory.Options options, int reqWidth, int reqHeight) {
136 | // Raw height and width of image
137 | final int height = options.outHeight;
138 | final int width = options.outWidth;
139 | int inSampleSize = 1;
140 |
141 | if (height > reqHeight || width > reqWidth) {
142 |
143 | final int halfHeight = height / 2;
144 | final int halfWidth = width / 2;
145 |
146 | // Calculate the largest inSampleSize value that is a power of 2 and keeps both
147 | // height and width larger than the requested height and width.
148 | while ((halfHeight / inSampleSize) > reqHeight
149 | && (halfWidth / inSampleSize) > reqWidth) {
150 | inSampleSize *= 2;
151 | }
152 | }
153 |
154 | return inSampleSize;
155 | }
156 |
157 | public static void recycleDrawable(Drawable drawable) {
158 | if (drawable instanceof BitmapDrawable) {
159 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
160 | bitmapDrawable.getBitmap().recycle();
161 | }
162 | }
163 |
164 | public static boolean isRTL() {
165 | Locale defLocale = Locale.getDefault();
166 | final int directionality = Character.getDirectionality(defLocale.getDisplayName().charAt(0));
167 | return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
168 | directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
169 | }
170 |
171 | public static void setAlpha(View v, float alpha) {
172 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
173 | v.setAlpha(alpha);
174 | } else {
175 | AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
176 | animation.setDuration(0);
177 | animation.setFillAfter(true);
178 | v.startAnimation(animation);
179 | }
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
12 |
13 |
14 |
19 |
20 |
21 |
27 |
28 |
29 |
35 |
36 |
37 |
43 |
44 |
45 |
46 |
47 |
53 |
54 |
55 |
60 |
61 |
62 |
68 |
69 |
70 |
76 |
77 |
78 |
84 |
85 |
86 |
87 |
88 |
89 |
96 |
97 |
98 |
105 |
106 |
107 |
113 |
114 |
115 |
120 |
121 |
122 |
127 |
128 |
129 |
135 |
136 |
137 |
143 |
144 |
145 |
151 |
152 |
153 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/java/it/neokree/materialnavigationdrawer/elements/MaterialAccount.java:
--------------------------------------------------------------------------------
1 | package it.neokree.materialnavigationdrawer.elements;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Point;
7 | import android.graphics.Typeface;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.graphics.drawable.Drawable;
10 | import android.os.AsyncTask;
11 | import android.view.View;
12 |
13 | import it.neokree.materialnavigationdrawer.elements.listeners.MaterialSectionListener;
14 | import it.neokree.materialnavigationdrawer.util.Utils;
15 |
16 | /**
17 | * Created by neokree on 11/12/14.
18 | */
19 | public class MaterialAccount {
20 |
21 | // datas
22 |
23 | private Drawable photo;
24 | private Drawable background;
25 | private Drawable circularPhoto;
26 | private String title;
27 | private String subTitle;
28 | private int accountNumber;
29 | private String notifications;
30 |
31 | private boolean hasNotifications;
32 |
33 | private Resources resources;
34 | private OnAccountDataLoaded listener;
35 | private MaterialSection sectionView;
36 |
37 | public static final int FIRST_ACCOUNT = 0;
38 | public static final int SECOND_ACCOUNT = 1;
39 | public static final int THIRD_ACCOUNT = 2;
40 |
41 | // constructors
42 |
43 | public MaterialAccount(Resources resources,String title, String subTitle, int photo,Bitmap background) {
44 | this.title = title;
45 | this.subTitle = subTitle;
46 | this.resources = resources;
47 |
48 | // resize and caching bitmap
49 | new ResizePhotoResource().execute(photo);
50 | if(background != null)
51 | new ResizeBackgroundBitmap().execute(background);
52 |
53 | }
54 |
55 | public MaterialAccount(Resources resources,String title, String subTitle, int photo,int background) {
56 | this.title = title;
57 | this.subTitle = subTitle;
58 | this.resources = resources;
59 |
60 | // resize and caching bitmap
61 | new ResizePhotoResource().execute(photo);
62 | new ResizeBackgroundResource().execute(background);
63 | }
64 |
65 | public MaterialAccount(Resources resources,String title, String subTitle, Bitmap photo, int background) {
66 | this.title = title;
67 | this.subTitle = subTitle;
68 | this.resources = resources;
69 |
70 | // resize and caching bitmap
71 | if(photo != null)
72 | new ResizePhotoBitmap().execute(photo);
73 | new ResizeBackgroundResource().execute(background);
74 | }
75 |
76 | public MaterialAccount(Resources resources,String title, String subTitle, Bitmap photo, Bitmap background) {
77 | this.title = title;
78 | this.subTitle = subTitle;
79 | this.resources = resources;
80 |
81 | // resize and caching bitmap
82 | if(photo != null)
83 | new ResizePhotoBitmap().execute(photo);
84 | if (background != null)
85 | new ResizeBackgroundBitmap().execute(background);
86 | }
87 |
88 | // setter
89 |
90 | public void setPhoto(int photo){
91 | new ResizePhotoResource().execute(photo);
92 | }
93 |
94 | public void setPhoto(Bitmap photo) {
95 | new ResizePhotoBitmap().execute(photo);
96 | }
97 |
98 | public void setBackground(Bitmap background) {
99 | new ResizeBackgroundBitmap().execute(background);
100 | }
101 |
102 | public void setBackground(int background) {
103 | new ResizeBackgroundResource().execute(background);
104 | }
105 |
106 | public void setTitle(String title) {
107 | this.title = title;
108 | }
109 |
110 | public void setSubTitle(String subTitle) {
111 | this.subTitle = subTitle;
112 | }
113 |
114 | public void setAccountNumber(int number) {
115 | this.accountNumber = number;
116 | }
117 |
118 | public void setAccountListener(OnAccountDataLoaded listener) {
119 | this.listener = listener;
120 | }
121 |
122 | public MaterialAccount setNotifications(int number) {
123 | hasNotifications = true;
124 | notifications = String.valueOf(number);
125 |
126 | if(number >= 100) {
127 | notifications = "99+";
128 | }
129 | if(number < 0) {
130 | notifications = "0";
131 | }
132 |
133 | return this;
134 |
135 | }
136 |
137 | // getter
138 |
139 | public Drawable getPhoto() {
140 | return photo;
141 | }
142 |
143 | public Drawable getBackground() {
144 | return background;
145 | }
146 |
147 | public Drawable getCircularPhoto() {
148 | return circularPhoto;
149 | }
150 |
151 | public String getTitle() {
152 | return title;
153 | }
154 |
155 | public String getSubTitle() {
156 | return subTitle;
157 | }
158 |
159 | public int getAccountNumber() {
160 | return accountNumber;
161 | }
162 |
163 | public View getSectionView(Context ctx, Typeface font, MaterialSectionListener listener, boolean rippleSupport,int position) {
164 | if(sectionView == null) {
165 | sectionView = new MaterialSection(ctx,MaterialSection.ICON_40DP,rippleSupport,MaterialSection.TARGET_LISTENER);
166 | sectionView.useRealColor();
167 | }
168 |
169 | // set dei dati passati
170 | sectionView.setTypeface(font);
171 | sectionView.setOnClickListener(listener);
172 |
173 | // set dei dati dell'account
174 | sectionView.setIcon(getCircularPhoto());
175 | sectionView.setTitle(getTitle());
176 | if(hasNotifications) {
177 | sectionView.setNotificationsText(notifications);
178 | }
179 | sectionView.setPosition(position);
180 |
181 | return sectionView.getView();
182 | }
183 |
184 | // custom
185 |
186 | public void recycle() {
187 | Utils.recycleDrawable(photo);
188 | Utils.recycleDrawable(circularPhoto);
189 | Utils.recycleDrawable(background);
190 | }
191 |
192 | public interface OnAccountDataLoaded {
193 |
194 | public void onUserPhotoLoaded(MaterialAccount account);
195 |
196 | public void onBackgroundLoaded(MaterialAccount account);
197 | }
198 |
199 | // asynctasks
200 |
201 | private class ResizePhotoResource extends AsyncTask {
202 |
203 | @Override
204 | protected BitmapDrawable doInBackground(Integer... params) {
205 | Point photoSize = Utils.getUserPhotoSize(resources);
206 |
207 | Bitmap photo = Utils.resizeBitmapFromResource(resources,params[0],photoSize.x,photoSize.y);
208 |
209 | circularPhoto = new BitmapDrawable(resources,Utils.getCroppedBitmapDrawable(photo));
210 | return new BitmapDrawable(resources,photo);
211 | }
212 |
213 | @Override
214 | protected void onPostExecute(BitmapDrawable drawable) {
215 | photo = drawable;
216 |
217 | if(listener != null)
218 | listener.onUserPhotoLoaded(MaterialAccount.this);
219 | }
220 | }
221 |
222 | private class ResizePhotoBitmap extends AsyncTask {
223 |
224 | @Override
225 | protected BitmapDrawable doInBackground(Bitmap... params) {
226 | Point photoSize = Utils.getUserPhotoSize(resources);
227 |
228 |
229 | Bitmap photo = Utils.resizeBitmap(params[0],photoSize.x,photoSize.y);
230 | params[0].recycle();
231 |
232 | circularPhoto = new BitmapDrawable(resources,Utils.getCroppedBitmapDrawable(photo));
233 | return new BitmapDrawable(resources,photo);
234 | }
235 |
236 | @Override
237 | protected void onPostExecute(BitmapDrawable drawable) {
238 | photo = drawable;
239 |
240 | if(listener != null)
241 | listener.onUserPhotoLoaded(MaterialAccount.this);
242 | }
243 | }
244 |
245 | private class ResizeBackgroundResource extends AsyncTask {
246 | @Override
247 | protected BitmapDrawable doInBackground(Integer... params) {
248 | Point backSize = Utils.getBackgroundSize(resources);
249 |
250 | Bitmap back = Utils.resizeBitmapFromResource(resources,params[0],backSize.x,backSize.y);
251 |
252 | return new BitmapDrawable(resources,back);
253 | }
254 |
255 | @Override
256 | protected void onPostExecute(BitmapDrawable drawable) {
257 | background = drawable;
258 |
259 | if(listener != null)
260 | listener.onBackgroundLoaded(MaterialAccount.this);
261 | }
262 | }
263 |
264 | private class ResizeBackgroundBitmap extends AsyncTask {
265 |
266 | @Override
267 | protected BitmapDrawable doInBackground(Bitmap... params) {
268 | Point backSize = Utils.getBackgroundSize(resources);
269 |
270 | Bitmap back = Utils.resizeBitmap(params[0],backSize.x,backSize.y);
271 | params[0].recycle();
272 |
273 | return new BitmapDrawable(resources,back);
274 | }
275 |
276 | @Override
277 | protected void onPostExecute(BitmapDrawable drawable) {
278 | background = drawable;
279 |
280 | if(listener != null)
281 | listener.onBackgroundLoaded(MaterialAccount.this);
282 | }
283 | }
284 | /*
285 | Old tasks
286 |
287 | private AsyncTask resizePhotoResource = new AsyncTask() {
288 | @Override
289 | protected BitmapDrawable doInBackground(Integer... params) {
290 | Point photoSize = Utils.getUserPhotoSize(resources);
291 |
292 | Bitmap photo = Utils.resizeBitmapFromResource(resources,params[0],photoSize.x,photoSize.y);
293 |
294 | circularPhoto = new BitmapDrawable(resources,Utils.getCroppedBitmapDrawable(photo));
295 | return new BitmapDrawable(resources,photo);
296 | }
297 |
298 | @Override
299 | protected void onPostExecute(BitmapDrawable drawable) {
300 | photo = drawable;
301 |
302 | if(listener != null)
303 | listener.onUserPhotoLoaded(MaterialAccount.this);
304 | }
305 | };
306 | private AsyncTask resizePhotoBitmap = new AsyncTask() {
307 | @Override
308 | protected BitmapDrawable doInBackground(Bitmap... params) {
309 | Point photoSize = Utils.getUserPhotoSize(resources);
310 |
311 |
312 | Bitmap photo = Utils.resizeBitmap(params[0],photoSize.x,photoSize.y);
313 | params[0].recycle();
314 |
315 | circularPhoto = new BitmapDrawable(resources,Utils.getCroppedBitmapDrawable(photo));
316 | return new BitmapDrawable(resources,photo);
317 | }
318 |
319 | @Override
320 | protected void onPostExecute(BitmapDrawable drawable) {
321 | photo = drawable;
322 |
323 | if(listener != null)
324 | listener.onUserPhotoLoaded(MaterialAccount.this);
325 | }
326 | };
327 | private AsyncTask resizeBackgroundResource = new AsyncTask() {
328 | @Override
329 | protected BitmapDrawable doInBackground(Integer... params) {
330 | Point backSize = Utils.getBackgroundSize(resources);
331 |
332 | Bitmap back = Utils.resizeBitmapFromResource(resources,params[0],backSize.x,backSize.y);
333 |
334 | return new BitmapDrawable(resources,back);
335 | }
336 |
337 | @Override
338 | protected void onPostExecute(BitmapDrawable drawable) {
339 | background = drawable;
340 |
341 | if(listener != null)
342 | listener.onBackgroundLoaded(MaterialAccount.this);
343 | }
344 | };
345 | private AsyncTask resizeBackgroundBitmap = new AsyncTask() {
346 | @Override
347 | protected BitmapDrawable doInBackground(Bitmap... params) {
348 | Point backSize = Utils.getBackgroundSize(resources);
349 |
350 | Bitmap back = Utils.resizeBitmap(params[0],backSize.x,backSize.y);
351 | params[0].recycle();
352 |
353 | return new BitmapDrawable(resources,back);
354 | }
355 |
356 | @Override
357 | protected void onPostExecute(BitmapDrawable drawable) {
358 | background = drawable;
359 |
360 | if(listener != null)
361 | listener.onBackgroundLoaded(MaterialAccount.this);
362 | }
363 | };*/
364 | }
365 |
--------------------------------------------------------------------------------
/MaterialNavigationDrawer/library/src/main/java/it/neokree/materialnavigationdrawer/elements/MaterialSection.java:
--------------------------------------------------------------------------------
1 | package it.neokree.materialnavigationdrawer.elements;
2 |
3 | import android.animation.Animator;
4 | import android.annotation.SuppressLint;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.res.Resources;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Bitmap;
10 | import android.graphics.Point;
11 | import android.graphics.Typeface;
12 | import android.graphics.drawable.Drawable;
13 | import android.os.Build;
14 | import android.util.TypedValue;
15 | import android.view.LayoutInflater;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 | import android.widget.ImageView;
19 | import android.widget.TextView;
20 |
21 | import com.balysv.materialripple.MaterialRippleLayout;
22 |
23 | import it.neokree.materialnavigationdrawer.elements.listeners.MaterialSectionListener;
24 | import it.neokree.materialnavigationdrawer.R;
25 | import it.neokree.materialnavigationdrawer.util.Utils;
26 |
27 | /**
28 | * Navigation Drawer section with Material Design style
29 | *
30 | * Created by neokree on 08/11/14.
31 | */
32 | @SuppressWarnings("unused")
33 | public class MaterialSection implements View.OnTouchListener, View.OnClickListener {
34 |
35 | public static final int TARGET_FRAGMENT = 0;
36 | public static final int TARGET_ACTIVITY = 1;
37 | public static final int TARGET_LISTENER = 2;
38 |
39 | public static final int ICON_NO_ICON = 0;
40 | public static final int ICON_24DP = 1;
41 | public static final int ICON_40DP = 2;
42 |
43 | private int position;
44 | private int targetType;
45 | private View view;
46 | private TextView text;
47 | private TextView notifications;
48 | private ImageView icon;
49 | private MaterialRippleLayout ripple;
50 | private MaterialSectionListener listener;
51 | private boolean isSelected;
52 | private boolean hasSectionColor;
53 | private boolean hasColorDark;
54 | private boolean rippleSupport = false;
55 | private boolean realColor;
56 | private boolean touchable;
57 |
58 | // COLORS
59 | private int colorPressed;
60 | private int colorUnpressed;
61 | private int colorSelected;
62 | private int sectionColor;
63 | private int iconColor;
64 | private int colorDark;
65 | private int textColor;
66 | private int notificationColor;
67 |
68 | private int numberNotifications;
69 |
70 | private String title;
71 |
72 | // TARGETS
73 | private Fragment targetFragment;
74 | private Intent targetIntent;
75 | private MaterialSectionListener targetListener;
76 |
77 | public MaterialSection(Context ctx, int iconType, boolean hasRippleSupport, int target ) {
78 | rippleSupport = hasRippleSupport;
79 |
80 | if(rippleAnimationSupport()) {
81 | // section with ripple effect
82 |
83 | switch(iconType) {
84 | case ICON_NO_ICON:
85 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section_ripple, null);
86 | break;
87 | case ICON_24DP:
88 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section_icon_ripple, null);
89 |
90 | icon = (ImageView) view.findViewById(R.id.section_icon);
91 | break;
92 | case ICON_40DP:
93 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section_icon_large_ripple, null);
94 |
95 | icon = (ImageView) view.findViewById(R.id.section_icon);
96 | break;
97 | }
98 |
99 | text = (TextView) view.findViewById(R.id.section_text);
100 | notifications = (TextView) view.findViewById(R.id.section_notification);
101 | ripple = (MaterialRippleLayout) view.findViewById(R.id.section_ripple);
102 |
103 | }
104 | else {
105 | // section with normal background
106 |
107 | switch (iconType) {
108 | case ICON_NO_ICON:
109 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section, null);
110 |
111 | text = (TextView) view.findViewById(R.id.section_text);
112 | notifications = (TextView) view.findViewById(R.id.section_notification);
113 | break;
114 | case ICON_24DP:
115 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section_icon, null);
116 |
117 | text = (TextView) view.findViewById(R.id.section_text);
118 | icon = (ImageView) view.findViewById(R.id.section_icon);
119 | notifications = (TextView) view.findViewById(R.id.section_notification);
120 | break;
121 | case ICON_40DP:
122 | view = LayoutInflater.from(ctx).inflate(R.layout.layout_material_section_icon_large, null);
123 |
124 | text = (TextView) view.findViewById(R.id.section_text);
125 | icon = (ImageView) view.findViewById(R.id.section_icon);
126 | notifications = (TextView) view.findViewById(R.id.section_notification);
127 | break;
128 | }
129 | }
130 |
131 | // resolve attributes from current theme
132 | Resources.Theme theme = ctx.getTheme();
133 | TypedValue typedValue = new TypedValue();
134 | theme.resolveAttribute(R.attr.sectionStyle,typedValue,true);
135 | TypedArray values = theme.obtainStyledAttributes(typedValue.resourceId,R.styleable.MaterialSection);
136 | try {
137 | colorPressed = values.getColor(R.styleable.MaterialSection_sectionBackgroundColorPressed,0x16000000);
138 | colorUnpressed = values.getColor(R.styleable.MaterialSection_sectionBackgroundColor,0x00FFFFFF);
139 | colorSelected = values.getColor(R.styleable.MaterialSection_sectionBackgroundColorSelected,0x0A000000);
140 |
141 | iconColor = values.getColor(R.styleable.MaterialSection_sectionColorIcon,0x000);
142 | textColor = values.getColor(R.styleable.MaterialSection_sectionColorText,0x000);
143 | notificationColor = values.getColor(R.styleable.MaterialSection_sectionColorNotification,0x000);
144 |
145 | // set text color into the view
146 | if(textColor != 0x000) {
147 | text.setTextColor(textColor);
148 | }
149 | if(notificationColor != 0x000) {
150 | notifications.setTextColor(notificationColor);
151 | }
152 |
153 | // set background color into the view
154 | if(!rippleAnimationSupport())
155 | view.setBackgroundColor(colorUnpressed);
156 | else {
157 | ripple.setRippleBackground(colorUnpressed);
158 | ripple.setRippleColor(colorPressed);
159 | }
160 |
161 | }
162 | finally {
163 | values.recycle();
164 | }
165 |
166 | if(rippleAnimationSupport()) {
167 | ripple.setOnClickListener(this);
168 | }
169 | else {
170 | view.setOnTouchListener(this);
171 | }
172 |
173 | isSelected = false;
174 | hasSectionColor = false;
175 | hasColorDark = false;
176 | touchable = true;
177 | realColor = false;
178 | targetType = target;
179 | numberNotifications = 0;
180 | }
181 |
182 | // methods for customizations
183 |
184 | public MaterialSection setSectionColor(int color) {
185 | hasSectionColor = true;
186 | sectionColor = color;
187 |
188 | return this;
189 | }
190 |
191 | public MaterialSection setSectionColor(int color,int colorDark) {
192 | setSectionColor(color);
193 | hasColorDark = true;
194 | this.colorDark = colorDark;
195 |
196 | return this;
197 | }
198 |
199 | /**
200 | * Set the number of notification for this section
201 | * @param notifications the number of notification active for this section
202 | * @return this section
203 | */
204 | public MaterialSection setNotifications(int notifications) {
205 | String textNotification;
206 |
207 | textNotification = String.valueOf(notifications);
208 |
209 | if(notifications < 1) {
210 | textNotification = "";
211 | }
212 | if(notifications > 99) {
213 | textNotification = "99+";
214 | }
215 |
216 | this.notifications.setText(textNotification);
217 | numberNotifications = notifications;
218 |
219 | return this;
220 | }
221 |
222 | public MaterialSection setNotificationsText(String text) {
223 | this.notifications.setText(text);
224 | return this;
225 | }
226 |
227 | public MaterialSection useRealColor() {
228 | realColor = true;
229 | if(icon != null) {
230 | Utils.setAlpha(icon,1f);
231 | }
232 |
233 | return this;
234 | }
235 |
236 |
237 | // internal methods
238 |
239 | // touch event without ripple support
240 | @Override
241 | @SuppressLint("NewApi")
242 | public boolean onTouch(View v, MotionEvent event) {
243 | if(touchable) {
244 |
245 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
246 | view.setBackgroundColor(colorPressed);
247 |
248 | return true;
249 | }
250 |
251 | if (event.getAction() == MotionEvent.ACTION_CANCEL) {
252 | if (isSelected)
253 | view.setBackgroundColor(colorSelected);
254 | else
255 | view.setBackgroundColor(colorUnpressed);
256 |
257 | return true;
258 | }
259 |
260 |
261 | if (event.getAction() == MotionEvent.ACTION_UP) {
262 |
263 | view.setBackgroundColor(colorSelected);
264 | afterClick();
265 |
266 | return true;
267 | }
268 | }
269 |
270 | return false;
271 | }
272 |
273 | //click event with ripple support
274 | @Override
275 | public void onClick(View v) {
276 | if(touchable) {
277 | ripple.setRippleBackground(colorSelected);
278 |
279 | afterClick();
280 | }
281 | }
282 |
283 | public void select() {
284 | isSelected = true;
285 | if(!rippleAnimationSupport())
286 | view.setBackgroundColor(colorSelected);
287 | else
288 | ripple.setRippleBackground(colorSelected);
289 |
290 | if(hasSectionColor) {
291 | text.setTextColor(sectionColor);
292 |
293 | if(icon != null && !realColor) {
294 | icon.setColorFilter(sectionColor);
295 | Utils.setAlpha(icon, 1f);
296 | }
297 | }
298 | }
299 |
300 | public void unSelect() {
301 | isSelected = false;
302 | if(!rippleAnimationSupport()) {
303 | view.setBackgroundColor(colorUnpressed);
304 | }
305 | else {
306 | ripple.setRippleBackground(colorUnpressed);
307 | }
308 |
309 | if (hasSectionColor) {
310 | text.setTextColor(textColor);
311 |
312 | if (icon != null && !realColor) {
313 | icon.setColorFilter(iconColor);
314 | Utils.setAlpha(icon, 0.54f);
315 | }
316 | }
317 | }
318 |
319 | public boolean isSelected() {
320 | return isSelected;
321 | }
322 |
323 | // setter
324 |
325 | public void setPosition(int position) {
326 | this.position = position;
327 | }
328 |
329 | public void setOnClickListener(MaterialSectionListener listener) {
330 | this.listener = listener;
331 | }
332 |
333 | public void setTitle(String title) {
334 | this.title = title;
335 | this.text.setText(title);
336 | }
337 |
338 | public void setIcon(Drawable icon) {
339 | this.icon.setImageDrawable(icon);
340 | if(!realColor)
341 | this.icon.setColorFilter(iconColor);
342 | }
343 |
344 | public void setIcon(Bitmap icon) {
345 | this.icon.setImageBitmap(icon);
346 | if(!realColor)
347 | this.icon.setColorFilter(iconColor);
348 | }
349 |
350 | public void setTarget(Fragment target) {
351 | this.targetFragment = target;
352 | }
353 |
354 | public void setTarget(Intent target) {
355 | this.targetIntent = target;
356 | }
357 |
358 | public void setTarget(MaterialSectionListener target) {
359 | this.targetListener = target;
360 | }
361 |
362 | public void setTypeface(Typeface typeface) {
363 | this.text.setTypeface(typeface);
364 | this.notifications.setTypeface(typeface);
365 | }
366 |
367 | public void setTouchable(boolean isTouchable) {
368 | touchable = isTouchable;
369 | }
370 |
371 | public void setPressingColor(int color) {
372 | colorPressed = color;
373 |
374 | if(rippleAnimationSupport())
375 | ripple.setRippleColor(colorPressed);
376 | }
377 |
378 | // alias of setColorUnpressed
379 | public void setBackgroundColor(int color) {
380 | colorUnpressed = color;
381 |
382 | if(!isSelected()) {
383 | if (rippleAnimationSupport()) {
384 | ripple.setRippleBackground(colorUnpressed);
385 | }
386 | else {
387 | view.setBackgroundColor(colorUnpressed);
388 | }
389 | }
390 | }
391 |
392 | public void setColorSelected(int color) {
393 | colorSelected = color;
394 |
395 | if(isSelected()) {
396 | if(rippleAnimationSupport())
397 | ripple.setRippleBackground(colorSelected);
398 | else
399 | view.setBackgroundColor(colorSelected);
400 | }
401 | }
402 |
403 | // getter
404 |
405 | public View getView() {
406 | return view;
407 | }
408 |
409 | public String getTitle() {
410 | return title;
411 | }
412 |
413 | public int getPosition() {
414 | return position;
415 | }
416 |
417 | public int getTarget() {
418 | return targetType;
419 | }
420 |
421 | public Fragment getTargetFragment() {
422 | return targetFragment;
423 | }
424 |
425 | public Intent getTargetIntent() {
426 | return targetIntent;
427 | }
428 |
429 | public MaterialSectionListener getTargetListener() {
430 | return targetListener;
431 | }
432 |
433 | public boolean hasSectionColor() {
434 | return hasSectionColor;
435 | }
436 |
437 | public boolean hasSectionColorDark() {
438 | return hasColorDark;
439 | }
440 |
441 | public int getSectionColor() {
442 | return sectionColor;
443 | }
444 |
445 | public int getSectionColorDark() {
446 | return colorDark;
447 | }
448 |
449 | public int getNotifications() {
450 | return numberNotifications;
451 | }
452 |
453 | public String getNotificationsText() {
454 | return this.notifications.getText().toString();
455 | }
456 |
457 | // private methods
458 |
459 | private void afterClick() {
460 | isSelected = true;
461 |
462 | if (hasSectionColor) {
463 | text.setTextColor(sectionColor);
464 |
465 | if (icon != null && !realColor) {
466 | icon.setColorFilter(sectionColor);
467 | Utils.setAlpha(icon, 1f);
468 | }
469 | }
470 |
471 | if (listener != null)
472 | listener.onClick(this);
473 |
474 | // se la sezione ha come target l'activity, dopo che questa viene avviata si deseleziona.
475 | if(this.getTarget() == TARGET_ACTIVITY)
476 | this.unSelect();
477 |
478 | // si fa arrivare il click anche allo sviluppatore
479 | if (this.getTarget() == TARGET_LISTENER && targetListener != null)
480 | this.targetListener.onClick(this);
481 | }
482 |
483 | private boolean rippleAnimationSupport() {
484 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && rippleSupport;
485 | }
486 |
487 | }
488 |
--------------------------------------------------------------------------------