Skip to content

Commit

Permalink
Menu button Icon scaling
Browse files Browse the repository at this point in the history
Menu buttons now scale drawables properly preserving their aspect ratio
  • Loading branch information
SC committed Jun 26, 2019
1 parent 68e7969 commit 665acce
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,14 @@ void updateBackground() {
});
}

int iconSize = -1;
int iconWidth = -1;
int iconHeight = -1;
if (getIconDrawable() != null) {
iconSize = Math.max(getIconDrawable().getIntrinsicWidth(), getIconDrawable().getIntrinsicHeight());
iconWidth = getIconDrawable().getIntrinsicWidth();
iconHeight = getIconDrawable().getIntrinsicHeight();
}
int iconOffset = (getCircleSize() - (iconSize > 0 ? iconSize : mIconSize)) / 2;
int iconWidthOffset = (getCircleSize() - (iconWidth > 0 ? iconWidth : mIconSize)) / 2;
int iconHeightOffset = (getCircleSize() - (iconHeight > 0 ? iconHeight : mIconSize)) / 2;
int circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0;
int circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0;

Expand All @@ -369,19 +372,12 @@ void updateBackground() {
circleInsetVertical += mProgressWidth;
}

/*layerDrawable.setLayerInset(
mShowShadow ? 1 : 0,
circleInsetHorizontal,
circleInsetVertical,
circleInsetHorizontal,
circleInsetVertical
);*/
layerDrawable.setLayerInset(
hasShadow() ? 2 : 1,
circleInsetHorizontal + iconOffset,
circleInsetVertical + iconOffset,
circleInsetHorizontal + iconOffset,
circleInsetVertical + iconOffset
circleInsetHorizontal + iconWidthOffset,
circleInsetVertical + iconHeightOffset,
circleInsetHorizontal + iconWidthOffset,
circleInsetVertical + iconHeightOffset
);

setBackgroundCompat(layerDrawable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
final FloatingActionButton programFab1 = new FloatingActionButton(getActivity());
programFab1.setButtonSize(FloatingActionButton.SIZE_MINI);
programFab1.setLabelText(getString(R.string.lorem_ipsum));
programFab1.setImageResource(R.drawable.ic_edit);
programFab1.setImageResource(R.drawable.ic_add_photo);
menuRed.addMenuButton(programFab1);
programFab1.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
12 changes: 12 additions & 0 deletions sample/src/main/res/drawable/ic_add_photo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="23dp"
android:height="21dp"
android:viewportWidth="23"
android:viewportHeight="21">
<path
android:pathData="M3,3L3,0L5,0L5,3L8,3L8,5L5,5L5,8L3,8L3,5L0,5L0,3L3,3ZM6,9L6,6L9,6L9,3L16,3L17.83,5L21,5C22.1,5 23,5.9 23,7L23,19C23,20.1 22.1,21 21,21L5,21C3.9,21 3,20.1 3,19L3,9L6,9ZM13,18C15.76,18 18,15.76 18,13C18,10.24 15.76,8 13,8C10.24,8 8,10.24 8,13C8,15.76 10.24,18 13,18ZM9.8,13C9.8,14.77 11.23,16.2 13,16.2C14.77,16.2 16.2,14.77 16.2,13C16.2,11.23 14.77,9.8 13,9.8C11.23,9.8 9.8,11.23 9.8,13Z"
android:strokeWidth="1"
android:fillColor="#000000"
android:fillType="nonZero"
android:strokeColor="#00000000"/>
</vector>
9 changes: 9 additions & 0 deletions sample/src/main/res/drawable/ic_audiotrack.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,3v9.28c-0.47,-0.17 -0.97,-0.28 -1.5,-0.28C8.01,12 6,14.01 6,16.5S8.01,21 10.5,21c2.31,0 4.2,-1.75 4.45,-4H15V6h4V3h-7z"/>
</vector>

0 comments on commit 665acce

Please sign in to comment.