Example usage for twitter4j User getScreenName

List of usage examples for twitter4j User getScreenName

Introduction

In this page you can find the example usage for twitter4j User getScreenName.

Prototype

String getScreenName();

Source Link

Document

Returns the screen name of the user

Usage

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

License:Apache License

public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs,
        String type) {//from  ww  w . java2s  . c o m
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;

    AppSettings settings = AppSettings.getInstance(context);

    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    int newFollowers = sharedPrefs.getInt("new_followers", 0);
    int newRetweets = sharedPrefs.getInt("new_retweets", 0);
    int newFavorites = sharedPrefs.getInt("new_favorites", 0);

    // set title
    if (newFavorites + newRetweets + newFollowers > 1) {
        title = context.getResources().getString(R.string.new_interactions);
    } else {
        title = context.getResources().getString(R.string.new_interaction_upper);
    }

    // set text
    String currText = sharedPrefs.getString("old_interaction_text", "");
    if (!currText.equals("")) {
        currText += "<br>";
    }
    if (settings.displayScreenName) {
        text = currText + "<b>" + interactor.getScreenName() + "</b> " + type;
    } else {
        text = currText + "<b>" + interactor.getName() + "</b> " + type;
    }
    sharedPrefs.edit().putString("old_interaction_text", text).commit();

    // set icon
    int types = 0;
    if (newFavorites > 0) {
        types++;
    }
    if (newFollowers > 0) {
        types++;
    }
    if (newRetweets > 0) {
        types++;
    }

    if (types > 1) {
        icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
    } else {
        if (newFavorites > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_important_dark);
        } else if (newRetweets > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark);
        } else {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        }
    }

    // set shorter text
    int total = newFavorites + newFollowers + newRetweets;
    if (total > 1) {
        smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower);
    } else {
        smallText = text;
    }

    Intent markRead = new Intent(context, ReadInteractionsService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(Html.fromHtml(
                    settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText))
            .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent)
            .setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);

    if (context.getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(
                Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text)));
    }

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(4, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, text);
        }

        // Light Flow notification
        sendToLightFlow(context, title, text);
    }
}

From source file:com.klinker.android.twitter.utils.text.TouchableSpan.java

License:Apache License

public void longClickMentions() {
    AlertDialog.Builder builder = getBuilder();

    builder.setItems(R.array.long_click_mentions, new DialogInterface.OnClickListener() {
        @Override/*from   w  w  w  .  j  av  a  2s  .c  om*/
        public void onClick(DialogInterface dialogInterface, int i) {
            final SharedPreferences sharedPrefs = mContext.getSharedPreferences(
                    "com.klinker.android.twitter_world_preferences",
                    Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

            switch (i) {
            case 0: // open profile
                TouchableSpan.this.onClick(null);
                break;
            case 1: // copy handle
                copy();
                break;
            case 2: // search user
                search();
                break;
            case 3: // favorite user
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Twitter twitter = Utils.getTwitter(mContext, settings);
                            User user = twitter.showUser(full.replace("@", ""));

                            int current = sharedPrefs.getInt("current_account", 1);

                            FavoriteUsersDataSource.getInstance(mContext).createUser(user, current);

                            sharedPrefs.edit()
                                    .putString("favorite_user_names_" + current,
                                            sharedPrefs.getString("favorite_user_names_" + current, "")
                                                    + user.getScreenName() + " ")
                                    .commit();
                        } catch (Exception e) {

                        }
                    }
                }).start();
                break;
            case 4: // mute user
                String current = sharedPrefs.getString("muted_users", "");
                sharedPrefs.edit()
                        .putString("muted_users", current + full.replaceAll(" ", "").replaceAll("@", "") + " ")
                        .commit();
                sharedPrefs.edit().putBoolean("refresh_me", true).commit();
                sharedPrefs.edit().putBoolean("just_muted", true).commit();
                if (mContext instanceof DrawerActivity) {
                    ((Activity) mContext).recreate();
                }
                break;
            case 5: // mute retweets
                String muted_rts = sharedPrefs.getString("muted_rts", "");
                sharedPrefs.edit()
                        .putString("muted_rts", muted_rts + full.replaceAll(" ", "").replaceAll("@", "") + " ")
                        .commit();
                sharedPrefs.edit().putBoolean("refresh_me", true).commit();
                sharedPrefs.edit().putBoolean("just_muted", true).commit();
                if (mContext instanceof DrawerActivity) {
                    ((Activity) mContext).recreate();
                }
                break;
            case 6: // share profile
                share("https://twitter.com/" + full.replace("@", "").replace(" ", ""));
                break;
            }
        }
    });

    builder.create().show();
}

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

