Android 通过按键旋转屏幕
2012-08-16 10:25
330 查看
很好的帖子:
自己做的立方体旋转效果
http://www.eoeandroid.com/thread-185331-1-1.html
Android多线程后台下源码
http://www.eoeandroid.com/thread-185328-1-1.html
android仿酷狗播放器
http://www.eoeandroid.com/thread-185894-1-1.html
-------------------帖子正文-----------------------
有个功能,通过长按menu按键,可以旋转屏幕方向(0°或者90°),这个功能有时蛮有用的,下面来看看是如何实现的:
1 修改按键处理程序
frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
函数
3、当然也可以新作一个rotate键来选择屏幕,以下是引用代码
本文出自 “Android小子的” 博客,请务必保留此出处http://androidrigl.blog.51cto.com/7531835/1247586
自己做的立方体旋转效果
http://www.eoeandroid.com/thread-185331-1-1.html
Android多线程后台下源码
http://www.eoeandroid.com/thread-185328-1-1.html
android仿酷狗播放器
http://www.eoeandroid.com/thread-185894-1-1.html
-------------------帖子正文-----------------------
有个功能,通过长按menu按键,可以旋转屏幕方向(0°或者90°),这个功能有时蛮有用的,下面来看看是如何实现的:
1 修改按键处理程序
frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
函数
public boolean interceptKeyTi(WindowState win, int code, int metaKeys, boolean down,int repeatCount, int flags) //在处理菜单键的地方 if (code == KeyEvent.KEYCODE_MENU) { final int chordBug = KeyEvent.META_SHIFT_ON; if (down && repeatCount == 0) { if (mEnableShiftMenuBugReports && (metaKeys & chordBug) == chordBug) { Intent intent = new Intent(Intent.ACTION_BUG_REPORT); mContext.sendOrderedBroadcast(intent, null); return true; } else if (SHOW_PROCESSES_ON_ALT_MENU &&(metaKeys & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { Intent service = new Intent(); service.setClassName(mContext, "com.android.server.LoadAverageService"); ContentResolver res = mContext.getContentResolver(); boolean shown = Settings.System.getInt(res, Settings.System.SHOW_PROCESSES, 0) != 0; if (!shown) { mContext.startService(service); } else { mContext.stopService(service); } Settings.System.putInt(res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1); return true; } } //上面是原来的内容,下面是添加的新内容 else if (down && repeatCount == 20 && MenuKeyUp && (!keyguardOn)) { //如果按下Menu键一定时间,抬起时执行此段函数 MenuKeyUp = false; try { int ro = mWindowManager.getRotation(); //获取当前方向 if( ro == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ) { ro = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } else { ro = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } }catch (RemoteException e) { Log.v(TAG, "!!! getRotation fail !!!"); } try { //旋转屏幕 mWindowManager.setRotation(ro, true, Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); //最后可跟不同的参数,可实现一些旋转效果 } catch (RemoteException e) { Log.v(TAG, "!!! mWindowManager.setRotation fail !!!"); } return true; } if(!down) { MenuKeyUp = true; } }2 修改实现选择的函数
/frameworks/base/services/java/com/android/server/WindowManagerService.java //找到该函数 public boolean setRotationUncheckedLocked(int rotation, int animFlags) //将以下妨碍选择的内容注释掉 //rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, // mRotation, mDisplayEnabled);
3、当然也可以新作一个rotate键来选择屏幕,以下是引用代码
} else if (code == KeyEvent.KEYCODE_ROTATE) { // ROTATE KEY pressed if (down) { mButtonPushFlg = true; try { int ro = mWindowManager.getRotation(); // Orientation vertical if (ro == 3 ) { mWindowManager.setRotation (Surface.ROTATION_0,true,mFancyRotationAnimation); //Orientation landscape } else { mWindowManager.setRotation(Surface.ROTATION_270,true,mFancyRotationAnimation); //Orientation portlate } } catch (RemoteException e) { // Igbore Log.i("info", "Rotation failed "); } } return true; }
本文出自 “Android小子的” 博客,请务必保留此出处http://androidrigl.blog.51cto.com/7531835/1247586
相关文章推荐
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕 zz
- Android 通过按键旋转屏幕
- Android 通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android中通过按键旋转屏幕
- Android开发: 通过修改数据库改变屏幕旋转方向screen rotation
- Android开发: 通过修改数据库改变屏幕旋转方向screen rotation
- 通过广播获取Android屏幕旋转事件
- 我的Android进阶之旅------>Android中通过adb shell input来模拟滑动、按键、点击事件
- 利用framework层任意设置Android屏幕的旋转方向
- 安卓Android-X86强制竖屏 安卓(Android)x86屏幕旋转解决方法
- 2013新春奉送:Android摄像头开发完美demo---(循环聚焦,缩放大小,旋转picture,查询支持的picturesize, ImageButton按键效果)
- Android 6.0 屏幕旋转系统流程分析
- 我的Android进阶之旅------>Android中通过adb shell input来模拟滑动、按键、点击事件
- Android-旋转屏幕前保存数据