zoukankan      html  css  js  c++  java
  • Launcher中Shortcut的创建流程简析

    本文将以ContactsDirect dial为例,来解析在Launcher创建shortcut的流程

    Direct dialAndroidManifest.xml(Contacts)中声明如下:

            <activity-alias android:name="alias.DialShortcut"
                android:targetActivity=".activities.ContactSelectionActivity"
                android:label="@string/shortcutDialContact"
                android:icon="@mipmap/ic_launcher_shortcut_directdial"
                android:enabled="@*android:bool/config_voice_capable">
                <intent-filter>
                    <action android:name="android.intent.action.CREATE_SHORTCUT" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.CAR_MODE" />
                </intent-filter>
            </activity-alias>

    这样,在LauncherWIDGETS页面便可找到Direct dial(android.intent.action.CREATE_SHORTCUT

    我们将Direct dial拖拽到桌面后,会触发.activities.ContactSelectionActivity.选择一个联系人,就完成了Direct dial的创建。

    点击该shortcut将跳转到给我们选择的联系人打电话界面。

    下面是我打的Log,重要步骤都被标红了。

    -----------launcher widget页面选择direct dialshortcut)并拖拽到launcher主界面-----------

    DragController-->onTouchEvent()-->MotionEvent.ACTION_UP, try to do drop() 

    DragController-->drop() 

    Workspace-->onDrop() 

    Workspace-->onDropExternal() 

    Launcher-->processShortcutFromDrop()-->componentName: com.android.contacts/alias.DialShortcut

    Launcher-->resetAddInfo() 

    Launcher-->processShortcut() 

    Launcher-->startActivityForResultSafely()-->requestCode : 1 

    DragLayer-->clearAnimatedView() 

    ContactSelectionActivity-->onCreate()--start 

    ContactSelectionActivity-->onCreate()-->mActionCode : -1 

    ContactSelectionActivity-->configureListFragment()-->mActionCOde : 120 

    ContactSelectionActivity-->onCreate()--end 

    Launcher-->updateRunning() 

    --------------------------为新建的direct dial快捷方式选择一个联系人--------------------------

    PhoneNumberPickerFragment-->onItemClick()-->position : 0, id : 1 

    PhoneNumberPickerFragment-->pickPhoneNumber()-->uri : content://com.android.contacts/data/1 

    ShortcutIntentBuilder-->createPhoneNumberShortcutIntent()-->uri : content://com.android.contacts/data/1, shortcutAction : android.intent.action.CALL 

    ShortcutIntentBuilder-->PhoneNumberLoadingAsyncTask-->loadData()-->mDisplayName : gaojx, mPhotoId : 0, mPhoneNumber : 155 2487, mPhoneType : 2, mPhoneLabel : null 

    ShortcutIntentBuilder-->PhoneNumberLoadingAsyncTask-->onPostExecute() 

    ShortcutIntentBuilder-->createPhoneNumberShortcutIntent() 

    PhoneNumberPickerFragment-->onShortcutIntentCreated() 

    ContactSelectionActivity-->PhoneNumberPickerActionListener-->onShortcutIntentCreated() 

    ContactSelectionActivity-->returnPickerResult()

    Launcher-->onActivityResult()-->requestCode : 1, resultCode : -1

    Launcher-->onActivityResult()-->resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID 

    Launcher-->completeAdd()-->args.requestCode : 1

    Launcher-->completeAddShortcut()-->container : -100, screen : 2, cellX : 1, cellY : 2 

    Launcher-->createShortcut()-->start 

    BubleTextView-->applyFromShortcutInfo()-->info.title : gaojx 

    Launcher-->createShortcut()-->end 

    Workspace-->createUserFolderIfNecessary() 

    Workspace-->addToExistingFolderIfNecessary() 

    LauncherModel-->addItemToDatabase() 

    Workspace-->addInScreen() 

    Launcher-->resetAddInfo() 

    DragLayer-->clearAnimatedView() 

    Launcher-->exitSpringLoadedDragModeDelayed()-->successfulDrop : true 

    Launcher-->updateRunning() 

    Launcher-->showWorkspace() 

    Launcher-->showWorkspace()-->mState != State.WORKSPACE 

    Launcher-->updateRunning() 

    ----------------------------点击launcher主界面上新建的direct dial-------------------------------- 

    Launcher-->onClick() 

    Launcher-->onClick()-->tag instanceof ShortcutInfo

    Launcher-->startActivitySafely() 

    Launcher-->startActivity()-->Action => android.intent.action.CALL, Data => tel:155%202487

    OutgoingCallBroadcaster-->onCreate() 

    OutgoingCallBroadcaster-->processIntent()-->intent=Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxxxxx flg=0x14800000 cmp=com.android.phone/.OutgoingCallBroadcaster bnds=[120,387][240,543] } 

    Launcher-->updateRunning()

    ....................................................................................................

    通过上面的Log我们可以看出shortcut的流程是:

    一:声明时指定的targetActivity属性是Launcher创建shortcut时要使用的。即LauncherstartActivityForResultSafely将启动我们设定的targetActivity,让我们选择该shortcut对应的联系人。

    二:选择完联系人后将调用LauncheronActivityResult()来真正完成shortcut的创建工作。

    三:点击shortcut时将调用LauncheronClick函数处理点击事件,最终通过LauncherstartActivitySafely函数调用startActivity函数(参数intent是我们从onActivityResult()到的)完成该shortcut的使命。

  • 相关阅读:
    start internal web server in .net 2.0
    windows scripts tips
    move vs2k3 to vs2k5
    w2k telnet port change
    Webservice自动表生成TableForGen
    用C#改写Head First Design PatternsSingleTon(原创)
    使用反射创建动态模块
    使用反射将委托挂钩
    用C#改写Head First Design PatternsState(原创)
    用Xmlhttp无刷新更新DIV
  • 原文地址:https://www.cnblogs.com/Lefter/p/3100320.html
Copyright © 2011-2022 走看看