@Override
  protected STATE handleIntent(Intent intent, long updatePeriod, ResultReceiver resultReceiver) {
    String action = intent.getAction();
    if (action == null) {
      return STATE.ERROR;
    }

    if (roomListService.updateRoomDeviceListIfRequired(intent, updatePeriod, this)
        == RoomListService.RemoteUpdateRequired.REQUIRED) {
      return STATE.DONE;
    }

    if (FAVORITE_ROOM_LIST.equals(action)) {
      RoomDeviceList favorites = favoritesService.getFavorites(this);
      sendSingleExtraResult(resultReceiver, SUCCESS, DEVICE_LIST, favorites);
    } else if (FAVORITE_ADD.equals(action)) {
      FhemDevice device = (FhemDevice) intent.getSerializableExtra(DEVICE);
      favoritesService.addFavorite(this, device.getName());
      if (resultReceiver != null) sendNoResult(resultReceiver, SUCCESS);
    } else if (FAVORITE_REMOVE.equals(action)) {
      FhemDevice device = (FhemDevice) intent.getSerializableExtra(DEVICE);
      favoritesService.removeFavorite(this, device.getName());
      if (resultReceiver != null) sendNoResult(resultReceiver, SUCCESS);
    } else if (FAVORITES_PRESENT.equals(action)) {
      boolean hasFavorites = favoritesService.hasFavorites(this);
      sendSingleExtraResult(resultReceiver, SUCCESS, HAS_FAVORITES, hasFavorites);
    } else if (FAVORITES_IS_FAVORITES.equalsIgnoreCase(action)) {
      boolean isFavorite =
          favoritesService.isFavorite(intent.getStringExtra(BundleExtraKeys.DEVICE_NAME), this);
      sendSingleExtraResult(resultReceiver, SUCCESS, IS_FAVORITE, isFavorite);
    }

    return STATE.DONE;
  }
示例#2
0
 @Override
 public void afterDeviceXMLRead(Context context) {
   String stateChangeText = "";
   if (getLastWindowState() != null) {
     stateChangeText += getLastWindowState() + " => ";
   }
   stateChangeText += getWindowState();
   setState(stateChangeText);
   super.afterDeviceXMLRead(context);
 }