License:Apache License

@Override
public void createdFriendship(User user) {
    AIR.log("Success following user: " + user.getScreenName());
    try {//from w  ww  .  j ava2 s. c  om
        JSONObject userJSON = UserUtils.getJSON(user);
        userJSON.put("listenerID", mCallbackID);
        userJSON.put("success", "true");
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
    }
}

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

License:Apache License

@Override
public void destroyedFriendship(User user) {
    AIR.log("Success unfollowing user: " + user.getScreenName());
    try {/*from  w w  w.j a va2  s  .com*/
        JSONObject userJSON = UserUtils.getJSON(user);
        userJSON.put("listenerID", mCallbackID);
        userJSON.put("success", "true");
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.utils.UserUtils.java

License:Apache License

public static JSONObject getJSON(User user) throws JSONException {
    JSONObject userJSON = new JSONObject();
    userJSON.put("id", user.getId());
    userJSON.put("screenName", user.getScreenName());
    userJSON.put("name", user.getName());
    userJSON.put("createdAt", user.getCreatedAt());
    userJSON.put("description", user.getDescription());
    userJSON.put("tweetsCount", user.getStatusesCount());
    userJSON.put("likesCount", user.getFavouritesCount());
    userJSON.put("followersCount", user.getFollowersCount());
    userJSON.put("friendsCount", user.getFriendsCount());
    userJSON.put("profileImageURL", user.getProfileImageURL());
    userJSON.put("isProtected", user.isProtected());
    userJSON.put("isVerified", user.isVerified());
    userJSON.put("location", user.getLocation());
    return userJSON;
}

From source file:com.mastfrog.acteur.twitter.TwitterSign.java

RemoteUserInfo getUserInfo(String oauth_nonce, TwitterOAuthPlugin.TwitterToken credential,
        AuthorizationResponse auth)/*  w w w  .  jav  a2  s .c om*/
        throws UnsupportedEncodingException, GeneralSecurityException, InterruptedException, IOException {
    //        System.setProperty("twitter4j.loggerFactory", "twitter4j.internal.logging.StdOutLogger");
    System.setProperty("twitter4j.debug", "true");
    System.setProperty("twitter4j.http.useSSL", "false");

    Twitter twitter = TwitterFactory.getSingleton();
    try {
        // Idiotic 
        twitter.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret);
    } catch (Exception e) {
        e.printStackTrace();
    }
    twitter.setOAuthAccessToken(new AccessToken(auth.accessToken, auth.accessTokenSecret));
    try {
        User user = twitter.verifyCredentials();

        RUI rui = new RUI();
        rui.put("displayName", user.getName());
        rui.put("name", user.getScreenName() + "@api.twitter.com");
        rui.put("screen_name", user.getScreenName());

        rui.put("picture", user.getProfileImageURLHttps());
        rui.put("pictureLarge", user.getBiggerProfileImageURLHttps());
        rui.put("id", user.getId());
        return rui;
    } catch (TwitterException ex) {
        throw new IOException(ex);
    } finally {
        twitter.shutdown();
    }
}

From source file:com.metadot.book.connectr.server.servlets.LoginTwitterCallbackServlet.java

License:Apache License

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    Twitter twitter = new TwitterFactory().getInstance();
    String key = AuthenticationProvider.getProp("twitter-consumer-key");
    String secret = AuthenticationProvider.getProp("twitter-consumer-secret");

    RequestToken token = (RequestToken) request.getSession().getAttribute("requestToken");
    String verifier = request.getParameter("oauth_verifier");
    twitter.setOAuthConsumer(key, secret);

    try {//w w  w  .j  a v a2  s  .  co  m
        twitter.getOAuthAccessToken(token, verifier);
        User user = twitter.verifyCredentials();
        log.info("Twitter user found:" + user.getName());
        request.getSession().removeAttribute("requestToken");
        String sid = ((Integer) user.getId()).toString();

        UserAccount u = new UserAccount(sid, AuthenticationProvider.TWITTER);
        // use screen name for uid
        u.setName(user.getScreenName());
        UserAccount connectr = new LoginHelper().loginStarts(request.getSession(), u);
        log.info("User id:" + connectr.getId().toString());

    } catch (TwitterException e) {
        e.printStackTrace();
    }

    response.sendRedirect(LoginHelper.getApplitionURL(request));
}

From source file:com.michaelfitzmaurice.clocktwerk.apps.FollowerCounter.java

License:Apache License

