Skip to content

Commit

Permalink
Add interface method to set menuText (#11)
Browse files Browse the repository at this point in the history
* Add FloatingMenu interface

* Revert "Add FloatingMenu interface"

This reverts commit 26c242f.

* add ancestor

* Revert "add ancestor"

This reverts commit ed8b46b.

* Add interface

* add methods to interface

* add another methods to interface

* add clickListeners to interface

* CR fix

* Add override anotations

* Fix high density related bug + better shadow

* CR fix

* Add interface method to set extended menu text

* missing anotations

* Expand/Collapsed menu text added to XML

* remove unneccesary setText methods

* setText methods should stay in ExtendedMenu class
  • Loading branch information
Josef Hruška authored and davidvavra committed Oct 23, 2016
1 parent 4869e35 commit ed43099
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.widget.ImageButton;
import android.widget.TextView;

import static android.R.attr.animation;
import static com.github.clans.fab.FloatingActionButton.SIZE_NORMAL;

/**
Expand Down Expand Up @@ -160,6 +161,26 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
private void initShowAnimation(TypedArray attr) {
int resourceId = attr.getResourceId(R.styleable.FloatingActionButton_fab_showAnimation, R.anim.fab_scale_up);
mShowAnimation = AnimationUtils.loadAnimation(getContext(), resourceId);
mShowAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
ExtendedFloatingActionMenu menu = getActionMenu();
CharSequence menuText = menu.mMenuText.getText().toString();
if (!menuText.equals(menu.extendedButtonTextExpanded)) {
menu.mMenuText.setText(menu.extendedButtonTextExpanded);
}
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
}

private void initHideAnimation(TypedArray attr) {
Expand All @@ -169,6 +190,26 @@ private void initHideAnimation(TypedArray attr) {

private void initHideExtendedAnimation() {
mHideExtendedAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.fab_extended_hide);
mHideExtendedAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
ExtendedFloatingActionMenu menu = getActionMenu();
CharSequence menuText = menu.mMenuText.getText().toString();
if (!menuText.equals(menu.extendedButtonTextCollapsed)) {
menu.mMenuText.setText(menu.extendedButtonTextCollapsed);
}
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
}

private void initReplaceExtendedAnimation() {
Expand Down Expand Up @@ -393,10 +434,6 @@ void playShowAnimation() {
startAnimation(mShowAnimation);
}

void playReplaceExtendedAnimation() {
startAnimation(mReplaceExtendedAnimation);
}

ExtendedFloatingActionMenu getActionMenu() {
return ((ExtendedFloatingActionMenu) getParent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.ArrayList;
import java.util.List;

import static android.R.attr.label;

/**
* Menu class for extended version of FloatingActionMenu
*
Expand All @@ -48,7 +50,8 @@ public class ExtendedFloatingActionMenu extends ViewGroup implements FloatingMen
private AnimatorSet mOpenAnimatorSet = new AnimatorSet();
private AnimatorSet mCloseAnimatorSet = new AnimatorSet();
private AnimatorSet mIconToggleSet;
private String extendedButtonText = null;
protected String extendedButtonTextCollapsed = null;
protected String extendedButtonTextExpanded = null;
private int mExtendedButtonTextColor = 0;
private int mExtendedButtonBackgroundColor;
private int mExtendedButtonTextSize = 0;
Expand Down Expand Up @@ -89,7 +92,7 @@ public class ExtendedFloatingActionMenu extends ViewGroup implements FloatingMen
private Typeface mCustomTypefaceFromFont;
private boolean mIconAnimated = true;
private ImageView mImageToggle;
private TextView mMenuText;
protected TextView mMenuText;
private Animation mMenuButtonShowAnimation;
private Animation mMenuButtonHideAnimation;
private Animation mImageToggleShowAnimation;
Expand Down Expand Up @@ -122,7 +125,8 @@ public ExtendedFloatingActionMenu(Context context, AttributeSet attrs, int defSt

private void init(Context context, AttributeSet attrs) {
TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0);
extendedButtonText = attr.getString(R.styleable.FloatingActionMenu_menu_extendedButtonText);
extendedButtonTextExpanded = attr.getString(R.styleable.FloatingActionMenu_menu_extendedButtonTextExpanded);
extendedButtonTextCollapsed = attr.getString(R.styleable.FloatingActionMenu_menu_extendedButtonTextCollapsed);
mExtendedButtonTextColor = attr.getInt(R.styleable.FloatingActionMenu_menu_extendedButtonTextColor, Color.WHITE);
mExtendedButtonBackgroundColor = attr.getInt(R.styleable.FloatingActionMenu_menu_extendedButtonTextColor, Color.WHITE);
mExtendedButtonTextSize = attr.getInt(R.styleable.FloatingActionMenu_menu_extendedButtonTextSize, 16);
Expand Down Expand Up @@ -256,7 +260,7 @@ private void createExtendedMenuButton() { // Create wide (extended) menu button

mMenuText = new TextView(getContext());
mMenuText.setTypeface(null, Typeface.BOLD);
mMenuText.setText(extendedButtonText);
mMenuText.setText(extendedButtonTextCollapsed);
mMenuText.setTextSize(mExtendedButtonTextSize);
mMenuText.setTextColor(mExtendedButtonTextColor);

Expand Down Expand Up @@ -705,6 +709,10 @@ public void run() {
}
}

if (!animate) {
mMenuText.setText(extendedButtonTextExpanded);
}

mUiHandler.postDelayed(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -757,6 +765,9 @@ public void run() {
delay += mAnimationDelayPerItem;
}
}
if (!animate) {
mMenuText.setText(extendedButtonTextExpanded);
}

mUiHandler.postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -1042,9 +1053,13 @@ public void removeMenuButton(ExtendedFloatingActionButton fab) {
removeView(fab);
mButtonsCount--;
}

public void setExtendedButtonTextCollapsed(String menuText) {
extendedButtonTextCollapsed = menuText;
}

public void setExtendedButtonText(String menuText) {
extendedButtonText = menuText;
public void setExtendedButtonTextExpanded(String menuText) {
extendedButtonTextExpanded = menuText;
}

public void setmExtendedButtonTextColor(int menuTextColor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

<declare-styleable name="FloatingActionMenu">
<attr name="menu_isExtended" format="boolean" />
<attr name="menu_extendedButtonText" format="string" />
<attr name="menu_extendedButtonTextCollapsed" format="string" />
<attr name="menu_extendedButtonTextExpanded" format="string" />
<attr name="menu_extendedButtonTextColor" format="integer" />
<attr name="menu_extendedButtonBackgroundColor" format="integer" />
<attr name="menu_extendedButtonTextSize" format="integer" />
Expand Down
6 changes: 4 additions & 2 deletions sample/src/main/res/layout/home_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
android:paddingRight="24dp"
android:src="@drawable/ic_drawing"
app:menu_backgroundColor="@color/black_a160"
app:menu_extendedButtonText="Add new expense"
app:menu_extendedButtonTextExpanded="IM EXPANDED"
app:menu_extendedButtonTextCollapsed="IM COLLAPSED"
app:menu_fab_label="MENU 1"
app:menu_labels_margin="20dp">

Expand Down Expand Up @@ -50,7 +51,8 @@
android:paddingRight="24dp"
android:src="@drawable/ic_drawing"
app:menu_backgroundColor="@color/black_a160"
app:menu_extendedButtonText="Add new expense"
app:menu_extendedButtonTextExpanded="IM EXPANDED"
app:menu_extendedButtonTextCollapsed="IM COLLAPSED"
app:menu_fab_label="MENU 2">

<com.github.clans.fab.ExtendedFloatingActionButton
Expand Down

0 comments on commit ed43099

Please sign in to comment.