diff --git a/README.md b/README.md index 882b0e5..c4cf186 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 ------- diff --git a/build.gradle b/build.gradle index dd6fa06..d4f9320 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -23,3 +23,7 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir } + +subprojects { + tasks.withType(Javadoc).all { enabled = false } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7746968..0cda57e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/library/build.gradle b/library/build.gradle index 5c18b93..194abae 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -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 { @@ -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' diff --git a/library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java b/library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java index 23335c2..3175120 100644 --- a/library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java +++ b/library/src/main/java/com/sa90/materialarcmenu/ArcMenu.java @@ -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; @@ -54,7 +55,8 @@ 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) { @@ -62,17 +64,16 @@ private void init(TypedArray attr) { 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)); @@ -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)); } /** @@ -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() { @@ -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()); @@ -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()); @@ -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) @@ -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(); diff --git a/library/src/main/java/com/sa90/materialarcmenu/MenuSideEnum.java b/library/src/main/java/com/sa90/materialarcmenu/MenuSideEnum.java index 53b0f0d..dcaba02 100644 --- a/library/src/main/java/com/sa90/materialarcmenu/MenuSideEnum.java +++ b/library/src/main/java/com/sa90/materialarcmenu/MenuSideEnum.java @@ -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) { diff --git a/library/src/main/java/com/sa90/materialarcmenu/StateChangeListener.java b/library/src/main/java/com/sa90/materialarcmenu/StateChangeListener.java index 10e962f..26ad470 100644 --- a/library/src/main/java/com/sa90/materialarcmenu/StateChangeListener.java +++ b/library/src/main/java/com/sa90/materialarcmenu/StateChangeListener.java @@ -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(); } diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml index 7cac6d3..dbce05a 100644 --- a/library/src/main/res/values/attr.xml +++ b/library/src/main/res/values/attr.xml @@ -9,6 +9,8 @@ + + diff --git a/samples/build.gradle b/samples/build.gradle index 2e799a4..f5fe6b6 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -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" diff --git a/samples/src/main/AndroidManifest.xml b/samples/src/main/AndroidManifest.xml index f6d35ec..7b6ccd2 100644 --- a/samples/src/main/AndroidManifest.xml +++ b/samples/src/main/AndroidManifest.xml @@ -25,7 +25,10 @@ + android:theme="@style/AppTheme.NoActionBar" /> + - + \ No newline at end of file diff --git a/samples/src/main/java/com/sa90/arcdemo/MainActivity.java b/samples/src/main/java/com/sa90/arcdemo/MainActivity.java index 11d7342..379a1fa 100644 --- a/samples/src/main/java/com/sa90/arcdemo/MainActivity.java +++ b/samples/src/main/java/com/sa90/arcdemo/MainActivity.java @@ -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() { @@ -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); + } + }; } diff --git a/samples/src/main/java/com/sa90/arcdemo/TopPlacementSampleActivity.java b/samples/src/main/java/com/sa90/arcdemo/TopPlacementSampleActivity.java new file mode 100644 index 0000000..8c762fa --- /dev/null +++ b/samples/src/main/java/com/sa90/arcdemo/TopPlacementSampleActivity.java @@ -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); + } +} diff --git a/samples/src/main/res/layout/activity_main.xml b/samples/src/main/res/layout/activity_main.xml index 3283cc1..8e44735 100644 --- a/samples/src/main/res/layout/activity_main.xml +++ b/samples/src/main/res/layout/activity_main.xml @@ -45,6 +45,15 @@ android:textColor="@android:color/black" android:textSize="16sp" /> + + + + + + + + + + + + + + + + + + + + + + + + + + +