开发者

How to get the position of the appwidget?

开发者 https://www.devze.com 2023-02-20 05:23 出处:网络
I want to get the position of the appwidget on the screen, but I don\'t know how to do it. What function I should use?

I want to get the position of the appwidget on the screen, but I don't know how to do it. What function I should use? edit: i found in launcher have these code:

/**
 * 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 comp开发者_C百科leteAddAppWidget(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);
    }
}

it is Build Launcher-specific widget info and save to database,i have found the database is LauncherModel,in LauncherModel have a private ArrayList ,if i get the ArrayList,i think i can get the position of the appwidget,can somebody tell me how to get this.thank you.


I found a method is ,intent.getsourceBounds()

You can find at this link : https://github.com/raumzeitlabor/raumzeitstatus/blob/master/android-widget/src/org/raumzeitlabor/status/StatusProvider.java

0

精彩评论

暂无评论...
验证码 换一张
取 消