コード例 #1
0
  // end-snippet-0
  void reload() {
    // begin-snippet-1

    // The in the Activity which renders the ActionBar
    Entity entity = Entity.newInstance("http://getsocialize.com", "Socialize");

    // Setup a listener to retain a reference
    MyActionBarListener listener = new MyActionBarListener();

    // Use the listener when you show the action bar
    // The "this" argument refers to the current Activity
    ActionBarUtils.showActionBar(this, R.layout.actionbar, entity, null, listener);

    // Later (After the action bar has loaded!), you can reference the view to refresh
    ActionBarView view = listener.getActionBarView();

    if (view != null) {
      Entity newEntity = new Entity(); // This would be your new entity
      view.setEntity(newEntity);
      view.refresh();
    }

    // end-snippet-1
  }
コード例 #2
0
  @Override
  protected void onCreate() {

    ActionBarOptions options = new ActionBarOptions();

    View actionBarWrapped =
        ActionBarUtils.showActionBar(
            this,
            R.layout.photo_actionbar,
            entity,
            options,
            new ActionBarListener() {

              @Override
              public void onCreate(ActionBarView actionBar) {

                actionBar.setOnActionBarEventListener(
                    new OnActionBarEventListener() {

                      @Override
                      public void onUpdate(ActionBarView actionBar) {
                        // Called when the action bar has its data updated
                      }

                      @Override
                      public void onPostUnlike(ActionBarView actionBar) {
                        // Called AFTER a user has removed a like
                      }

                      @Override
                      public void onPostShare(ActionBarView actionBar, Share share) {
                        // Called AFTER a user has posted a share
                      }

                      @Override
                      public void onPostLike(ActionBarView actionBar, Like like) {
                        // Called AFTER a user has posted a like
                      }

                      @Override
                      public void onLoad(ActionBarView actionBar) {
                        // Called when the action bar is loaded
                      }

                      @Override
                      public void onLoadFail(Exception error) {
                        // Called when the action bar load failed
                      }

                      @Override
                      public void onGetLike(ActionBarView actionBar, Like like) {
                        // Called when the action bar retrieves the like for the
                        // current user
                      }

                      @Override
                      public void onGetEntity(ActionBarView actionBar, Entity entity) {
                        // Called when the action bar retrieves the entity data
                      }

                      @Override
                      public boolean onClick(ActionBarView actionBar, ActionBarEvent evt) {
                        if (evt.equals(ActionBarEvent.SHARE)) {
                          ShareUtils.showShareDialog(
                              PhotoActionBarActivity.this,
                              entity,
                              new SocialNetworkDialogListener() {

                                @Override
                                public boolean onBeforePost(
                                    Activity parent,
                                    SocialNetwork socialNetwork,
                                    final PostData postData) {
                                  if (socialNetwork.equals(SocialNetwork.FACEBOOK)) {

                                    // Because we are accessing a network address we can't be on the
                                    // main UI thread.
                                    // If you are loading an image from the local device you
                                    // probably won't need this.
                                    new Thread() {

                                      @Override
                                      public void run() {
                                        InputStream in = null;
                                        Bitmap image = null;

                                        try {

                                          // In this example we are going to manually load an image
                                          // from an HTTP URL
                                          // however you could just as easily use an image file
                                          // already on the device.
                                          in =
                                              new BufferedInputStream(
                                                  new URL(
                                                          "https://lh5.googleusercontent.com/-oPgrWjOC-6w/T9UWPfl2qoI/AAAAAAAABMQ/KtRKcWwRsJ0/s932/P1010444.JPG")
                                                      .openStream(),
                                                  IO_BUFFER_SIZE);
                                          image = BitmapFactory.decodeStream(in);

                                          in.close();

                                          // Format the picture for Facebook
                                          byte[] imageData =
                                              FacebookUtils.getImageForPost(
                                                  PhotoActionBarActivity.this,
                                                  image,
                                                  CompressFormat.JPEG);

                                          // Add the photo to the post
                                          postData.getPostValues().put("photo", imageData);

                                          // Add the link returned from Socialize to use
                                          // SmartDownloads
                                          postData
                                              .getPostValues()
                                              .put(
                                                  "caption",
                                                  "A test photo of something "
                                                      + postData
                                                          .getPropagationInfo()
                                                          .getEntityUrl());

                                          // Add other fields to postData as necessary

                                          // Post to me/photos
                                          FacebookUtils.post(
                                              PhotoActionBarActivity.this,
                                              "me/photos",
                                              postData.getPostValues(),
                                              new SocialNetworkPostListener() {

                                                @Override
                                                public void onNetworkError(
                                                    Activity context,
                                                    SocialNetwork network,
                                                    Exception error) {
                                                  // Handle error
                                                }

                                                @Override
                                                public void onCancel() {
                                                  // The user cancelled the auth process
                                                }

                                                @Override
                                                public void onAfterPost(
                                                    Activity parent,
                                                    SocialNetwork socialNetwork,
                                                    JSONObject responseObject) {
                                                  // The post was successful
                                                }
                                              });
                                        } catch (IOException e) {
                                          // Handle error
                                        } finally {
                                          if (image != null) {
                                            image.recycle();
                                          }
                                        }
                                      }
                                    }.start();

                                    // Don't let Socialize do the share
                                    return true;
                                  }

                                  return false;
                                }
                              });

                          return true;
                        }
                        return false;
                      }
                    });
              }
            });

    setContentView(actionBarWrapped);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Debug.profileActionBar) {
      android.os.Debug.startMethodTracing("actionbar");
    }

    View actionBar =
        ActionBarUtils.showActionBar(
            this,
            R.layout.actionbar,
            entity,
            null,
            new ActionBarListener() {
              @Override
              public void onCreate(ActionBarView actionBar) {
                // Add clickable links to comments
                actionBar.setOnCommentViewActionListener(
                    new LinkifyCommentViewActionListener() {

                      @Override
                      public void onCommentList(
                          CommentListView view, List<Comment> comments, int start, int end) {
                        super.onCommentList(view, comments, start, end);
                        if (Debug.profileCommentList) {
                          Debug.profileCommentList = false;
                          android.os.Debug.stopMethodTracing();
                        }
                      }
                    });

                // Add listeners for profiling.
                actionBar.setOnActionBarEventListener(
                    new OnActionBarShareEventListener() {

                      @Override
                      public boolean onClick(ActionBarView actionBar, ActionBarEvent evt) {

                        if (evt.equals(ActionBarEvent.SHARE) && Debug.profileShareDialog) {
                          android.os.Debug.startMethodTracing("sharedialog");
                        } else if (evt.equals(ActionBarEvent.COMMENT) && Debug.profileCommentList) {
                          android.os.Debug.startMethodTracing("commentlist");
                        }

                        return super.onClick(actionBar, evt);
                      }

                      @Override
                      public void onShow(Dialog dialog, SharePanelView dialogView) {
                        super.onShow(dialog, dialogView);
                        if (Debug.profileShareDialog) {
                          Debug.profileShareDialog = false;
                          android.os.Debug.stopMethodTracing();
                        }
                      }

                      @Override
                      public void onError(SocializeException error) {
                        Toast.makeText(
                                DefaultActionBarActivity.this, "Share failed!", Toast.LENGTH_SHORT)
                            .show();
                      }

                      @Override
                      public void onNetworkError(
                          Activity context, SocialNetwork network, Exception error) {
                        Toast.makeText(
                                DefaultActionBarActivity.this, "Share failed!", Toast.LENGTH_SHORT)
                            .show();
                      }

                      @Override
                      public void onAfterPost(
                          Activity parent, SocialNetwork socialNetwork, JSONObject responseObject) {
                        Toast.makeText(
                                DefaultActionBarActivity.this,
                                "Share successful",
                                Toast.LENGTH_SHORT)
                            .show();
                      }

                      @Override
                      public void onLoad(ActionBarView actionBar) {
                        super.onLoad(actionBar);
                        if (Debug.profileActionBar) {
                          Debug.profileActionBar = false;
                          android.os.Debug.stopMethodTracing();
                        }
                      }
                    });
              }
            });

    setContentView(actionBar);
  }