├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── BlurViewProject.iml
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── libs
│ └── colorpicker.aar
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── licheedev
│ │ └── blurviewproject
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── licheedev
│ │ └── blurviewproject
│ │ ├── BaseTestActivity.java
│ │ ├── LiveBlurActivity.java
│ │ ├── MainActivity.java
│ │ ├── StaticBlurActivity.java
│ │ ├── fragment
│ │ ├── ImageFragment.java
│ │ ├── ListFragment.java
│ │ └── ScrollFragment.java
│ │ └── listener
│ │ └── ToBlurListener.java
│ └── res
│ ├── drawable
│ ├── img_dog1.jpg
│ ├── img_dog2.jpg
│ ├── img_dog3.jpg
│ ├── img_doge.png
│ └── img_isla.png
│ ├── layout
│ ├── activity_live_blur.xml
│ ├── activity_main.xml
│ ├── activity_static_blur.xml
│ ├── fragment_image.xml
│ ├── fragment_list.xml
│ ├── fragment_scroll.xml
│ ├── layout_control.xml
│ └── list_item.xml
│ ├── menu
│ ├── menu_base_test.xml
│ ├── menu_live_blur.xml
│ ├── menu_main.xml
│ └── menu_static_blur.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── blurview
├── .gitignore
├── blurview.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── licheedev
│ │ └── blurview
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── licheedev
│ │ └── blurview
│ │ ├── BlurView.java
│ │ └── PartBlurView.java
│ └── res
│ └── values
│ ├── blurview_attr.xml
│ └── strings.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshot
└── ss.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 | *.iml
9 | /*/*.iml
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Blur View Project
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/BlurViewProject.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BlurViewDemo
2 | 实现高斯模糊控件
3 |
4 | 
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.licheedev.blurviewproject"
9 | minSdkVersion 15
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | renderscriptTargetApi 18
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 | repositories {
25 | flatDir {
26 | dirs 'libs'
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(dir: 'libs', include: ['*.jar'])
32 | compile 'com.android.support:appcompat-v7:22.2.0'
33 | compile('com.rengwuxian.materialedittext:library:2.0.3') {
34 | transitive = true;
35 | }
36 | compile(name: 'colorpicker', ext: 'aar')
37 | compile project(':blurview')
38 | }
39 |
--------------------------------------------------------------------------------
/app/libs/colorpicker.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/libs/colorpicker.aar
--------------------------------------------------------------------------------
/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 E:\DevTools\Android\sdk/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/licheedev/blurviewproject/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject;
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 |
22 |
23 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/BaseTestActivity.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.SeekBar;
9 | import android.widget.TextView;
10 | import android.widget.Toast;
11 |
12 | import com.flask.colorpicker.ColorPickerView;
13 | import com.flask.colorpicker.OnColorSelectedListener;
14 | import com.flask.colorpicker.builder.ColorPickerClickListener;
15 | import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
16 |
17 | public abstract class BaseTestActivity extends AppCompatActivity implements View.OnClickListener {
18 |
19 | private TextView mTvBlurRadius;
20 | private SeekBar mSbBlurRadius;
21 | private TextView mTvDownSample;
22 | private SeekBar mSbDownSample;
23 | private View mColorView;
24 | private Button mBtnColor;
25 |
26 | protected int mBlurRadius = 0;
27 | protected int mDownSample = 1;
28 | protected int mColor;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | }
34 |
35 | protected void initControl() {
36 | // 设置模糊半径
37 | mTvBlurRadius = (TextView) findViewById(R.id.tvBlurRadius);
38 | mSbBlurRadius = (SeekBar) findViewById(R.id.sbBlurRadius);
39 | mSbBlurRadius.setMax(24);
40 | mSbBlurRadius.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
41 | @Override
42 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
43 | setBlurRadiusText(progress);
44 | updateBlurView(mBlurRadius, mDownSample, mColor);
45 | }
46 |
47 | @Override
48 | public void onStartTrackingTouch(SeekBar seekBar) {
49 |
50 | }
51 |
52 | @Override
53 | public void onStopTrackingTouch(SeekBar seekBar) {
54 |
55 | }
56 | });
57 | mSbBlurRadius.setProgress(0);
58 | // 设置缩小样本因数
59 | mTvDownSample = (TextView) findViewById(R.id.tvDownSample);
60 | mSbDownSample = (SeekBar) findViewById(R.id.sbDownSample);
61 | mSbDownSample.setMax(64 - 1);
62 | mSbDownSample.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
63 | @Override
64 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
65 | setDownSampleText(progress);
66 | updateBlurView(mBlurRadius, mDownSample, mColor);
67 | }
68 |
69 | @Override
70 | public void onStartTrackingTouch(SeekBar seekBar) {
71 |
72 | }
73 |
74 | @Override
75 | public void onStopTrackingTouch(SeekBar seekBar) {
76 |
77 | }
78 | });
79 | mSbDownSample.setProgress(0);
80 | // 设置颜色
81 | mColorView = findViewById(R.id.colorView);
82 | mBtnColor = (Button) findViewById(R.id.btnColor);
83 | mBtnColor.setOnClickListener(this);
84 | setColorText(getResources().getColor(R.color.green_a20));
85 | }
86 |
87 |
88 | @Override
89 | public void onClick(View v) {
90 | switch (v.getId()) {
91 | case R.id.btnColor:
92 | selectColor();
93 | break;
94 |
95 | }
96 | }
97 |
98 | private void selectColor() {
99 | ColorPickerDialogBuilder
100 | .with(this)
101 | .setTitle("选择颜色")
102 | .initialColor(mColor)
103 | .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
104 | .density(12)
105 | .setOnColorSelectedListener(new OnColorSelectedListener() {
106 | @Override
107 | public void onColorSelected(int selectedColor) {
108 | Toast.makeText(getApplicationContext(),
109 | "已选择颜色: #" + Integer.toHexString(selectedColor), Toast.LENGTH_SHORT)
110 | .show();
111 | }
112 | })
113 | .setPositiveButton("确定", new ColorPickerClickListener() {
114 | @Override
115 | public void onClick(DialogInterface dialog, int selectedColor,
116 | Integer[] allColors) {
117 | setColorText(selectedColor);
118 | updateBlurView(mBlurRadius, mDownSample, mColor);
119 | }
120 | })
121 | .setNegativeButton("取消", new DialogInterface.OnClickListener() {
122 | @Override
123 | public void onClick(DialogInterface dialog, int which) {
124 | }
125 | })
126 | .build()
127 | .show();
128 | }
129 |
130 |
131 | protected void setBlurRadiusText(int blurRadius) {
132 | mBlurRadius = blurRadius;
133 | mTvBlurRadius.setText("模糊半径:" + mBlurRadius);
134 | }
135 |
136 | protected void setDownSampleText(int downSample) {
137 | mDownSample = downSample + 1;
138 | mTvDownSample.setText("样本因数:" + mDownSample);
139 | }
140 |
141 | protected void setColorText(int color) {
142 | mColor = color;
143 | mBtnColor.setText("颜色:#" + Integer.toHexString(color));
144 | mColorView.setBackgroundColor(mColor);
145 | }
146 |
147 | /**
148 | * 更新模糊
149 | *
150 | * @param blurRadius
151 | * @param downSample
152 | * @param color
153 | */
154 | protected abstract void updateBlurView(int blurRadius, int downSample, int color);
155 |
156 | protected void updateBlurView() {
157 | updateBlurView(mBlurRadius, mDownSample, mColor);
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/LiveBlurActivity.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentManager;
6 | import android.support.v4.app.FragmentStatePagerAdapter;
7 | import android.support.v4.view.ViewPager;
8 | import android.widget.FrameLayout;
9 |
10 | import com.licheedev.blurview.PartBlurView;
11 | import com.licheedev.blurviewproject.fragment.ImageFragment;
12 | import com.licheedev.blurviewproject.fragment.ListFragment;
13 | import com.licheedev.blurviewproject.fragment.ScrollFragment;
14 | import com.licheedev.blurviewproject.listener.ToBlurListener;
15 |
16 | public class LiveBlurActivity extends BaseTestActivity implements ToBlurListener {
17 |
18 | private ViewPager mViewPager;
19 | private PartBlurView mBlurView1;
20 | private PartBlurView mBlurView2;
21 | private FrameLayout mContainer;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_live_blur);
27 | initControl();
28 | initViews();
29 |
30 | }
31 |
32 | private void initViews() {
33 | mContainer = (FrameLayout) findViewById(R.id.container);
34 | mViewPager = (ViewPager) findViewById(R.id.viewPager);
35 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
36 | @Override
37 | public void onPageScrolled(int position, float positionOffset,
38 | int positionOffsetPixels) {
39 | toBlur();
40 | }
41 |
42 | @Override
43 | public void onPageSelected(int position) {
44 |
45 | }
46 |
47 | @Override
48 | public void onPageScrollStateChanged(int state) {
49 |
50 | }
51 | });
52 | mViewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
53 | mBlurView1 = (PartBlurView) findViewById(R.id.blurView1);
54 | mBlurView1.setToBlurView(mContainer);
55 | mBlurView2 = (PartBlurView) findViewById(R.id.blurView2);
56 | mBlurView2.setToBlurView(mContainer);
57 | mViewPager.post(new Runnable() {
58 | @Override
59 | public void run() {
60 | mBlurView1.blur();
61 | updateBlurView();
62 | }
63 | });
64 | }
65 |
66 | @Override
67 | protected void updateBlurView(int blurRadius, int downSample, int color) {
68 | mBlurView2.blur(blurRadius, downSample, color);
69 | }
70 |
71 | private class MyAdapter extends FragmentStatePagerAdapter {
72 |
73 | public MyAdapter(FragmentManager fm) {
74 | super(fm);
75 | }
76 |
77 | @Override
78 | public Fragment getItem(int position) {
79 | switch (position) {
80 | case 0:
81 | return ImageFragment.getInstance(R.drawable.img_dog1);
82 | case 1:
83 | return ImageFragment.getInstance(R.drawable.img_dog2);
84 | case 2:
85 | return ImageFragment.getInstance(R.drawable.img_dog3);
86 | case 3:
87 | return new ListFragment();
88 | case 4:
89 | return new ScrollFragment();
90 | default:
91 | return null;
92 | }
93 | }
94 |
95 | @Override
96 | public int getCount() {
97 | return 5;
98 | }
99 | }
100 |
101 |
102 | @Override
103 | public void toBlur() {
104 | mBlurView1.blur();
105 | mBlurView2.blur();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | findViewById(R.id.btn1).setOnClickListener(this);
15 | findViewById(R.id.btn2).setOnClickListener(this);
16 | }
17 |
18 | @Override
19 | public void onClick(View v) {
20 | switch (v.getId()) {
21 | case R.id.btn1:
22 | startActivity(new Intent(this, StaticBlurActivity.class));
23 | break;
24 | case R.id.btn2:
25 | startActivity(new Intent(this, LiveBlurActivity.class));
26 | break;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/StaticBlurActivity.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject;
2 |
3 | import android.os.Bundle;
4 | import android.widget.ImageView;
5 |
6 | import com.licheedev.blurview.BlurView;
7 |
8 | public class StaticBlurActivity extends BaseTestActivity {
9 |
10 | private ImageView mIvSrc;
11 | private BlurView mBlurView;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_static_blur);
17 | initControl();
18 | initViews();
19 | }
20 |
21 | private void initViews() {
22 | mIvSrc = (ImageView) findViewById(R.id.ivSrc);
23 | mBlurView = (BlurView) findViewById(R.id.blurView);
24 | mBlurView.setToBlurView(mIvSrc); // 并联需要模糊的视图
25 | mIvSrc.post(new Runnable() {
26 | @Override
27 | public void run() {
28 | // 初始化完毕,更新模糊视图状态
29 | updateBlurView();
30 | }
31 | });
32 | }
33 |
34 | @Override
35 | protected void updateBlurView(int blurRadius, int downSample, int color) {
36 | mBlurView.blur(blurRadius, downSample, color);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/fragment/ImageFragment.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 |
11 | import com.licheedev.blurviewproject.R;
12 |
13 | /**
14 | * Created by John on 2015/7/19.
15 | */
16 | public class ImageFragment extends Fragment {
17 |
18 |
19 | public ImageFragment() {
20 | }
21 |
22 | public static ImageFragment getInstance(int resId) {
23 | ImageFragment fragment = new ImageFragment();
24 | Bundle args = new Bundle();
25 | args.putInt("resid", resId);
26 | fragment.setArguments(args);
27 | return fragment;
28 | }
29 |
30 | @Nullable
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
33 | Bundle savedInstanceState) {
34 | ImageView imageView = (ImageView) inflater.inflate(R.layout.fragment_image, container, false);
35 | int res = getArguments().getInt("resid");
36 | imageView.setImageResource(res);
37 | return imageView;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/fragment/ListFragment.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject.fragment;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AbsListView;
11 | import android.widget.BaseAdapter;
12 | import android.widget.ImageView;
13 | import android.widget.ListView;
14 | import android.widget.TextView;
15 |
16 | import com.licheedev.blurviewproject.R;
17 | import com.licheedev.blurviewproject.listener.ToBlurListener;
18 |
19 | /**
20 | * Created by John on 2015/7/19.
21 | */
22 | public class ListFragment extends Fragment {
23 |
24 | private ToBlurListener mListener;
25 |
26 | @Override
27 | public void onAttach(Activity activity) {
28 | super.onAttach(activity);
29 | mListener = (ToBlurListener) activity;
30 | }
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
35 | Bundle savedInstanceState) {
36 | ListView listView = (ListView) inflater.inflate(R.layout.fragment_list, container, false);
37 | listView.setOnScrollListener(new AbsListView.OnScrollListener() {
38 | @Override
39 | public void onScrollStateChanged(AbsListView view, int scrollState) {
40 |
41 | }
42 |
43 | @Override
44 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
45 | int totalItemCount) {
46 | mListener.toBlur();
47 | }
48 | });
49 | listView.setAdapter(new MyAdapter());
50 | return listView;
51 | }
52 |
53 |
54 | private static class MyAdapter extends BaseAdapter {
55 |
56 | @Override
57 | public int getCount() {
58 | return 100;
59 | }
60 |
61 | @Override
62 | public Object getItem(int position) {
63 | return null;
64 | }
65 |
66 | @Override
67 | public long getItemId(int position) {
68 | return position + 1;
69 | }
70 |
71 | @Override
72 | public View getView(int position, View convertView, ViewGroup parent) {
73 | ViewHolder holder;
74 | if (convertView == null) {
75 | convertView = LayoutInflater.from(parent.getContext())
76 | .inflate(R.layout.list_item, parent, false);
77 | holder = new ViewHolder(convertView);
78 | convertView.setTag(holder);
79 | } else {
80 | holder = (ViewHolder) convertView.getTag();
81 | }
82 | holder.textView.setText("这是doge " + getItemId(position));
83 | return convertView;
84 | }
85 | }
86 |
87 | private static class ViewHolder {
88 |
89 | ImageView imageView;
90 | TextView textView;
91 |
92 | public ViewHolder(View view) {
93 | imageView = (ImageView) view.findViewById(R.id.imageView);
94 | textView = (TextView) view.findViewById(R.id.textView);
95 | }
96 | }
97 |
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/fragment/ScrollFragment.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject.fragment;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.DragEvent;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ScrollView;
12 |
13 | import com.licheedev.blurviewproject.R;
14 | import com.licheedev.blurviewproject.listener.ToBlurListener;
15 |
16 | /**
17 | * Created by John on 2015/7/19.
18 | */
19 | public class ScrollFragment extends Fragment {
20 |
21 | private ToBlurListener mListener;
22 |
23 | @Override
24 | public void onAttach(Activity activity) {
25 | super.onAttach(activity);
26 | mListener = (ToBlurListener) activity;
27 | }
28 |
29 | @Nullable
30 | @Override
31 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
32 | Bundle savedInstanceState) {
33 |
34 | View view = inflater.inflate(R.layout.fragment_scroll, container, false);
35 | ScrollView scrollView = (ScrollView) view.findViewById(R.id.scrollView);
36 | scrollView.setOnDragListener(new View.OnDragListener() {
37 | @Override
38 | public boolean onDrag(View v, DragEvent event) {
39 | mListener.toBlur();
40 | return false;
41 | }
42 | });
43 |
44 | return view;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/licheedev/blurviewproject/listener/ToBlurListener.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurviewproject.listener;
2 |
3 | /**
4 | * Created by John on 2015/7/19.
5 | */
6 | public interface ToBlurListener {
7 | void toBlur();
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_dog1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/drawable/img_dog1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_dog2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/drawable/img_dog2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_dog3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/drawable/img_dog3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_doge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/drawable/img_doge.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img_isla.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/drawable/img_isla.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_live_blur.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
14 |
15 |
19 |
23 |
24 |
25 |
26 |
37 |
38 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_static_blur.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
15 |
16 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_scroll.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_control.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
28 |
31 |
32 |
33 |
38 |
39 |
45 |
46 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_base_test.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_live_blur.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_static_blur.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3300ff00
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Blur View Project
3 |
4 | Hello world!
5 | Settings
6 | StaticBlurActivity
7 | LiveBlurActivity
8 | BaseTestActivity
9 | 本周四的第二财季电话会议也不例外,谷歌高管通过一系列数字来说明YouTube如何冲击着传统电视。
10 | 谷歌首席业务官(CBO)奥米德·柯德斯塔尼(OmidKordestani)称:“与美国任何一家有线电视网络相比,YouTube吸引的18岁至49岁人群最多。”
11 | YouTube不仅主导了该年龄段人群,更重要的是,这些人群像对待电视一样对待YouTube。
12 | 柯德斯塔尼说:“第二季度YouTube用户数量同比增长了3倍,他们访问YouTube主页就好像是打开电视机一样。一旦用户来到YouTube,每次观看视频的时间也更长。至于移动平台,现在每次访问的观看时间超过40分钟,同比增长了50%多。”
13 | 对于YouTube当前所处的生命阶段,上述事实意义重大。谷歌想强调的是:YouTube已经不仅仅是视频仓库,在观看之前人们需要知道他们想要看什么。如今的YouTube正成为一个发现平台,扮演着内容管理者的角色。YouTube正在模仿电视机上的数字节目单。
14 | 由于用户逐渐向在线视频平台转移,广告收入也随之而来。
15 | 每一年谷歌都会模仿电视网络的广告预售活动“upfront”,推出自己的“BrandCast”活动。该活动中,YouTube会请出一些大牌明星,展示其最新的广告产品,与世界各大品牌与广告商谈判,希望赢得他们的广告投资承诺。
16 | 柯德斯塔尼说:“与去年同期相比,今年BrandCast在美国获得的投资承诺增长了3倍。第二季度在YouTube上投放视频广告的广告主数量同比增长了40%,前100大广告客户每位广告主的平均开支同比增长了60%。”
17 | 相比之下,投资公司Jefferies Co分析师约翰·简迪斯(JohnJanedis)本月早些时候曾表示,今年电视网络的“upfront”表现低于预期。
18 | 谷歌CFO露丝·波拉特(RuthPorat)在电话会议也给出了清晰的信号:YouTube将向电视发起攻击。波拉特在电话会议中两次提到:“我们的工作重心就是要把更大一部分预算吸引到YouTube平台上。”
19 | 谷歌宣称YouTube正在取代传统电视已经有一段时间了,但事实上,谷歌距离该目标还很遥远。
20 | 调研机构尼尔森(Nielsen)数据显示,美国消费者每天观看近5个小时的电视节目,而每天通过计算机或智能手机上网的时间仅为看电视时间的一半。
21 | 因此,当前电视仍是广告主的最大投资平台。媒体机构Carat预计,去年全球电视广告开支为2300亿美元。而媒体传播公司实力传播(ZenithOptimedia)数据显示,去年全球在线视频广告开支仅为110亿美元。当然,在线视频广告的发展速度较快,预计2014年至2017年的年复合增长率将达到29%。即便如此,届时的230亿美元规模也只是当前电视广告开支的1/10。
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
15 |
16 |
21 |
22 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/blurview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/blurview/blurview.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/blurview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | renderscriptTargetApi 18
13 | renderscriptSupportModeEnabled true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:appcompat-v7:22.2.0'
26 | }
27 |
--------------------------------------------------------------------------------
/blurview/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 E:\DevTools\Android\sdk/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 |
--------------------------------------------------------------------------------
/blurview/src/androidTest/java/com/licheedev/blurview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurview;
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 | }
--------------------------------------------------------------------------------
/blurview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/blurview/src/main/java/com/licheedev/blurview/BlurView.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.os.Build;
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 | import java.util.concurrent.atomic.AtomicBoolean;
18 |
19 | /**
20 | * 全覆盖高斯模糊
21 | * Created by John on 2015/7/18.
22 | */
23 | public class BlurView extends View {
24 |
25 | protected RenderScript mRenderScript;
26 | protected ScriptIntrinsicBlur mBlurScript;
27 |
28 | protected final int DEFAULT_BLUR_RADIUS = 4;
29 | protected final int DEFAULT_DOWN_SAMPLE_FACTOR = 10;
30 | protected final int DEFAULT_OVERLAY_COLOR = Color.TRANSPARENT;
31 |
32 | protected int mBlurRadius; // 模糊半径
33 | protected int mDownSampleFactor; // 缩小样本因数
34 | protected int mOverlayColor; // 覆盖层颜色
35 | protected float mScale;
36 |
37 | protected View mToBlurView;
38 |
39 | protected AtomicBoolean isWorking = new AtomicBoolean(false);
40 |
41 | public BlurView(Context context) {
42 | this(context, null);
43 | }
44 |
45 | public BlurView(Context context, AttributeSet attrs) {
46 | this(context, attrs, 0);
47 | }
48 |
49 | public BlurView(Context context, AttributeSet attrs, int defStyleAttr) {
50 | super(context, attrs, defStyleAttr);
51 | initAttrs(context, attrs, defStyleAttr);
52 | initRenderScript(context);
53 | }
54 |
55 | /**
56 | * 初始化属性
57 | *
58 | * @param context
59 | * @param attrs
60 | * @param defStyleAttr
61 | */
62 | protected void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
63 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BlurView, defStyleAttr, 0);
64 | mBlurRadius = a.getInt(R.styleable.BlurView_blurRadius, DEFAULT_BLUR_RADIUS);
65 | setBlurRadius(mBlurRadius);
66 | mDownSampleFactor = a.getInt(R.styleable.BlurView_downSampleFactor,
67 | DEFAULT_DOWN_SAMPLE_FACTOR);
68 | setDownSampleFactor(mDownSampleFactor);
69 | mOverlayColor = a.getColor(R.styleable.BlurView_overlayColor, DEFAULT_OVERLAY_COLOR);
70 | a.recycle();
71 | }
72 |
73 | /**
74 | * 初始化RenderScript
75 | *
76 | * @param context
77 | */
78 | protected void initRenderScript(Context context) {
79 | mRenderScript = RenderScript.create(context.getApplicationContext());
80 | mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
81 | }
82 |
83 | /**
84 | * 销毁RenderScript
85 | */
86 | protected void destroyRenderScript() {
87 | if (mBlurScript != null) {
88 | mBlurScript.destroy();
89 | mBlurScript = null;
90 | }
91 | if (mRenderScript != null) {
92 | mRenderScript.destroy();
93 | mRenderScript = null;
94 | }
95 | }
96 |
97 | /**
98 | * 获取要被模糊的视图对象
99 | *
100 | * @return
101 | */
102 | public View getToBlurView() {
103 | return mToBlurView;
104 | }
105 |
106 | /**
107 | * 设置要被模糊的视图对象
108 | *
109 | * @param toBlurView
110 | */
111 | public void setToBlurView(View toBlurView) {
112 | mToBlurView = toBlurView;
113 | }
114 |
115 | /**
116 | * 获取模糊半径
117 | *
118 | * @return
119 | */
120 | public int getBlurRadius() {
121 | return mBlurRadius;
122 | }
123 |
124 | /**
125 | * 设置模糊半径
126 | *
127 | * @param blurRadius 模糊半径,数值越大,图像越模糊,处理耗时越长
128 | */
129 | public void setBlurRadius(int blurRadius) {
130 | if (blurRadius < 0 || blurRadius > 25) {
131 | throw new IllegalArgumentException(
132 | "the blurRadius must be (0 <= blurRadius <= 25), current is " + blurRadius);
133 | }
134 | mBlurRadius = blurRadius;
135 | }
136 |
137 | /**
138 | * 获取模糊图像缩小样本因数
139 | *
140 | * @return
141 | */
142 | public int getDownSampleFactor() {
143 | return mDownSampleFactor;
144 | }
145 |
146 | /**
147 | * 设置进行模糊时,图像缩小样本因数,处理图象时,会先对目标图像进行 1/样本因数 的比例进行缩放,再进行模糊处理。
148 | * 因数越大,选取的图像越小,模糊细节越少,但性能更好。
149 | *
150 | * @param downSampleFactor 图像缩小样本因数,因数越大,选取的图像越小,模糊细节越少,但性能更好
151 | */
152 | public void setDownSampleFactor(int downSampleFactor) {
153 | if (downSampleFactor < 1 || downSampleFactor > 64) {
154 | throw new IllegalArgumentException(
155 | "the downSampleFactor must be (1 <= downSampleFactor <= 64), current is " + downSampleFactor);
156 | }
157 | mDownSampleFactor = downSampleFactor;
158 | mScale = 1f / mDownSampleFactor;
159 | }
160 |
161 | public int getOverlayColor() {
162 | return mOverlayColor;
163 | }
164 |
165 | public void setOverlayColor(int overlayColor) {
166 | mOverlayColor = overlayColor;
167 | }
168 |
169 | /**
170 | * 获取目标视图的图像,进行模糊处理,并将模糊好的图像设置为此视图的背景
171 | */
172 | public void blur() {
173 | if (mToBlurView == null) {
174 | blurBackground(null);
175 | } else {
176 | startBlur();
177 | }
178 |
179 | }
180 |
181 | /**
182 | * 获取目标视图的图像,进行模糊处理,并将模糊好的图像设置为此视图的背景
183 | *
184 | * @param blurRadius 模糊半径
185 | * @param downSampleFactor 缩小样本因数
186 | * @param overlayColor 覆盖层颜色
187 | */
188 | public void blur(int blurRadius, int downSampleFactor, int overlayColor) {
189 | setBlurRadius(blurRadius);
190 | setDownSampleFactor(downSampleFactor);
191 | setOverlayColor(overlayColor);
192 | blur();
193 | }
194 |
195 | protected void startBlur() {
196 | if (!isWorking.get() && mToBlurView.getWidth() != 0 && mToBlurView.getHeight() != 0) {
197 | isWorking.compareAndSet(false, true);
198 | Bitmap bitmap = doBlur();
199 | blurBackground(bitmap);
200 | isWorking.compareAndSet(true, false);
201 | }
202 | }
203 |
204 | /**
205 | * 进行模糊处理
206 | *
207 | * @return 已经进行模糊的图像
208 | */
209 | protected Bitmap doBlur() {
210 | Bitmap desBitmap = getSampleBitmap();
211 | // 模糊半径为0时,不进行模糊处理
212 | if (mBlurRadius != 0) {
213 | desBitmap = getBlurredBitmap(desBitmap);
214 | }
215 | return desBitmap;
216 | }
217 |
218 | /**
219 | * 获取视图的样本图像
220 | *
221 | * @return
222 | */
223 | protected Bitmap getSampleBitmap() {
224 | int viewWidth = mToBlurView.getWidth();
225 | int viewHeight = mToBlurView.getHeight();
226 | Canvas canvas = new Canvas();
227 | int downWidth, downHeight;
228 | if (mDownSampleFactor > 1) {
229 | downWidth = (int) (viewWidth * mScale + 0.5f);
230 | downHeight = (int) (viewHeight * mScale + 0.5f);
231 | canvas.scale(mScale, mScale); // 缩小画布
232 | } else {
233 | downWidth = viewWidth;
234 | downHeight = viewHeight;
235 | }
236 | if (downWidth == 0 || downHeight == 0) {
237 | return null;
238 | }
239 | Bitmap sampleBitmap = Bitmap.createBitmap(downWidth, downHeight, Bitmap.Config.ARGB_8888);
240 | canvas.setBitmap(sampleBitmap);
241 | // TODO 背景方面有问题
242 | mToBlurView.draw(canvas); // 将需要模糊的视图的画面画在画布上
243 | canvas.drawColor(mOverlayColor); // 画覆盖层
244 | return sampleBitmap;
245 | }
246 |
247 | /**
248 | * 获取视图样本的已模糊图像
249 | *
250 | * @param toBlurBitmap 需要被模糊的图像
251 | * @return
252 | */
253 | protected Bitmap getBlurredBitmap(Bitmap toBlurBitmap) {
254 | if (toBlurBitmap == null) {
255 | return null;
256 | }
257 | final Allocation input = Allocation.createFromBitmap(mRenderScript, toBlurBitmap,
258 | Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
259 | final Allocation output = Allocation.createTyped(mRenderScript, input.getType());
260 | mBlurScript.setRadius(mBlurRadius);
261 | mBlurScript.setInput(input);
262 | mBlurScript.forEach(output);
263 | output.copyTo(toBlurBitmap);
264 | return toBlurBitmap;
265 | }
266 |
267 | /**
268 | * 将处理好的图像设置为视图的背景
269 | * @param bitmap
270 | */
271 | protected void blurBackground(Bitmap bitmap) {
272 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
273 | if (bitmap == null) {
274 | setBackgroundDrawable(null);
275 | } else {
276 | setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
277 | }
278 | } else {
279 | if (bitmap == null) {
280 | setBackground(null);
281 | } else {
282 | setBackground(new BitmapDrawable(getResources(), bitmap));
283 | }
284 | }
285 | }
286 |
287 | @Override
288 | protected void onDetachedFromWindow() {
289 | super.onDetachedFromWindow();
290 | destroyRenderScript();
291 | }
292 |
293 | }
294 |
--------------------------------------------------------------------------------
/blurview/src/main/java/com/licheedev/blurview/PartBlurView.java:
--------------------------------------------------------------------------------
1 | package com.licheedev.blurview;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.util.AttributeSet;
6 |
7 | /**
8 | * 部分覆盖高斯模糊
9 | * Created by John on 2015/7/18.
10 | */
11 | public class PartBlurView extends BlurView {
12 |
13 | public PartBlurView(Context context) {
14 | super(context);
15 | }
16 |
17 | public PartBlurView(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 |
21 | public PartBlurView(Context context, AttributeSet attrs, int defStyleAttr) {
22 | super(context, attrs, defStyleAttr);
23 | }
24 |
25 | @Override
26 | protected Bitmap doBlur() {
27 | Bitmap desBitmap = getSampleBitmap();
28 | desBitmap = getCroppedBitmap(desBitmap);
29 | // 模糊半径为0时,不进行模糊处理
30 | if (mBlurRadius != 0) {
31 | desBitmap = getBlurredBitmap(desBitmap);
32 | }
33 | return desBitmap;
34 | }
35 |
36 | /**
37 | * 截取被此视图覆盖掉的那一部分的图像
38 | *
39 | * @param toCropBitmap 被此视图覆盖掉的那一部分的图像
40 | * @return
41 | */
42 | protected Bitmap getCroppedBitmap(Bitmap toCropBitmap) {
43 |
44 | if (toCropBitmap == null) {
45 | return null;
46 | }
47 | int viewLeft = mToBlurView.getLeft();
48 | int viewTop = mToBlurView.getTop();
49 | int cropLeft, cropTop, cropWidth, cropHeight;
50 | if (mDownSampleFactor > 1) {
51 | cropLeft = (int) ((Math.abs(viewLeft - getLeft())) * mScale + 0.5f);
52 | cropTop = (int) ((Math.abs(viewTop - getTop())) * mScale + 0.5f);
53 | cropWidth = (int) ((getWidth() * mScale) + 0.5f);
54 | cropHeight = (int) (getHeight() * mScale + 0.5f);
55 | } else {
56 | cropLeft = Math.abs(getLeft() - viewLeft);
57 | cropTop = Math.abs(viewTop - getTop());
58 | cropWidth = getWidth();
59 | cropHeight = getHeight();
60 | }
61 | if (cropWidth == 0 || cropHeight == 0) {
62 | return null;
63 | }
64 | Bitmap croppedBitmap = Bitmap
65 | .createBitmap(toCropBitmap, cropLeft, cropTop, cropWidth, cropHeight);
66 | toCropBitmap.recycle();
67 | return croppedBitmap;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/blurview/src/main/res/values/blurview_attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/blurview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Blur View
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:1.2.3'
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/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 18 18:46:06 CST 2015
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.4-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 |
--------------------------------------------------------------------------------
/screenshot/ss.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/licheedev/BlurViewDemo/8c43deb414f2011481c31f6f9aef7286591560dd/screenshot/ss.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':blurview'
2 |
--------------------------------------------------------------------------------