2011-03-25 85 views
2

我想要在屏幕上显示appwidget的位置,但我不知道该怎么做。 我应该使用什么功能? 编辑:我在发射发现有这些代码:如何获取appwidget的位置?

/** 
* Add a widget to the workspace. 
* 
* @param data The intent describing the appWidgetId. 
* @param cellInfo The position on screen where to create the widget. 
*/ 
private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo, 
     boolean insertAtFirst) { 

    Bundle extras = data.getExtras(); 
    int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 

    if (LOGD) d(LOG_TAG, "dumping extras content="+extras.toString()); 

    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 

    // Calculate the grid spans needed to fit this widget 
    CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); 
    int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight); 

    // Try finding open space on Launcher screen 
    final int[] xy = mCellCoordinates; 
    if (!findSlot(cellInfo, xy, spans[0], spans[1])) { 
     if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); 
     return; 
    } 

    // Build Launcher-specific widget info and save to database 
    LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); 
    launcherInfo.spanX = spans[0]; 
    launcherInfo.spanY = spans[1]; 

    LauncherModel.addItemToDatabase(this, launcherInfo, 
      LauncherSettings.Favorites.CONTAINER_DESKTOP, 
      mWorkspace.getCurrentScreen(), xy[0], xy[1], false); 

    if (!mRestoring) { 
     sModel.addDesktopAppWidget(launcherInfo); 

     // Perform actual inflation because we're live 
     launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); 

     launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); 
     launcherInfo.hostView.setTag(launcherInfo); 

     mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], 
       launcherInfo.spanX, launcherInfo.spanY, insertAtFirst); 
    } else if (sModel.isDesktopLoaded()) { 
     sModel.addDesktopAppWidget(launcherInfo); 
    } 
} 

它是构建特定启动的微件信息,并保存到数据库中,我已经找到了数据库LauncherModel,在LauncherModel有一个私人的ArrayList,如果我得到的ArrayList,我想我可以得到appwidget的位置,有人可以告诉我如何得到这个。谢谢。

回答