Last active
October 6, 2017 08:41
-
-
Save menny/7878762 to your computer and use it in GitHub Desktop.
Gist for https://github.com/menny/menny.github.io/blob/master/_posts/2013-12-09-branding-edge-effect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void brandGlowEffect(Context context, int brandColor) { | |
int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android"); | |
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId); | |
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.SRC_IN); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void brandGlowEffect(Context context, int brandColor) { | |
//glow | |
int glowDrawableId = context.getResources().getIdentifier("overscroll_glow", "drawable", "android"); | |
Drawable androidGlow = context.getResources().getDrawable(glowDrawableId); | |
androidGlow.setColorFilter(brandColor, PorterDuff.Mode.SRC_IN); | |
//edge | |
int edgeDrawableId = context.getResources().getIdentifier("overscroll_edge", "drawable", "android"); | |
Drawable androidEdge = context.getResources().getDrawable(edgeDrawableId); | |
androidEdge.setColorFilter(brandColor, PorterDuff.Mode.SRC_IN); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public EdgeEffect(Context context) { | |
final Resources res = context.getResources(); | |
mEdge = res.getDrawable(R.drawable.overscroll_edge); | |
mGlow = res.getDrawable(R.drawable.overscroll_glow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean draw(Canvas canvas) { | |
... | |
int glowBottom = (int) Math.min( | |
mGlowHeight * mGlowScaleY * mGlowHeight / mGlowWidth * 0.6f, | |
mGlowHeight * MAX_GLOW_HEIGHT); | |
if (mWidth < mMinWidth) { | |
// Center the glow and clip it. | |
int glowLeft = (mWidth - mMinWidth)/2; | |
mGlow.setBounds(glowLeft, 0, mWidth - glowLeft, glowBottom); | |
} else { | |
// Stretch the glow to fit. | |
mGlow.setBounds(0, 0, mWidth, glowBottom); | |
} | |
mGlow.draw(canvas); | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thumbs up for PorterDuff.Mode.SRC_IN