Skip to content

Commit

Permalink
Merge pull request #2 from saurabharora90/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
saurabharora90 committed Dec 25, 2015
2 parents f11dd5d + cd0b7fc commit 21c472b
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 27 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MaterialArcMenu-green.svg?style=true)](https://android-arsenal.com/details/1/2936)

Material Arc Menu
=================

Expand All @@ -18,7 +20,7 @@ Usage
Add a dependency to your `build.gradle`:

dependencies {
compile 'com.sa90.materialarcmenu:library:1.0.0'
compile 'com.sa90.materialarcmenu:library:1.1.0'
}

and include the `com.sa90.materialarcmenu.ArcMenu` as a viewgroup (with the sub-menu's as child) in your layout.
Expand Down Expand Up @@ -107,20 +109,30 @@ Currently the library offers the following customization options:
- `menu_ripple_color`: Controls the ripple color of the FAB Menu. Defaults to `colorControlHighlight`
- `menu_radius`: Controls the radius of the arc
- `menu_open`: Controls which side of the FAB menu is the arc menu displayed on. Currently supports one of `arc_left` or `arc_right`
- `menu_animation_time`: Controls the animation time to transition the menu from close to open state and vice versa. The time is represented in milli-seconds

API
-------
Currently the library offers the following API's

- `toggleMenu`: Open or close the menu depending on its current state.
- `isMenuOpened`: Returns whether the menu is opened or closed.
- `setAnimationTime`: Controls the animation time to transition the menu from close to open state and vice versa. The time is represented in milli-seconds
- `setStateChangeListener`: Allows you to listen to the state changes of the Menu, i.e. `onMenuOpened` and `onMenuClosed` events

License
-------

Copyright 2015 Saurabh Arora

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.
limitations under the License.
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
versionName "1.1.0"
}
buildTypes {
release {
Expand All @@ -32,7 +32,7 @@ ext {
artifact = 'library'

libraryDescription = 'An android custom view which allows you to have a arc style-menu on your pages'
libraryVersion = '1.0.0'
libraryVersion = '1.1.0'

developerId = 'saurabharora90'
developerName = 'Saurabh Arora'
Expand Down
19 changes: 18 additions & 1 deletion library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ public class ArcMenu extends ViewGroup {
private static final double POSITIVE_QUADRANT = 90;
private static final double NEGATIVE_QUADRANT = -90;
private static final double ANGLE_FOR_ONE_SUB_MENU = 0;
private static final int ANIMATION_TIME = 300; //This time is in milliseconds

FloatingActionButton fabMenu;
Drawable mDrawable;
ColorStateList mColorStateList;
int mRippleColor;
long mAnimationTime;
float mCurrentRadius, mFinalRadius;
boolean mIsOpened = false;
double mQuadrantAngle;
MenuSideEnum mMenuSideEnum;
int cx, cy; //Represents the center points of the circle whose arc we are considering
private StateChangeListener mStateChangeListener;

public ArcMenu(Context context) {
super(context);
Expand All @@ -54,6 +57,7 @@ private void init(TypedArray attr) {
mColorStateList = attr.getColorStateList(R.styleable.ArcMenu_menu_color);
mFinalRadius = attr.getDimension(R.styleable.ArcMenu_menu_radius, resources.getDimension(R.dimen.default_radius));
mMenuSideEnum = MenuSideEnum.fromId(attr.getInt(R.styleable.ArcMenu_menu_open, 0));
mAnimationTime = attr.getInteger(R.styleable.ArcMenu_menu_animation_time, ANIMATION_TIME);
mCurrentRadius = 0;

if(mDrawable == null) {
Expand Down Expand Up @@ -238,6 +242,7 @@ public void onClick(View v) {

private void beginOpenAnimation() {
ValueAnimator openMenuAnimator = ValueAnimator.ofFloat(0, mFinalRadius);
openMenuAnimator.setDuration(mAnimationTime);
openMenuAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand All @@ -254,7 +259,8 @@ public void onAnimationStart(Animator animation) {

@Override
public void onAnimationEnd(Animator animation) {

if(mStateChangeListener!=null)
mStateChangeListener.onMenuOpened();
}

@Override
Expand All @@ -273,6 +279,7 @@ public void onAnimationRepeat(Animator animation) {

private void beginCloseAnimation() {
ValueAnimator closeMenuAnimator = ValueAnimator.ofFloat(mFinalRadius, 0);
closeMenuAnimator.setDuration(mAnimationTime);
closeMenuAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand All @@ -290,6 +297,8 @@ public void onAnimationStart(Animator animation) {
@Override
public void onAnimationEnd(Animator animation) {
toggleVisibilityOfAllChildViews(mIsOpened);
if(mStateChangeListener!=null)
mStateChangeListener.onMenuClosed();
}

@Override
Expand Down Expand Up @@ -318,4 +327,12 @@ public void toggleMenu() {
public boolean isMenuOpened() {
return mIsOpened;
}

public void setAnimationTime(long animationTime) {
mAnimationTime = animationTime;
}

public void setStateChangeListener(StateChangeListener stateChangeListener) {
this.mStateChangeListener = stateChangeListener;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sa90.materialarcmenu;

/**
* Created by Saurabh on 25/12/15.
*/
public interface StateChangeListener {
void onMenuOpened();
void onMenuClosed();
}
1 change: 1 addition & 0 deletions library/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<enum name="arc_left" value="0"/>
<enum name="arc_right" value="1"/>
</attr>
<attr name="menu_animation_time" format="integer"/>
</declare-styleable>
</resources>
3 changes: 2 additions & 1 deletion samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.sa90.materialarcmenu:library:1.0.0'
//compile 'com.sa90.materialarcmenu:library:1.0.0'
compile project(":library")
}
4 changes: 4 additions & 0 deletions samples/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<activity
android:name=".ImageButtonActivity"
android:label="@string/title_activity_image_button"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".AnimationTimeActivity"
android:label="@string/title_activity_animation_time"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

Expand Down
56 changes: 56 additions & 0 deletions samples/src/main/java/com/sa90/arcdemo/AnimationTimeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.sa90.arcdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.sa90.materialarcmenu.ArcMenu;

public class AnimationTimeActivity extends AppCompatActivity {

ArcMenu arcMenu;
Button btnSet;
EditText etAnimationTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_time);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

arcMenu = (ArcMenu) findViewById(R.id.arcMenu);
btnSet = (Button) findViewById(R.id.btnSet);
etAnimationTime = (EditText) findViewById(R.id.etAnimationTime);

btnSet.setOnClickListener(mSetClickListener);
}

private View.OnClickListener mSetClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String time = etAnimationTime.getText().toString();
if(time.isEmpty() || time.length() == 0)
return;
try {
arcMenu.setAnimationTime(Long.parseLong(time));
}
catch (NumberFormatException e) {
Toast.makeText(AnimationTimeActivity.this, "Keyed in value is not a number", Toast.LENGTH_SHORT).show();
}
}
};

@Override
public void onBackPressed() {
if(arcMenu.isMenuOpened())
arcMenu.toggleMenu();
else
super.onBackPressed();
}

}
24 changes: 24 additions & 0 deletions samples/src/main/java/com/sa90/arcdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.sa90.materialarcmenu.ArcMenu;
import com.sa90.materialarcmenu.StateChangeListener;

public class MainActivity extends AppCompatActivity {

Expand All @@ -21,9 +23,23 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);

arcMenu = (ArcMenu) findViewById(R.id.arcMenu);
//arcMenu.setAnimationTime(600);

arcMenu.setStateChangeListener(new StateChangeListener() {
@Override
public void onMenuOpened() {
Snackbar.make(arcMenu, "Menu Opened", Snackbar.LENGTH_SHORT).show();
}

@Override
public void onMenuClosed() {
Snackbar.make(arcMenu, "Menu Closed", Snackbar.LENGTH_SHORT).show();
}
});

findViewById(R.id.fab1).setOnClickListener(subMenuClickListener);
findViewById(R.id.tvNext).setOnClickListener(mNextClickListener);
findViewById(R.id.tvAnimationDemo).setOnClickListener(mAnimationTimeDemoClickListener);
}

private View.OnClickListener subMenuClickListener = new View.OnClickListener() {
Expand All @@ -40,4 +56,12 @@ public void onClick(View v) {
startActivity(intent);
}
};

private View.OnClickListener mAnimationTimeDemoClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, AnimationTimeActivity.class);
startActivity(intent);
}
};
}
85 changes: 85 additions & 0 deletions samples/src/main/res/layout/activity_animation_time.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".AnimationTimeActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?android:attr/actionBarSize"
android:padding="10dp"
android:orientation="vertical">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/etAnimationTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Enter Animation Time"/>

</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/btnSet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Set Animation Time"/>

</LinearLayout>

<com.sa90.materialarcmenu.ArcMenu
android:id="@+id/arcMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:menu_scr="@android:drawable/ic_dialog_dialer"
app:menu_open="arc_left">

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab1"
android:layout_width="wrap_content"
android:src="@android:drawable/ic_dialog_email"
android:layout_height="wrap_content" />

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:src="@android:drawable/ic_dialog_alert"
android:layout_height="wrap_content" />

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:src="@android:drawable/ic_dialog_info"
android:layout_height="wrap_content" />

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:src="@android:drawable/ic_dialog_map"
android:layout_height="wrap_content" />

</com.sa90.materialarcmenu.ArcMenu>

</android.support.design.widget.CoordinatorLayout>
Loading

0 comments on commit 21c472b

Please sign in to comment.