标签:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD): 这一个标志的意思是去掉锁屏界面,但这对安全锁(图案或者密码锁屏界面)是无效的。在没有设置安全锁的时候,我们需要上滑一下(可能是其它方式)退出锁屏界面,才能进入桌面,这个标志就是去掉这一界面,使得比如网易云音乐这类在锁屏界面播放的时候,只需要直接解锁云音乐的锁屏即可,不需要再上滑解除系统本身的锁屏。
可以认为锁屏界面是一个窗口视图,解锁图案界面是另一个窗口视图,FLAG_DISMISS_KEYGUARD只能控制去除锁屏界面窗口。
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED): 这一个标志的意思是使得窗口浮在锁屏界面之上。这给像电话这类应用一个快捷的不需要解锁的就能使用的便利。
flag & | ~的使用方法:
public static final int FLAG_A = 0x4; public static final int FLAG_B = 0x8; private int flag = 0;
添加标志,并且不同标志是叠加到这一个变量上的:
flag |= FLAG_A;
flag |= FLAG_B;
判断是否添加了该标志:
boolean hasA = (0 != (flag & FLAG_A)); boolean hasB = (0 != (flag & FLAG_B));
删除某一已添加的标志:
if(hasA){ flag &= ~FLAG_A; } if(hasB){ flag &= ~FLAG_B; }
FLAG_A和FLAG_B的设置也是有讲究的,& | ~是按位操作符,所以必须FLAG必须是按位不重复的。比如FLAG_A = 1; FLAG_B = 2是可以的,FLAG_C = 3就同时包括了FLAG_A和FLAG_B,所以当flag = FLAG_C时,hasA和hasB就同时为true了。
通常我们如下约定FLAG标志:
public static final int SUPPORT_DELETE = 1 << 0; public static final int SUPPORT_ROTATE = 1 << 1; public static final int SUPPORT_SHARE = 1 << 2; public static final int SUPPORT_CROP = 1 << 3; public static final int SUPPORT_SHOW_ON_MAP = 1 << 4; public static final int SUPPORT_SETAS = 1 << 5; public static final int SUPPORT_FULL_IMAGE = 1 << 6; public static final int SUPPORT_ALL = 0xffffffff;
这样就绝对不会有重复了。
public class LogicalTest{ public static final int FLAG_A = 0x00400000; public static final int FLAG_B = 0x00080000; private static int flag = 0; public static void main(String[] args){ flag |= FLAG_A; System.out.println("--- flag = " + Integer.toHexString(flag)+ ", hasA() = " + hasA() + ", hasB() = " + hasB()); flag |= FLAG_B; System.out.println("--- flag = " + Integer.toHexString(flag) + ", hasA() = " + hasA() + ", hasB() = " + hasB()); if(hasA())flag &= ~FLAG_A; System.out.println("--- flag = " + Integer.toHexString(flag) + ", hasA() = " + hasA() + ", hasB() = " + hasB()); if(hasB())flag &= ~FLAG_B; System.out.println("--- flag = " + Integer.toHexString(flag) + ", hasA() = " + hasA() + ", hasB() = " + hasB()); } public static boolean hasA(){ return (0 != (flag & FLAG_A)); } public static boolean hasB(){ return (0 != (flag & FLAG_B)); } }
运行结果:
--- flag = 400000, hasA() = true, hasB() = false --- flag = 480000, hasA() = true, hasB() = true --- flag = 80000, hasA() = false, hasB() = true --- flag = 0, hasA() = false, hasB() = false
FLAG_DISMISS_KEYGUARD & FLAG_SHOW_WHEN_LOCKED
标签:
原文地址:http://www.cnblogs.com/fordreamxin/p/5462695.html