2012-09-28 3 views
2

내 런처를 쓰는 동안 appwidgets에 문제가 있습니다. 코드의 Android widgets problemAppWidgets이 맞춤 런처에서 작동하지 않습니다.

일부 부품 :

final AppWidgetHostView hostView = mAppWidgetHost.createView(this, appWidgetId, providerInfo); 

     if (providerInfo.configure != null) { 
      // Launch over to configure widget, if needed 
      Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); 
      intent.setComponent(providerInfo.configure); 
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 
      mAppWidgetProviderInfo = providerInfo; 

      startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); 
     } else { 
      // Otherwise just add it 
      completeAddAppWidget(appWidgetId, info.container, info.screen, providerInfo); 

      // Exit spring loaded mode if necessary after adding the widget 
      exitSpringLoadedDragModeDelayed(true, false); 
     } 

completeAddAppWidget 방법 :

private void completeAddAppWidget(final int appWidgetId, long container, 
             int screen, AppWidgetProviderInfo providerInfo) { 
     // Calculate the grid spans needed to fit this widget 
     CellLayout layout = getCellLayout(container, screen); 

     int[] spanXY = getSpanForWidget(providerInfo, null); 

     // Try finding open space on Launcher screen 
     // We have saved the position to which the widget was dragged-- this 
     // really only matters 
     // if we are placing widgets on a "spring-loaded" screen 
     int[] cellXY = mTmpAddItemCellCoordinates; 
     int[] touchXY = mPendingAddInfo.dropPos; 
     boolean foundCellSpan = false; 
     if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { 
      cellXY[0] = mPendingAddInfo.cellX; 
      cellXY[1] = mPendingAddInfo.cellY; 
      foundCellSpan = true; 
     } else if (touchXY != null) { 
      // when dragging and dropping, just find the closest free spot 
      int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 
        spanXY[0], spanXY[1], cellXY); 
      foundCellSpan = (result != null); 
     } else { 
      foundCellSpan = layout 
        .findCellForSpan(cellXY, spanXY[0], spanXY[1]); 
     } 

     if (!foundCellSpan) { 
      if (appWidgetId != -1) { 
       // Deleting an app widget ID is a void call but writes to disk 
       // before returning 
       // to the caller... 
       new Thread("deleteAppWidgetId") { 
        public void run() { 
         mAppWidgetHost.deleteAppWidgetId(appWidgetId); 
        } 
       }.start(); 
      } 
      showOutOfSpaceMessage(); 
      return; 
     } 

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

     LauncherModel.addItemToDatabase(this, launcherInfo, container, screen, 
       cellXY[0], cellXY[1], false); 

     if (!mRestoring) { 
      // Perform actual inflation because we're live 
      launcherInfo.hostView = mAppWidgetHost.createView(this, 
        appWidgetId, providerInfo); 

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

      mWorkspace.addInScreen(launcherInfo.hostView, container, screen, 
        cellXY[0], cellXY[1], launcherInfo.spanX, 
        launcherInfo.spanY, isWorkspaceLocked()); 

      addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, providerInfo); 
     } 
    } 

답변

1

내가 잠시 다시이 문제를 가지고 만 시계 위젯, 다른 하나는하지 않습니다 정상적으로 작동합니다. appwidget이 변경 될 때마다 startListening()을 호출하고 remove 등을 추가해야합니다.

관련 문제