Exemplo n.º 1
0
    @Override
    public void onComplete(LikeActionController likeActionController, FacebookException error) {
      if (isCancelled) {
        return;
      }

      if (likeActionController != null) {
        if (!likeActionController.shouldEnableView()) {
          error = new FacebookException("Cannot use LikeView. The device may not be supported.");
        }

        // Always associate with the controller, so it can get updates if the view gets
        // enabled again.
        associateWithLikeActionController(likeActionController);
        updateLikeStateAndLayout();
      }

      if (error != null) {
        if (onErrorListener != null) {
          onErrorListener.onError(error);
        }
      }

      LikeView.this.creationCallback = null;
    }
Exemplo n.º 2
0
  private void updateLikeStateAndLayout() {
    boolean enabled = !explicitlyDisabled;

    if (likeActionController == null) {
      likeButton.setSelected(false);
      socialSentenceView.setText(null);
      likeBoxCountView.setText(null);
    } else {
      likeButton.setSelected(likeActionController.isObjectLiked());
      socialSentenceView.setText(likeActionController.getSocialSentence());
      likeBoxCountView.setText(likeActionController.getLikeCountString());

      enabled &= likeActionController.shouldEnableView();
    }

    super.setEnabled(enabled);
    likeButton.setEnabled(enabled);

    updateLayout();
  }
Exemplo n.º 3
0
  private void setObjectIdAndTypeForced(String newObjectId, ObjectType newObjectType) {
    tearDownObjectAssociations();

    objectId = newObjectId;
    objectType = newObjectType;

    if (Utility.isNullOrEmpty(newObjectId)) {
      return;
    }

    creationCallback = new LikeActionControllerCreationCallback();
    LikeActionController.getControllerForObjectId(newObjectId, newObjectType, creationCallback);
  }
Exemplo n.º 4
0
  private void initializeLikeButton(Context context) {
    likeButton =
        new LikeButton(
            context, likeActionController != null && likeActionController.isObjectLiked());
    likeButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            toggleLike();
          }
        });

    LinearLayout.LayoutParams buttonLayout =
        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    likeButton.setLayoutParams(buttonLayout);
  }
Exemplo n.º 5
0
  private void toggleLike() {
    if (likeActionController != null) {
      Activity activity = null;
      if (parentFragment == null) {
        Context context = getContext();
        if (context instanceof Activity) {
          activity = (Activity) context;
        } else if (context instanceof ContextWrapper) {
          Context baseContext = ((ContextWrapper) context).getBaseContext();
          if (baseContext instanceof Activity) {
            activity = (Activity) baseContext;
          }
        }
      }

      likeActionController.toggleLike(activity, parentFragment, getAnalyticsParameters());
    }
  }
Exemplo n.º 6
0
  private void updateLayout() {
    // Make sure the container is horizontally aligned according to specifications.
    LayoutParams containerViewLayoutParams = (LayoutParams) containerView.getLayoutParams();
    LinearLayout.LayoutParams buttonLayoutParams =
        (LinearLayout.LayoutParams) likeButton.getLayoutParams();
    int viewGravity =
        horizontalAlignment == HorizontalAlignment.LEFT
            ? Gravity.LEFT
            : horizontalAlignment == HorizontalAlignment.CENTER
                ? Gravity.CENTER_HORIZONTAL
                : Gravity.RIGHT;

    containerViewLayoutParams.gravity = viewGravity | Gravity.TOP;
    buttonLayoutParams.gravity = viewGravity;

    // Choose the right auxiliary view to make visible.
    socialSentenceView.setVisibility(GONE);
    likeBoxCountView.setVisibility(GONE);

    View auxView;
    if (likeViewStyle == Style.STANDARD
        && likeActionController != null
        && !Utility.isNullOrEmpty(likeActionController.getSocialSentence())) {
      auxView = socialSentenceView;
    } else if (likeViewStyle == Style.BOX_COUNT
        && likeActionController != null
        && !Utility.isNullOrEmpty(likeActionController.getLikeCountString())) {
      updateBoxCountCaretPosition();
      auxView = likeBoxCountView;
    } else {
      // No more work to be done.
      return;
    }
    auxView.setVisibility(VISIBLE);

    // Now position the auxiliary view properly
    LinearLayout.LayoutParams auxViewLayoutParams =
        (LinearLayout.LayoutParams) auxView.getLayoutParams();
    auxViewLayoutParams.gravity = viewGravity;

    containerView.setOrientation(
        auxiliaryViewPosition == AuxiliaryViewPosition.INLINE
            ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    if (auxiliaryViewPosition == AuxiliaryViewPosition.TOP
        || (auxiliaryViewPosition == AuxiliaryViewPosition.INLINE
            && horizontalAlignment == HorizontalAlignment.RIGHT)) {
      // Button comes after the auxiliary view. Make sure it is at the end
      containerView.removeView(likeButton);
      containerView.addView(likeButton);
    } else {
      // In all other cases, the button comes first
      containerView.removeView(auxView);
      containerView.addView(auxView);
    }

    switch (auxiliaryViewPosition) {
      case TOP:
        auxView.setPadding(edgePadding, edgePadding, edgePadding, internalPadding);
        break;
      case BOTTOM:
        auxView.setPadding(edgePadding, internalPadding, edgePadding, edgePadding);
        break;
      case INLINE:
        if (horizontalAlignment == HorizontalAlignment.RIGHT) {
          auxView.setPadding(edgePadding, edgePadding, internalPadding, edgePadding);
        } else {
          auxView.setPadding(internalPadding, edgePadding, edgePadding, edgePadding);
        }
        break;
    }
  }