Skip to content

Commit

Permalink
Generate default pressed and ripple colors
Browse files Browse the repository at this point in the history
  • Loading branch information
makovkastar committed Apr 4, 2015
1 parent 6ba6935 commit 75c10ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 19 additions & 4 deletions library/src/main/java/com/melnykov/fab/FloatingActionButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
Expand Down Expand Up @@ -91,8 +92,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
private void init(Context context, AttributeSet attributeSet) {
mVisible = true;
mColorNormal = getColor(R.color.material_blue_500);
mColorPressed = getColor(R.color.material_blue_600);
mColorRipple = getColor(android.R.color.white);
mColorPressed = darkenColor(mColorNormal);
mColorRipple = lightenColor(mColorNormal);
mColorDisabled = getColor(android.R.color.darker_gray);
mType = TYPE_NORMAL;
mShadow = true;
Expand All @@ -111,9 +112,9 @@ private void initAttributes(Context context, AttributeSet attributeSet) {
mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal,
getColor(R.color.material_blue_500));
mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed,
getColor(R.color.material_blue_600));
darkenColor(mColorNormal));
mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple,
getColor(android.R.color.white));
lightenColor(mColorNormal));
mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled,
mColorDisabled);
mShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_shadow, true);
Expand Down Expand Up @@ -411,6 +412,20 @@ private boolean hasHoneycombApi() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}

private static int darkenColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.9f;
return Color.HSVToColor(hsv);
}

private static int lightenColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 1.1f;
return Color.HSVToColor(hsv);
}

private class AbsListViewScrollDetectorImpl extends AbsListViewScrollDetector {
private ScrollDirectionListener mScrollDirectionListener;
private AbsListView.OnScrollListener mOnScrollListener;
Expand Down
1 change: 0 additions & 1 deletion library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
<resources>
<!-- http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<color name="material_blue_500">#5677fc</color>
<color name="material_blue_600">#4e6cef</color>
</resources>

0 comments on commit 75c10ee

Please sign in to comment.