Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Commit

Permalink
Replace OnFABsMenuUpdateListener with FABsMenuListener
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Aug 22, 2017
1 parent 495ba96 commit 369272f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 60 deletions.
66 changes: 36 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ allprojects {
Next, add the dependency to your `build.gradle`:
```groovy
dependencies {
compile 'me.jahirfiquitiva:FABsMenu:1.0.3'
compile 'me.jahirfiquitiva:FABsMenu:1.0.4'
}
```

Expand All @@ -43,19 +43,20 @@ Then sync the gradle files.
Finally, use it in your layout, just like this:

```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Menu Layout is needed for the overlay to work -->
<!-- Menu Layout is needed for the overlay to work -->
<jahirfiquitiva.libs.fabsmenu.FABsMenuLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
fab:fabs_menu_overlayColor="#4d000000"
fab:fabs_menu_clickableOverlay="true">
<!-- FABs Menu is the main view. It will contain all the items FABs and it create the menu fab itself -->
fab:fabs_menu_overlayColor="#4d000000"
fab:fabs_menu_clickableOverlay="true">

<!-- FABs Menu is the main view. It will contain all the items FABs and it create the menu fab itself -->
<jahirfiquitiva.libs.fabsmenu.FABsMenu
android:id="@+id/fabs_menu"
android:layout_width="wrap_content"
Expand All @@ -70,8 +71,9 @@ Finally, use it in your layout, just like this:
fab:fab_labelsPosition="left"
fab:fab_expandDirection="up">

<!-- This is the item that appears at the top of the menu -->
<!-- This is the item that appears at the top of the menu -->
<jahirfiquitiva.libs.fabsmenu.TitleFAB
android:id="@+id/to_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:srcCompat="@drawable/ic_share"
Expand Down Expand Up @@ -104,7 +106,7 @@ Finally, use it in your layout, just like this:
fab:backgroundTint="@color/blue_semi"
fab:rippleColor="@color/blue_semi_pressed"/>

<!-- This item will appear just above the menu FAB -->
<!-- This item will appear just above the menu FAB -->
<jahirfiquitiva.libs.fabsmenu.TitleFAB
android:id="@+id/green_fab"
android:layout_width="wrap_content"
Expand All @@ -116,7 +118,7 @@ Finally, use it in your layout, just like this:
fab:rippleColor="@color/green_pressed"/>

</jahirfiquitiva.libs.fabsmenu.FABsMenu>

</jahirfiquitiva.libs.fabsmenu.FABsMenuLayout>

</RelativeLayout>
Expand All @@ -125,23 +127,27 @@ Finally, use it in your layout, just like this:
And call the methods in java code:
```java
final FABsMenu menu = findViewById(R.id.fabs_menu);
menu.setMenuUpdateListener(new FABsMenu.OnFABsMenuUpdateListener() {
@Override
public void onMenuClicked() {
showToast("You pressed the menu!");
menu.toggle(); // Expands or collapses the menu depending on its state
}

@Override
public void onMenuExpanded() {
showToast("The menu has been expanded!");
}

@Override
public void onMenuCollapsed() {
showToast("The menu has been collapsed!");
}
});
menu.setMenuUpdateListener(new FABsMenuListener() {
// You don't need to override all methods. Just the ones you want.

@Override
public void onMenuClicked(FABsMenu fabsMenu) {
super.onMenuClicked(fabsMenu); // Default implementation opens the menu on click
showToast("You pressed the menu!");
}

@Override
public void onMenuCollapsed(FABsMenu fabsMenu) {
super.onMenuCollapsed(fabsMenu);
showToast("The menu has been collapsed!");
}

@Override
public void onMenuExpanded(FABsMenu fabsMenu) {
super.onMenuExpanded(fabsMenu);
showToast("The menu has been expanded!");
}
});
```

You can also add or remove buttons programmatically:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.widget.Toast;

import jahirfiquitiva.libs.fabsmenu.FABsMenu;
import jahirfiquitiva.libs.fabsmenu.FABsMenuListener;
import jahirfiquitiva.libs.fabsmenu.TitleFAB;

public class MainActivity extends AppCompatActivity {
Expand All @@ -36,21 +37,25 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

final FABsMenu menu = findViewById(R.id.fabs_menu);
menu.setMenuUpdateListener(new FABsMenu.OnFABsMenuUpdateListener() {
menu.setMenuUpdateListener(new FABsMenuListener() {
// You don't need to override all methods. Just the ones you want.

@Override
public void onMenuClicked() {
public void onMenuClicked(FABsMenu fabsMenu) {
super.onMenuClicked(fabsMenu); // Default implementation opens the menu on click
showToast("You pressed the menu!");
menu.toggle();
}

@Override
public void onMenuExpanded() {
showToast("The menu has been expanded!");
public void onMenuCollapsed(FABsMenu fabsMenu) {
super.onMenuCollapsed(fabsMenu);
showToast("The menu has been collapsed!");
}

@Override
public void onMenuCollapsed() {
showToast("The menu has been collapsed!");
public void onMenuExpanded(FABsMenu fabsMenu) {
super.onMenuExpanded(fabsMenu);
showToast("The menu has been expanded!");
}
});

Expand Down
18 changes: 13 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@
~ limitations under the License.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Menu Layout is needed for the overlay to work -->
<jahirfiquitiva.libs.fabsmenu.FABsMenuLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
fab:fabs_menu_overlayColor="#4d000000"
fab:fabs_menu_clickableOverlay="true">

<!-- FABs Menu is the main view. It will contain all the items FABs and it create the menu fab itself -->
<jahirfiquitiva.libs.fabsmenu.FABsMenu
android:id="@+id/fabs_menu"
android:layout_width="wrap_content"
Expand All @@ -37,6 +42,7 @@
fab:fab_labelsPosition="left"
fab:fab_expandDirection="up">

<!-- This is the item that appears at the top of the menu -->
<jahirfiquitiva.libs.fabsmenu.TitleFAB
android:id="@+id/to_remove"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -71,6 +77,7 @@
fab:backgroundTint="@color/blue_semi"
fab:rippleColor="@color/blue_semi_pressed"/>

<!-- This item will appear just above the menu FAB -->
<jahirfiquitiva.libs.fabsmenu.TitleFAB
android:id="@+id/green_fab"
android:layout_width="wrap_content"
Expand All @@ -82,6 +89,7 @@
fab:rippleColor="@color/green_pressed"/>

</jahirfiquitiva.libs.fabsmenu.FABsMenu>

</jahirfiquitiva.libs.fabsmenu.FABsMenuLayout>

</RelativeLayout>
28 changes: 10 additions & 18 deletions library/src/main/java/jahirfiquitiva/libs/fabsmenu/FABsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class FABsMenu extends ViewGroup {
private int maxButtonWidth;
private int maxButtonHeight;
private TouchDelegateGroup touchDelegateGroup;
private OnFABsMenuUpdateListener menuUpdateListener;
private FABsMenuListener menuListener;

public FABsMenu(Context context) {
this(context, null);
Expand Down Expand Up @@ -188,7 +188,7 @@ private void createAddButton(Context context) {
menuButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (menuUpdateListener != null) menuUpdateListener.onMenuClicked();
if (menuListener != null) menuListener.onMenuClicked(FABsMenu.this);
}
});

Expand Down Expand Up @@ -595,8 +595,8 @@ private void collapse(boolean immediately) {
collapseAnimation.setDuration(immediately ? 0 : animationDuration);
collapseAnimation.start();
expandAnimation.cancel();
if (menuUpdateListener != null) {
menuUpdateListener.onMenuCollapsed();
if (menuListener != null) {
menuListener.onMenuCollapsed(this);
}
}
}
Expand All @@ -616,8 +616,8 @@ public void expand() {
toggleOverlay(true, false);
collapseAnimation.cancel();
expandAnimation.start();
if (menuUpdateListener != null) {
menuUpdateListener.onMenuExpanded();
if (menuListener != null) {
menuListener.onMenuExpanded(this);
}
}
}
Expand Down Expand Up @@ -809,12 +809,12 @@ public void setMaxButtonHeight(int maxButtonHeight) {
this.maxButtonHeight = maxButtonHeight;
}

public OnFABsMenuUpdateListener getMenuUpdateListener() {
return menuUpdateListener;
public FABsMenuListener getMenuListener() {
return menuListener;
}

public void setMenuUpdateListener(OnFABsMenuUpdateListener menuUpdateListener) {
this.menuUpdateListener = menuUpdateListener;
public void setMenuUpdateListener(FABsMenuListener menuListener) {
this.menuListener = menuListener;
}

public void setMenuButtonIcon(@NonNull Bitmap bitmap) {
Expand Down Expand Up @@ -865,14 +865,6 @@ public void setAnimationDuration(int animationDuration) {
public @interface LABELS_POSITION {
}

public interface OnFABsMenuUpdateListener {
void onMenuClicked();

void onMenuExpanded();

void onMenuCollapsed();
}

private static class RotatingDrawable extends LayerDrawable {
private float mRotation;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2017. Jahir Fiquitiva
*
* 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.
*/

package jahirfiquitiva.libs.fabsmenu;

public abstract class FABsMenuListener {
public void onMenuClicked(FABsMenu fabsMenu) {
fabsMenu.toggle();
}

public void onMenuExpanded(FABsMenu fabsMenu) {
}

public void onMenuCollapsed(FABsMenu fabsMenu) {
}
}

0 comments on commit 369272f

Please sign in to comment.