Example usage for twitter4j AsyncTwitter addListener

List of usage examples for twitter4j AsyncTwitter addListener

Introduction

In this page you can find the example usage for twitter4j AsyncTwitter addListener.

Prototype

void addListener(TwitterListener listener);

Source Link

Document

Adds twitter listener

Usage

From source file:com.marpies.ane.twitter.functions.GetUserFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long userID = FREObjectUtils.getDouble(args[0]).longValue();
    String screenName = (args[1] == null) ? null : FREObjectUtils.getString(args[1]);
    mCallbackID = FREObjectUtils.getInt(args[2]);

    AccessToken accessToken = TwitterAPI.getAccessToken();
    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(accessToken);
    twitter.addListener(this);
    if (screenName != null) {
        AIR.log("Getting user info for " + screenName);
        twitter.showUser(screenName);//from  w ww . j a v a  2 s.  com
    } else {
        AIR.log("Getting user info for userID: " + userID);
        twitter.showUser(userID);
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.GetUserTimelineFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    int count = FREObjectUtils.getInt(args[0]);
    long sinceID = (args[1] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[1]));
    long maxID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2]));
    mExcludeReplies = FREObjectUtils.getBoolean(args[3]);
    long userID = FREObjectUtils.getDouble(args[4]).longValue();
    String screenName = (args[5] == null) ? null : FREObjectUtils.getString(args[5]);
    mCallbackID = FREObjectUtils.getInt(args[6]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);

    /* If user ID was not provided then use the one of currently logged in user */
    if (userID < 0) {
        userID = TwitterAPI.getLoggedInUser().getId();
    }/*  ww w .  j av  a 2 s .co m*/

    Paging paging = getPaging(count, sinceID, maxID);
    if (paging != null) {
        if (screenName != null) {
            twitter.getUserTimeline(screenName, paging);
        } else {
            twitter.getUserTimeline(userID, paging);
        }
    } else {
        if (screenName != null) {
            twitter.getUserTimeline(screenName);
        } else {
            twitter.getUserTimeline(userID);
        }
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.InitFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    if (TwitterAPI.isInitialized())
        return null;

    String consumerKey = FREObjectUtils.getString(args[0]);
    String consumerSecret = FREObjectUtils.getString(args[1]);
    String urlScheme = FREObjectUtils.getString(args[2]);
    Boolean showLogs = FREObjectUtils.getBoolean(args[3]);

    AIR.setLogEnabled(showLogs);/*from   ww w .  j a  v a2s  .c o  m*/

    TwitterAPI.init(consumerKey, consumerSecret, urlScheme);

    /* Verify cached access tokens */
    if (TwitterAPI.hasAccessTokens()) {
        AIR.log("Verifying credentials");
        AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
        twitter.addListener(this);
        twitter.verifyCredentials();
    } else {
        AIR.dispatchEvent(AIRTwitterEvent.CREDENTIALS_CHECK, "{ \"result\": \"missing\" }");
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.LikeStatusFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long statusID = Long.valueOf(FREObjectUtils.getString(args[0]));
    mCallbackID = FREObjectUtils.getInt(args[1]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);
    twitter.createFavorite(statusID);//from  w ww.  j a v  a  2s.co m

    return null;
}

From source file:com.marpies.ane.twitter.functions.RetweetStatusFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long statusID = Long.valueOf(FREObjectUtils.getString(args[0]));
    mCallbackID = FREObjectUtils.getInt(args[1]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);
    twitter.retweetStatus(statusID);//from www  .j  a  va  2  s. c  o  m

    return null;
}

From source file:com.marpies.ane.twitter.functions.SendDirectMessageFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    String message = FREObjectUtils.getString(args[0]);
    long userID = FREObjectUtils.getDouble(args[1]).longValue();
    String screenName = (args[2] == null) ? null : FREObjectUtils.getString(args[2]);
    mCallbackID = FREObjectUtils.getInt(args[3]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);
    if (screenName != null) {
        twitter.sendDirectMessage(screenName, message);
    } else {//from   www .  j av  a2s .c om
        twitter.sendDirectMessage(userID, message);
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.UndoLikeStatusFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long statusID = Long.valueOf(FREObjectUtils.getString(args[0]));
    mCallbackID = FREObjectUtils.getInt(args[1]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);
    twitter.destroyFavorite(statusID);//ww  w  .  j  a v  a  2  s .  co  m

    return null;
}

From source file:com.marpies.ane.twitter.functions.UnfollowUserFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    long userID = FREObjectUtils.getDouble(args[0]).longValue();
    String screenName = (args[1] == null) ? null : FREObjectUtils.getString(args[1]);
    mCallbackID = FREObjectUtils.getInt(args[2]);

    AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);
    if (screenName != null) {
        twitter.destroyFriendship(screenName);
    } else {/*from ww w . j ava2 s  .co  m*/
        twitter.destroyFriendship(userID);
    }

    return null;
}

From source file:com.marpies.ane.twitter.functions.UpdateStatusFunction.java

License:Apache License

@Override
public FREObject call(FREContext context, FREObject[] args) {
    super.call(context, args);

    String text = (args[0] == null) ? null : FREObjectUtils.getString(args[0]);
    mCallbackID = FREObjectUtils.getInt(args[1]);
    long inReplyToStatusID = (args[2] == null) ? -1 : Long.valueOf(FREObjectUtils.getString(args[2]));
    final List<MediaSource> mediaSources = (args[3] == null) ? null
            : FREObjectUtils.getListOfMediaSource((FREArray) args[3]);

    final AsyncTwitter twitter = TwitterAPI.getAsyncInstance(TwitterAPI.getAccessToken());
    twitter.addListener(this);

    final StatusUpdate status = new StatusUpdate(text);
    if (inReplyToStatusID >= 0) {
        status.setInReplyToStatusId(inReplyToStatusID);
    }/*from  ww w  .ja  v  a 2  s . co m*/
    /* If we have some media, system files must be created and uploaded to Twitter */
    if (mediaSources != null) {
        /* Save cache dir path before running the async task */
        AIR.setCacheDir(AIR.getContext().getActivity().getCacheDir().getAbsolutePath());
        /* Execute async task that creates files out of the given sources (URLs and Bitmaps) */
        createFilesFromSources(mediaSources, twitter, status);
        return null;
    }

    /* Posts status without media */
    twitter.updateStatus(status);

    return null;
}

From source file:com.marpies.ane.twitter.LoginActivity.java

License:Apache License

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

    mStopped = false;/*from   w w  w .  j  a  va 2s  . c  o  m*/

    Bundle extras = getIntent().getExtras();
    boolean forceLogin = extras.getBoolean(EXTRA_PREFIX + ".forceLogin");

    /* If we have access tokens (user has logged in before) */
    if (TwitterAPI.hasAccessTokens()) {
        AIR.log("User is already logged in");
        AIR.dispatchEvent(AIRTwitterEvent.LOGIN_ERROR, "User is already logged in");
        finish();
    }
    /* Get new access tokens */
    else {
        final AsyncTwitter twitter = TwitterAPI.getAsyncInstance();
        twitter.addListener(getOAuthRequestTokenListener(forceLogin));
        twitter.getOAuthRequestTokenAsync(TwitterAPI.getCallbackURL());
    }
}