public static void main(String[] args) throws Exception {

    File outputDir = new File(args[0]);
    String[] users = new String[args.length - 1];
    System.arraycopy(args, 1, users, 0, users.length);

    LOG.info("Setting up Twitter client...");
    Twitter twitter = new TwitterFactory().getInstance();
    LOG.info("Twitter client connected");

    LOG.info("Getting followers for users " + Arrays.asList(users));
    ResponseList<User> foundUsers = twitter.lookupUsers(users);
    for (User user : foundUsers) {
        LOG.info("\t'{}' has {} followers", user.getName(), user.getFollowersCount());
        recordFollowersToCsv(outputDir, user.getScreenName(), user.getFollowersCount());
    }/*from   w  w w  .  j a va 2 s .c o m*/
}

From source file:com.michaelfitzmaurice.clocktwerk.TweetResponder.java

License:Apache License

public Collection<Status> getNewMentions() throws TweetException {

    long sinceId = lastSeenMention();
    try {//  w w  w  .j  a v a  2  s  .com
        LOG.info("Checking for new Twitter mentions of {} since Tweet {}", myScreenName, sinceId);
        Paging paging = new Paging(sinceId);
        ResponseList<Status> mentions = twitterClient.getMentionsTimeline(paging);
        int numberOfMentions = mentions.size();
        LOG.info("Found {} new mentions", numberOfMentions);
        for (Status status : mentions) {
            User user = status.getUser();
            String mentionSummary = format("Date:%s, ID:%s, From:%s (%s), Text:'%s'", status.getCreatedAt(),
                    status.getId(), user.getScreenName(), user.getName(), status.getText());
            LOG.debug("New mention: [{}]", mentionSummary);
        }
        return mentions;
    } catch (TwitterException e) {
        throw new TweetException("Error getting Twitter mentions", e);
    }

    // TODO handle paging
}

From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java

License:Apache License

public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString,
        Status status) {//from   www  .  ja v  a  2 s  . co  m
    TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro();

    if (queryName != null)
        queryName = queryName.toLowerCase();
    if (queryOwner != null)
        queryOwner = queryOwner.toLowerCase();

    result.setQueryName(queryName);
    result.setQueryOwner(queryOwner);
    result.setQuery(queryString);
    result.setStatusId(status.getId());
    result.setText(status.getText());

    result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status));
    result.setLang(status.getLang());

    result.setCreatedAt(status.getCreatedAt().getTime());

    User user = status.getUser();
    result.setUserId(user.getId());
    result.setScreenName(user.getScreenName());
    result.setUserLocation(user.getLocation());
    result.setUserName(user.getName());
    result.setUserDescription(user.getDescription());
    result.setUserIsProtected(user.isProtected());
    result.setUserFollowersCount(user.getFollowersCount());
    result.setUserCreatedAt(user.getCreatedAt().getTime());
    result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt()));
    result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt()));
    result.setUserFriendsCount(user.getFriendsCount());
    result.setUserListedCount(user.getListedCount());
    result.setUserStatusesCount(user.getStatusesCount());
    result.setUserFavoritesCount(user.getFavouritesCount());

    result.setCurrentUserRetweetId(status.getCurrentUserRetweetId());

    result.setInReplyToScreenName(status.getInReplyToScreenName());
    result.setInReplyToStatusId(status.getInReplyToStatusId());
    result.setInReplyToUserId(status.getInReplyToUserId());

    if (status.getGeoLocation() != null) {
        result.setLatitude(status.getGeoLocation().getLatitude());
        result.setLongitude(status.getGeoLocation().getLongitude());
    }

    result.setSource(status.getSource());
    result.setTrucated(status.isTruncated());
    result.setPossiblySensitive(status.isPossiblySensitive());

    result.setRetweet(status.getRetweetedStatus() != null);
    if (result.getRetweet()) {
        result.setRetweetStatusId(status.getRetweetedStatus().getId());
        result.setRetweetedText(status.getRetweetedStatus().getText());
    }
    result.setRetweeted(status.isRetweeted());
    result.setRetweetCount(status.getRetweetCount());
    result.setRetweetedByMe(status.isRetweetedByMe());

    result.setFavoriteCount(status.getFavoriteCount());
    result.setFavourited(status.isFavorited());

    if (status.getPlace() != null) {
        result.setPlace(status.getPlace().getFullName());
    }

    Scopes scopesObj = status.getScopes();
    if (scopesObj != null) {
        List scopes = Arrays.asList(scopesObj.getPlaceIds());
        result.setScopes(scopes);
    }
    return result;
}