├── .gitignore
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── fivehundredpx
│ │ └── blurdemo
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── fivehundredpx
│ │ └── blurdemo
│ │ └── MainActivity.java
│ └── res
│ ├── drawable-xxhdpi
│ ├── p0.jpg
│ ├── p1.jpg
│ ├── p2.jpg
│ ├── p3.jpg
│ ├── p4.jpg
│ ├── p5.jpg
│ ├── p6.jpg
│ ├── p7.jpg
│ ├── p8.jpg
│ └── p9.jpg
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── strings.xml
│ └── styles.xml
├── blurdemo.gif
├── blurringview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── fivehundredpx
│ │ └── blur
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── fivehundredpx
│ │ └── android
│ │ └── blur
│ │ └── BlurringView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ ├── defaults.xml
│ └── strings.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── releases
└── com
│ └── fivehundredpx
│ └── blurringview
│ ├── 1.0.0
│ ├── blurringview-1.0.0.aar
│ ├── blurringview-1.0.0.aar.md5
│ ├── blurringview-1.0.0.aar.sha1
│ ├── blurringview-1.0.0.pom
│ ├── blurringview-1.0.0.pom.md5
│ └── blurringview-1.0.0.pom.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | /.idea
6 | .DS_Store
7 | /build
8 | *.iml
9 | /spoon-output
10 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 500px Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## [Currently unmaintained]
2 |
3 | # 500px Android Blurring View
4 |
5 | For more information, please see [our blog post](http://developers.500px.com/2015/03/17/a-blurring-view-for-android.html).
6 |
7 | ## Download
8 |
9 | Define via Gradle:
10 |
11 | ``` groovy
12 | repositories {
13 | maven { url 'https://github.com/500px/500px-android-blur/raw/master/releases/' }
14 | }
15 |
16 | dependencies {
17 | compile 'com.fivehundredpx:blurringview:1.0.0'
18 | }
19 | ```
20 |
21 | Enable renderscript in your module's `defaultConfig`:
22 | ```groovy
23 | android {
24 | defaultConfig {
25 |
26 | renderscriptTargetApi 21
27 | renderscriptSupportModeEnabled true
28 | ...
29 | }
30 | }
31 |
32 | ```
33 |
34 |
35 | ## Usage
36 |
37 | First, give the blurring view a reference to the view to be blurred:
38 |
39 | ``` java
40 | blurringView.setBlurredView(blurredView);
41 | ```
42 |
43 | and then whenever the blurred view changes, invalidate the blurring view:
44 |
45 | ``` java
46 | blurringView.invalidate();
47 | ```
48 |
49 | ## Demo
50 |
51 | 
52 |
53 | ## License
54 |
55 | This project is licensed under the terms of [the MIT license](LICENSE.txt).
56 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '24.0.2'
6 |
7 | defaultConfig {
8 | applicationId "com.fivehundredpx.blurringviewsample"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | renderscriptTargetApi 21
14 | renderscriptSupportModeEnabled true
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile project(':blurringview')
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | compile 'com.android.support:appcompat-v7:23.1.1'
28 | compile 'com.android.support:support-v4:23.1.1'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Developer/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/fivehundredpx/blurdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.fivehundredpx.blurdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fivehundredpx/blurdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fivehundredpx.blurdemo;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.animation.ValueAnimator;
7 | import android.os.Bundle;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.view.animation.OvershootInterpolator;
11 | import android.widget.ImageView;
12 |
13 | import com.fivehundredpx.android.blur.BlurringView;
14 |
15 | import java.util.Random;
16 |
17 | /**
18 | * Demonstrates the use of the blurring view.
19 | */
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | mBlurringView = (BlurringView) findViewById(R.id.blurring_view);
27 | View blurredView = findViewById(R.id.blurred_view);
28 |
29 | // Give the blurring view a reference to the blurred view.
30 | mBlurringView.setBlurredView(blurredView);
31 |
32 | mImageViews[0] = (ImageView) findViewById(R.id.image0);
33 | mImageViews[1] = (ImageView) findViewById(R.id.image1);
34 | mImageViews[2] = (ImageView) findViewById(R.id.image2);
35 | mImageViews[3] = (ImageView) findViewById(R.id.image3);
36 | mImageViews[4] = (ImageView) findViewById(R.id.image4);
37 | mImageViews[5] = (ImageView) findViewById(R.id.image5);
38 | mImageViews[6] = (ImageView) findViewById(R.id.image6);
39 | mImageViews[7] = (ImageView) findViewById(R.id.image7);
40 | mImageViews[8] = (ImageView) findViewById(R.id.image8);
41 | }
42 |
43 | public void shuffle(View view) {
44 |
45 | // Randomly pick a different start in the array of available images.
46 | int newStartIndex;
47 | do {
48 | newStartIndex = IMAGE_IDS[mRandom.nextInt(IMAGE_IDS.length)];
49 | } while (newStartIndex == mStartIndex);
50 | mStartIndex = newStartIndex;
51 |
52 | // Update the images for the image views contained in the blurred view.
53 | for (int i = 0; i < mImageViews.length; i++) {
54 | int drawableId = IMAGE_IDS[(mStartIndex + i) % IMAGE_IDS.length];
55 | mImageViews[i].setImageDrawable(getResources().getDrawable(drawableId));
56 | }
57 |
58 | // Invalidates the blurring view when the content of the blurred view changes.
59 | mBlurringView.invalidate();
60 | }
61 |
62 | private ValueAnimator.AnimatorUpdateListener listener = new ValueAnimator.AnimatorUpdateListener() {
63 | @Override
64 | public void onAnimationUpdate(ValueAnimator animation) {
65 | mBlurringView.invalidate();
66 | }
67 | };
68 |
69 | public void shift(View view) {
70 | if (!mShifted) {
71 | for (ImageView imageView : mImageViews) {
72 | ObjectAnimator tx = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_X, (mRandom.nextFloat() - 0.5f) * 500);
73 | tx.addUpdateListener(listener);
74 | ObjectAnimator ty = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_Y, (mRandom.nextFloat() - 0.5f) * 500);
75 | ty.addUpdateListener(listener);
76 | AnimatorSet set = new AnimatorSet();
77 | set.playTogether(tx, ty);
78 | set.setDuration(3000);
79 | set.setInterpolator(new OvershootInterpolator());
80 | set.addListener(new AnimationEndListener(imageView));
81 | set.start();
82 | }
83 | mShifted = true;
84 | } else {
85 | for (ImageView imageView : mImageViews) {
86 | ObjectAnimator tx = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_X, 0);
87 | tx.addUpdateListener(listener);
88 | ObjectAnimator ty = ObjectAnimator.ofFloat(imageView, View.TRANSLATION_Y, 0);
89 | ty.addUpdateListener(listener);
90 | AnimatorSet set = new AnimatorSet();
91 | set.playTogether(tx, ty);
92 | set.setDuration(3000);
93 | set.setInterpolator(new OvershootInterpolator());
94 | set.addListener(new AnimationEndListener(imageView));
95 | set.start();
96 | }
97 | mShifted = false;
98 | }
99 | }
100 |
101 | private BlurringView mBlurringView;
102 |
103 | private static final int[] IMAGE_IDS = {
104 | R.drawable.p0, R.drawable.p1, R.drawable.p2, R.drawable.p3, R.drawable.p4,
105 | R.drawable.p5, R.drawable.p6, R.drawable.p7, R.drawable.p8, R.drawable.p9
106 | };
107 |
108 | private ImageView[] mImageViews = new ImageView[9];
109 | private int mStartIndex;
110 |
111 | private Random mRandom = new Random();
112 |
113 | private boolean mShifted;
114 |
115 | private static class AnimationEndListener implements Animator.AnimatorListener {
116 |
117 | View mView;
118 |
119 | public AnimationEndListener(View v) {
120 | mView = v;
121 | }
122 |
123 | @Override
124 | public void onAnimationStart(Animator animation) {
125 | mView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
126 | }
127 |
128 | @Override
129 | public void onAnimationEnd(Animator animation) {
130 | mView.setLayerType(View.LAYER_TYPE_NONE, null);
131 | }
132 |
133 | @Override
134 | public void onAnimationCancel(Animator animation) {
135 | mView.setLayerType(View.LAYER_TYPE_NONE, null);
136 | }
137 |
138 | @Override
139 | public void onAnimationRepeat(Animator animation) {}
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p0.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p8.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/p9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/drawable-xxhdpi/p9.jpg
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
21 |
22 |
29 |
30 |
38 |
39 |
47 |
48 |
56 |
57 |
65 |
66 |
74 |
75 |
83 |
84 |
92 |
93 |
101 |
102 |
103 |
104 |
105 |
106 |
114 |
115 |
123 |
124 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 500px Blurring View Demo
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/blurdemo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/blurdemo.gif
--------------------------------------------------------------------------------
/blurringview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/blurringview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion '24.0.2'
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0.0"
13 | renderscriptTargetApi 21
14 | renderscriptSupportModeEnabled true
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | uploadArchives {
25 | repositories.mavenDeployer {
26 | pom.groupId = 'com.fivehundredpx'
27 | pom.artifactId = 'blurringview'
28 | pom.version = android.defaultConfig.versionName
29 | repository(url: "file:./releases/")
30 | }
31 | }
--------------------------------------------------------------------------------
/blurringview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Developer/android-sdk-macosx/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/blurringview/src/androidTest/java/com/fivehundredpx/blur/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.fivehundredpx.blur;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/blurringview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/blurringview/src/main/java/com/fivehundredpx/android/blur/BlurringView.java:
--------------------------------------------------------------------------------
1 | package com.fivehundredpx.android.blur;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.support.v8.renderscript.Allocation;
11 | import android.support.v8.renderscript.Element;
12 | import android.support.v8.renderscript.RenderScript;
13 | import android.support.v8.renderscript.ScriptIntrinsicBlur;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 |
17 | /**
18 | * A custom view for presenting a dynamically blurred version of another view's content.
19 | *
20 | * Use {@link #setBlurredView(android.view.View)} to set up the reference to the view to be blurred.
21 | * After that, call {@link #invalidate()} to trigger blurring whenever necessary.
22 | */
23 | public class BlurringView extends View {
24 |
25 | public BlurringView(Context context) {
26 | this(context, null);
27 | }
28 |
29 | public BlurringView(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 |
32 | final Resources res = getResources();
33 | final int defaultBlurRadius = res.getInteger(R.integer.default_blur_radius);
34 | final int defaultDownsampleFactor = res.getInteger(R.integer.default_downsample_factor);
35 | final int defaultOverlayColor = res.getColor(R.color.default_overlay_color);
36 |
37 | initializeRenderScript(context);
38 |
39 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PxBlurringView);
40 | setBlurRadius(a.getInt(R.styleable.PxBlurringView_blurRadius, defaultBlurRadius));
41 | setDownsampleFactor(a.getInt(R.styleable.PxBlurringView_downsampleFactor,
42 | defaultDownsampleFactor));
43 | setOverlayColor(a.getColor(R.styleable.PxBlurringView_overlayColor, defaultOverlayColor));
44 | a.recycle();
45 | }
46 |
47 | public void setBlurredView(View blurredView) {
48 | mBlurredView = blurredView;
49 | }
50 |
51 | @Override
52 | protected void onDraw(Canvas canvas) {
53 | super.onDraw(canvas);
54 | if (mBlurredView != null) {
55 | if (prepare()) {
56 | // If the background of the blurred view is a color drawable, we use it to clear
57 | // the blurring canvas, which ensures that edges of the child views are blurred
58 | // as well; otherwise we clear the blurring canvas with a transparent color.
59 | if (mBlurredView.getBackground() != null && mBlurredView.getBackground() instanceof ColorDrawable) {
60 | mBitmapToBlur.eraseColor(((ColorDrawable) mBlurredView.getBackground()).getColor());
61 | } else {
62 | mBitmapToBlur.eraseColor(Color.TRANSPARENT);
63 | }
64 |
65 | mBlurredView.draw(mBlurringCanvas);
66 | blur();
67 |
68 | canvas.save();
69 | canvas.translate(mBlurredView.getX() - getX(), mBlurredView.getY() - getY());
70 | canvas.scale(mDownsampleFactor, mDownsampleFactor);
71 | canvas.drawBitmap(mBlurredBitmap, 0, 0, null);
72 | canvas.restore();
73 | }
74 | canvas.drawColor(mOverlayColor);
75 | }
76 | }
77 |
78 | public void setBlurRadius(int radius) {
79 | mBlurScript.setRadius(radius);
80 | }
81 |
82 | public void setDownsampleFactor(int factor) {
83 | if (factor <= 0) {
84 | throw new IllegalArgumentException("Downsample factor must be greater than 0.");
85 | }
86 |
87 | if (mDownsampleFactor != factor) {
88 | mDownsampleFactor = factor;
89 | mDownsampleFactorChanged = true;
90 | }
91 | }
92 |
93 | public void setOverlayColor(int color) {
94 | mOverlayColor = color;
95 | }
96 |
97 | private void initializeRenderScript(Context context) {
98 | mRenderScript = RenderScript.create(context);
99 | mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
100 | }
101 |
102 | protected boolean prepare() {
103 | final int width = mBlurredView.getWidth();
104 | final int height = mBlurredView.getHeight();
105 |
106 | if (mBlurringCanvas == null || mDownsampleFactorChanged
107 | || mBlurredViewWidth != width || mBlurredViewHeight != height) {
108 | mDownsampleFactorChanged = false;
109 |
110 | mBlurredViewWidth = width;
111 | mBlurredViewHeight = height;
112 |
113 | int scaledWidth = width / mDownsampleFactor;
114 | int scaledHeight = height / mDownsampleFactor;
115 |
116 | // The following manipulation is to avoid some RenderScript artifacts at the edge.
117 | scaledWidth = scaledWidth - scaledWidth % 4 + 4;
118 | scaledHeight = scaledHeight - scaledHeight % 4 + 4;
119 |
120 | if (mBlurredBitmap == null
121 | || mBlurredBitmap.getWidth() != scaledWidth
122 | || mBlurredBitmap.getHeight() != scaledHeight) {
123 | mBitmapToBlur = Bitmap.createBitmap(scaledWidth, scaledHeight,
124 | Bitmap.Config.ARGB_8888);
125 | if (mBitmapToBlur == null) {
126 | return false;
127 | }
128 |
129 | mBlurredBitmap = Bitmap.createBitmap(scaledWidth, scaledHeight,
130 | Bitmap.Config.ARGB_8888);
131 | if (mBlurredBitmap == null) {
132 | return false;
133 | }
134 | }
135 |
136 | mBlurringCanvas = new Canvas(mBitmapToBlur);
137 | mBlurringCanvas.scale(1f / mDownsampleFactor, 1f / mDownsampleFactor);
138 | mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
139 | Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
140 | mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
141 | }
142 | return true;
143 | }
144 |
145 | protected void blur() {
146 | mBlurInput.copyFrom(mBitmapToBlur);
147 | mBlurScript.setInput(mBlurInput);
148 | mBlurScript.forEach(mBlurOutput);
149 | mBlurOutput.copyTo(mBlurredBitmap);
150 | }
151 |
152 | @Override
153 | protected void onDetachedFromWindow() {
154 | super.onDetachedFromWindow();
155 | if (mRenderScript != null) {
156 | mRenderScript.destroy();
157 | }
158 | }
159 |
160 | private int mDownsampleFactor;
161 | private int mOverlayColor;
162 |
163 | private View mBlurredView;
164 | private int mBlurredViewWidth, mBlurredViewHeight;
165 |
166 | private boolean mDownsampleFactorChanged;
167 | private Bitmap mBitmapToBlur, mBlurredBitmap;
168 | private Canvas mBlurringCanvas;
169 | private RenderScript mRenderScript;
170 | private ScriptIntrinsicBlur mBlurScript;
171 | private Allocation mBlurInput, mBlurOutput;
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/blurringview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/blurringview/src/main/res/values/defaults.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 15
4 | 8
5 | #AAFFFFFF
6 |
--------------------------------------------------------------------------------
/blurringview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 500px Blurring View for Android
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Oct 14 19:49:39 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/500px/500px-android-blur/01bd56f4d66ef48585041ceafe5aa4eb8248e409/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.aar
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.aar.md5:
--------------------------------------------------------------------------------
1 | 9ebf86ad5ab985d0825f9edd4ab8c909
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.aar.sha1:
--------------------------------------------------------------------------------
1 | 1c72735ba251619e8ed78d85a71a5852855b1869
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.pom:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.fivehundredpx
6 | blurringview
7 | 1.0.0
8 | aar
9 |
10 |
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.pom.md5:
--------------------------------------------------------------------------------
1 | 472f939b894fcaddaa4bf8d0454910e9
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/1.0.0/blurringview-1.0.0.pom.sha1:
--------------------------------------------------------------------------------
1 | 390ffea26598d981c778faa515aa3f32f5708727
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/maven-metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.fivehundredpx
4 | blurringview
5 |
6 | 1.0.0
7 |
8 | 1.0.0
9 |
10 | 20160225231654
11 |
12 |
13 |
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/maven-metadata.xml.md5:
--------------------------------------------------------------------------------
1 | f98f654d6d48e350ee7d006b525cfc7e
--------------------------------------------------------------------------------
/releases/com/fivehundredpx/blurringview/maven-metadata.xml.sha1:
--------------------------------------------------------------------------------
1 | 3a32d523833745277ee689ff04b0444286b8c6ba
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':blurringview'
2 |
--------------------------------------------------------------------------------