当前位置: 移动技术网 > IT编程>移动开发>Android > Android利用手势完成屏幕密码锁功能

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

沧州西站,恋清尘,宋祖德爆料李天一

本文实例为大家分享了android画笔屏幕锁小程序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

1.如果使用gestureoverlayview,在xml配置文件中使用android.gesture.gestureoverlayview,否则会报classnotfoundexception

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

3.使用了service和broadcastreciever进行监听,监测到屏幕亮暗进行程序启动,参考了文章:

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<typecount;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:将会对来电开锁功能进行更新

上图:


更多内容请参考专题:android密码使用教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网