Android实现利用手势完成屏幕密码锁功能

2014-11-24 10:56:01 来源: 作者: 浏览: 0

2.关于判断MEDIA_MOUNTED,API的解释:getExternalStorageState() returns MEDIA_MOUNTED if the media ispresent and mounted at its mount point with read/write access.


4.关于android.intent.action.MAIN


决定应用程序最先启动的Activity


android.intent.category.LAUNCHER


决定应用程序是否显示在程序列表里


5.关于R.id的问题,将要import类R所在的包


6.利用了Android SDK范例开发中的GestureOverlayView进行开发画图工具


7.实现了在service中启动activity


Intent i = new Intent(UpdateService.this,Lock.class);


i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


this.startActivity(i);



8. //隐藏界面


this.requestWindowFeature(Window.FEATURE_NO_TITLE);


this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);


Don't call setContentView() before requestFeature().


9.全屏并屏蔽HOME键,以及屏蔽返回键,完成办法。


public booleanonKeyDown(int keyCode,KeyEvent event){


switch(keyCode){


caseKeyEvent.KEYCODE_HOME:return true;


caseKeyEvent.KEYCODE_BACK:return true;


caseKeyEvent.KEYCODE_CALL:return true;


caseKeyEvent.KEYCODE_SYM: return true;


caseKeyEvent.KEYCODE_VOLUME_DOWN: return true;


caseKeyEvent.KEYCODE_VOLUME_UP: return true;


caseKeyEvent.KEYCODE_STAR: return true;


}


returnsuper.onKeyDown(keyCode, event);


}


屏蔽home键的代码:



public voidonAttachedToWindow() {


this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);


super.onAttachedToWindow();


}



//出现问题:WindowManager.LayoutParams.TYPE_KEYGUARD以及


LayoutParams.FLAG_FULLSCREEN出现冲突,无法解决,搜索网上无解决办法。


参考文档:


\frameworks\policies\base\phone\com\android\internal\policy\impl\PhoneWindowManager.java1089行


if (code ==KeyEvent.KEYCODE_HOME) {



// If a system window has focus,then it doesn't make sense


// right now to interact withapplications.


WindowManager.LayoutParams attrs =win != null win.getAttrs() : null;


if (attrs != null) {


final int type = attrs.type;


if (type ==WindowManager.LayoutParams.TYPE_KEYGUARD


|| type ==WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {


// the "app" iskeyguard, so give it the key


return false;


}


final int typeCount =WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;


for (int i=0; i

if (type ==WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {


// don't do anything,but also don't pass it to the app


return true;


}


}


}



因此解决问题!



10.出现了返回HOME页后重新从程序页进入,发现又进入开锁界面:


经过查询思考,发现,其实是HOME页后将程序放入处理栈当中,所以重新进入时就会继续回到栈顶,并且破坏了全屏效果。


因此必须实现返回键功能,而不是HOME键。


因此,使用finish();方法就足够了,狗日的SDK开发,竟然写了一个外部监听,不能使用finish方法,后来改写成内部类,直接搞定。


根据个人感觉,其实监听写内部类还是比较保险的,开发初级阶段,慢慢摸索。


newGestureOverlayView.OnGesturePerformedListener()



最后,上效果图,4天的结果,还不错。起码解决了全屏显示和屏蔽HOME键的问题。


PS:将会对来电开锁功能进行更新


上图:






-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: