




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、您还未登录!|CSDN 首页资讯论坛博客下载搜索更多公告:CSDN 社区招聘.Net 开发工程师、运营专员,UI 设计师在Android 的Settings-Sound and Display 中有Orientation 这一设置项,反转手机,手机屏幕会随之旋转,一般只可以旋转90度。这一settings 设置是在文件SoundAndDisplaySettings.java 中,该项对应串为:view plaincopy to clipboardprint?1. private static final String KEY_ACCELEROMETER = accelerom 其默认值保存在x
2、ml 文件中,默认是Enable 。UI 程序初始化时会根据其值是框中打勾(代码在onCreate 函数中:view plaincopy to clipboardprint?1. protected void onCreate(Bundle savedInstanceState 2. 3. mAccelerometer = (CheckBoxPreference findPreferenc CELEROMETER; 4. mAccelerometer.setPersistent(false; 5. 6. 当用户改变了该值时,会保存起来: 利用GSensor 让屏幕实现360度旋转 收藏lian
3、gshengyang 的专栏登录注册空间博客好友相册留言用户操作留言 发消息 加为 ,ID :liangshengyang 共5242次访问,排名2万外人,关注者4人。,qq:,的文章原创 18 篇翻译 0 篇转载 1 篇评论 9 篇订阅我的博客2011/5/19利用GSensor 让屏幕实现360度旋转 - lia view plaincopy to clipboardprint?1. public boolean onPreferenceTreeClick(PreferenceScreen prefeeen, Preference preference 2. 3. else if (pre
4、ference = mAccelerometer 4. Settings.System.putInt(getContentResolver(,5. Settings.System.ACCELEROMETER_ROTATION6. mAccelerometer.isChecked( ? 1 : 0;7. 8. 文件frameworks/policies/base/phone/com/android/internal/policy/eWindowManager.java中的SettingsServer会随时监控其值,对用户设置:view plaincopy to clipboardprint?1.
5、 public void update( 2. ContentResolver resolver = mContext.getContentRe3. boolean updateRotation = false;4. synchronized (mLock 5. 6. int accelerometerDefault = Settings.System.getIn,7. Settings.System.ACCELEROMETER_ROTATIOULT_ACCELEROMETER_ROTATION;8. if (mAccelerometerDefault != accelerometerDefa
6、u9. mAccelerometerDefault = accelerometerDefau10. updateOrientationListenerLp(;11. 12. 13. 上述是设置生效流程。当Orientation设置Enable时,会发生什么呢?liangshengyang的公告文章分类AndroidC/C+/LinuxGitGstreamer存档2011年02月(52011年01月(12010年11月(12010年09月(42010年08月(12010年07月(72011/5/19利用GSensor让屏幕实现360度旋转 - lia在PhoneWindowManager.jav
7、a有个Listener,它会根据Sensor判别出的,调用WindowManager.setRotation让屏幕进行旋转。另外,当应用程序屏幕旋转时则不会旋转,见函数needSensorRunningLp(。view plaincopy to clipboardprint?1. class MyOrientationListener extends WindowOrientationListen2. MyOrientationListener(Context context 3. super(context;4. 5.6. Override7. public void onOrientati
8、onChanged(int rotation 8. / Send updates based on orientation value9. if (true Log.i(TAG, onOrientationChanged, rotation co +rotation;10. try 11. mWindowManager.setRotation(rotation, false,12. mFancyRotationAnimation;13. catch (RemoteException e 14. / Ignore15. 16. 17. 18. MyOrientationListener mOri
9、entationListener;19. boolean useSensorForOrientationLp(int appOrientation 20. if (appOrientation = ActivityInfo.SCREEN_ORIENTATIOR 21. return true;22. 23. if (mAccelerometerDefault != 0 & (24. appOrientation = ActivityInfo.SCREEN_ORIENTATR |25. appOrientation = ActivityInfo.SCREEN_ORIENTATPECIFIED 2
10、6. return true;27. 28. return false;29. 30.31. /*32. * We always let the sensor be switched on by default exce33. * the user has explicitly disabled sensor based rotation or34. * screen is switched off.35. */36. boolean needSensorRunningLp( 37. if (mCurrentAppOrientation = ActivityInfo.SCREEN_ORN_SE
11、NSOR 38. / If the application has explicitly requested to follow t39. / orientation, then we need to turn the sensor or.40. return true;41. 42. if (mAccelerometerDefault = 0 43. / If the setting for using the sensor by default is ena44. / we will always leave it on. Note that the user could45. / a w
12、indow that forces an orientation that does not u46. / sensor and in theory we could turn it off. howeverext47. / turning it on we wont have a good value for the cu48. / orientation for a little bit, which can cause orientati49. / changes to lag, so wed like to keep it always on. (50. / still be turn
13、ed off when the screen is off.51. return false;52. 53. return true;54. 在WindowOrientationListener(见文件javaframeworks/base/core/ja d/view/WindowOrientationListener.java中会监听Sensor的值,对旋行判断,然后调用抽象方法onOrientationChanged,因此,只要在子类重新实现这个函数即可对四个不同方向做出响应(见上面让屏幕旋转即是一遗憾的是在Donut和clair中,对旋转方向的识别只给出了90度旋转,在了一个270度旋
14、转,不支持180度即倒立的操作。可以在修改下面代码,判断来自于Gsensor的值,识别出旋转方向:view plaincopy to clipboardprint?1. public void onSensorChanged(SensorEvent event 2. float values = event.values;3. float X = values_DATA_X;4. float Y = values_DATA_Y;5. float Z = values_DATA_Z;6. float OneEightyOverPi = 57.29577957855f;7. float gravi
15、ty = (float Math.sqrt(X*X+Y*Y+Z*Z;8. float zyangle = (floatMath.asin(Z/gravity*OneEightyOve9. int rotation = -1;10. if (zyangle = PIVOT_LO11. / Check orientation only if the phone is flat enough12. / Dont trust the angle if the magnitude is small compae y value13. float angle = (floatMath.atan2(Y, -
16、X * OneEightyOver14. int orientation = 90 - (intMath.round(angle;15. / normalize to 0 - 359 range16. while (orientation = 360 17. orientation -= 360;18. 19. while (orientation = PL_LOWER & (orientation = LP_UP float threshold; float delta = zyangle - PIVOT; if (mSensorRotation = Surface.ROTATION_90
17、if (delta = threshold ? Surface.RO _0 : Surface.ROTATION_90; else if (delta 0 / Delta is negative else threshold = PL_UPPER-(PL_LF_UPPER * delta; threshold = PL_UPPER+(PL_LF_LOWER * delta; rotation = (orientation = LANDSCAPE_LOWER & (orien LP_LOWER rotation = Surface.ROTATION_90; else if (orientatio
18、n = PL_UPPER | (orientation = P T_LOWER rotation = Surface.ROTATION_0; if (rotation != -1 & (rotation != mSensorRotation mSensorRotation = rotation; 6/8 2011/5/19 利用GSensor让屏幕实现360度旋转 - lia 54. 55. 56. 57. onOrientationChanged(mSensorRotation; 在Froyo中,对上述算法进行了修改,让其报出270度的旋转方向。 发表于 2010年09月22日 11:10:00 | 评论( 1 | 举报 旧一篇:Android中Native代码SIGSEGV调试-调用堆栈解
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业创新的营销策略与实践
- 3《当冲突发生》(教学设计)2023-2024学年统编版道德与法治四年级下册
- Unit 1 How do we feel (教学设计)-2024-2025学年沪教版(2024)英语三年级上册
- 兴趣班外聘合同标准文本
- 中介旺铺出租合同标准文本
- 个人装修拆除合同标准文本
- 公园门卫服务合同标准文本
- KTV清洁合同标准文本
- AI与心理健康服务的结合应用
- Ag2Se薄膜的制备及热电性能研究
- YY/T 0109-2024医用超声雾化器
- 2024年涉密人员考试试题库保密基本知识试题含答案
- 2024年退股事宜洽谈备忘录3篇
- 2025版科技成果转化合作协议书3篇
- 微创介入诊断治疗管理制度
- 新质生产力促进老年人公共体育服务高质量发展研究
- 大学生学业个人规划
- 软件产品售后服务及维护流程指南
- T-ZNZ 248-2024 红黄壤贫瘠耕地快速培肥技术规范
- 2024-2025一年级下册体育教学计划和教案
- 2024年度安徽省高校教师资格证之高等教育学题库附答案(典型题)
评论
0/150
提交评论