Skip to content

Instantly share code, notes, and snippets.

@pdegand
Created June 10, 2014 20:41
Show Gist options
  • Save pdegand/299823b57e4d729bbd5a to your computer and use it in GitHub Desktop.
Save pdegand/299823b57e4d729bbd5a to your computer and use it in GitHub Desktop.
Sample of pure Java StackBlur usage
/**
* Based on a generated NavigationDrawerFragment from AndroidStudio ...
*/
public class NavigationDrawerFragment extends Fragment {
private static final int BLUR_RADIUS_RATIO = 20;
private static final float BLUR_THRESHOLD = 0.1f;
...
private DrawerLayout mDrawerLayout;
private StackBlurManager stackBlurManager;
...
public void setUp(int fragmentId, DrawerLayout drawerLayout, final ImageView originalImageView,
final ImageView blurredImageView) {
mDrawerLayout = drawerLayout;
final Interpolator interpolator = new DecelerateInterpolator();
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setScrimColor(Color.TRANSPARENT); // Glassy effect
...
Bitmap oldBitmap = ((BitmapDrawable) originalImageView.getDrawable()).getBitmap();
stackBlurManager = new StackBlurManager(
Bitmap.createScaledBitmap(
oldBitmap,
oldBitmap.getWidth() / 6,
oldBitmap.getHeight() / 6,
false));
blurredImageView.setImageBitmap(
stackBlurManager.process((int) (interpolator.getInterpolation(BLUR_THRESHOLD) * BLUR_RADIUS_RATIO)));
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(),
mDrawerLayout,
R.drawable.ic_drawer,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
//setAlpha() makes it compat >=v11 ...
if (slideOffset > BLUR_THRESHOLD) {
originalImageView.setAlpha(0f);
blurredImageView.setImageBitmap(
stackBlurManager.process(
(int) (interpolator.getInterpolation(slideOffset) * BLUR_RADIUS_RATIO)));
} else {
originalImageView.setAlpha(((-1 / BLUR_THRESHOLD) * slideOffset + 1));
}
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
...
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
...
}
};
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment