Example #1
0
    @Override
    public void onReceive(Context context, Intent intent) {
      String intentAction = intent.getAction();
      Bundle extras = intent.getExtras();
      boolean shouldRespond = true;
      if (extras != null) {
        // See if an Id was set in the broadcast Intent. If it was, treat it as a filter.
        String broadcastObjectId = extras.getString(LikeActionController.ACTION_OBJECT_ID_KEY);
        shouldRespond =
            Utility.isNullOrEmpty(broadcastObjectId)
                || Utility.areObjectsEqual(objectId, broadcastObjectId);
      }

      if (!shouldRespond) {
        return;
      }

      if (LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_UPDATED.equals(intentAction)) {
        updateLikeStateAndLayout();
      } else if (LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_ERROR.equals(
          intentAction)) {
        if (onErrorListener != null) {
          onErrorListener.onError(NativeProtocol.getExceptionFromErrorData(extras));
        }
      } else if (LikeActionController.ACTION_LIKE_ACTION_CONTROLLER_DID_RESET.equals(
          intentAction)) {
        // This will recreate the controller and associated objects
        setObjectIdAndTypeForced(objectId, objectType);
        updateLikeStateAndLayout();
      }
    }
  public boolean start() {
    if (running) {
      return false;
    }

    // Make sure that the service can handle the requested protocol version
    int availableVersion =
        NativeProtocol.getLatestAvailableProtocolVersionForService(protocolVersion);
    if (availableVersion == NativeProtocol.NO_PROTOCOL_AVAILABLE) {
      return false;
    }

    Intent intent = NativeProtocol.createPlatformServiceIntent(context);
    if (intent == null) {
      return false;
    } else {
      running = true;
      context.bindService(intent, this, Context.BIND_AUTO_CREATE);
      return true;
    }
  }