Пример #1
0
  public void share(Day giorno) {

    Bundle params = new Bundle();
    params.putString("name", "Ecco cosa mi è successo " + giorno.getData());
    params.putString("caption", giorno.getTesto());
    params.putString("description", "DearDiary è il tuo diario quotidiano su Android!");
    params.putString("link", "https://www.facebook.com/peppeuz");
    params.putString("picture", "http://imgbin.org/images/12252.png");
    if (Session.getActiveSession() == null) {
      alert();

    } else {
      WebDialog feedDialog =
          (new WebDialog.FeedDialogBuilder(activity, Session.getActiveSession(), params))
              .setOnCompleteListener(
                  new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                      if (error == null) {

                        final String postId = values.getString("post_id");
                        if (postId != null) {
                          Toast.makeText(
                                  activity,
                                  "Post effettuato correttamente!"
                                  // + postId

                                  ,
                                  Toast.LENGTH_SHORT)
                              .show();
                        } else {
                          // User clicked the Cancel button
                          Toast.makeText(
                                  activity.getApplicationContext(),
                                  "Post annullato",
                                  Toast.LENGTH_SHORT)
                              .show();
                        }
                      } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(
                                activity.getApplicationContext(),
                                "Post annullato",
                                Toast.LENGTH_SHORT)
                            .show();
                      } else {
                        // Generic, ex: network error
                        Toast.makeText(
                                activity.getApplicationContext(),
                                "Si è presentato un errore durante la pubblicazione",
                                Toast.LENGTH_SHORT)
                            .show();
                      }
                    }
                  })
              .build();
      feedDialog.show();
    }
  }
  private void sendRequestDialog(String userId) {
    Bundle params = new Bundle();
    params.putString("message", "Send items to your friends when they arrive at the location.");
    params.putString("to", userId);
    WebDialog requestsDialog =
        (new WebDialog.RequestsDialogBuilder(this, Session.getActiveSession(), params))
            .setOnCompleteListener(
                new OnCompleteListener() {

                  public void onComplete(Bundle values, FacebookException error) {
                    if (values == null) return;
                    final String requestId = values.getString("request");
                    if (requestId != null) {
                      Toast.makeText(getApplicationContext(), "Request sent", Toast.LENGTH_SHORT)
                          .show();
                    } else {
                      Toast.makeText(
                              getApplicationContext(), "Request cancelled", Toast.LENGTH_SHORT)
                          .show();
                    }
                  }
                })
            .build();

    requestsDialog.show();
  }
 void _ui(String params, int cbIndex) {
   String action = null;
   Bundle parameters = new Bundle();
   try {
     JSONObject jsonObject = new JSONObject(params);
     action = jsonObject.getString("method");
     Iterator iterator = jsonObject.keys();
     String key = null;
     String value = null;
     while (iterator.hasNext()) {
       key = (String) iterator.next();
       Object object = jsonObject.get(key);
       if (object instanceof String) {
         value = (String) object;
         if (key.compareTo("method") != 0) parameters.putString(key, value);
       } else if (object instanceof Integer) {
         parameters.putInt(key, ((Integer) object).intValue());
       } else if (object instanceof Boolean) {
         parameters.putBoolean(key, ((Boolean) object).booleanValue());
       } else if (object instanceof Double) {
         parameters.putDouble(key, ((Double) object).doubleValue());
       } else {
         Log.v(TAG, "other type:" + object.toString());
       }
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   WebDialog uiDialog =
       (new WebDialog.Builder(mActivity, Session.getActiveSession(), action, parameters))
           .setOnCompleteListener(new WebDialogListener(cbIndex))
           .build();
   uiDialog.show();
 }
Пример #4
0
 private void sendInviteToFriend() {
   StringBuilder sbIds = new StringBuilder();
   for (String id : mInviteIds) {
     sbIds.append(id).append(",");
   }
   WebDialog dialog =
       new WebDialog.RequestsDialogBuilder(this, Session.getActiveSession())
           .setMessage(getString(R.string.my_firend_invite_send_short_msg))
           .setTo(sbIds.substring(0, sbIds.length() - 1))
           .setOnCompleteListener(
               new OnCompleteListener() {
                 @Override
                 public void onComplete(Bundle values, FacebookException error) {
                   // TODO Auto-generated method stub
                   if (error != null) {
                     showErrorConfirmDialog(error.getMessage());
                   } else if (values != null && values.size() == 0) {
                     showErrorConfirmDialog(R.string.invite_fail);
                   } else {
                     onInviteComplete(mInviteIds);
                     mInviteIds = null;
                   }
                 }
               })
           .build();
   dialog.show();
 }
Пример #5
0
  public void publishFeedDialog(
      String name, String caption, String description, String link, String picture) {

    final Context context = UtilActivity.this;
    final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {

      Bundle params = new Bundle();
      params.putString("name", name);
      params.putString("caption", caption);
      params.putString("description", description);
      params.putString("link", link);
      params.putString("picture", picture);

      WebDialog feedDialog =
          (new WebDialog.FeedDialogBuilder(context, Session.getActiveSession(), params))
              .setOnCompleteListener(
                  new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values, FacebookException error) {
                      if (error == null) {
                        // When the story is posted, echo the success
                        // and the post Id.
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                          Toast.makeText(context, "Posted story, id: " + postId, Toast.LENGTH_SHORT)
                              .show();
                        } else {
                          // User clicked the Cancel button
                          Toast.makeText(context, "Publish cancelled", Toast.LENGTH_SHORT).show();
                        }
                      } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(context, "Publish cancelled", Toast.LENGTH_SHORT).show();
                      } else {
                        // Generic, ex: network error
                        Toast.makeText(context, "Error posting story", Toast.LENGTH_SHORT).show();
                      }
                    }
                  })
              .build();
      feedDialog.show();

    } else {

      AlertDialog.Builder builder = new AlertDialog.Builder(context);
      builder.setMessage("Facebook app not available.");
      builder.setNeutralButton(context.getResources().getString(android.R.string.ok), null);
      builder.create().show();
    }
  }
