protected boolean loadEntity(
      Activity context, SocializeEntityLoader entityLoader, Entity entity) {
    if (entity != null) {
      if (entityLoader.canLoad(context, entity)) {

        if (logger != null && logger.isInfoEnabled()) {
          logger.info("Calling entity loader for entity with key [" + entity.getKey() + "]");
        }

        entityLoader.loadEntity(context, entity);

        return true;
      } else {
        if (logger != null && logger.isDebugEnabled()) {
          logger.debug(
              "Entity loaded indicates that entity with key ["
                  + entity.getKey()
                  + "] cannot be loaded");
        }
      }
    } else {
      handleWarn(
          "No entity object found under key [" + Socialize.ENTITY_OBJECT + "] in EntityLaucher");
    }

    return false;
  }
  public void testGetEntity() throws Exception {

    final CountDownLatch latch = new CountDownLatch(1);

    EntityUtils.getEntity(
        getContext(),
        "http://entity1.com",
        new EntityGetListener() {

          @Override
          public void onGet(Entity entity) {
            addResult(0, entity);
            latch.countDown();
          }

          @Override
          public void onError(SocializeException error) {
            error.printStackTrace();
            latch.countDown();
          }
        });

    latch.await(20, TimeUnit.SECONDS);

    Entity after = getResult(0);

    assertNotNull(after);
    assertEquals("http://entity1.com", after.getKey());

    assertNotNull(after.getEntityStats());
    assertNotNull(after.getUserEntityStats());
  }
  public void testEntityMetaDataWithUrl() throws Exception {

    final String entityKey = "testEntityMetaDataWithUrl" + Math.random();

    Entity entity = Entity.newInstance(entityKey, "testAddEntity");

    String url = "http://www.getsocialize.com";

    JSONObject metaData = new JSONObject();
    metaData.put("url", url);

    String jsonString = metaData.toString();

    entity.setMetaData(jsonString);

    final CountDownLatch latch = new CountDownLatch(1);

    // Force no config
    ConfigUtils.getConfig(getContext())
        .setProperty(SocializeConfig.SOCIALIZE_REQUIRE_AUTH, "false");

    EntityUtils.saveEntity(
        TestUtils.getActivity(this),
        entity,
        new EntityAddListener() {

          @Override
          public void onError(SocializeException error) {
            error.printStackTrace();
            addResult(0, error);
            latch.countDown();
          }

          @Override
          public void onCreate(Entity entity) {
            addResult(0, entity);
            latch.countDown();
          }
        });

    latch.await(20, TimeUnit.SECONDS);

    Object result = getResult(0);

    assertNotNull(result);
    assertTrue("Result is not a entity object", (result instanceof Entity));

    Entity entityAfter = (Entity) result;

    String metaDataAfter = entityAfter.getMetaData();

    assertNotNull(metaDataAfter);

    JSONObject json = new JSONObject(metaDataAfter);
    String urlAfter = json.getString("url");

    assertEquals(url, urlAfter);
  }
  public void testGetEntities() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);

    EntityUtils.getEntities(
        getContext(),
        0,
        100,
        new EntityListListener() {

          @Override
          public void onList(ListResult<Entity> entities) {
            addResult(0, entities);
            latch.countDown();
          }

          @Override
          public void onError(SocializeException error) {
            error.printStackTrace();
            latch.countDown();
          }
        });

    latch.await(20, TimeUnit.SECONDS);

    ListResult<Entity> after = getResult(0);

    assertNotNull(after);
    assertTrue(after.size() >= 2);

    // Make sure it contains what we expect.
    JSONObject json = TestUtils.getJSON(getContext(), "entities.json");
    JSONArray jsonArray = json.getJSONArray("items");

    JSONObject jsonObject0 = (JSONObject) jsonArray.get(0);
    JSONObject jsonObject1 = (JSONObject) jsonArray.get(1);

    String key0 = jsonObject0.getString("key");
    String key1 = jsonObject1.getString("key");

    List<Entity> items = after.getItems();

    int found = 0;

    for (Entity entity : items) {
      if (entity.getKey().equals(key0) || entity.getKey().equals(key1)) {
        found++;
      }

      if (found >= 2) {
        break;
      }
    }

    assertEquals(2, found);
  }
  /*
   * (non-Javadoc)
   * @see com.socialize.networks.AbstractSocialNetworkSharer#doShare(android.app.Activity, com.socialize.entity.Entity, com.socialize.entity.PropagationUrlSet, java.lang.String, com.socialize.networks.SocialNetworkListener, com.socialize.api.action.ActionType)
   */
  @Override
  protected void doShare(
      Activity context,
      Entity entity,
      PropagationInfo urlSet,
      String comment,
      SocialNetworkListener listener,
      ActionType type) {

    Tweet tweet = new Tweet();

    switch (type) {
      case SHARE:
        if (StringUtils.isEmpty(comment)) comment = "Shared " + entity.getDisplayName();
        break;
      case LIKE:
        comment = "\u2764 likes " + entity.getDisplayName();
        break;
      case VIEW:
        comment = "Viewed " + entity.getDisplayName();
        break;
    }

    StringBuilder status = new StringBuilder();

    if (StringUtils.isEmpty(comment)) {
      status.append(entity.getDisplayName());
    } else {
      status.append(comment);
    }

    status.append(", ");
    status.append(urlSet.getEntityUrl());

    tweet.setText(status.toString());

    UserSettings settings = UserUtils.getUserSettings(context);

    if (settings != null && settings.isLocationEnabled()) {
      tweet.setLocation(LocationUtils.getLastKnownLocation(context));
      tweet.setShareLocation(true);
    }

    TwitterUtils.tweet(context, tweet, listener);
  }
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {

    if (position <= 1) {

      String entity = null;

      switch (position) {
        case 0:
          entity = "http://getsocialize.com";
          break;
      }

      CommentUtils.showCommentView(
          this,
          Entity.newInstance(entity, "Socialize"),
          new OnCommentViewActionListener() {

            @Override
            public void onError(SocializeException error) {
              error.printStackTrace();
            }

            @Override
            public void onRender(CommentListView view) {}

            @Override
            public void onReload(CommentListView view) {}

            @Override
            public void onPostComment(Comment comment) {}

            @Override
            public void onCreate(CommentListView view) {}

            @Override
            public void onCommentList(
                CommentListView view, List<Comment> comments, int start, int end) {}

            @Override
            public void onBeforeSetComment(Comment comment, CommentListItem item) {}

            @Override
            public void onAfterSetComment(Comment comment, CommentListItem item) {}
          });
    } else {
      Class<?> activityClass = activities[position - 1];
      if (activityClass != null) {
        Intent intent = new Intent(this, activityClass);
        startActivity(intent);
      }
    }
  }
  // begin-snippet-0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Define/obtain your entity
    Entity entity = Entity.newInstance("http://getsocialize.com", "Socialize");

    // Get a reference to the button you want to transform
    // This can be any type of CompoundButton (CheckBox, RadioButton, Switch, ToggleButton)

    CheckBox btnCustomCheckBoxLike = (CheckBox) findViewById(R.id.btnCustomCheckBoxLike);

    // Make the button a socialize like button!
    LikeUtils.makeLikeButton(
        this,
        btnCustomCheckBoxLike,
        entity,
        new LikeButtonListener() {

          @Override
          public void onClick(CompoundButton button) {
            // You can use this callback to set any loading text or display a progress dialog
            button.setText("--");
          }

          @Override
          public void onCheckedChanged(CompoundButton button, boolean isChecked) {
            // The like was posted successfully, change the button to reflect the change
            if (isChecked) {
              button.setText("Unlike");
            } else {
              button.setText("Like");
            }
          }

          @Override
          public void onError(CompoundButton button, Exception error) {
            // An error occurred posting the like, we need to return the button to its original
            // state
            Log.e("Socialize", "Error on like button", error);
            if (button.isChecked()) {
              button.setText("Unlike");
            } else {
              button.setText("Like");
            }
          }
        });
  }
  // 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
  }
 @Override
 public void loadEntity(Activity activity, Entity entity) {
   // Demo only.. you would usually load your entity here.
   String msg = "Clicked on entity with key: " + entity.getKey();
   Toast.makeText(activity, msg, Toast.LENGTH_SHORT).show();
 }
  public void testAddEntity() throws Exception {
    final String entityKey = "testAddEntity" + Math.random();
    Entity entity = Entity.newInstance(entityKey, "testAddEntity");

    final CountDownLatch latch = new CountDownLatch(1);

    // Force no config
    ConfigUtils.getConfig(getContext())
        .setProperty(SocializeConfig.SOCIALIZE_REQUIRE_AUTH, "false");

    EntityUtils.saveEntity(
        TestUtils.getActivity(this),
        entity,
        new EntityAddListener() {

          @Override
          public void onError(SocializeException error) {
            error.printStackTrace();
            addResult(0, error);
            latch.countDown();
          }

          @Override
          public void onCreate(Entity entity) {
            addResult(0, entity);
            latch.countDown();
          }
        });

    latch.await(20, TimeUnit.SECONDS);

    Object result = getResult(0);

    assertNotNull(result);
    assertTrue("Result is not a entity object", (result instanceof Entity));

    Entity entityAfter = (Entity) result;
    assertTrue("Entity ID is not greater than 0", entityAfter.getId() > 0);

    // Now use the normal UI to retrieve the entity
    clearResults();
    final CountDownLatch latch2 = new CountDownLatch(1);

    EntityUtils.getEntity(
        TestUtils.getActivity(this),
        entityAfter.getId(),
        new EntityGetListener() {

          @Override
          public void onGet(Entity entity) {
            addResult(0, entity);
            latch2.countDown();
          }

          @Override
          public void onError(SocializeException error) {
            error.printStackTrace();
            latch2.countDown();
          }
        });

    latch2.await(20, TimeUnit.SECONDS);

    Entity after = getResult(0);

    assertNotNull(after);
    assertEquals(entityAfter.getId(), after.getId());
    assertEquals(entityAfter.getKey(), after.getKey());
  }