From ffdd843247e3242e1e429863fd2de0c3fe57d241 Mon Sep 17 00:00:00 2001 From: loukaspd Date: Mon, 25 Jul 2016 23:59:19 +0300 Subject: [PATCH] setLabelText - setMenuButtonLabelText programmatically (issue #274) --- .../com/github/clans/fab/FloatingActionButton.java | 6 ++++++ .../com/github/clans/fab/FloatingActionMenu.java | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java index e9c98df..e6428c7 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionButton.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionButton.java @@ -25,6 +25,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; @@ -511,6 +512,10 @@ Label getLabelView() { return (Label) getTag(R.id.fab_label); } + void setLabelView(Label label) { + setTag(R.id.fab_label, label); + } + void setColors(int colorNormal, int colorPressed, int colorRipple) { mColorNormal = colorNormal; mColorPressed = colorPressed; @@ -1078,6 +1083,7 @@ public void setLabelText(String text) { TextView labelView = getLabelView(); if (labelView != null) { labelView.setText(text); + labelView.setVisibility(TextUtils.isEmpty(text) ? INVISIBLE : VISIBLE); } } 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..c12e0bb 100755 --- a/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java +++ b/library/src/main/java/com/github/clans/fab/FloatingActionMenu.java @@ -476,9 +476,8 @@ public void onClick(View v) { private void addLabel(FloatingActionButton fab) { String text = fab.getLabelText(); - if (TextUtils.isEmpty(text)) return; - final Label label = new Label(mLabelsContext); + label.setVisibility(TextUtils.isEmpty(text) ? INVISIBLE : VISIBLE); label.setClickable(true); label.setFab(fab); label.setShowAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsShowAnimation)); @@ -527,7 +526,7 @@ private void addLabel(FloatingActionButton fab) { label.setOnClickListener(fab.getOnClickListener()); addView(label); - fab.setTag(R.id.fab_label, label); + fab.setLabelView(label); } private void setLabelEllipsize(Label label) { @@ -655,8 +654,8 @@ public void run() { fab.show(animate); } - Label label = (Label) fab.getTag(R.id.fab_label); - if (label != null && label.isHandleVisibilityChanges()) { + Label label = fab.getLabelView(); + if (label != null && label.isHandleVisibilityChanges() && !TextUtils.isEmpty(label.getText())) { label.show(animate); } } @@ -711,8 +710,8 @@ public void run() { fab.hide(animate); } - Label label = (Label) fab.getTag(R.id.fab_label); - if (label != null && label.isHandleVisibilityChanges()) { + Label label = fab.getLabelView(); + if (label != null && label.isHandleVisibilityChanges() && !TextUtils.isEmpty(label.getText())) { label.hide(animate); } }