使用:

1.在执行弹出界面前,先将其当前屏幕截图。

 BlurBuilder.snapShotWithoutStatusBar(getActivity());

2.为了确保界面切入无效果。

 startActivity(wechatIntent);
context.overridePendingTransition(
android.view.animation.Animation.INFINITE,
android.view.animation.Animation.INFINITE);

3.在切换的页面中初始化背景ImageView:

 private void applyBlur() {
iv_shared_layout.setImageBitmap(BlurBuilder.blur(iv_shared_layout));
if (BlurBuilder.isBlurFlag()) {
iv_shared_layout.setVisibility(View.VISIBLE);
}
}

4.在acitivity的super.finish();或者在onDestroy中回收资源:

 @Override
public void finish() {
defaultFinishNotActivityHelper();
BlurBuilder.recycle();
overridePendingTransition(android.view.animation.Animation.INFINITE,
android.view.animation.Animation.INFINITE);
}

毛玻璃模糊效果使用类:

 public class BlurBuilder {

     private static final float BITMAP_SCALE = 0.4f;
private static final float BLUR_RADIUS = 7.5f; private static Bitmap tab_bg = null;
private static Bitmap overlay = null;
private static boolean blurFlag = false; public static boolean isBlurFlag() {
return BlurBuilder.blurFlag;
} public static void setBlurFlag(boolean blurFlag) {
BlurBuilder.blurFlag = blurFlag;
} public static Bitmap blur(View v) {
if (tab_bg == null) {
android.util.Log.i("", "tab_bg == null");
blurFlag = false;
return null;
}
blurFlag = true;
blur(v.getContext(), tab_bg);
return overlay;
} public static void blur(Context ctx, Bitmap image) {
if (overlay != null) {
recycle();
}
try {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE); overlay = Bitmap.createScaledBitmap(image, (int) (width),
(int) (height), false); overlay = FastBlur.doBlur(overlay, (int) BLUR_RADIUS, true);
} catch (Exception e) {
e.printStackTrace();
}
} public static void getScreenshot(View v) {
if (tab_bg != null) {
recycle();
}
try {
tab_bg = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Bitmap.Config.RGB_565);
Canvas c = new Canvas(tab_bg);
v.draw(c);
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 获取当前屏幕截图,不包含状态栏
*
* @param activity
* @return
*/
public static void snapShotWithoutStatusBar(Activity activity) {
if (tab_bg != null) {
recycle();
}
View view = activity.getWindow().getDecorView();
try {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
tab_bg = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView()
.getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top; int width = ScreenUtils.getScreenWidth(activity);
int height = ScreenUtils.getScreenHeight(activity);
tab_bg = Bitmap.createBitmap(tab_bg, 0, statusBarHeight, width,
height - statusBarHeight);
view.destroyDrawingCache();
} catch (Exception e) {
e.printStackTrace();
getScreenshot(view);
}
} public static void recycle() { try {
if (tab_bg != null) {
tab_bg.recycle();
System.gc();
tab_bg = null;
}
if (overlay != null) {
overlay.recycle();
System.gc();
overlay = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

毛玻璃模糊效果类:

 public class FastBlur {

     public static Bitmap doBlur(Bitmap sentBitmap, int radius,
boolean canReuseInBitmap) { Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
} if (radius < 1) {
return (null);
} int w = bitmap.getWidth();
int h = bitmap.getHeight(); int[] pix = new int[w * h];
bitmap.getPixels(pix, 0, w, 0, 0, w, h); int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1; int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int vmin[] = new int[Math.max(w, h)]; int divsum = (div + 1) >> 1;
divsum *= divsum;
int dv[] = new int[256 * divsum];
for (i = 0; i < 256 * divsum; i++) {
dv[i] = (i / divsum);
} yw = yi = 0; int[][] stack = new int[div][3];
int stackpointer;
int stackstart;
int[] sir;
int rbs;
int r1 = radius + 1;
int routsum, goutsum, boutsum;
int rinsum, ginsum, binsum; for (y = 0; y < h; y++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
for (i = -radius; i <= radius; i++) {
p = pix[yi + Math.min(wm, Math.max(i, 0))];
sir = stack[i + radius];
sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff);
rbs = r1 - Math.abs(i);
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;
if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
}
}
stackpointer = radius; for (x = 0; x < w; x++) { r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum]; rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum; stackstart = stackpointer - radius + div;
sir = stack[stackstart % div]; routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2]; if (y == 0) {
vmin[x] = Math.min(x + radius + 1, wm);
}
p = pix[yw + vmin[x]]; sir[0] = (p & 0xff0000) >> 16;
sir[1] = (p & 0x00ff00) >> 8;
sir[2] = (p & 0x0000ff); rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2]; rsum += rinsum;
gsum += ginsum;
bsum += binsum; stackpointer = (stackpointer + 1) % div;
sir = stack[(stackpointer) % div]; routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2]; rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2]; yi++;
}
yw += w;
}
for (x = 0; x < w; x++) {
rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
yp = -radius * w;
for (i = -radius; i <= radius; i++) {
yi = Math.max(0, yp) + x; sir = stack[i + radius]; sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi]; rbs = r1 - Math.abs(i); rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs; if (i > 0) {
rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2];
} else {
routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2];
} if (i < hm) {
yp += w;
}
}
yi = x;
stackpointer = radius;
for (y = 0; y < h; y++) {
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16)
| (dv[gsum] << 8) | dv[bsum]; rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum; stackstart = stackpointer - radius + div;
sir = stack[stackstart % div]; routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2]; if (x == 0) {
vmin[y] = Math.min(y + r1, hm) * w;
}
p = x + vmin[y]; sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p]; rinsum += sir[0];
ginsum += sir[1];
binsum += sir[2]; rsum += rinsum;
gsum += ginsum;
bsum += binsum; stackpointer = (stackpointer + 1) % div;
sir = stack[stackpointer]; routsum += sir[0];
goutsum += sir[1];
boutsum += sir[2]; rinsum -= sir[0];
ginsum -= sir[1];
binsum -= sir[2]; yi += w;
}
} bitmap.setPixels(pix, 0, w, 0, 0, w, h); return (bitmap);
}
}

