Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scaleType property for Fab and MiniFab. #73

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 @@ -48,6 +48,7 @@
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -114,6 +115,7 @@ public interface MenuListener {
private int menuId;
private int fabGravity;
private Drawable fabDrawable;
private ScaleType fabScaleType;
private ColorStateList fabDrawableTint;
private ColorStateList fabBackgroundTint;
private ColorStateList miniFabDrawableTint;
Expand All @@ -123,6 +125,7 @@ public interface MenuListener {
private boolean miniFabTitlesEnabled;
private int miniFabTitleTextColor;
private int[] miniFabTitleTextColorArray;
private ScaleType miniFabScaleType;
private Drawable touchGuardDrawable;
private boolean useTouchGuard;

Expand All @@ -131,6 +134,17 @@ public interface MenuListener {
// Variable to hold whether the menu was open or not on config change
private boolean shouldOpenMenu;

private static final ScaleType[] scaleTypeArray = {
ScaleType.MATRIX,
ScaleType.FIT_XY,
ScaleType.FIT_START,
ScaleType.FIT_CENTER,
ScaleType.FIT_END,
ScaleType.CENTER,
ScaleType.CENTER_CROP,
ScaleType.CENTER_INSIDE
};

private FabSpeedDial(Context context) {
super(context);
}
Expand Down Expand Up @@ -193,6 +207,20 @@ private void resolveOptionalAttributes(TypedArray typedArray) {
fabDrawable = ContextCompat.getDrawable(getContext(), R.drawable.fab_add_clear_selector);
}

final int indexFabScaleType = typedArray.getInt(R.styleable.FabSpeedDial_fabScaleType, -1);
if (indexFabScaleType >= 0) {
fabScaleType = scaleTypeArray[indexFabScaleType];
} else {
fabScaleType = ScaleType.FIT_CENTER;
}

final int indexMiniFabScaleType = typedArray.getInt(R.styleable.FabSpeedDial_miniFabScaleType, -1);
if (indexMiniFabScaleType >= 0) {
miniFabScaleType = scaleTypeArray[indexMiniFabScaleType];
} else {
miniFabScaleType = ScaleType.FIT_CENTER;
}

fabDrawableTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_fabDrawableTint);
if (fabDrawableTint == null) {
fabDrawableTint = getColorStateList(R.color.fab_drawable_tint);
Expand Down Expand Up @@ -265,6 +293,7 @@ protected void onAttachedToWindow() {
// Set up the client's FAB
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setImageDrawable(fabDrawable);
fab.setScaleType(fabScaleType);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fab.setImageTintList(fabDrawableTint);
}
Expand Down Expand Up @@ -456,7 +485,7 @@ private void addMenuItems() {

private View createFabMenuItem(MenuItem menuItem) {
ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
.inflate(getMenuItemLayoutId(), this, false);
.inflate(getMenuItemLayoutId(), this, false);

FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
Expand All @@ -466,6 +495,7 @@ private View createFabMenuItem(MenuItem menuItem) {
cardViewMenuItemMap.put(cardView, menuItem);

miniFab.setImageDrawable(menuItem.getIcon());
miniFab.setScaleType(miniFabScaleType);
miniFab.setOnClickListener(this);
cardView.setOnClickListener(this);

Expand Down
20 changes: 20 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@

<!-- Optional attributes -->
<attr name="fabDrawable" format="color|reference" />
<attr name="fabScaleType">
<enum name="matrix" value="0" />
<enum name="fitXY" value="1" />
<enum name="fitStart" value="2" />
<enum name="fitCenter" value="3" />
<enum name="fitEnd" value="4" />
<enum name="center" value="5" />
<enum name="centerCrop" value="6" />
<enum name="centerInside" value="7" />
</attr>
<attr name="fabDrawableTint" format="color|reference" />
<attr name="fabBackgroundTint" format="color|reference" />

Expand All @@ -36,6 +46,16 @@
<attr name="miniFabDrawableTint" format="color|reference" />
<attr name="miniFabTitleTextColor" format="color|reference" />
<attr name="miniFabTitleTextColorList" format="reference" />
<attr name="miniFabScaleType">
<enum name="matrix" value="0" />
<enum name="fitXY" value="1" />
<enum name="fitStart" value="2" />
<enum name="fitCenter" value="3" />
<enum name="fitEnd" value="4" />
<enum name="center" value="5" />
<enum name="centerCrop" value="6" />
<enum name="centerInside" value="7" />
</attr>

<attr name="touchGuard" format="boolean" />
<attr name="touchGuardDrawable" format="color|reference" />
Expand Down
4 changes: 3 additions & 1 deletion samples/src/main/res/layout/activity_menu_items_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@
android:layout_gravity="bottom|end"
app:fabGravity="bottom_end"
app:fabMenu="@menu/menu_main"
app:fabScaleType="centerInside"
app:miniFabBackgroundTint="@android:color/white"
app:miniFabDrawableTint="?attr/colorPrimaryDark"
app:miniFabTitleTextColor="?attr/colorPrimaryDark" />
app:miniFabTitleTextColor="?attr/colorPrimaryDark"
app:miniFabScaleType="centerInside" />

</android.support.design.widget.CoordinatorLayout>