Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Add support for INVISIBLE views. (enables dynamic subActions visibility) #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Support for INVISIBLE View (dynamic subActionButtons)
  • Loading branch information
ndesjardinsfic committed Dec 5, 2014
commit e58aacc7cda27a2504e703d67dba154e3be1ad44
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -99,7 +98,6 @@ public FloatingActionMenu(View mainActionView,
// Wait for the right time
item.view.post(new ItemViewQueueListener(item));
}
}
}
}

Expand All @@ -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.");
}
Expand All @@ -136,24 +133,24 @@ 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);
}
else {
// 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);
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<subActionItems.size(); i++) {
Item item = subActionItems.get(i);
if (View.GONE != item.view.getVisibility()) {
if (View.INVISIBLE != item.view.getVisibility()) {
float[] coords = new float[] {0f, 0f};
measure.getPosTan((i) * measure.getLength() / divisor, coords, null);
measure.getPosTan((visibleCounter++) * measure.getLength() / divisor, coords, null);
// get the x and y values of these points and set them to each of sub action items.
item.x = (int) coords[0] - item.width / 2;
item.y = (int) coords[1] - item.height / 2;
Expand All @@ -306,7 +302,7 @@ private int getVisibleSubActionsCount() {
int size = 0;
for(int i=0; i<subActionItems.size(); i++) {
Item item = subActionItems.get(i);
if (View.GONE != item.view.getVisibility()) {
if (View.INVISIBLE != item.view.getVisibility()) {
size ++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ public void animateMenuOpening(Point center) {

Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {

menu.getSubActionItems().get(i).view.setScaleX(0);
menu.getSubActionItems().get(i).view.setScaleY(0);
menu.getSubActionItems().get(i).view.setAlpha(0);

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new OvershootInterpolator(0.9f));
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));

if(i == 0) {
lastAnimation = animation;
}

// Put a slight lag between each of the menu items to make it asymmetric
animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
animation.start();
FloatingActionMenu.Item item = menu.getSubActionItems().get(i);
item.view.setScaleX(0);
item.view.setScaleY(0);
item.view.setAlpha(0);

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, item.x - center.x + item.width / 2);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, item.y - center.y + item.height / 2);
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(item.view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new OvershootInterpolator(0.9f));
animation.addListener(new SubActionItemAnimationListener(item, ActionType.OPENING));

if (i == 0) {
lastAnimation = animation;
}

// Put a slight lag between each of the menu items to make it asymmetric
animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
animation.start();
}
if(lastAnimation != null) {
lastAnimation.addListener(new LastAnimationListener());
Expand All @@ -77,24 +77,25 @@ public void animateMenuClosing(Point center) {

Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, - (menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2));
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));

if(i == 0) {
lastAnimation = animation;
}

animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
animation.start();
FloatingActionMenu.Item item = menu.getSubActionItems().get(i);
PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, -(item.x - center.x + item.width / 2));
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(item.y - center.y + item.height / 2));
PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -720);
PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(item.view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
animation.addListener(new SubActionItemAnimationListener(item, ActionType.CLOSING));

if (i == 0) {
lastAnimation = animation;
}

animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
animation.start();
}
if(lastAnimation != null) {
lastAnimation.addListener(new LastAnimationListener());
Expand Down