android 获取当前屏幕作为毛玻璃模糊背景Acitivity作为弹出框。的更多相关文章

  1. Android 学习笔记之AndBase框架学习(二) 使用封装好的进度框,Toast框,弹出框,确认框...

    PS:渐渐明白,在实验室呆三年都不如在企业呆一年... 学习内容: 1.使用AbActivity内部封装的方法实现进度框,Toast框,弹出框,确认框...   AndBase中AbActivity封 ...

  2. Android 自定义界面的弹出框(可输入数据)

    上午写了一篇博文,介绍了如何定义从屏幕底部弹出PopupWindow,写完之后,突然想起之前写过自定义内容显示的弹出框,就随手写了两个实例,分享出来: 第一种实现方式:继承Dialog 1.1 线定义 ...

  3. Android Animation动画实战(二):从屏幕底部弹出PopupWindow

    在这篇文章之前,我已经陆陆续续写了几篇博客,介绍了Android Animation是如何使用的,有还不明白的,可以点击查看: 1. Android Animation动画详解(一): 补间动画 2. ...

  4. ALV屏幕捕捉回车及下拉框事件&ALV弹出框回车及下拉框事件

    示例展示: 屏幕依据输入的物料编码或下拉框物料编码拍回车自动带出物料描述: 点击弹出框,输入物料编码拍回车带出物料描述,点击确认,更新ALV: 1.创建屏幕9000,用于处理ALV弹出框: 2.针对屏 ...

  5. 【Android】各式各样的弹出框与对菜单键、返回键的监听

    Android自带各式各样的弹出框.弹出框也是安卓主要的组件之中的一个.同一时候安卓程序能够对菜单键.返回键的监听.但在安卓4.0之后就禁止对Home键的屏蔽与监听,强制保留为系统守护按键.假设非要对 ...

  6. android自定义弹出框样式实现

    前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...

  7. android 三种弹出框之一PopupWindow

    PopupWindow 在android的弹出框我目前了解到的是有三种:AlertDialog,PopupWindow,Activity伪弹框, AlertDialog太熟悉了,这里就不介绍了 就先看 ...

  8. android 弹出框(输入框和选择框)

    1.输入框: final EditText inputServer = new EditText(this); inputServer.setFilters(new InputFilter[]{new ...

  9. 自设table表格,获取内容,并经弹出框的url传参,获取结果显示在弹出框,并加载合计

    table表格,选择框 form id="editForm1"> <table class="table_form"> <td > ...

随机推荐

  1. [BZOJ1370][Baltic2003]Gang团伙

    [BZOJ1370][Baltic2003]Gang团伙 试题描述 在某城市里住着n个人,任何两个认识的人不是朋友就是敌人,而且满足: 1. 我朋友的朋友是我的朋友: 2. 我敌人的敌人是我的朋友: ...

  2. asp.net 网站 或者web Api 发布

    asp.net 发布iis时可能遇到的内部服务错误常见的有两种: 1.如下图,500.19 Internal Server Error(内部服务错误) 这种错误可能是由于本机的注册表中的asp.net ...

  3. doTjs源码研究笔记

    首先是入口方法 /*tmpl:模板文本 c:用户自定义配置 def:定义编译时执行的数据*/doT.template = function(tmpl, c, def) { } 然后进入第一句代码 c ...

  4. ZJOI 游记

    在备战YZ提前招生考时去ZJOI玩了趟,ZJ果然人才辈出= =神犇讲课各种神听不懂啊orz day 0 Mon. 上午在AB班愉快地玩耍,下午就去HZ了. HZ真热啊... 学军也是节约= =空调都不 ...

  5. shell笔记-local、export用法 、declare、set

    local一般用于局部变量声明,多在在函数内部使用.     1.    Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止.     2. ...

  6. 【转】Oracle数据库中Sequence的用法

    在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方. 1.Create Sequence (注释:你需要有CREATE S ...

  7. sphinx 增量索引与主索引使用测试

    2013年10月28日 15:01:16 首先对新增的商品建立增量索引,搜索时只使用增量索引: array (size=1) 0 => array (size=6) 'gid' => st ...

  8. Java for LeetCode 160 Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  9. Java for LeetCode 076 Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  10. 51nod 1264 线段相交

    题目:传送门. 题意:给两条线段,有一个公共点或有部分重合认为相交,问他们是否相交. 题解:这属于非规范相交的情况,模板题. #include <iostream> #include &l ...