Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #14

Merged
merged 10 commits into from
Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage
Add a dependency to your `build.gradle`:

dependencies {
compile 'com.sa90.materialarcmenu:library:1.4.1'
compile 'com.sa90.materialarcmenu:library:1.5.0'
}

and include the `com.sa90.materialarcmenu.ArcMenu` as a viewgroup (with the sub-menu's as child) in your layout. The menu (floating action button) has a margin of 16dp (customizable) added to it by default to follow the material design guidelines.
Expand Down Expand Up @@ -111,8 +111,9 @@ Currently the library offers the following customization options:
- `menu_radius`: Controls the radius of the arc
- `menu_elevation`: Controls elevation (shadow cast) of the FAB Menu. Default to 6dp.
- `menu_margin`: Controls the margin applied to the FAB Menu. Currently the same margin is applied to all four corners (defaults to 16dp).
- `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_open`: Controls which side of the FAB menu is the arc menu displayed on. Currently supports one of `arc_left`, `arc_right` , `arc_top_left` or `arc_top_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
- `fabSize`: Sets the size of the FAB icon used in the ArcMenu. Can be either `mini` or `normal`

API
-------
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -23,3 +23,7 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

subprojects {
tasks.withType(Javadoc).all { enabled = false }
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jan 30 19:46:37 SGT 2016
#Mon Sep 12 05:59:25 SGT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.4.1"
versionName "1.5.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.4.1'
libraryVersion = '1.5.0'

developerId = 'saurabharora90'
developerName = 'Saurabh Arora'
Expand Down
104 changes: 76 additions & 28 deletions library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.support.annotation.AttrRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
Expand Down Expand Up @@ -54,25 +55,25 @@ public ArcMenu(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.ArcMenu, 0, 0);
init(attr);
fabMenu = new FloatingActionButton(context);

fabMenu = new FloatingActionButton(context, attrs);
}

private void init(TypedArray attr) {
Resources resources = getResources();

mDrawable = attr.getDrawable(R.styleable.ArcMenu_menu_scr);
mColorStateList = attr.getColorStateList(R.styleable.ArcMenu_menu_color);
mFinalRadius = attr.getDimension(R.styleable.ArcMenu_menu_radius, resources.getDimension(R.dimen.default_radius));
mElevation = attr.getDimension(R.styleable.ArcMenu_menu_elevation, resources.getDimension(R.dimen.default_elevation));
mFinalRadius = attr.getDimension(R.styleable.ArcMenu_menu_radius,
resources.getDimension(R.dimen.default_radius));
mElevation = attr.getDimension(R.styleable.ArcMenu_menu_elevation,
resources.getDimension(R.dimen.default_elevation));
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) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
mDrawable = resources.getDrawable(android.R.drawable.ic_dialog_email, null);
else
mDrawable = resources.getDrawable(android.R.drawable.ic_dialog_email);
mDrawable = ContextCompat.getDrawable(getContext(), android.R.drawable.ic_dialog_email);
}

mRippleColor = attr.getColor(R.styleable.ArcMenu_menu_ripple_color, getThemeAccentColor(getContext(), R.attr.colorControlHighlight));
Expand All @@ -81,12 +82,24 @@ private void init(TypedArray attr) {
mColorStateList = ColorStateList.valueOf(getThemeAccentColor(getContext(), R.attr.colorAccent));
}

if(mMenuSideEnum == MenuSideEnum.ARC_LEFT)
mQuadrantAngle = POSITIVE_QUADRANT;
else
mQuadrantAngle = NEGATIVE_QUADRANT;
switch (mMenuSideEnum) {

case ARC_LEFT:
mQuadrantAngle = POSITIVE_QUADRANT;
break;
case ARC_TOP_LEFT:
mQuadrantAngle = NEGATIVE_QUADRANT;
break;
case ARC_RIGHT:
mQuadrantAngle = NEGATIVE_QUADRANT;
break;
case ARC_TOP_RIGHT:
mQuadrantAngle = POSITIVE_QUADRANT;
break;
}

menuMargin = attr.getDimensionPixelSize(R.styleable.ArcMenu_menu_margin, resources.getDimensionPixelSize(R.dimen.fab_margin));
menuMargin = attr.getDimensionPixelSize(R.styleable.ArcMenu_menu_margin,
resources.getDimensionPixelSize(R.dimen.fab_margin));
}

/**
Expand Down Expand Up @@ -116,7 +129,8 @@ private void addMainMenu() {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
layoutMenu();
layoutChildren();
if(!isInEditMode())
layoutChildren();
}

private void layoutChildren() {
Expand All @@ -138,13 +152,17 @@ private void layoutChildrenArc() {
leftPoint = (int) (mCurrentRadius * Math.cos(Math.toRadians(totalAngleForChild)));
topPoint = (int) (mCurrentRadius * Math.sin(Math.toRadians(totalAngleForChild)));

if(mMenuSideEnum == MenuSideEnum.ARC_RIGHT) {
left = cx + leftPoint;
top = cy + topPoint;
}
else {
left = cx - leftPoint;
top = cy - topPoint;
switch (mMenuSideEnum) {

case ARC_LEFT:
case ARC_TOP_LEFT:
left = cx - leftPoint;
top = cy - topPoint;
break;
default:
left = cx + leftPoint;
top = cy + topPoint;
break;
}

child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
Expand All @@ -160,14 +178,23 @@ private void layoutChildrenArc() {
*/
//TODO: work on fixing this
private void layoutMenu() {
if(mMenuSideEnum == MenuSideEnum.ARC_RIGHT) {
cx = 0 + menuMargin;
cy = getMeasuredHeight() - fabMenu.getMeasuredHeight() - menuMargin;
}

else {
cx = getMeasuredWidth() - fabMenu.getMeasuredWidth() - menuMargin;
cy = getMeasuredHeight() - fabMenu.getMeasuredHeight() - menuMargin;
switch (mMenuSideEnum) {
case ARC_LEFT:
cx = getMeasuredWidth() - fabMenu.getMeasuredWidth() - menuMargin;
cy = getMeasuredHeight() - fabMenu.getMeasuredHeight() - menuMargin;
break;
case ARC_TOP_LEFT:
cx = getMeasuredWidth() - fabMenu.getMeasuredWidth() - menuMargin;
cy = menuMargin;
break;
case ARC_RIGHT:
cx = menuMargin;
cy = getMeasuredHeight() - fabMenu.getMeasuredHeight() - menuMargin;
break;
case ARC_TOP_RIGHT:
cx = menuMargin;
cy = menuMargin;
break;
}

fabMenu.layout(cx, cy, cx + fabMenu.getMeasuredWidth(), cy + fabMenu.getMeasuredHeight());
Expand Down Expand Up @@ -393,6 +420,10 @@ public void onAnimationRepeat(Animator animation) {
}

//ALL API Calls

/**
* Toggles the state of the ArcMenu, i.e. closes it if it is open and opens it if it is closed
*/
public void toggleMenu() {
mIsOpened = !mIsOpened;
if(mIsOpened)
Expand All @@ -401,19 +432,36 @@ public void toggleMenu() {
beginCloseAnimation();
}

/**
* Get the state of the ArcMenu, i.e. whether it is open or closed
* @return true if the menu is open
*/
public boolean isMenuOpened() {
return mIsOpened;
}

/**
* Controls the animation time to transition the menu from close to open state and vice versa.
* The time is represented in milli-seconds
* @param animationTime
*/
public void setAnimationTime(long animationTime) {
mAnimationTime = animationTime;
}

/**
* Allows you to listen to the state changes of the Menu, i.e.
* {@link StateChangeListener#onMenuOpened()} and {@link StateChangeListener#onMenuClosed()} events
* @param stateChangeListener
*/
public void setStateChangeListener(StateChangeListener stateChangeListener) {
this.mStateChangeListener = stateChangeListener;
}

@SuppressWarnings("unused")
/**
* Sets the display radius of the ArcMenu
*/
public void setRadius(float radius) {
this.mFinalRadius = radius;
invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created by Saurabh on 14/12/15.
*/
public enum MenuSideEnum {
ARC_LEFT(0), ARC_RIGHT(1);
ARC_LEFT(0), ARC_RIGHT(1), ARC_TOP_LEFT(2), ARC_TOP_RIGHT(3);
int id;

MenuSideEnum(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

/**
* Created by Saurabh on 25/12/15.
*
* Interface for listening to the state changes of the menu
*/
public interface StateChangeListener {

/**
* Fired when the ArcMenu is opened
*/
void onMenuOpened();

/**
* Fired when the arc menu is closed
*/
void onMenuClosed();
}
2 changes: 2 additions & 0 deletions library/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<attr name="menu_open" format="enum">
<enum name="arc_left" value="0"/>
<enum name="arc_right" value="1"/>
<enum name="arc_top_left" value="2"/>
<enum name="arc_top_right" value="3"/>
</attr>
<attr name="menu_animation_time" format="integer"/>
<attr name="menu_elevation" format="dimension"/>
Expand Down
2 changes: 1 addition & 1 deletion samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.sa90.arcdemo"
Expand Down
7 changes: 5 additions & 2 deletions samples/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
<activity
android:name=".AnimationTimeActivity"
android:label="@string/title_activity_animation_time"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".TopPlacementSampleActivity"
android:label="Top Placement Demo"
android:theme="@style/AppTheme.NoActionBar"/>
</application>

</manifest>
</manifest>
9 changes: 9 additions & 0 deletions samples/src/main/java/com/sa90/arcdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void onMenuClosed() {
findViewById(R.id.fab1).setOnClickListener(subMenuClickListener);
findViewById(R.id.tvNext).setOnClickListener(mNextClickListener);
findViewById(R.id.tvAnimationDemo).setOnClickListener(mAnimationTimeDemoClickListener);
findViewById(R.id.tvTopPlacement).setOnClickListener(mTopPlacementClickListener);
}

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

private View.OnClickListener mTopPlacementClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, TopPlacementSampleActivity.class);
startActivity(intent);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sa90.arcdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

public class TopPlacementSampleActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top_placement_sample);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
10 changes: 10 additions & 0 deletions samples/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
android:textColor="@android:color/black"
android:textSize="16sp" />

<TextView
android:id="@+id/tvTopPlacement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Click here for top placement sample"
android:textColor="@android:color/black"
android:textSize="16sp" />

</LinearLayout>

<com.sa90.materialarcmenu.ArcMenu
Expand All @@ -53,6 +62,7 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:menu_open="arc_left"
app:fabSize="normal"
app:menu_scr="@android:drawable/ic_dialog_dialer">

<android.support.design.widget.FloatingActionButton
Expand Down
Loading