禁用UI在我的活动,当用户将手机他/她耳朵附近? [英] Disable UI in my Activity when user places the phone near his/her ear?

查看:145
本文介绍了禁用UI在我的活动,当用户将手机他/她耳朵附近?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何禁用我的UI我的活动,当用户发生的电话他/她耳朵附近?

How can I disable my UI of my activity when user place the phone near his/her ear?

我知道有是获得一个回调的API时,有一个传感器来测试接近:

I know there is an API which get a call back when there is a sensor to test for Proximity:

http://developer.android.com/reference/android/hardware/ Sensor.html

http://developer.android.com/reference/android/hardware/ SensorManager.html

但我怎么可以禁用UI(用户一样的脸会不会误作为UI触摸),然后重新启用回当手机远离用户的脸?

But how can I disable UI (like user's face won't mistakenly as UI touching) and then re-enable back when the phone is further away from User's face?

感谢您。

推荐答案

您可以看看<一个href=\"https://github.com/android/platform_packages_apps_phone/blob/master/src/com/android/phone/PhoneApp.java\"相对=nofollow> PhoneApp 和<一个href=\"https://github.com/android/platform_packages_apps_phone/blob/master/src/com/android/phone/InCallScreen.java\"相对=nofollow> InCallScreen 从AOSP源$ C ​​$ C,了解有关如何做你想做的一些想法。这里的要点:

You can look at the PhoneApp and InCallScreen source code from AOSP for some ideas on how to do what you want. Here are the main points:


  • 在支持它的设备上,AOSP code利用隐藏 PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK 根据需要(见关闭触摸屏上的 PhoneApp.updateProximitySensorMode()法)。

  • 在其他设备上,方法是使用一个触摸锁定叠加(只是显示/隐藏视图覆盖整个屏幕,这会消耗触摸事件)。参见 initTouchLock() enableTouchLock() onTouch() InCallScreen 源的方法(code处理 mTouchLockOverlay 居多)。

  • On devices that support it, the AOSP code utilize the hidden PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK to turn off the touchscreen as needed (see the PhoneApp.updateProximitySensorMode() method).
  • On other devices, the approach is to use a "touch lock" overlay (simply showing/hiding a View covering the whole screen which will consume the touch events). See initTouchLock(), enableTouchLock() and onTouch() methods in the InCallScreen source (code dealing with mTouchLockOverlay mostly).

我会建议使用叠加的方法,因为它可以在所有设备上运行。

I would recommend using the overlay approach since it will work on all devices.

根据您的UI层次结构,使用覆盖可能也被比作切换你的正常的用户界面的触摸和可见性状态,因为它更容易实现,你可以很轻松地添加一些视觉反馈较好(调光/动画也许?)同时叠加显示。

Depending on your UI hierarchy, using an overlay might also be better compared to toggling the touch and visibility state of your normal UI since it is simpler to implement and you can add some visual feedback very easily (dimming/animation maybe?) while the overlay is shown.

这篇关于禁用UI在我的活动,当用户将手机他/她耳朵附近?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