diff --git a/gradle.properties b/gradle.properties index 2e6a6c0..ccfa213 100755 --- a/gradle.properties +++ b/gradle.properties @@ -17,8 +17,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=1.6.4 -VERSION_CODE=10604 +VERSION_NAME=1.6.4-mod2 +VERSION_CODE=1060402 GROUP=com.github.clans POM_DESCRIPTION=Floating Action Button implementation for Android diff --git a/library/build.gradle b/library/build.gradle index 5493a7b..9695295 100755 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "23.0.3" defaultConfig { - minSdkVersion 14 + minSdkVersion 23 targetSdkVersion 23 versionCode Integer.parseInt(project.VERSION_CODE) versionName project.VERSION_NAME diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java index 0b80e4c..763428b 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java @@ -1,5 +1,6 @@ package com.github.clans.fab; +import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; @@ -22,6 +23,7 @@ import android.view.animation.AnimationUtils; import android.view.animation.AnticipateInterpolator; import android.view.animation.Interpolator; +import android.view.animation.LinearInterpolator; import android.view.animation.OvershootInterpolator; import android.widget.ImageView; @@ -30,7 +32,11 @@ public class FloatingActionMenu extends ViewGroup { - private static final int ANIMATION_DURATION = 300; + private String tag; + + public static final int TOTAL_ANIMATION_DURATION = 300; // Netscout change: made public + public static final int DEFAULT_ANIMATION_DELAY_PER_ITEM = 50; // Netscout change: new field + private static final float CLOSED_PLUS_ROTATION = 0f; private static final float OPENED_PLUS_ROTATION_LEFT = -90f - 45f; private static final float OPENED_PLUS_ROTATION_RIGHT = 90f + 45f; @@ -75,8 +81,9 @@ public class FloatingActionMenu extends ViewGroup { private int mMenuColorNormal; private int mMenuColorPressed; private int mMenuColorRipple; - private Drawable mIcon; - private int mAnimationDelayPerItem; + private Drawable mOpenIcon; // Netscout change: can now be set at runtime, and open & close icons replace single (rotating) toggle icon + private Drawable mCloseIcon; // Netscout change: use this instead of the rotated mIcon. + private int mAnimationDelayPerItem = DEFAULT_ANIMATION_DELAY_PER_ITEM; // Netscout addition: default value private Interpolator mOpenInterpolator; private Interpolator mCloseInterpolator; private boolean mIsAnimated = true; @@ -87,7 +94,8 @@ public class FloatingActionMenu extends ViewGroup { private int mLabelsStyle; private Typeface mCustomTypefaceFromFont; private boolean mIconAnimated = true; - private ImageView mImageToggle; + private ImageView mImageOpenButton; // Netscout: changed from mImageToggle + private ImageView mImageCloseButton; // Netscout: added private Animation mMenuButtonShowAnimation; private Animation mMenuButtonHideAnimation; private Animation mImageToggleShowAnimation; @@ -95,7 +103,9 @@ public class FloatingActionMenu extends ViewGroup { private boolean mIsMenuButtonAnimationRunning; private boolean mIsSetClosedOnTouchOutside; private int mOpenDirection; - private OnMenuToggleListener mToggleListener; + // Netscout addition: FAM originally only supported a toggle listener which fired when finished + private OnMenuToggleStartedListener mToggleStartedListener; + private OnMenuToggleFinishedListener mToggleFinishedListener; private ValueAnimator mShowBackgroundAnimator; private ValueAnimator mHideBackgroundAnimator; @@ -106,8 +116,13 @@ public class FloatingActionMenu extends ViewGroup { private String mMenuLabelText; private boolean mUsingMenuLabel; - public interface OnMenuToggleListener { - void onMenuToggle(boolean opened); + // Netscout addition: FAM originally only supported a toggle listener which fired when finished + public interface OnMenuToggleStartedListener { + void onMenuToggleStarted(boolean opened); + } + + public interface OnMenuToggleFinishedListener { + void onMenuToggleFinished(boolean opened); } public FloatingActionMenu(Context context) { @@ -155,10 +170,13 @@ private void init(Context context, AttributeSet attrs) { mMenuColorNormal = attr.getColor(R.styleable.FloatingActionMenu_menu_colorNormal, 0xFFDA4336); mMenuColorPressed = attr.getColor(R.styleable.FloatingActionMenu_menu_colorPressed, 0xFFE75043); mMenuColorRipple = attr.getColor(R.styleable.FloatingActionMenu_menu_colorRipple, 0x99FFFFFF); - mAnimationDelayPerItem = attr.getInt(R.styleable.FloatingActionMenu_menu_animationDelayPerItem, 50); - mIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_icon); - if (mIcon == null) { - mIcon = getResources().getDrawable(R.drawable.fab_add); + mOpenIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_open_icon); + if (mOpenIcon == null) { + mOpenIcon = getResources().getDrawable(R.drawable.fab_add); + } + mCloseIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_close_icon); + if (mCloseIcon == null) { + mCloseIcon = getResources().getDrawable(R.drawable.fab_add); } mLabelsSingleLine = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_singleLine, false); mLabelsEllipsize = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_ellipsize, 0); @@ -186,8 +204,8 @@ private void init(Context context, AttributeSet attrs) { initPadding(padding); } - mOpenInterpolator = new OvershootInterpolator(); - mCloseInterpolator = new AnticipateInterpolator(); + mOpenInterpolator = new LinearInterpolator(); + mCloseInterpolator = new LinearInterpolator(); mLabelsContext = new ContextThemeWrapper(getContext(), mLabelsStyle); initBackgroundDimAnimation(); @@ -214,7 +232,7 @@ private void initBackgroundDimAnimation() { final int blue = Color.blue(mBackgroundColor); mShowBackgroundAnimator = ValueAnimator.ofInt(0, maxAlpha); - mShowBackgroundAnimator.setDuration(ANIMATION_DURATION); + mShowBackgroundAnimator.setDuration(TOTAL_ANIMATION_DURATION); mShowBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -224,7 +242,7 @@ public void onAnimationUpdate(ValueAnimator animation) { }); mHideBackgroundAnimator = ValueAnimator.ofInt(maxAlpha, 0); - mHideBackgroundAnimator.setDuration(ANIMATION_DURATION); + mHideBackgroundAnimator.setDuration(TOTAL_ANIMATION_DURATION); mHideBackgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -260,15 +278,25 @@ private void createMenuButton() { mMenuButton.updateBackground(); mMenuButton.setLabelText(mMenuLabelText); - mImageToggle = new ImageView(getContext()); - mImageToggle.setImageDrawable(mIcon); + mImageOpenButton = new ImageView(getContext()); + mImageOpenButton.setImageDrawable(mOpenIcon); + + mImageCloseButton = new ImageView(getContext()); + mImageCloseButton.setImageDrawable(mCloseIcon); addView(mMenuButton, super.generateDefaultLayoutParams()); - addView(mImageToggle); + + addView(mImageOpenButton); + addView(mImageCloseButton); + mImageCloseButton.bringToFront(); + mImageCloseButton.setImageAlpha(0); // We will fade this in using an animation createDefaultIconAnimation(); } + // Keep the rotation animation, but add to it a transparency transition where the open button + // fades to transparent and the close button fades to opaque when it opens (and the reverse when + // it closes). private void createDefaultIconAnimation() { float collapseAngle; float expandAngle; @@ -280,28 +308,70 @@ private void createDefaultIconAnimation() { expandAngle = mLabelsPosition == LABELS_POSITION_LEFT ? OPENED_PLUS_ROTATION_RIGHT : OPENED_PLUS_ROTATION_LEFT; } - ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat( - mImageToggle, + ObjectAnimator collapseCloseButtonRotationAnimator = ObjectAnimator.ofFloat( + mImageCloseButton, "rotation", collapseAngle, CLOSED_PLUS_ROTATION ); - ObjectAnimator expandAnimator = ObjectAnimator.ofFloat( - mImageToggle, + ObjectAnimator collapseOpenButtonRotationAnimator = ObjectAnimator.ofFloat( + mImageOpenButton, + "rotation", + collapseAngle, + CLOSED_PLUS_ROTATION + ); + + ObjectAnimator collapseCloseButtonAlphaAnimator = ObjectAnimator.ofInt( + mImageCloseButton, + "imageAlpha", + 255, + 0 + ); + + ObjectAnimator collapseOpenButtonAlphaAnimator = ObjectAnimator.ofInt( + mImageOpenButton, + "imageAlpha", + 0, + 255 + ); + + ObjectAnimator expandCloseButtonAlphaAnimator = ObjectAnimator.ofInt( + mImageCloseButton, + "imageAlpha", + 0, + 255 + ); + + ObjectAnimator expandOpenButtonAlphaAnimator = ObjectAnimator.ofInt( + mImageOpenButton, + "imageAlpha", + 255, + 0 + ); + + ObjectAnimator expandOpenButtonRotationAnimator = ObjectAnimator.ofFloat( + mImageOpenButton, + "rotation", + CLOSED_PLUS_ROTATION, + expandAngle + ); + + ObjectAnimator expandCloseButtonRotationAnimator = ObjectAnimator.ofFloat( + mImageCloseButton, "rotation", CLOSED_PLUS_ROTATION, expandAngle ); - mOpenAnimatorSet.play(expandAnimator); - mCloseAnimatorSet.play(collapseAnimator); + mOpenAnimatorSet.playTogether(expandCloseButtonRotationAnimator, expandOpenButtonRotationAnimator, expandCloseButtonAlphaAnimator, expandOpenButtonAlphaAnimator ); + mCloseAnimatorSet.playTogether(collapseCloseButtonRotationAnimator, collapseOpenButtonRotationAnimator, collapseCloseButtonAlphaAnimator, collapseOpenButtonAlphaAnimator ); mOpenAnimatorSet.setInterpolator(mOpenInterpolator); mCloseAnimatorSet.setInterpolator(mCloseInterpolator); - mOpenAnimatorSet.setDuration(ANIMATION_DURATION); - mCloseAnimatorSet.setDuration(ANIMATION_DURATION); + mOpenAnimatorSet.setDuration(TOTAL_ANIMATION_DURATION); + mCloseAnimatorSet.setDuration(TOTAL_ANIMATION_DURATION); } @Override @@ -311,12 +381,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mMaxButtonWidth = 0; int maxLabelWidth = 0; - measureChildWithMargins(mImageToggle, widthMeasureSpec, 0, heightMeasureSpec, 0); + measureChildWithMargins(mImageOpenButton, widthMeasureSpec, 0, heightMeasureSpec, 0); + measureChildWithMargins(mImageCloseButton, widthMeasureSpec, 0, heightMeasureSpec, 0); for (int i = 0; i < mButtonsCount; i++) { View child = getChildAt(i); - if (child.getVisibility() == GONE || child == mImageToggle) continue; + if (child.getVisibility() == GONE || child == mImageOpenButton || child == mImageCloseButton) continue; measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); mMaxButtonWidth = Math.max(mMaxButtonWidth, child.getMeasuredWidth()); @@ -326,7 +397,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int usedWidth = 0; View child = getChildAt(i); - if (child.getVisibility() == GONE || child == mImageToggle) continue; + if (child.getVisibility() == GONE || child == mImageOpenButton || child == mImageCloseButton) continue; usedWidth += child.getMeasuredWidth(); height += child.getMeasuredHeight(); @@ -372,11 +443,14 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { mMenuButton.layout(menuButtonLeft, menuButtonTop, menuButtonLeft + mMenuButton.getMeasuredWidth(), menuButtonTop + mMenuButton.getMeasuredHeight()); - int imageLeft = buttonsHorizontalCenter - mImageToggle.getMeasuredWidth() / 2; - int imageTop = menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageToggle.getMeasuredHeight() / 2; + int imageLeft = buttonsHorizontalCenter - mImageOpenButton.getMeasuredWidth() / 2; + int imageTop = menuButtonTop + mMenuButton.getMeasuredHeight() / 2 - mImageOpenButton.getMeasuredHeight() / 2; - mImageToggle.layout(imageLeft, imageTop, imageLeft + mImageToggle.getMeasuredWidth(), - imageTop + mImageToggle.getMeasuredHeight()); + mImageOpenButton.layout(imageLeft, imageTop, imageLeft + mImageOpenButton.getMeasuredWidth(), + imageTop + mImageOpenButton.getMeasuredHeight()); + + mImageCloseButton.layout(imageLeft, imageTop, imageLeft + mImageOpenButton.getMeasuredWidth(), + imageTop + mImageOpenButton.getMeasuredHeight()); int nextY = openUp ? menuButtonTop + mMenuButton.getMeasuredHeight() + mButtonSpacing @@ -385,8 +459,9 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { for (int i = mButtonsCount - 1; i >= 0; i--) { View child = getChildAt(i); - if (child == mImageToggle) continue; + if (child == mImageCloseButton || child == mImageOpenButton) continue; + if (!(child instanceof FloatingActionButton)) continue; FloatingActionButton fab = (FloatingActionButton) child; if (fab.getVisibility() == GONE) continue; @@ -446,15 +521,16 @@ private int adjustForOvershoot(int dimension) { protected void onFinishInflate() { super.onFinishInflate(); bringChildToFront(mMenuButton); - bringChildToFront(mImageToggle); - mButtonsCount = getChildCount(); + bringChildToFront(mImageOpenButton); + bringChildToFront(mImageCloseButton); + mButtonsCount = getChildCount() - 1; // Netscout change: adjusted for extra (i.e. close) button! createLabels(); } private void createLabels() { for (int i = 0; i < mButtonsCount; i++) { - if (getChildAt(i) == mImageToggle) continue; + if (getChildAt(i) == mImageCloseButton || getChildAt(i) == mImageOpenButton) continue; final FloatingActionButton fab = (FloatingActionButton) getChildAt(i); @@ -524,6 +600,7 @@ private void addLabel(FloatingActionButton fab) { label.setTypeface(mCustomTypefaceFromFont); } label.setText(text); + label.setId(fab.getId()); label.setOnClickListener(fab.getOnClickListener()); addView(label); @@ -572,9 +649,11 @@ private void hideMenuButtonWithImage(boolean animate) { if (!isMenuButtonHidden()) { mMenuButton.hide(animate); if (animate) { - mImageToggle.startAnimation(mImageToggleHideAnimation); + mImageCloseButton.startAnimation(mImageToggleHideAnimation); + mImageOpenButton.startAnimation(mImageToggleHideAnimation); } - mImageToggle.setVisibility(INVISIBLE); + mImageCloseButton.setVisibility(INVISIBLE); + mImageOpenButton.setVisibility(INVISIBLE); mIsMenuButtonAnimationRunning = false; } } @@ -583,9 +662,11 @@ private void showMenuButtonWithImage(boolean animate) { if (isMenuButtonHidden()) { mMenuButton.show(animate); if (animate) { - mImageToggle.startAnimation(mImageToggleShowAnimation); + mImageCloseButton.startAnimation(mImageToggleShowAnimation); + mImageOpenButton.startAnimation(mImageToggleShowAnimation); } - mImageToggle.setVisibility(VISIBLE); + mImageCloseButton.setVisibility(VISIBLE); + mImageOpenButton.setVisibility(VISIBLE); } } @@ -637,6 +718,11 @@ public void open(final boolean animate) { } } + // Netscout addition: + if (mToggleStartedListener != null) { + mToggleStartedListener.onMenuToggleStarted(true); + } + int delay = 0; int counter = 0; mIsMenuOpening = true; @@ -670,8 +756,8 @@ public void run() { public void run() { mMenuOpened = true; - if (mToggleListener != null) { - mToggleListener.onMenuToggle(true); + if (mToggleFinishedListener != null) { + mToggleFinishedListener.onMenuToggleFinished(true); } } }, ++counter * mAnimationDelayPerItem); @@ -693,6 +779,11 @@ public void close(final boolean animate) { } } + // Netscout addition: + if (mToggleStartedListener != null) { + mToggleStartedListener.onMenuToggleStarted(false); + } + int delay = 0; int counter = 0; mIsMenuOpening = false; @@ -726,8 +817,8 @@ public void run() { public void run() { mMenuOpened = false; - if (mToggleListener != null) { - mToggleListener.onMenuToggle(false); + if (mToggleFinishedListener != null) { + mToggleFinishedListener.onMenuToggleFinished(false); } } }, ++counter * mAnimationDelayPerItem); @@ -759,24 +850,24 @@ public void setIconAnimationCloseInterpolator(Interpolator closeInterpolator) { */ public void setAnimated(boolean animated) { mIsAnimated = animated; - mOpenAnimatorSet.setDuration(animated ? ANIMATION_DURATION : 0); - mCloseAnimatorSet.setDuration(animated ? ANIMATION_DURATION : 0); + mOpenAnimatorSet.setDuration(animated ? TOTAL_ANIMATION_DURATION : 0); + mCloseAnimatorSet.setDuration(animated ? TOTAL_ANIMATION_DURATION : 0); } public boolean isAnimated() { return mIsAnimated; } - public void setAnimationDelayPerItem(int animationDelayPerItem) { - mAnimationDelayPerItem = animationDelayPerItem; - } - public int getAnimationDelayPerItem() { return mAnimationDelayPerItem; } - public void setOnMenuToggleListener(OnMenuToggleListener listener) { - mToggleListener = listener; + public void setOnMenuToggleStartedListener(OnMenuToggleStartedListener listener) { + mToggleStartedListener = listener; + } + + public void setOnMenuToggleFinishedListener(OnMenuToggleFinishedListener listener) { + mToggleFinishedListener = listener; } public void setIconAnimated(boolean animated) { @@ -787,8 +878,9 @@ public boolean isIconAnimated() { return mIconAnimated; } + // NJA: This is probably broken with the latest animation changes public ImageView getMenuIconView() { - return mImageToggle; + return mImageOpenButton; } public void setIconToggleAnimatorSet(AnimatorSet toggleAnimatorSet) { @@ -912,6 +1004,9 @@ public void toggleMenuButton(boolean animate) { } } + // NJA: Note on setClosedOnTouchOutside(): this caused a weird flicker in our + // FAM-with-overflow. A better way to get the same effect is to make the scrim's onClick() + // handler (which we'll presumably keep using) close them. public void setClosedOnTouchOutside(boolean close) { mIsSetClosedOnTouchOutside = close; } @@ -958,16 +1053,27 @@ public int getMenuButtonColorRipple() { return mMenuColorRipple; } + // Netscout addition: enforce delay-per-item to be total delay divided by # of buttons + private void updateAnimationDelay() { + // NJA: hacking the per-item animation to delay to be a little quicker so we have a little + // buffer period before post-animation stuff happens (which is in onAnimationEnd() in our + // FAM-with-overflow) code) + if (mButtonsCount > 0) mAnimationDelayPerItem = (90 * TOTAL_ANIMATION_DURATION / 100)/mButtonsCount; + else mAnimationDelayPerItem = DEFAULT_ANIMATION_DELAY_PER_ITEM; + } + public void addMenuButton(FloatingActionButton fab) { addView(fab, mButtonsCount - 2); mButtonsCount++; addLabel(fab); + updateAnimationDelay(); } public void removeMenuButton(FloatingActionButton fab) { removeView(fab.getLabelView()); removeView(fab); mButtonsCount--; + updateAnimationDelay(); } public void addMenuButton(FloatingActionButton fab, int index) { @@ -981,15 +1087,16 @@ public void addMenuButton(FloatingActionButton fab, int index) { addView(fab, index); mButtonsCount++; addLabel(fab); + updateAnimationDelay(); } public void removeAllMenuButtons() { close(true); - + List viewsToRemove = new ArrayList<>(); for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); - if (v != mMenuButton && v != mImageToggle && v instanceof FloatingActionButton) { + if (v != mMenuButton && v != mImageCloseButton && v != mImageOpenButton && v instanceof FloatingActionButton) { viewsToRemove.add((FloatingActionButton) v); } } @@ -1013,4 +1120,50 @@ public void setOnMenuButtonClickListener(OnClickListener clickListener) { public void setOnMenuButtonLongClickListener(OnLongClickListener longClickListener) { mMenuButton.setOnLongClickListener(longClickListener); } + + // Netscout addition + public void setCloseAnimationListener(Animator.AnimatorListener listener) { + mCloseAnimatorSet.addListener(listener); + } + + // Netscout addition + public void setOpenAnimationListener(Animator.AnimatorListener listener) { + mOpenAnimatorSet.addListener(listener); + } + + // Netscout addition + public String getTag() { + return tag; + } + + // Netscout addition + public void setTag(String tag1) { + this.tag = tag; + } + + // Netscout addition + public Drawable getOpenIcon() { + return mOpenIcon; + } + + // Netscout addition + public Drawable getCloseIcon() { + return mCloseIcon; + } + + // Netscout addition + public void setOpenIcon(Drawable icon) { + mOpenIcon = icon; + mImageOpenButton.setImageDrawable(mOpenIcon); + } + + // Netscout addition + public void setCloseIcon(Drawable icon) { + mCloseIcon = icon; + mImageCloseButton.setImageDrawable(mCloseIcon); + } + + public ImageView getOpenButton() { + return mImageOpenButton; + } } diff --git a/library/src/main/java/com/github/clans/fab/Label.java b/library/src/main/java/com/github/clans/fab/Label.java index 7d689cb..ababf7f 100755 --- a/library/src/main/java/com/github/clans/fab/Label.java +++ b/library/src/main/java/com/github/clans/fab/Label.java @@ -19,6 +19,7 @@ import android.graphics.drawable.shapes.RoundRectShape; import android.os.Build; import android.util.AttributeSet; + import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; @@ -293,7 +294,6 @@ public boolean onTouchEvent(MotionEvent event) { onActionUp(); mFab.onActionUp(); break; - case MotionEvent.ACTION_CANCEL: onActionUp(); mFab.onActionUp(); @@ -301,6 +301,7 @@ public boolean onTouchEvent(MotionEvent event) { } mGestureDetector.onTouchEvent(event); + return super.onTouchEvent(event); } diff --git a/library/src/main/res/drawable-hdpi/ic_common_more_horiz_white_36dp.png b/library/src/main/res/drawable-hdpi/ic_common_more_horiz_white_36dp.png new file mode 100644 index 0000000..09aa9d5 Binary files /dev/null and b/library/src/main/res/drawable-hdpi/ic_common_more_horiz_white_36dp.png differ diff --git a/library/src/main/res/drawable-hdpi/ic_common_settings_white_36dp.png b/library/src/main/res/drawable-hdpi/ic_common_settings_white_36dp.png new file mode 100644 index 0000000..87cd2f0 Binary files /dev/null and b/library/src/main/res/drawable-hdpi/ic_common_settings_white_36dp.png differ diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index a88bc79..3fa15da 100755 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -49,7 +49,8 @@ - + + diff --git a/library/src/main/res/values/ids.xml b/library/src/main/res/values/ids.xml index 28a9fb1..81dd6b7 100755 --- a/library/src/main/res/values/ids.xml +++ b/library/src/main/res/values/ids.xml @@ -1,4 +1,9 @@ + + + + + \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 0ed7dcc..a16727c 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "com.github.fab.sample" - minSdkVersion 14 + minSdkVersion 23 targetSdkVersion 23 versionCode Integer.parseInt(project.VERSION_CODE) versionName project.VERSION_NAME diff --git a/sample/src/main/java/com/github/clans/fab/sample/MenusFragment.java b/sample/src/main/java/com/github/clans/fab/sample/MenusFragment.java index af0a82c..7da4b37 100644 --- a/sample/src/main/java/com/github/clans/fab/sample/MenusFragment.java +++ b/sample/src/main/java/com/github/clans/fab/sample/MenusFragment.java @@ -24,12 +24,36 @@ import java.util.ArrayList; import java.util.List; +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; + public class MenusFragment extends Fragment { + public class FabMenuItem { + public int textId = -1; + public int iconId = -1; + @SuppressWarnings("WeakerAccess") public int itemId = -1; + + @SuppressWarnings("WeakerAccess") public FabMenuItem(int itemId, int textId, int iconId) { + this.itemId = itemId; + this.textId = textId; + this.iconId = iconId; + } + }; + + public FabMenuItem FAB_MENU_ITEM_ADD_TO_AUTOTEST = new FabMenuItem(R.id.fabMenuItem_test_common_addToAutoTest, + R.string.common_test_Add_to_AutoTest, R.drawable.ic_common_settings_white_36dp); + + public FabMenuItem FAB_MENU_ITEM_BROWSE = new FabMenuItem(R.id.fabMenuItem_test_common_browse, + R.string.common_test_Browse, R.drawable.ic_common_settings_white_36dp); + + public FabMenuItem FAB_MENU_ITEM_MORE = new FabMenuItem(R.id.fabMenuItem_test_menu_more, + R.string.common_test_More, R.drawable.ic_common_more_horiz_white_36dp); + private FloatingActionMenu menuRed; private FloatingActionMenu menuYellow; private FloatingActionMenu menuGreen; private FloatingActionMenu menuBlue; + private FloatingActionMenu menuFabPrimaryMenu; private FloatingActionMenu menuDown; private FloatingActionMenu menuLabelsRight; @@ -48,6 +72,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa return inflater.inflate(R.layout.menus_fragment, container, false); } + private void styleFab(FloatingActionButton fab) { + fab.setColorNormal(getContext().getColor(R.color.fab_color)); + fab.setColorPressed(getContext().getColor(R.color.fab_color)); + fab.setButtonSize(FloatingActionButton.SIZE_MINI); + } + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -56,6 +86,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { menuYellow = (FloatingActionMenu) view.findViewById(R.id.menu_yellow); menuGreen = (FloatingActionMenu) view.findViewById(R.id.menu_green); menuBlue = (FloatingActionMenu) view.findViewById(R.id.menu_blue); + menuFabPrimaryMenu = (FloatingActionMenu) view.findViewById(R.id.fab_primary_menu); menuDown = (FloatingActionMenu) view.findViewById(R.id.menu_down); menuLabelsRight = (FloatingActionMenu) view.findViewById(R.id.menu_labels_right); @@ -93,6 +124,29 @@ public void onClick(View v) { menuYellow.hideMenuButton(false); menuGreen.hideMenuButton(false); menuBlue.hideMenuButton(false); + + // Initialize stand-in Andromeda FAM: + List primaryFabContents = new ArrayList<>(); + primaryFabContents.add(FAB_MENU_ITEM_ADD_TO_AUTOTEST); + primaryFabContents.add(FAB_MENU_ITEM_BROWSE); + primaryFabContents.add(FAB_MENU_ITEM_MORE); + + for (FabMenuItem fabMenuItem : primaryFabContents) { + FloatingActionButton fab = new FloatingActionButton(getContext()); + fab.setImageDrawable(getContext().getDrawable(fabMenuItem.iconId)); + fab.setLabelText(getContext().getString(fabMenuItem.textId)); + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); + + fab.setLayoutParams(lp); + fab.setId(fabMenuItem.itemId); + styleFab(fab); + menuFabPrimaryMenu.addMenuButton(fab); + } + + menuFabPrimaryMenu.setOpenIcon(getContext().getDrawable(R.drawable.ic_star)); + + menuFabPrimaryMenu.setVisibility(View.VISIBLE); + menuLabelsRight.hideMenuButton(false); fabEdit = (FloatingActionButton) view.findViewById(R.id.fab_edit); @@ -109,11 +163,12 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { menus.add(menuYellow); menus.add(menuGreen); menus.add(menuBlue); + menus.add(menuFabPrimaryMenu); menus.add(menuLabelsRight); - menuYellow.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() { + menuYellow.setOnMenuToggleFinishedListener(new FloatingActionMenu.OnMenuToggleFinishedListener() { @Override - public void onMenuToggle(boolean opened) { + public void onMenuToggleFinished(boolean opened) { String text; if (opened) { text = "Menu opened"; @@ -157,7 +212,8 @@ public void onClick(View v) { } }); - createCustomAnimation(); + // createCustomAnimation(); // Netscout change: disable this so we can test with the + // green menu. } private void createCustomAnimation() { diff --git a/sample/src/main/res/layout/menus_fragment.xml b/sample/src/main/res/layout/menus_fragment.xml index ee76f6a..5a6fc8d 100644 --- a/sample/src/main/res/layout/menus_fragment.xml +++ b/sample/src/main/res/layout/menus_fragment.xml @@ -85,7 +85,8 @@ android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" - fab:menu_icon="@drawable/ic_star" + fab:menu_open_icon="@drawable/ic_star" + fab:menu_close_icon="@drawable/ic_close" fab:menu_animationDelayPerItem="0" fab:menu_colorNormal="#43A047" fab:menu_colorPressed="#2E7D32" @@ -154,6 +155,22 @@ + + + + + #99FFFFFF #000 + #994878 + \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index cd830b4..1461f32 100755 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -6,4 +6,8 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed ultricies risus. Integer nisi orci, lacinia sit amet mi in, mollis scelerisque purus. Nunc risus ligula, maximus eu orci a, facilisis dictum velit. Proin nec laoreet magna. Nulla ut sagittis lorem. Morbi id enim fermentum, semper diam et, tempus leo. Aliquam vel congue orci. Suspendisse potenti. Curabitur finibus diam augue, vel bibendum sapien ultrices non. Navigation open Navigation close + Add to AutoTest + Browse + More + diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index 4619a1f..0381fdf 100755 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -49,4 +49,23 @@ sans-serif-light + + + + +