From 88f6647a3a83346b88c7964f14ef11d3b1aaebc3 Mon Sep 17 00:00:00 2001 From: nicolasdesjardins Date: Wed, 3 Dec 2014 13:11:15 -0500 Subject: [PATCH 1/3] Support for View.GONE attribute un subActions and layout to subButtons --- .../library/FloatingActionMenu.java | 101 ++++++++++++------ .../samples/MenuWithFABActivity.java | 19 +++- 2 files changed, 80 insertions(+), 40 deletions(-) diff --git a/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java b/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java index 184897d..cb9b646 100644 --- a/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java +++ b/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java @@ -4,6 +4,7 @@ package com.oguzdev.circularfloatingactionmenu.library; import android.app.Activity; +import android.content.ClipData; import android.content.Context; import android.graphics.Path; import android.graphics.PathMeasure; @@ -88,14 +89,16 @@ public FloatingActionMenu(View mainActionView, // Find items with undefined sizes for(final Item item : subActionItems) { - if(item.width == 0 || item.height == 0) { - // Figure out the size by temporarily adding it to the Activity content view hierarchy - // and ask the size from the system - ((ViewGroup) getActivityContentView()).addView(item.view); - // Make item view invisible, just in case - item.view.setAlpha(0); - // Wait for the right time - item.view.post(new ItemViewQueueListener(item)); + if (View.GONE != item.view.getVisibility()) { + if (item.width == 0 || item.height == 0) { + // Figure out the size by temporarily adding it to the Activity content view hierarchy + // and ask the size from the system + ((ViewGroup) getActivityContentView()).addView(item.view); + // Make item view invisible, just in case + item.view.setAlpha(0); + // Wait for the right time + item.view.post(new ItemViewQueueListener(item)); + } } } } @@ -121,15 +124,19 @@ public void open(boolean animated) { // It is required that these Item views are not currently added to any parent // Because they are supposed to be added to the Activity content view, // just before the animation starts - if (subActionItems.get(i).view.getParent() != null) { - throw new RuntimeException("All of the sub action items have to be independent from a parent."); + Item item = subActionItems.get(i); + if (View.GONE != item.view.getVisibility()) { + if (item.view.getParent() != null) { + throw new RuntimeException("All of the sub action items have to be independent from a parent."); + } + + // Initially, place all items right at the center of the main action view + // Because they are supposed to start animating from that point. + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(item.width, item.height, Gravity.TOP | Gravity.LEFT); + params.setMargins(center.x - item.width / 2, center.y - item.height / 2, 0, 0); + // + ((ViewGroup) getActivityContentView()).addView(item.view, params); } - // Initially, place all items right at the center of the main action view - // Because they are supposed to start animating from that point. - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(subActionItems.get(i).width, subActionItems.get(i).height, Gravity.TOP | Gravity.LEFT); - params.setMargins(center.x - subActionItems.get(i).width / 2, center.y - subActionItems.get(i).height / 2, 0, 0); - // - ((ViewGroup) getActivityContentView()).addView(subActionItems.get(i).view, params); } // Tell the current MenuAnimationHandler to animate from the center animationHandler.animateMenuOpening(center); @@ -137,13 +144,16 @@ public void open(boolean animated) { else { // If animations are disabled, just place each of the items to their calculated destination positions. for (int i = 0; i < subActionItems.size(); i++) { - // This is currently done by giving them large margins - final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(subActionItems.get(i).width, subActionItems.get(i).height, Gravity.TOP | Gravity.LEFT); - params.setMargins(subActionItems.get(i).x, subActionItems.get(i).y, 0, 0); - subActionItems.get(i).view.setLayoutParams(params); - // Because they are placed into the main content view of the Activity, - // which is itself a FrameLayout - ((ViewGroup) getActivityContentView()).addView(subActionItems.get(i).view, params); + Item item = subActionItems.get(i); + if (View.GONE != item.view.getVisibility()) { + // This is currently done by giving them large margins + final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(item.width, item.height, Gravity.TOP | Gravity.LEFT); + params.setMargins(item.x, item.y, 0, 0); + item.view.setLayoutParams(params); + // Because they are placed into the main content view of the Activity, + // which is itself a FrameLayout + ((ViewGroup) getActivityContentView()).addView(item.view, params); + } } } // do not forget to specify that the menu is open. @@ -170,7 +180,10 @@ public void close(boolean animated) { else { // If animations are disabled, just detach each of the Item views from the Activity content view. for (int i = 0; i < subActionItems.size(); i++) { - ((ViewGroup) getActivityContentView()).removeView(subActionItems.get(i).view); + Item item = subActionItems.get(i); + //if (View.GONE != item.view.getVisibility()) { + ((ViewGroup) getActivityContentView()).removeView(item.view); + //} } } // do not forget to specify that the menu is now closed. @@ -215,9 +228,12 @@ public void updateItemPositions() { // Simply update layout params for each item for (int i = 0; i < subActionItems.size(); i++) { // This is currently done by giving them large margins - final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(subActionItems.get(i).width, subActionItems.get(i).height, Gravity.TOP | Gravity.LEFT); - params.setMargins(subActionItems.get(i).x, subActionItems.get(i).y, 0, 0); - subActionItems.get(i).view.setLayoutParams(params); + Item item = subActionItems.get(i); + if (View.GONE != item.view.getVisibility()) { + final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(item.width, item.height, Gravity.TOP | Gravity.LEFT); + params.setMargins(item.x, item.y, 0, 0); + item.view.setLayoutParams(params); + } } } @@ -265,21 +281,36 @@ private void calculateItemPositions() { // Prevent overlapping when it is a full circle int divisor; - if(Math.abs(endAngle - startAngle) >= 360 || subActionItems.size() <= 1) { - divisor = subActionItems.size(); + int size = getVisibleSubActionsCount(); + if(Math.abs(endAngle - startAngle) >= 360 || size <= 1) { + divisor = size; } else { - divisor = subActionItems.size() -1; + divisor = size -1; } // Measure this path, in order to find points that have the same distance between each other for(int i=0; i Date: Fri, 5 Dec 2014 14:09:17 -0500 Subject: [PATCH 2/3] Support for INVISIBLE View (dynamic subActionButtons) --- .../library/FloatingActionMenu.java | 22 ++--- .../animation/DefaultAnimationHandler.java | 85 ++++++++++--------- 2 files changed, 52 insertions(+), 55 deletions(-) diff --git a/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java b/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java index cb9b646..cc3b3e4 100644 --- a/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java +++ b/library/src/main/java/com/oguzdev/circularfloatingactionmenu/library/FloatingActionMenu.java @@ -89,7 +89,6 @@ public FloatingActionMenu(View mainActionView, // Find items with undefined sizes for(final Item item : subActionItems) { - if (View.GONE != item.view.getVisibility()) { if (item.width == 0 || item.height == 0) { // Figure out the size by temporarily adding it to the Activity content view hierarchy // and ask the size from the system @@ -99,7 +98,6 @@ public FloatingActionMenu(View mainActionView, // Wait for the right time item.view.post(new ItemViewQueueListener(item)); } - } } } @@ -125,7 +123,6 @@ public void open(boolean animated) { // Because they are supposed to be added to the Activity content view, // just before the animation starts Item item = subActionItems.get(i); - if (View.GONE != item.view.getVisibility()) { if (item.view.getParent() != null) { throw new RuntimeException("All of the sub action items have to be independent from a parent."); } @@ -136,8 +133,10 @@ public void open(boolean animated) { params.setMargins(center.x - item.width / 2, center.y - item.height / 2, 0, 0); // ((ViewGroup) getActivityContentView()).addView(item.view, params); - } } + + getActivityContentView().invalidate(); + getActivityContentView().requestLayout(); // Tell the current MenuAnimationHandler to animate from the center animationHandler.animateMenuOpening(center); } @@ -145,7 +144,6 @@ public void open(boolean animated) { // If animations are disabled, just place each of the items to their calculated destination positions. for (int i = 0; i < subActionItems.size(); i++) { Item item = subActionItems.get(i); - if (View.GONE != item.view.getVisibility()) { // This is currently done by giving them large margins final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(item.width, item.height, Gravity.TOP | Gravity.LEFT); params.setMargins(item.x, item.y, 0, 0); @@ -153,7 +151,6 @@ public void open(boolean animated) { // Because they are placed into the main content view of the Activity, // which is itself a FrameLayout ((ViewGroup) getActivityContentView()).addView(item.view, params); - } } } // do not forget to specify that the menu is open. @@ -181,9 +178,7 @@ public void close(boolean animated) { // If animations are disabled, just detach each of the Item views from the Activity content view. for (int i = 0; i < subActionItems.size(); i++) { Item item = subActionItems.get(i); - //if (View.GONE != item.view.getVisibility()) { - ((ViewGroup) getActivityContentView()).removeView(item.view); - //} + ((ViewGroup) getActivityContentView()).removeView(item.view); } } // do not forget to specify that the menu is now closed. @@ -229,7 +224,7 @@ public void updateItemPositions() { for (int i = 0; i < subActionItems.size(); i++) { // This is currently done by giving them large margins Item item = subActionItems.get(i); - if (View.GONE != item.view.getVisibility()) { + if (View.INVISIBLE != item.view.getVisibility()) { final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(item.width, item.height, Gravity.TOP | Gravity.LEFT); params.setMargins(item.x, item.y, 0, 0); item.view.setLayoutParams(params); @@ -289,12 +284,13 @@ private void calculateItemPositions() { divisor = size -1; } + int visibleCounter = 0; // Measure this path, in order to find points that have the same distance between each other for(int i=0; i Date: Fri, 5 Dec 2014 14:11:24 -0500 Subject: [PATCH 3/3] Support for INVISIBLE View (dynamic subActionButtons) --- .../circularfloatingactionmenu/samples/MenuWithFABActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/src/main/java/com/oguzdev/circularfloatingactionmenu/samples/MenuWithFABActivity.java b/samples/src/main/java/com/oguzdev/circularfloatingactionmenu/samples/MenuWithFABActivity.java index 1d9e9d9..6169981 100644 --- a/samples/src/main/java/com/oguzdev/circularfloatingactionmenu/samples/MenuWithFABActivity.java +++ b/samples/src/main/java/com/oguzdev/circularfloatingactionmenu/samples/MenuWithFABActivity.java @@ -114,7 +114,7 @@ protected void onCreate(Bundle savedInstanceState) { SubActionButton build4 = lCSubBuilder.setContentView(lcIcon4, blueContentParams).build(); SubActionButton build5 = lCSubBuilder.setContentView(lcIcon5, blueContentParams).build(); - build3.setVisibility(View.GONE); + build3.setVisibility(View.INVISIBLE); FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this) .addSubActionView(build1)