使用:

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. [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草

    [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...

  2. C++中的复制、赋值、析构

    一直对C++的复制(Copy).赋值(Assign)操作比较困惑,现在看书的时候看到了,就把它顺便记下来. 一.什么时候触发 一下代码可以熟悉什么时候触发复制操作,以及什么时候触发赋值操作: // t ...

  3. centos7下cups + samba共打印服务的教程

    centos7系统我们用到的不多但是这款系统比centos6功能要强大了不少,下文来介绍一篇centos7下cups + samba,共打印服务的例子,具体如下所示.   这个算是rhce课程的篇外篇 ...

  4. Controller之间传递数据:协议传值

    http://itjoy.org/?p=416 前边介绍过从第一个页面传递数据到第二个页面,那么反过来呢我们该如何操作?还是同一个例子,将第二个页面的字符串传递到第一个页面显示出来,这中形式就可以使用 ...

  5. python下的MySQLdb使用

    下载安装MySQLdb <1>linux版本 http://sourceforge.net/projects/mysql-python/ 下载,在安装是要先安装setuptools,然后在 ...

  6. Java for LeetCode 153 Find Minimum in Rotated Sorted Array

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  7. Java for LeetCode 036 Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  8. codeforces B. New Year Present 解题报告

    题目链接:http://codeforces.com/contest/379/problem/B 题目意思:给定一个有n个钱包的序列,其中第i个钱包需要投入ai个钱币,需要编写一个程序,使得在对第i个 ...

  9. 如何在Ubuntu下安装”.deb“、”.bin“、”.tar.gz“、”.tar.bz2“格式的软件包!

    今天在Ubuntu11.10中安装Google chrome浏览器是遇到了问题,下载好的“.deb”格式的安装文件google-chrome-stable.deb双击后或者右键快捷菜单选择 Synap ...

  10. 基因变异(codevs 3194)

    题目描述 Description 小毛终于来到了冥王星,这是一颗已经不属于行星的矮行星,它的表面温度低于-220度.在这里,小毛惊奇的发现,他带来的厌氧菌开始了基因变异,裂变的速度与光照时间(秒)成乘 ...