关闭

实现第三方锁屏

169人阅读 评论(0) 收藏 举报
分类:
最近做了个锁屏项目, 网上有很多人说修改

launcher的主页来屏蔽home键.这个我试了下,有个很大的弊端就是单你每次按home键的时候都会让你选择launcher主页.就算你选择把你的程序设为主页它还是会弹出选择框个人感觉非常烦.还有一种就是启动一个窗体使窗体满屏,在窗体中加载我们想要的布局.这样home键的事件就不会影响窗体从而实现锁屏.


下面就来看下窗体类

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
//锁屏工具了全屏窗体
public class LockLayer {
	private WindowManager mWindowManager;
	private View mLockView;
	private LayoutParams mLockViewLayoutParams;
	private static LockLayer mLockLayer;
	private boolean isLocked;

	public static synchronized LockLayer getInstance(Context context) {
		if (mLockLayer == null) {
			mLockLayer = new LockLayer();
			mLockLayer.init(context);
		}
		return mLockLayer;
	}

	private LockLayer() {
	}

	public void init(Context context) {
		isLocked = false;
		mWindowManager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		mLockViewLayoutParams = new LayoutParams();
		mLockViewLayoutParams.width = LayoutParams.MATCH_PARENT;
		mLockViewLayoutParams.height = LayoutParams.MATCH_PARENT;
		// 实现关键
		mLockViewLayoutParams.type = LayoutParams.TYPE_SYSTEM_ALERT
				| LayoutParams.TYPE_SYSTEM_OVERLAY;
		// apktool value,这个值具体是哪个变量还请网友帮忙
		// 让window占满整个手机屏幕,不留任何边界LayoutParams.FLAG_LAYOUT_IN_SCREEN
		mLockViewLayoutParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
				| LayoutParams.FLAG_NOT_FOCUSABLE
				| LayoutParams.FLAG_LAYOUT_IN_SCREEN;
	}
	//锁屏
	public synchronized void lock() {
		if (mLockView != null && !isLocked) {
			Log.i("jjf", "....lock");
			mWindowManager.addView(mLockView, mLockViewLayoutParams);
			isLocked = true;
		}
	}
	//解锁
	public synchronized void unlock() {
		if (mWindowManager != null && isLocked) {
			Log.i("jjf", "unlock2");
			mWindowManager.removeView(mLockView);
			isLocked = false;
		}
	}
	//判断是否是锁屏状态
	public boolean isShow() {
		return isLocked;
	}
	//加载锁屏布局
	public synchronized void setLockView(View v) {
		mLockView = v;
	}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:24294次
    • 积分:799
    • 等级:
    • 排名:千里之外
    • 原创:58篇
    • 转载:4篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论