Пример #6
0
  private void publishFeedDialog(
      String name,
      String caption,
      String description,
      String link,
      String urlPicture,
      final ListenerShareFacebook listenerShareFacebook) {

    Bundle params = new Bundle();
    params.putString("name", name);
    params.putString("caption", caption);
    params.putString("description", description);

    if (link != null) {
      params.putString("link", link);
    } else {
      params.putString("link", "https://www.google.com/");
    }

    params.putString("picture", urlPicture);

    Session session = Session.getActiveSession();

    WebDialog feedDialog =
        (new WebDialog.FeedDialogBuilder(mActivity, session, params))
            .setOnCompleteListener(
                new OnCompleteListener() {
                  public void onComplete(Bundle values, FacebookException error) {
                    if (error == null) {
                      final String postId = values.getString("post_id");
                      if (postId != null) {
                        listenerShareFacebook.onShareFacebookSuccess();
                      } else {
                        // User clicked the Cancel button
                        listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
                      }
                    } else if (error instanceof FacebookOperationCanceledException) {
                      // User clicked the "x" button
                      listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
                    } else {
                      // network error
                      listenerShareFacebook.onShareFacebookFailure("Error posting story");
                    }
                  }
                })
            .build();

    feedDialog.show();
  }
Пример #7
0
  private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", getName());
    params.putString("description", getMessage());
    params.putString("link", getLink());
    params.putString("picture", currentView.getImageUrl());

    dialog.show();
    WebDialog feedDialog =
        (new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params))
            .setOnCompleteListener(
                new WebDialog.OnCompleteListener() {

                  @Override
                  public void onComplete(Bundle values, FacebookException error) {
                    closeProgressDialog();

                    if (error == null) {
                      // When the story is posted, echo the success and the post Id.
                      final String postId = values.getString("post_id");
                      if (postId != null) {
                        //                            displayAlert("Message", "Posted story, id:
                        // "+postId);
                      } else {
                        // User clicked the Cancel button
                        displayAlert("Message", "Publish cancelled");
                      }
                    } else if (error instanceof FacebookOperationCanceledException) {
                      // User clicked the "x" button
                      displayAlert("Message", "Publish cancelled");
                    } else {
                      // Generic, ex: network error
                      displayAlert("Message", "Sorry, please try again!");
                    }
                  }
                })
            .build();
    feedDialog.show();
  }