对Android近期任务列表(RecentApplications)的简单分析.doc
《对Android近期任务列表(RecentApplications)的简单分析.doc》由会员分享,可在线阅读,更多相关《对Android近期任务列表(RecentApplications)的简单分析.doc(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、,对Android近期任务列表(Recent Applications)的简单分析分类:Android开发2013-12-31 11:061599人阅读评论(0)收藏举报这里的近期任务列表就是长按Home键出来的那个Dialog,里面放着近期打开过的应用,当然3.0以上系统的多任务切换键也是。这个Dialog的实现在Android源码的/frameworks/base/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java中。接下来就对这个源码分析一下。javaview plaincopy1. publ
2、icclassRecentApplicationsDialogextendsDialogimplementsOnClickListener2. /Elementsfordebuggingsupport3. /privatestaticfinalStringLOG_TAG=RecentApplicationsDialog;4. privatestaticfinalbooleanDBG_FORCE_EMPTY_LIST=false;5. 6. staticprivateStatusBarManagersStatusBar;7. 8. privatestaticfinalintNUM_BUTTONS
3、=8;9. privatestaticfinalintMAX_RECENT_TASKS=NUM_BUTTONS*2;/allowforsomediscards10. 11. finalTextViewmIcons=newTextViewNUM_BUTTONS;12. ViewmNoAppsText;13. IntentFiltermBroadcastIntentFilter=newIntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);14. 15. classRecentTag16. ActivityManager.RecentTaskInfoinf
4、o;17. Intentintent;18. 19. 20. HandlermHandler=newHandler();21. RunnablemCleanup=newRunnable()22. publicvoidrun()23. /dumpextramemorywerehangingonto24. for(TextViewicon:mIcons)25. icon.setCompoundDrawables(null,null,null,null);26. icon.setTag(null);27. 28. 29. ;30. 31. publicRecentApplicationsDialog
5、(Contextcontext)32. super(context,com.android.internal.R.style.Theme_Dialog_RecentApplications);33. 34. 35. 36. /*37. *Wecreatetherecentapplicationsdialogjustonce,anditstaysaround(hidden)38. *untilactivatedbytheuser.39. *40. *seePhoneWindowManager#showRecentAppsDialog41. */42. Override43. protectedv
6、oidonCreate(BundlesavedInstanceState)44. super.onCreate(savedInstanceState);45. 46. Contextcontext=getContext();47. 48. if(sStatusBar=null)49. sStatusBar=(StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);50. 51. 52. Windowwindow=getWindow();53. window.requestFeature(Window.FEATU
7、RE_NO_TITLE);54. window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);55. window.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,56. WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);57. window.setTitle(Recents);58. 59. setContentView(com.android.internal.R.layout.recent_apps_dial
8、og);60. 61. finalWindowManager.LayoutParamsparams=window.getAttributes();62. params.width=WindowManager.LayoutParams.MATCH_PARENT;63. params.height=WindowManager.LayoutParams.MATCH_PARENT;64. window.setAttributes(params);65. window.setFlags(0,WindowManager.LayoutParams.FLAG_DIM_BEHIND);66. 67. /默认显示
9、8个68. mIcons0=(TextView)findViewById(com.android.internal.R.id.button0);69. mIcons1=(TextView)findViewById(com.android.internal.R.id.button1);70. mIcons2=(TextView)findViewById(com.android.internal.R.id.button2);71. mIcons3=(TextView)findViewById(com.android.internal.R.id.button3);72. mIcons4=(TextV
10、iew)findViewById(com.android.internal.R.id.button4);73. mIcons5=(TextView)findViewById(com.android.internal.R.id.button5);74. mIcons6=(TextView)findViewById(com.android.internal.R.id.button6);75. mIcons7=(TextView)findViewById(com.android.internal.R.id.button7);76. mNoAppsText=findViewById(com.andro
11、id.internal.R.id.no_applications_message);77. 78. /关键在哪,你懂得.79. for(TextViewb:mIcons)80. b.setOnClickListener(this);81. 82. 83. 84. Override85. publicbooleanonKeyDown(intkeyCode,KeyEventevent)86. if(keyCode=KeyEvent.KEYCODE_TAB)87. /IgnoreallmetakeysotherthanSHIFT.Theappswitchkeycouldbea88. /fallbac
12、kactionchordedwithALT,METAorevenCTRLdependingonthekeymap.89. /DPadnavigationishandledbytheViewRootelsewhere.90. finalbooleanbackward=event.isShiftPressed();91. finalintnumIcons=mIcons.length;92. intnumButtons=0;93. while(numButtonsnumIcons&mIconsnumButtons.getVisibility()=View.VISIBLE)94. numButtons
13、+=1;95. 96. if(numButtons!=0)97. intnextFocus=backward?numButtons-1:0;98. for(inti=0;inumButtons;i+)99. if(mIconsi.hasFocus()100. if(backward)101. nextFocus=(i+numButtons-1)%numButtons;102. else103. nextFocus=(i+1)%numButtons;104. 105. break;106. 107. 108. finalintdirection=backward?View.FOCUS_BACKW
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 近期 任务 列表 RecentApplications 简单 分析
限制150内