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

Made Label to inherit FAB tags #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class FloatingActionButton extends ImageButton {

public static final int SIZE_NORMAL = 0;
Expand Down Expand Up @@ -69,6 +72,8 @@ public class FloatingActionButton extends ImageButton {
private boolean mUsingElevation;
private boolean mUsingElevationCompat;

private List<Integer> mUsedTags;

// Progress
private boolean mProgressBarEnabled;
private int mProgressWidth = Util.dpToPx(getContext(), 6f);
Expand Down Expand Up @@ -118,6 +123,8 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAtt
}

private void init(Context context, AttributeSet attrs, int defStyleAttr) {
mUsedTags = new ArrayList<>();

TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336);
mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043);
Expand Down Expand Up @@ -1311,4 +1318,23 @@ public void setLabelTextColor(int color) {
public void setLabelTextColor(ColorStateList colors) {
getLabelView().setTextColor(colors);
}

@Override
public void setTag(int key, Object tag) {
super.setTag(key, tag);

if (key == R.id.fab_label) return;

if (!mUsedTags.contains(key)) {
mUsedTags.add(key);
}
Label label = getLabelView();
if (label != null) {
label.setTag(key, tag);
}
}

List<Integer> getUsedTags() {
return mUsedTags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ private void addLabel(FloatingActionButton fab) {
label.setFab(fab);
label.setShowAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsShowAnimation));
label.setHideAnimation(AnimationUtils.loadAnimation(getContext(), mLabelsHideAnimation));
for (Integer key : fab.getUsedTags()) {
label.setTag(key, fab.getTag(key));
}

if (mLabelsStyle > 0) {
label.setTextAppearance(getContext(), mLabelsStyle);
Expand Down Expand Up @@ -977,7 +980,7 @@ public void addMenuButton(FloatingActionButton fab, int index) {

public void removeAllMenuButtons() {
close(true);

List<FloatingActionButton> viewsToRemove = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
Expand Down