Beispiel #1
0
  private void updateLikeStateAndLayout() {
    if (likeActionController == null) {
      likeButton.setLikeState(false);
      socialSentenceView.setText(null);
      likeBoxCountView.setText(null);
    } else {
      likeButton.setLikeState(likeActionController.isObjectLiked());
      socialSentenceView.setText(likeActionController.getSocialSentence());
      likeBoxCountView.setText(likeActionController.getLikeCountString());
    }

    updateLayout();
  }
Beispiel #2
0
  private void setObjectIdForced(String newObjectId) {
    tearDownObjectAssociations();

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

    creationCallback = new LikeActionControllerCreationCallback();
    LikeActionController.getControllerForObjectId(getContext(), newObjectId, creationCallback);
  }
Beispiel #3
0
  private void initializeLikeButton(Context context) {
    likeButton =
        new LikeButton(
            context, likeActionController != null ? likeActionController.isObjectLiked() : false);
    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);
  }
Beispiel #4
0
  private void toggleLike() {
    if (likeActionController != null) {
      Context context = getContext();
      Activity activity = null;
      if (context instanceof Activity) {
        activity = (Activity) context;
      } else if (context instanceof ContextWrapper) {
        Context baseContext = ((ContextWrapper) context).getBaseContext();
        if (baseContext instanceof Activity) {
          activity = (Activity) baseContext;
        }
      }

      if (activity != null) {
        likeActionController.toggleLike(activity, getAnalyticsParameters());
      }
    }
  }
Beispiel #5
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;
    }
  }
Beispiel #6
0
 /**
  * If your app does not use UiLifeCycleHelper, then you must call this method in the calling
  * activity's onActivityResult method, to process any pending like actions, where tapping the
  * button had resulted in the Like dialog being shown in the Facebook application.
  *
  * @param context Hosting context
  * @param requestCode From the originating call to onActivityResult
  * @param resultCode From the originating call to onActivityResult
  * @param data From the originating call to onActivityResult
  * @return Indication of whether the Intent was handled
  */
 public static boolean handleOnActivityResult(
     Context context, int requestCode, int resultCode, Intent data) {
   return LikeActionController.handleOnActivityResult(context, requestCode, resultCode, data);
 }