Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.
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
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:2.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -20,13 +20,13 @@ allprojects {

// http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
project.ext {
ANDROID_COMPILE_SDK_VERSION = 23
ANDROID_BUILD_TOOLS_VERSION = "23.0.1"
ANDROID_COMPILE_SDK_VERSION = 25
ANDROID_BUILD_TOOLS_VERSION = "25.0.0"

ANDROID_MIN_SDK_VERSION = 8
ANDROID_TARGET_SDK_VERSION = 23
ANDROID_RS_TARGET_VERSION = 23
ANDROID_MIN_SDK_VERSION = 9
ANDROID_TARGET_SDK_VERSION = 25
ANDROID_RS_TARGET_VERSION = 25

// Google Stuffs
supportPackageVersion = "23.1.1"
supportPackageVersion = "25.0.0"
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Thu Nov 10 00:05:20 EET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
104 changes: 104 additions & 0 deletions lib/src/main/java/com/ms/square/android/etsyblur/BlurDrawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.ms.square.android.etsyblur;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;

/**
* BlurDrawable.java
*
* @author JurgisG on 2016-11-09.
*/
public class BlurDrawable extends BitmapDrawable {

private final Context mContext;
private Bitmap mBitmap;
private Bitmap mBlurredBitmap;

private int mBlurRadius = 5;
private float mBlur = 1f;

private int mAlpha = 255;
private ColorFilter mColorFilter;

public BlurDrawable(Context context, Resources res, Bitmap bitmap) {
super(res, bitmap);
this.mContext = context;
setBitmap(bitmap);
}

@Override
public void draw(Canvas canvas) {
if (mBitmap != null) {
Paint paint = new Paint();
paint.setAlpha(mAlpha);
if (mColorFilter != null) {
paint.setColorFilter(mColorFilter);
}
canvas.drawBitmap(mBitmap, 0, 0, paint);
paint.setAlpha((int) (mAlpha * mBlur));
canvas.drawBitmap(mBlurredBitmap, 0, 0, paint);
}
}

@Override
public void setAlpha(int alpha) {
mAlpha = alpha;
}

@Override
public void setColorFilter(ColorFilter colorFilter) {
mColorFilter = colorFilter;
}

@Override
public int getOpacity() {
return PixelFormat.UNKNOWN;
}

public void setBitmap(Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
if (mBitmap != null && mBitmap.sameAs(bitmap)) {
} else {
mBitmap = bitmap;
updateBlurredBitmap();
}
} else {
mBitmap = bitmap;
updateBlurredBitmap();
}
}

private void updateBlurredBitmap() {
if (mBlurredBitmap != null) {
mBlurredBitmap.recycle();
mBlurredBitmap = null;
}
mBlurredBitmap = Blur.apply(mContext, mBitmap, mBlurRadius);
invalidateSelf();
}

public int getBlurRadius() {
return mBlurRadius;
}

public void setBlurRadius(int blurRadius) {
blurRadius = Math.min(25, Math.max(1, blurRadius));
if (mBlurRadius != blurRadius) {
this.mBlurRadius = blurRadius;
updateBlurredBitmap();
}
}

public void setBlur(float blur) {
mBlur = Math.min(1f, Math.max(0f, blur));
invalidateSelf();
}

}
3 changes: 3 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BitmapDrawableActivity"
android:label="@string/title_blur_drawable_demo"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.ms.square.android.etsyblurdemo;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.SeekBar;

import com.ms.square.android.etsyblur.BlurDrawable;

public class BitmapDrawableActivity extends AppCompatActivity {

private BlurDrawable drawable;
private SeekBar.OnSeekBarChangeListener listener1 = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
drawable.setBlurRadius(seekBar.getProgress() + 1);
}
};
private SeekBar.OnSeekBarChangeListener listener2 = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
drawable.setBlur(((float) i) / 100f);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
};;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bitmap_drawable);
ImageView mBlurView = (ImageView) findViewById(R.id.blur_view);
SeekBar seekBar = (SeekBar) findViewById(R.id.seek_bar);
seekBar.setOnSeekBarChangeListener(listener1);
SeekBar seekBar2 = (SeekBar) findViewById(R.id.seek_bar2);
seekBar2.setOnSeekBarChangeListener(listener2);
Resources resources = getResources();
Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(this, R.drawable.lolipop_bg)).getBitmap();
drawable = new BlurDrawable(this, resources, bitmap);
drawable.setBlur(0f);
drawable.setBlurRadius(1);
mBlurView.setImageDrawable(drawable);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ms.square.android.etsyblurdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand Down Expand Up @@ -45,10 +46,14 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
if (position == 1){
startActivity(new Intent(this, BitmapDrawableActivity.class));
}else {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
}

public void onSectionAttached(int number) {
Expand Down Expand Up @@ -126,7 +131,7 @@ public PlaceholderFragment() {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
Expand Down
42 changes: 42 additions & 0 deletions sample/src/main/res/layout/activity_bitmap_drawable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_bitmap_drawable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.ms.square.android.etsyblurdemo.BitmapDrawableActivity">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/blur_radius" />

<SeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="24" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/blur_intensity" />

<SeekBar
android:id="@+id/seek_bar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100" />


<ImageView
android:id="@+id/blur_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />


</LinearLayout>
5 changes: 4 additions & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

<string name="app_name">EtsyBlur Demo</string>
<string name="title_section1">Activity Feed</string>
<string name="title_section2">Categories</string>
<string name="title_section2">Blur Drawable example</string>
<string name="title_section3">Settings</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_dialog">Open Dialog</string>
<string name="blur_radius">Blur Radius</string>
<string name="blur_intensity">Blur Intensity</string>
<string name="title_blur_drawable_demo">Blur Drawable Demo</string>

</resources>