diff --git a/CHANGELOG.md b/CHANGELOG.md index ccc4f0b..0b14093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,30 @@ Change Log ========== +Version 2.0.0f (2016-09-15) *[fork update]* +---------------------------- + +Update fork to be in up to date to the main repo. + +Version 2.0.0 (2016-09-15) +---------------------------- + +- Stripping main library classes to bare minimum - `MaterialMenuDrawable` and `MaterialMenuView`. +- Added `app:mm_iconState="enum"` attribute to `MaterialMenuView` that allows setting the +initial state of the drawable. + Version 1.6.0 (2016-09-11) ---------------------------- +**Major update** + - Fork repo - Move repository to jcenter -- Drop deprecated compatibility by remove depencency to NineOldAndroids, ActionBarCompat and ActionBarSherlock (change min api to 11) +- Removed `nineoldadroids` dependency! +- Removed all `extras` packages since ActionBarCompat or ActionBarSherlock are not being maintained +for quite a while now. Most usages will be with `Toolbar`. Integrating the drawable into it will be up +to the user of the library (see README or demo). +- Bumped min api version to 14 - Update demo support libs Version 1.5.4 (2015-05-30) diff --git a/README-1.0.md b/README-1.0.md new file mode 100644 index 0000000..5ab0f95 --- /dev/null +++ b/README-1.0.md @@ -0,0 +1,293 @@ +Material Menu +=============== + +This document is a reference for versions up to 1.5.5 which are old and **unmaintained**. Please use version 2.0.0+ for latest features. + +Including in your project +------------------------- + + +```groovy +// stock actionBar +compile 'com.balysv.materialmenu:material-menu:1.5.5' + +// Toolbar and ActionBarCompat-v22 (includes support-v7:22.0.x) +compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.5' + +// actionBarCompat-v20 (up to support-v7:20.0.0 - does not support Toolbar) +compile 'com.balysv.materialmenu:material-menu-abc:1.5.5' + +// actionBarSherlock +compile 'com.balysv.materialmenu:material-menu-abs:1.5.5' +``` + +Usage +----- + +The library provides two wrappers of `MaterialMenuDrawable` that eases implementation into the ActionBar, NavigationDrawer slide interaction or into any other custom layout. + +### MaterialMenuView + +A plain old `View` that draws the icon and provides an API to manipulate its state. + +Customisation is also available through attributes: + +```xml +app:mm_color="color" // Color of drawable +app:mm_visible="boolean" // Visible +app:mm_transformDuration="integer" // Transformation animation duration +app:mm_scale="integer" // Scale factor of drawable +app:mm_strokeWidth="integer" // Stroke width of icons (can only be 1, 2 or 3) +app:mm_rtlEnabled="boolean" // Enabled RTL layout support (flips all drawables) +app:mm_iconState="enum" // Set the intial state of the drawable (burger, arrow, x or check) +``` + +### MaterialMenuIcon + +A POJO that initializes the drawable and replaces the ActionBar icon. + +Jump to instructions for : +- [ActionBar (stock, Sherlock, Compat)]( https://github.com/balysv/material-menu#use-as-action-bar-icon-stock-compat-or-sherlock) +- [Toolbar](https://github.com/balysv/material-menu#use-in-toolbar) +- [NavigationDrawer interaction ](https://github.com/balysv/material-menu#navigationdrawer-slide-interaction) + +## API + +There are four icon states: + +```java +BURGER, ARROW, X, CHECK +``` + +To morph the drawable state + +```java +MaterialMenu.animateState(IconState state) +``` + +To change the drawable state without animation + +```java +MaterialMenu.setState(IconState state) +``` + +To animate the drawable manually (i.e. on navigation drawer slide): + +```java +MaterialMenu.setTransformationOffset(AnimationState state, float value) +``` +To hide or show the drawable: + +```java +MaterialMenu.setVisible(boolean visible) +``` + +where `AnimationState` is one of `BURGER_ARROW, BURGER_X, ARROW_X, ARROW_CHECK, BURGER_CHECK, X_CHECK` +and `value` is between `0` and `2` + +**Note:** The current implementation resolves its state by current offset value. Make sure you use `offset` between `0` and `1` for forward animation and `1` and `2` for backwards to correctly save icon state on activity recreation. + +### Customisation + +```java +// change color +MaterialMenu.setColor(int color) + +// change icon visibility +MaterialMenu.setVisible(boolean visible) + +// change transformation animation duration +MaterialMenu.setTransformationDuration(int duration) + +// change transformation interpolator +MaterialMenu.setInterpolator(Interpolator interpolator) + +// set RTL layout support +MaterialMenu.setRTLEnabled(boolean enabled) +``` + +### Action Bar + +#### Use as Action Bar icon (stock, Compat or Sherlock) + +Depending on the `ActionBar` you use, use one of the following classes: +`MaterialMenuIcon`, `MaterialMenuIconCompat` or `MaterialMenuIconSherlock`. + +In your `Activity` add the following: + +```java +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + materialMenu = new MaterialMenuIcon(this, Color.WHITE, Stroke.THIN); +} + +protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + materialMenu.syncState(savedInstanceState); +} + +protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + materialMenu.onSaveInstanceState(outState); +} + +public boolean onOptionsItemSelected(MenuItem item) { + if (item.getId() == android.R.id.home) { + // Handle your drawable state here + materialMenu.animateState(newState); + } +} +``` + +#### Use in Toolbar + +Use it as a standalone drawable. Note: you have to handle icon state yourself: + +```java +private MaterialMenuDrawable materialMenu; + +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + // Handle your drawable state here + materialMenu.animateState(newState); + } + }); + materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN); + toolbar.setNavigationIcon(materialMenu); +} +``` + +OR + +Use `MaterialMenuIconToolbar` which handles saved state: + +```java +private MaterialMenuIconToolbar materialMenu; + +@Override +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + // Handle your drawable state here + materialMenu.animateState(newState); + } + }); + materialMenu = new MaterialMenuIconToolbar(this, Color.WHITE, Stroke.THIN) { + @Override public int getToolbarViewId() { + return R.id.toolbar; + } + }; +} + +@Override +protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + materialMenu.syncState(savedInstanceState); +} + +@Override protected void onSaveInstanceState(Bundle outState) { + materialMenu.onSaveInstanceState(outState); + super.onSaveInstanceState(outState); +} +``` + +#### Use in custom Action Bar view + +Simply add `MaterialMenuView` in your custom layout and register an `OnClickListener` to do the +transformations. + +See [source of Demo][2] for details + +#### NavigationDrawer slide interaction + +Implement `MaterialMenu` into your ActionBar as described above and add a custom `DrawerListener`: + +```java +private DrawerLayout drawerLayout; +private boolean isDrawerOpened; +private MaterialMenuIcon materialMenu; + +@Override +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + materialMenu = new MaterialMenuIcon(this, Color.WHITE, Stroke.THIN); // or retrieve from your custom view, etc + drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { + @Override + public void onDrawerSlide(View drawerView, float slideOffset) { + materialMenu.setTransformationOffset( + MaterialMenuDrawable.AnimationState.BURGER_ARROW, + isDrawerOpened ? 2 - slideOffset : slideOffset + ); + } + + @Override + public void onDrawerOpened(View drawerView) { + isDrawerOpened = true; + } + + @Override + public void onDrawerClosed(View drawerView) { + isDrawerOpened = false; + } + + @Override + public void onDrawerStateChanged(int newState) { + if(newState == DrawerLayout.STATE_IDLE) { + if(isDrawerOpened) menu.setState(MaterialMenuDrawable.IconState.ARROW) + else menu.setState(MaterialMenuDrawable.IconState.BURGER) + } + } + }); +} + + +@Override +protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + isDrawerOpened = drawerLayout.isDrawerOpen(Gravity.START); // or END, LEFT, RIGHT + materialMenu.syncState(savedInstanceState); +} + +@Override +protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + materialMenu.onSaveInstanceState(outState); +} +``` + +Developed By +-------------------- +Balys Valentukevicius @ [Lemon Labs][1] + +License +----------- + +``` +Copyright 2014 Balys Valentukevicius + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` + +[1]: http://www.lemonlabs.co +[2]: https://github.com/balysv/material-menu/blob/master/demo/src/stock/java/com/balysv/materialmenu/demo/stock/CustomViewActivity.java +[3]: http://gradleplease.appspot.com/ diff --git a/README.md b/README.md index a27b563..6717d9c 100644 --- a/README.md +++ b/README.md @@ -10,31 +10,43 @@ Have full control of the animation: ##Including in your project -[![Bintray](https://img.shields.io/bintray/v/sosite/maven/material-menu.svg)](https://bintray.com/sosite/maven/material-menu/_latestVersion) [Releases](https://github.com/sosite/material-menu/releases) - ```groovy -// stock actionBar -compile 'com.socros.android.lib:material-menu:1.6.0' - -// Toolbar and ActionBarCompat-v22 (includes support-v7:22.1.1) -compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.4' +compile 'com.socros.android.lib:material-menu:2.0.0f' ``` -```groovy -repositories { - jcenter() -} -``` +[![Bintray](https://img.shields.io/bintray/v/sosite/maven/material-menu.svg)](https://bintray.com/sosite/maven/material-menu/_latestVersion) [Releases](https://github.com/sosite/material-menu/releases) ##Usage -The library provides two wrappers of `MaterialMenuDrawable` that eases implementation into the ActionBar, NavigationDrawer slide interaction or into any other custom layout. +###MaterialMenuDrawable + +Use it as a standalone drawable in your `Toolbar`: + +```java +private MaterialMenuDrawable materialMenu; + +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.toolbar); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + // Handle your drawable state here + materialMenu.animateState(newState); + } + }); + materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN); + toolbar.setNavigationIcon(materialMenu); +} +``` ###MaterialMenuView -A plain old `View` that draws the icon and provides an API to manipulate its state. +A plain old `View` that draws the icon and provides an API to manipulate its state. You can embed it +in any layout including a `Toolbar`. -Customisation is also available through attributes: +Customisation is also available through xml attributes: ```xml app:mm_color="color" // Color of drawable @@ -43,17 +55,9 @@ app:mm_transformDuration="integer" // Transformation animation duration app:mm_scale="integer" // Scale factor of drawable app:mm_strokeWidth="integer" // Stroke width of icons (can only be 1, 2 or 3) app:mm_rtlEnabled="boolean" // Enabled RTL layout support (flips all drawables) +app:mm_iconState="enum" // Set the intial state of the drawable (burger, arrow, x or check) ``` -###MaterialMenuIcon - -A POJO that initializes the drawable and replaces the ActionBar icon. - -Jump to instructions for : -- [ActionBar](#use-as-action-bar-icon) -- [Toolbar](#use-in-toolbar) -- [NavigationDrawer interaction](#navigationdrawer-slide-interaction) - ##API There are four icon states: @@ -65,13 +69,13 @@ BURGER, ARROW, X, CHECK To morph the drawable state ```java -MaterialMenu.animateState(IconState state) +MaterialMenu.animateIconState(IconState state) ``` To change the drawable state without animation ```java -MaterialMenu.setState(IconState state) +MaterialMenu.setIconState(IconState state) ``` To animate the drawable manually (i.e. on navigation drawer slide): @@ -88,136 +92,25 @@ MaterialMenu.setVisible(boolean visible) where `AnimationState` is one of `BURGER_ARROW, BURGER_X, ARROW_X, ARROW_CHECK, BURGER_CHECK, X_CHECK` and `value` is between `0` and `2` -**Note:** The current implementation resolves its state by current offset value. Make sure you use `offset` between `0` and `1` for forward animation and `1` and `2` for backwards to correctly save icon state on activity recreation. - -###Customisation - -```java -// change color -MaterialMenu.setColor(int color) - -// change icon visibility -MaterialMenu.setVisible(boolean visible) - -// change transformation animation duration -MaterialMenu.setTransformationDuration(int duration) - -// change transformation interpolator -MaterialMenu.setInterpolator(Interpolator interpolator) - -// set RTL layout support -MaterialMenu.setRTLEnabled(boolean enabled) -``` - -###Use as Action Bar icon - -In your `Activity` add the following: - -```java -protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - materialMenu = new MaterialMenuIcon(this, Color.WHITE, Stroke.THIN); -} - -protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - materialMenu.syncState(savedInstanceState); -} - -protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - materialMenu.onSaveInstanceState(outState); -} +**Note:** The icon state is resolved by current offset value. Make sure you use `offset` between `0` and `1` for forward animation and `1` and `2` for backwards to correctly save icon state on activity recreation. -public boolean onOptionsItemSelected(MenuItem item) { - if (item.getId() == android.R.id.home) { - // Handle your drawable state here - materialMenu.animateState(newState); - } -} -``` +## NavigationDrawer slide interaction -###Use in Toolbar - -Use it as a standalone drawable. Note: you have to handle icon state yourself: +Implement `MaterialMenu` into your ActionBar as described above and add a custom `DrawerListener`: ```java +private DrawerLayout drawerLayout; +private boolean isDrawerOpened; private MaterialMenuDrawable materialMenu; +@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.toolbar); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override public void onClick(View v) { - // Handle your drawable state here - materialMenu.animateState(newState); - } - }); materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN); toolbar.setNavigationIcon(materialMenu); -} -``` - -OR - -Use `MaterialMenuIconToolbar` which handles saved state: - -```java -private MaterialMenuIconToolbar materialMenu; -@Override -protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.toolbar); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override public void onClick(View v) { - // Handle your drawable state here - materialMenu.animateState(newState); - } - }); - materialMenu = new MaterialMenuIconToolbar(this, Color.WHITE, Stroke.THIN) { - @Override public int getToolbarViewId() { - return R.id.toolbar; - } - }; -} - -@Override -protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - materialMenu.syncState(savedInstanceState); -} - -@Override protected void onSaveInstanceState(Bundle outState) { - materialMenu.onSaveInstanceState(outState); - super.onSaveInstanceState(outState); -} -``` - -###Use in custom Action Bar view - -Simply add `MaterialMenuView` in your custom layout and register an `OnClickListener` to do the -transformations. - -See [source of Demo][4] for details - -###NavigationDrawer slide interaction - -Implement `MaterialMenu` into your ActionBar as described above and add a custom `DrawerListener`: - -```java -private DrawerLayout drawerLayout; -private boolean isDrawerOpened; -private MaterialMenuIcon materialMenu; - -@Override -protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - materialMenu = new MaterialMenuIcon(this, Color.WHITE, Stroke.THIN); // or retrieve from your custom view, etc drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override @@ -241,38 +134,27 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onDrawerStateChanged(int newState) { if(newState == DrawerLayout.STATE_IDLE) { - if(isDrawerOpened) menu.setState(MaterialMenuDrawable.IconState.ARROW) - else menu.setState(MaterialMenuDrawable.IconState.BURGER) + if(isDrawerOpened) { + menu.setIconState(MaterialMenuDrawable.IconState.ARROW); + } else { + menu.setIconState(MaterialMenuDrawable.IconState.BURGER); + } } } }); } - - -@Override -protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - isDrawerOpened = drawerLayout.isDrawerOpen(Gravity.START); // or END, LEFT, RIGHT - materialMenu.syncState(savedInstanceState); -} - -@Override -protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - materialMenu.onSaveInstanceState(outState); -} ``` ##Developed By -Balys Valentukevicius @ [Lemon Labs][1] +Balys Valentukevicius -Wojciech Rozwadowski @ [Socros][2] +Wojciech Rozwadowski ##License ``` -Copyright 2014 Balys Valentukevicius +Copyright 2016 Balys Valentukevicius Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -287,7 +169,4 @@ See the License for the specific language governing permissions and limitations under the License. ``` -[1]: http://www.lemonlabs.co -[2]: http://socros.com -[3]: https://github.com/sosite/material-menu/blob/masterchef/demo/src/stock/java/com/balysv/materialmenu/demo/stock/CustomViewActivity.java -[4]: http://gradleplease.appspot.com/ +[1]: https://github.com/balysv/material-menu/blob/master/README-1.0.md diff --git a/demo/build.gradle b/demo/build.gradle index a674750..42799df 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -2,37 +2,20 @@ apply plugin: 'com.android.application' android { compileSdkVersion 24 - buildToolsVersion "24.0.1" + buildToolsVersion "24.0.2" defaultConfig { applicationId "com.balysv.materialmenu.demo" minSdkVersion 14 targetSdkVersion 24 versionCode 1 - versionName "1.0" - } - - productFlavors { - stock { - applicationId "com.balysv.materialmenu.demo.stock" - resValue "string", "app_name", "Material menu - stock" - } - toolbar { - applicationId "com.balysv.materialmenu.demo.toolbar" - resValue "string", "app_name", "Material menu - toolbar" - } - abc_v21 { - applicationId "com.balysv.materialmenu.demo.abc_v21" - resValue "string", "app_name", "Material menu - abc_v21" - } + versionName "2.0" } } dependencies { compile project(':library') - toolbarCompile project(':extras-toolbar'); - abc_v21Compile project(':extras-toolbar') - compile 'com.android.support:support-v4:24.2.0' - compile 'com.android.support:cardview-v7:24.2.0' + compile 'com.android.support:support-v4:24.2.1' + compile "com.android.support:design:24.2.1" } diff --git a/demo/src/abc_v21/AndroidManifest.xml b/demo/src/abc_v21/AndroidManifest.xml deleted file mode 100644 index 48e2c35..0000000 --- a/demo/src/abc_v21/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - diff --git a/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/BaseActivity.java b/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/BaseActivity.java deleted file mode 100644 index a72461d..0000000 --- a/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/BaseActivity.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.balysv.materialmenu.demo.abc_v21; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - -import com.balysv.materialmenu.demo.BaseActivityHelper; -import com.balysv.materialmenu.demo.R; - -public abstract class BaseActivity extends AppCompatActivity { - - protected BaseActivityHelper helper; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.demo); - helper = new BaseActivityHelper(); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - helper.refreshDrawerState(); - } -} diff --git a/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/HomeIconActivity.java b/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/HomeIconActivity.java deleted file mode 100644 index 942ebe1..0000000 --- a/demo/src/abc_v21/java/com/balysv/materialmenu/demo/abc_v21/HomeIconActivity.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.balysv.materialmenu.demo.abc_v21; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.MenuItem; - -import com.balysv.materialmenu.extras.toolbar.MaterialMenuIconCompat; - -import static com.balysv.materialmenu.MaterialMenuDrawable.Stroke; -import static com.balysv.materialmenu.demo.BaseActivityHelper.generateState; -import static com.balysv.materialmenu.demo.BaseActivityHelper.intToState; - - -public class HomeIconActivity extends BaseActivity { - - private MaterialMenuIconCompat materialMenu; - private int actionBarMenuState; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - materialMenu = new MaterialMenuIconCompat(this, Color.BLACK, Stroke.THIN); - helper.init(getWindow().getDecorView(), materialMenu); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - materialMenu.syncState(savedInstanceState); - } - - @Override protected void onSaveInstanceState(Bundle outState) { - materialMenu.onSaveInstanceState(outState); - super.onSaveInstanceState(outState); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - // random state - actionBarMenuState = generateState(actionBarMenuState); - materialMenu.animatePressedState(intToState(actionBarMenuState)); - } - return super.onOptionsItemSelected(item); - } -} diff --git a/demo/src/abc_v21/res/values-v21/styles.xml b/demo/src/abc_v21/res/values-v21/styles.xml deleted file mode 100644 index ecfa918..0000000 --- a/demo/src/abc_v21/res/values-v21/styles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - - - - - - - - - - diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index 9611847..59dbad0 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -1,5 +1,18 @@ + package="com.balysv.materialmenu.demo"> - + + + + + + + + diff --git a/demo/src/main/java/com/balysv/materialmenu/demo/BaseActivityHelper.java b/demo/src/main/java/com/balysv/materialmenu/demo/BaseActivityHelper.java deleted file mode 100644 index c65fb71..0000000 --- a/demo/src/main/java/com/balysv/materialmenu/demo/BaseActivityHelper.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.balysv.materialmenu.demo; - -import android.graphics.Color; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.view.Gravity; -import android.view.View; -import android.widget.SeekBar; - -import com.balysv.materialmenu.MaterialMenu; -import com.balysv.materialmenu.MaterialMenuDrawable; -import com.balysv.materialmenu.MaterialMenuView; - -import java.util.Random; - -import static com.balysv.materialmenu.MaterialMenuDrawable.IconState; - -public class BaseActivityHelper implements View.OnClickListener, SeekBar.OnSeekBarChangeListener { - - private MaterialMenuView materialMenuView; - private int materialButtonState; - private MaterialMenu materialIcon; - private DrawerLayout drawerLayout; - private boolean direction; - - public void init(View parent, MaterialMenu actionBarIcon) { - SeekBar duration = (SeekBar) parent.findViewById(R.id.item_animation_duration); - duration.setMax(4600); - duration.setProgress(2600); - duration.setOnSeekBarChangeListener(this); - - materialMenuView = (MaterialMenuView) parent.findViewById(R.id.material_menu_button); - materialMenuView.setOnClickListener(this); - materialIcon = actionBarIcon; - - parent.findViewById(R.id.switch_item_arrow).setOnClickListener(this); - parent.findViewById(R.id.switch_item_menu).setOnClickListener(this); - parent.findViewById(R.id.switch_item_x).setOnClickListener(this); - parent.findViewById(R.id.switch_item_check).setOnClickListener(this); - parent.findViewById(R.id.switch_item_show).setOnClickListener(this); - parent.findViewById(R.id.switch_item_hide).setOnClickListener(this); - parent.findViewById(R.id.animate_item_arrow).setOnClickListener(this); - parent.findViewById(R.id.animate_item_menu).setOnClickListener(this); - parent.findViewById(R.id.animate_item_x).setOnClickListener(this); - parent.findViewById(R.id.animate_item_check).setOnClickListener(this); - - drawerLayout = ((DrawerLayout) parent.findViewById(R.id.drawer_layout)); - drawerLayout.setScrimColor(Color.parseColor("#66000000")); - drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { - - @Override - public void onDrawerSlide(View drawerView, float slideOffset) { - materialIcon.setTransformationOffset( - MaterialMenuDrawable.AnimationState.BURGER_ARROW, - direction ? 2 - slideOffset : slideOffset - ); - } - - @Override - public void onDrawerOpened(android.view.View drawerView) { - direction = true; - } - - @Override - public void onDrawerClosed(android.view.View drawerView) { - direction = false; - } - }); - - drawerLayout.postDelayed(new Runnable() { - @Override public void run() { - drawerLayout.openDrawer(Gravity.LEFT); - } - }, 1500); - } - - @Override public void onClick(View v) { - final int id = v.getId(); - switch (id) { - case R.id.animate_item_menu: - materialMenuView.animateState(IconState.BURGER); - break; - case R.id.animate_item_arrow: - materialMenuView.animateState(IconState.ARROW); - break; - case R.id.animate_item_x: - materialMenuView.animateState(IconState.X); - break; - case R.id.animate_item_check: - materialMenuView.animateState(IconState.CHECK); - break; - case R.id.switch_item_menu: - materialMenuView.setState(IconState.BURGER); - break; - case R.id.switch_item_arrow: - materialMenuView.setState(IconState.ARROW); - break; - case R.id.switch_item_x: - materialMenuView.setState(IconState.X); - break; - case R.id.switch_item_check: - materialMenuView.setState(IconState.CHECK); - break; - case R.id.switch_item_show: - materialMenuView.setVisible(true); - break; - case R.id.switch_item_hide: - materialMenuView.setVisible(false); - break; - case R.id.material_menu_button: - setMainState(); - break; - } - } - - @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - materialMenuView.setTransformationDuration(400 + progress); - } - - @Override public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override public void onStopTrackingTouch(SeekBar seekBar) { - } - - private void setMainState() { - materialButtonState = generateState(materialButtonState); - materialMenuView.animatePressedState(intToState(materialButtonState)); - } - - public void refreshDrawerState() { - this.direction = drawerLayout.isDrawerOpen(GravityCompat.START); - } - - public static int generateState(int previous) { - int generated = new Random().nextInt(4); - return generated != previous ? generated : generateState(previous); - } - - public static IconState intToState(int state) { - switch (state) { - case 0: - return IconState.BURGER; - case 1: - return IconState.ARROW; - case 2: - return IconState.X; - case 3: - return IconState.CHECK; - } - throw new IllegalArgumentException("Must be a number [0,3)"); - } -} diff --git a/demo/src/main/java/com/balysv/materialmenu/demo/DemoActivity.java b/demo/src/main/java/com/balysv/materialmenu/demo/DemoActivity.java new file mode 100644 index 0000000..15dacd2 --- /dev/null +++ b/demo/src/main/java/com/balysv/materialmenu/demo/DemoActivity.java @@ -0,0 +1,186 @@ +package com.balysv.materialmenu.demo; + +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.SeekBar; + +import com.balysv.materialmenu.MaterialMenuDrawable; +import com.balysv.materialmenu.MaterialMenuView; + +import java.util.Random; + +import static com.balysv.materialmenu.MaterialMenuDrawable.Stroke; + + +public class DemoActivity extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener { + + private Toolbar toolbar; + private MaterialMenuView materialMenuView; + private int materialButtonState; + private DrawerLayout drawerLayout; + private boolean direction; + private int actionBarMenuState; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Setup + setContentView(R.layout.demo); + toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + MaterialMenuDrawable materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN); + toolbar.setNavigationIcon(materialMenu); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + // random state + actionBarMenuState = generateState(actionBarMenuState); + getMaterialMenu(toolbar).animateIconState(intToState(actionBarMenuState)); + } + }); + + // Demo view initialization + initViews(); + drawerLayout.postDelayed(new Runnable() { + @Override public void run() { + drawerLayout.openDrawer(GravityCompat.START); + } + }, 1500); + } + + private void initViews() { + materialMenuView = (MaterialMenuView) findViewById(R.id.material_menu_button); + materialMenuView.setOnClickListener(this); + + drawerLayout = ((DrawerLayout) findViewById(R.id.drawer_layout)); + drawerLayout.setScrimColor(Color.parseColor("#66000000")); + drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { + + @Override + public void onDrawerSlide(View drawerView, float slideOffset) { + getMaterialMenu(toolbar).setTransformationOffset( + MaterialMenuDrawable.AnimationState.BURGER_ARROW, + direction ? 2 - slideOffset : slideOffset + ); + } + + @Override + public void onDrawerOpened(android.view.View drawerView) { + direction = true; + } + + @Override + public void onDrawerClosed(android.view.View drawerView) { + direction = false; + } + }); + + SeekBar duration = (SeekBar) findViewById(R.id.item_animation_duration); + duration.setMax(4600); + duration.setProgress(2600); + duration.setOnSeekBarChangeListener(this); + + findViewById(R.id.switch_item_arrow).setOnClickListener(this); + findViewById(R.id.switch_item_menu).setOnClickListener(this); + findViewById(R.id.switch_item_x).setOnClickListener(this); + findViewById(R.id.switch_item_check).setOnClickListener(this); + findViewById(R.id.switch_item_show).setOnClickListener(this); + findViewById(R.id.switch_item_hide).setOnClickListener(this); + findViewById(R.id.animate_item_arrow).setOnClickListener(this); + findViewById(R.id.animate_item_menu).setOnClickListener(this); + findViewById(R.id.animate_item_x).setOnClickListener(this); + findViewById(R.id.animate_item_check).setOnClickListener(this); + } + + @Override protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + refreshDrawerState(); + } + + @Override public void onClick(View v) { + final int id = v.getId(); + switch (id) { + case R.id.animate_item_menu: + materialMenuView.animateIconState(MaterialMenuDrawable.IconState.BURGER); + break; + case R.id.animate_item_arrow: + materialMenuView.animateIconState(MaterialMenuDrawable.IconState.ARROW); + break; + case R.id.animate_item_x: + materialMenuView.animateIconState(MaterialMenuDrawable.IconState.X); + break; + case R.id.animate_item_check: + materialMenuView.animateIconState(MaterialMenuDrawable.IconState.CHECK); + break; + case R.id.switch_item_menu: + materialMenuView.setIconState(MaterialMenuDrawable.IconState.BURGER); + break; + case R.id.switch_item_arrow: + materialMenuView.setIconState(MaterialMenuDrawable.IconState.ARROW); + break; + case R.id.switch_item_x: + materialMenuView.setIconState(MaterialMenuDrawable.IconState.X); + break; + case R.id.switch_item_check: + materialMenuView.setIconState(MaterialMenuDrawable.IconState.CHECK); + break; + case R.id.switch_item_show: + materialMenuView.setVisible(true); + break; + case R.id.switch_item_hide: + materialMenuView.setVisible(false); + break; + case R.id.material_menu_button: + setMainState(); + break; + } + } + + private void setMainState() { + materialButtonState = generateState(materialButtonState); + materialMenuView.animateIconState(intToState(materialButtonState)); + } + + private void refreshDrawerState() { + this.direction = drawerLayout.isDrawerOpen(GravityCompat.START); + } + + @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + materialMenuView.setTransformationDuration(400 + progress); + } + + @Override public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override public void onStopTrackingTouch(SeekBar seekBar) { + } + + private static MaterialMenuDrawable getMaterialMenu(Toolbar toolbar) { + return (MaterialMenuDrawable) toolbar.getNavigationIcon(); + } + + private static int generateState(int previous) { + int generated = new Random().nextInt(4); + return generated != previous ? generated : generateState(previous); + } + + private static MaterialMenuDrawable.IconState intToState(int state) { + switch (state) { + case 0: + return MaterialMenuDrawable.IconState.BURGER; + case 1: + return MaterialMenuDrawable.IconState.ARROW; + case 2: + return MaterialMenuDrawable.IconState.X; + case 3: + return MaterialMenuDrawable.IconState.CHECK; + } + throw new IllegalArgumentException("Must be a number [0,3)"); + } +} diff --git a/demo/src/main/res/layout/action_bar.xml b/demo/src/main/res/layout/action_bar.xml deleted file mode 100644 index 5e478d7..0000000 --- a/demo/src/main/res/layout/action_bar.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/demo/src/main/res/layout/demo.xml b/demo/src/main/res/layout/demo.xml index 3facc07..900ce22 100644 --- a/demo/src/main/res/layout/demo.xml +++ b/demo/src/main/res/layout/demo.xml @@ -7,171 +7,184 @@ android:layout_height="match_parent" tools:context=".DemoActivity"> - + android:orientation="vertical"> - + android:id="@+id/toolbar" + app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + android:background="?attr/colorPrimary"/> - - - - - - + + - - + + + + + - - - - -