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.javielinux.database.EntitySearch.java

License:Apache License

public InfoSaveTweets saveTweets(Context cnt, boolean saveNotifications, long since_id) {
    ConnectionManager.getInstance().open(cnt);
    Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();
    InfoSaveTweets out = new InfoSaveTweets();
    try {/*  w w  w .jav  a 2s .  c o  m*/
        int nResult = DataFramework.getInstance().getEntityListCount("tweets",
                "favorite=0 and search_id=" + getId());

        Query query = getQuery(cnt);
        if (since_id != -1)
            query.setSinceId(since_id);

        QueryResult result = twitter.search(query);
        ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets();

        if (tweets.size() > 0) {

            out.setNewMessages(tweets.size());
            out.setNewerId(tweets.get(0).getId());
            out.setOlderId(tweets.get(tweets.size() - 1).getId());
            if (saveNotifications) {
                setValue("new_tweets_count", getInt("new_tweets_count") + tweets.size());
                save();
            }

            Log.d(Utils.TAG, tweets.size() + " mensajes nuevos en " + getString("name"));

            long fisrtId = 1;
            Cursor c = DataFramework.getInstance().getCursor("tweets", new String[] { DataFramework.KEY_ID },
                    null, null, null, null, DataFramework.KEY_ID + " desc", "1");
            if (!c.moveToFirst()) {
                c.close();
                fisrtId = 1;
            } else {
                long Id = c.getInt(0) + 1;
                c.close();
                fisrtId = Id;
            }

            for (int i = tweets.size() - 1; i >= 0; i--) {

                /*String sql = "INSERT INTO 'tweets' ("  + DataFramework.KEY_ID + ", search_id, url_avatar, username, user_id, tweet_id,"
                      + "text, source, to_username, to_user_id, date, favorite) VALUES (" + fisrtId + "," + getId()
                      + ",'" +tweets.get(i).getProfileImageUrl() + "','"+tweets.get(i).getFromUser()+"','"
                      + tweets.get(i).getFromUserId() + "','" + tweets.get(i).getId() + "','" + tweets.get(i).getText() 
                      + "','" + tweets.get(i).getSource()   + "','"+tweets.get(i).getToUser()
                      +"','"+tweets.get(i).getToUserId()+"','"+String.valueOf(tweets.get(i).getCreatedAt().getTime())
                      + "',0);\n";*/
                User u = tweets.get(i).getUser();
                ContentValues args = new ContentValues();
                args.put(DataFramework.KEY_ID, "" + fisrtId);
                args.put("search_id", "" + getId());
                if (u.getProfileImageURL() != null) {
                    args.put("url_avatar", u.getProfileImageURL().toString());
                } else {
                    args.put("url_avatar", "");
                }
                args.put("username", u.getScreenName());
                args.put("fullname", u.getName());
                args.put("user_id", "" + u.getId());
                args.put("tweet_id", Utils.fillZeros("" + tweets.get(i).getId()));
                args.put("text", tweets.get(i).getText());
                args.put("source", tweets.get(i).getSource());
                args.put("to_username", tweets.get(i).getInReplyToScreenName());
                args.put("to_user_id", "" + tweets.get(i).getInReplyToUserId());
                args.put("date", String.valueOf(tweets.get(i).getCreatedAt().getTime()));
                if (tweets.get(i).getGeoLocation() != null) {
                    args.put("latitude", tweets.get(i).getGeoLocation().getLatitude());
                    args.put("longitude", tweets.get(i).getGeoLocation().getLongitude());
                }
                args.put("favorite", "0");

                DataFramework.getInstance().getDB().insert("tweets", null, args);

                fisrtId++;

            }

            if (saveNotifications) {
                setValue("last_tweet_id_notifications", tweets.get(0).getId() + "");
                save();
            }

            int total = nResult + tweets.size();
            if (total > Utils.MAX_ROW_BYSEARCH) {
                Log.d(Utils.TAG, "Limpiando base de datos");
                String date = DataFramework.getInstance()
                        .getEntityList("tweets", "favorite=0 and search_id=" + getId(), "date desc")
                        .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                String sqldelete = "DELETE FROM tweets WHERE favorite=0 AND search_id=" + getId()
                        + " AND date  < '" + date + "'";
                DataFramework.getInstance().getDB().execSQL(sqldelete);
            }

        }

    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.database.EntityTweetUser.java

License:Apache License

public InfoSaveTweets saveTweets(Context context, Twitter twitter) {

    InfoSaveTweets out = new InfoSaveTweets();

    try {/*w w w.  j a v a2s  .  c o  m*/
        String where = "type_id = " + tweet_type + " AND user_tt_id=" + getId();

        int nResult = DataFramework.getInstance().getEntityListCount("tweets_user", where);
        if (nResult > 0)
            mLastIdNotification = DataFramework.getInstance().getTopEntity("tweets_user", where, "date desc")
                    .getLong("tweet_id");

        boolean breakTimeline = false;

        PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

        int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60"));
        if (maxDownloadTweet <= 0)
            maxDownloadTweet = 60;

        ResponseList<twitter4j.Status> statii = null;
        ResponseList<twitter4j.DirectMessage> directs = null;

        if (mLastIdNotification > 0) {
            if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {

                Paging p = new Paging(1, maxDownloadTweet);
                p.setSinceId(mLastIdNotification);

                try {
                    statii = twitter.getHomeTimeline(p);
                } catch (OutOfMemoryError e) {
                    e.printStackTrace();
                }

                if (statii != null && statii.size() >= maxDownloadTweet - 10) {
                    p = new Paging(1, 10);
                    p.setSinceId(mLastIdNotification);
                    p.setMaxId(statii.get(statii.size() - 1).getId());
                    if (twitter.getHomeTimeline().size() > 0) {
                        breakTimeline = true;
                    }
                }

            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                statii = twitter.getMentionsTimeline(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getDirectMessages(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getSentDirectMessages(p);
            }
        } else {
            try {
                Log.d(Utils.TAG, "Primera carga de " + getTypeText());
                if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {
                    statii = twitter.getHomeTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                    statii = twitter.getMentionsTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                    directs = twitter.getDirectMessages();
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                    directs = twitter.getSentDirectMessages();
                }
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            }
        }

        // guardar statii

        if (statii != null) {

            if (statii.size() > 0) {
                out.setNewMessages(statii.size());
                out.setNewerId(statii.get(0).getId());
                out.setOlderId(statii.get(statii.size() - 1).getId());

                Log.d(Utils.TAG,
                        statii.size() + " mensajes nuevos en " + getTypeText() + " de " + getString("name"));

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                try {
                    boolean isFirst = true;
                    for (int i = statii.size() - 1; i >= 0; i--) {
                        User u = statii.get(i).getUser();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId()));
                            args.put("source", statii.get(i).getSource());
                            args.put("to_username", statii.get(i).getInReplyToScreenName());
                            args.put("to_user_id", "" + statii.get(i).getInReplyToUserId());
                            args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime()));
                            if (statii.get(i).getRetweetedStatus() != null) {
                                args.put("is_retweet", 1);
                                args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser()
                                        .getProfileImageURL().toString());
                                args.put("retweet_username",
                                        statii.get(i).getRetweetedStatus().getUser().getScreenName());
                                args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource());
                                String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus());
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getRetweetedStatus().getText());
                                    args.put("text_urls",
                                            Utils.getTextURLs(statii.get(i).getRetweetedStatus()));
                                } else {
                                    args.put("text", t);
                                }
                                args.put("is_favorite", 0);
                            } else {
                                String t = Utils.getTwitLoger(statii.get(i));
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getText());
                                    args.put("text_urls", Utils.getTextURLs(statii.get(i)));
                                } else {
                                    args.put("text", t);
                                }

                                if (statii.get(i).isFavorited()) {
                                    args.put("is_favorite", 1);
                                }
                            }

                            if (statii.get(i).getGeoLocation() != null) {
                                args.put("latitude", statii.get(i).getGeoLocation().getLatitude());
                                args.put("longitude", statii.get(i).getGeoLocation().getLongitude());
                            }
                            args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId());

                            if (breakTimeline && isFirst)
                                args.put("has_more_tweets_down", 1);

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            out.addId(nextId);

                            nextId++;

                            if (isFirst)
                                isFirst = false;
                        }

                    }

                    // finalizar

                    int total = nResult + statii.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH
                            || total > Utils.MAX_ROW_BYSEARCH_FORCE) {
                        try {
                            Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente "
                                    + total + " registros");
                            String date = DataFramework.getInstance()
                                    .getEntityList("tweets_user",
                                            "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                    .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                            String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                    + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                            DataFramework.getInstance().getDB().execSQL(sqldelete);
                        } catch (OutOfMemoryError e) {
                        }
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }

        // guardar directs

        if (directs != null) {
            if (directs.size() > 0) {
                out.setNewMessages(directs.size());
                out.setNewerId(directs.get(0).getId());
                out.setOlderId(directs.get(directs.size() - 1).getId());

                Log.d(Utils.TAG, directs.size() + " mensajes directos a " + getString("name"));

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                try {
                    for (int i = directs.size() - 1; i >= 0; i--) {
                        User u = directs.get(i).getSender();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + directs.get(i).getId()));
                            args.put("source", "");
                            args.put("to_username", directs.get(i).getRecipientScreenName());
                            args.put("to_user_id", "" + directs.get(i).getRecipientId());
                            args.put("date", String.valueOf(directs.get(i).getCreatedAt().getTime()));
                            args.put("text", directs.get(i).getText());

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            out.addId(nextId);

                            Log.d(Utils.TAG,
                                    "getRecipientScreenName: " + directs.get(i).getRecipientScreenName());

                            nextId++;
                        }

                    }

                    // finalizar

                    int total = nResult + directs.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH) {
                        Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total
                                + " registros");
                        String date = DataFramework.getInstance()
                                .getEntityList("tweets_user",
                                        "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                        String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                        DataFramework.getInstance().getDB().execSQL(sqldelete);
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }
    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.infos.InfoTweet.java

License:Apache License

public InfoTweet(User user) {
    urls = new ArrayList<URLContent>();
    mTypeFrom = FROM_USER;//from w ww .  j  av a 2s  .  c  o m

    urlAvatar = user.getProfileImageURL().toString();
    userId = user.getId();
    username = user.getScreenName();
    fullname = user.getName();
    try {
        id = user.getStatus().getId();
        text = user.getStatus().getText();
        source = user.getStatus().getSource();
        toUsername = user.getStatus().getInReplyToScreenName();
        toUserId = user.getStatus().getInReplyToUserId();
        createAt = user.getStatus().getCreatedAt();
        toReplyId = user.getStatus().getInReplyToStatusId();
        if (user.getStatus().getGeoLocation() != null) {
            latitude = user.getStatus().getGeoLocation().getLatitude();
            longitude = user.getStatus().getGeoLocation().getLongitude();
        }
    } catch (Exception e) {
    }

    calculateLinks();
}

From source file:com.javielinux.infos.InfoUsers.java

License:Apache License

public InfoUsers(User user) {
    setId(user.getId());/*w ww  .  j  av a  2s  .  c  o  m*/
    setName(user.getScreenName());
    setFullname(user.getName());
    setCreated(user.getCreatedAt());
    setLocation(user.getLocation());
    if (user.getURL() != null)
        setUrl(user.getURL().toString());
    setFollowers(user.getFollowersCount());
    setFollowing(user.getFriendsCount());
    setTweets(user.getStatusesCount());
    setBio(user.getDescription());
    if (user.getStatus() != null)
        setTextTweet(user.getStatus().getText());
    setUrlAvatar(user.getProfileImageURL().toString());

    ArrayList<Entity> ents = DataFramework.getInstance().getEntityList("users",
            "service is null or service = \"twitter.com\"");

    for (Entity ent : ents) {
        friendly.put(ent.getString("name"), new Friend(ent.getString("name")));
    }

}

From source file:com.klinker.android.twitter.adapters.PeopleArrayAdapter.java

License:Apache License

public void bindView(final View view, int position, final User user) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    final long id = user.getId();
    holder.userId = id;/*www .  j ava 2s  .com*/

    holder.name.setText(user.getName());
    holder.screenName.setText("@" + user.getScreenName());

    //holder.picture.loadImage(user.getBiggerProfileImageURL(), true, null, NetworkedCacheableImageView.CIRCLE);
    final String url = user.getBiggerProfileImageURL();
    if (settings.roundContactImages) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadCircleImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    } else {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    }

    holder.background.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", user.getName());
            viewProfile.putExtra("screenname", user.getScreenName());
            viewProfile.putExtra("proPic", user.getBiggerProfileImageURL());
            //viewProfile.putExtra("tweetid", holder.tweetId);
            viewProfile.putExtra("retweet", false);

            context.startActivity(viewProfile);
        }
    });

    if (openFirst && position == 0) {
        holder.background.performClick();
        ((Activity) context).finish();
    }

    setFollowingStatus(holder, user);
}

From source file:com.klinker.android.twitter.adapters.PicturesArrayAdapter.java

License:Apache License

public void bindView(final View view, Context mContext, final String url, final Status status) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    Log.v("talon_picture", "text: " + status.getText());

    Status thisStatus;//from   w w w .j a v  a2s  .  co  m

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }
    final String fRetweeter = retweeter;

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    final long id = thisStatus.getId();
    final String profilePic = user.getBiggerProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);
    final String tweetText = html[0];
    final String picUrl = html[1];
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    holder.url = url;

    holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() {
        @Override
        public void onImageLoaded(CacheableBitmapDrawable result) {
            holder.iv.setBackgroundDrawable(null);
        }
    });

    holder.iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String link;

            boolean displayPic = !picUrl.equals("");
            if (displayPic) {
                link = picUrl;
            } else {
                link = otherUrl.split("  ")[0];
            }

            Log.v("tweet_page", "clicked");
            Intent viewTweet = new Intent(context, TweetPager.class);
            viewTweet.putExtra("name", name);
            viewTweet.putExtra("screenname", screenname);
            viewTweet.putExtra("time", time);
            viewTweet.putExtra("tweet", tweetText);
            viewTweet.putExtra("retweeter", fRetweeter);
            viewTweet.putExtra("webpage", link);
            viewTweet.putExtra("other_links", otherUrl);
            viewTweet.putExtra("picture", displayPic);
            viewTweet.putExtra("tweetid", id);
            viewTweet.putExtra("proPic", profilePic);
            viewTweet.putExtra("users", users);
            viewTweet.putExtra("hashtags", hashtags);

            context.startActivity(viewTweet);
        }
    });

}

From source file:com.klinker.android.twitter.adapters.TimelineArrayAdapter.java

License:Apache License

public void bindView(final View view, Status status, int position) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    if (holder.expandArea.getVisibility() == View.VISIBLE) {
        removeExpansionNoAnimation(holder);
    }/*from ww w .j av a 2 s. c o m*/

    Status thisStatus;

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    holder.tweetId = thisStatus.getId();
    final long id = holder.tweetId;
    final String profilePic = user.getOriginalProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);

    final String tweetText = html[0];
    final String picUrl = html[1];
    holder.picUrl = picUrl;
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    if (!settings.reverseClickActions) {
        final String fRetweeter = retweeter;
        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                String link;

                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube");
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");
                Intent viewTweet = new Intent(context, TweetPager.class);
                viewTweet.putExtra("name", name);
                viewTweet.putExtra("screenname", screenname);
                viewTweet.putExtra("time", time);
                viewTweet.putExtra("tweet", tweetText);
                viewTweet.putExtra("retweeter", fRetweeter);
                viewTweet.putExtra("webpage", link);
                viewTweet.putExtra("other_links", otherUrl);
                viewTweet.putExtra("picture", displayPic);
                viewTweet.putExtra("tweetid", holder.tweetId);
                viewTweet.putExtra("proPic", profilePic);
                viewTweet.putExtra("users", users);
                viewTweet.putExtra("hashtags", hashtags);

                context.startActivity(viewTweet);

                return true;
            }
        });

        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }
            }
        });

    } else {
        final String fRetweeter = retweeter;
        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }

                String link;

                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube");
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");
                Intent viewTweet = new Intent(context, TweetPager.class);
                viewTweet.putExtra("name", name);
                viewTweet.putExtra("screenname", screenname);
                viewTweet.putExtra("time", time);
                viewTweet.putExtra("tweet", tweetText);
                viewTweet.putExtra("retweeter", fRetweeter);
                viewTweet.putExtra("webpage", link);
                viewTweet.putExtra("other_links", otherUrl);
                viewTweet.putExtra("picture", displayPic);
                viewTweet.putExtra("tweetid", holder.tweetId);
                viewTweet.putExtra("proPic", profilePic);
                viewTweet.putExtra("users", users);
                viewTweet.putExtra("hashtags", hashtags);

                context.startActivity(viewTweet);
            }
        });

        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }

                return true;
            }
        });
    }

    if (!screenname.equals(username)) {
        holder.profilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent viewProfile = new Intent(context, ProfilePager.class);
                viewProfile.putExtra("name", name);
                viewProfile.putExtra("screenname", screenname);
                viewProfile.putExtra("proPic", profilePic);
                viewProfile.putExtra("tweetid", holder.tweetId);
                viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE);
                viewProfile.putExtra("long_click", false);

                context.startActivity(viewProfile);
            }
        });

        holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {

                Intent viewProfile = new Intent(context, ProfilePager.class);
                viewProfile.putExtra("name", name);
                viewProfile.putExtra("screenname", screenname);
                viewProfile.putExtra("proPic", profilePic);
                viewProfile.putExtra("tweetid", holder.tweetId);
                viewProfile.putExtra("retweet", holder.retweeter.getVisibility() == View.VISIBLE);
                viewProfile.putExtra("long_click", true);

                context.startActivity(viewProfile);

                return false;
            }
        });
    } else {
        // need to clear the click listener so it isn't left over from another profile
        holder.profilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                return true;
            }
        });
    }

    if (talonLayout == AppSettings.LAYOUT_FULL_SCREEN
            || (settings.nameAndHandleOnTweet && settings.addonTheme)) {
        if (holder.screenTV.getVisibility() == View.GONE) {
            holder.screenTV.setVisibility(View.VISIBLE);
        }
        holder.screenTV.setText("@" + screenname);
        holder.name.setText(name);
    } else {
        if (!settings.showBoth) {
            holder.name.setText(settings.displayScreenName ? "@" + screenname : name);
        } else {
            if (holder.screenTV.getVisibility() == View.GONE) {
                holder.screenTV.setVisibility(View.VISIBLE);
            }
            holder.name.setText(name);
            holder.screenTV.setText("@" + screenname);
        }
    }

    if (!settings.absoluteDate) {
        holder.time.setText(Utils.getTimeAgo(time, context));
    } else {
        Date date = new Date(time);
        holder.time
                .setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date));
    }

    holder.tweet.setText(tweetText);

    boolean picture = false;

    if (settings.inlinePics) {
        if (holder.picUrl.equals("")) {
            if (holder.image.getVisibility() != View.GONE) {
                holder.image.setVisibility(View.GONE);
            }

            if (holder.playButton.getVisibility() == View.VISIBLE) {
                holder.playButton.setVisibility(View.GONE);
            }
        } else {
            if (holder.picUrl.contains("youtube")) {

                if (holder.playButton.getVisibility() == View.GONE) {
                    holder.playButton.setVisibility(View.VISIBLE);
                }

                final String fRetweeter = retweeter;

                holder.image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String link;

                        boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube");
                        if (displayPic) {
                            link = holder.picUrl;
                        } else {
                            link = otherUrl.split("  ")[0];
                        }

                        Intent viewTweet = new Intent(context, TweetPager.class);
                        viewTweet.putExtra("name", name);
                        viewTweet.putExtra("screenname", screenname);
                        viewTweet.putExtra("time", time);
                        viewTweet.putExtra("tweet", tweetText);
                        viewTweet.putExtra("retweeter", fRetweeter);
                        viewTweet.putExtra("webpage", link);
                        viewTweet.putExtra("other_links", otherUrl);
                        viewTweet.putExtra("picture", displayPic);
                        viewTweet.putExtra("tweetid", holder.tweetId);
                        viewTweet.putExtra("proPic", profilePic);
                        viewTweet.putExtra("users", users);
                        viewTweet.putExtra("hashtags", hashtags);
                        viewTweet.putExtra("clicked_youtube", true);

                        context.startActivity(viewTweet);
                    }
                });

                holder.image.setImageDrawable(transparent);

                picture = true;

            } else {
                holder.image.setImageDrawable(transparent);

                picture = true;

                if (holder.playButton.getVisibility() == View.VISIBLE) {
                    holder.playButton.setVisibility(View.GONE);
                }

                holder.image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (holder.picUrl.contains(" ")) {
                            context.startActivity(new Intent(context, ViewPictures.class).putExtra("pictures",
                                    holder.picUrl));
                        } else {
                            context.startActivity(new Intent(context, PhotoViewerDialog.class).putExtra("url",
                                    holder.picUrl));
                        }
                    }
                });
            }

            if (holder.image.getVisibility() == View.GONE) {
                holder.image.setVisibility(View.VISIBLE);
            }
        }
    }

    if (type == NORMAL) {
        if (retweeter.length() > 0) {
            holder.retweeter.setText(context.getResources().getString(R.string.retweeter) + retweeter);
            holder.retweeterName = retweeter;
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (holder.retweeter.getVisibility() == View.VISIBLE) {
            holder.retweeter.setVisibility(View.GONE);
        }
    } else if (type == RETWEET) {

        int count = status.getRetweetCount();

        if (count > 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweets_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (count == 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweet_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        }
    }

    if (picture) {
        CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl);
        if (wrapper != null) {
            holder.image.setImageDrawable(wrapper);
            picture = false;
        }
    }

    final boolean hasPicture = picture;
    mHandler[currHandler].removeCallbacksAndMessages(null);
    mHandler[currHandler].postDelayed(new Runnable() {
        @Override
        public void run() {
            if (holder.tweetId == id) {
                if (hasPicture) {
                    loadImage(context, holder, holder.picUrl, mCache, id);
                }

                if (settings.useEmoji
                        && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
                    String text = holder.tweet.getText().toString();
                    if (EmojiUtils.emojiPattern.matcher(text).find()) {
                        final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
                        holder.tweet.setText(span);
                    }
                }

                holder.tweet.setSoundEffectsEnabled(false);
                holder.tweet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            Log.v("talon_clickable", "clicked in the cursor adapter");
                            // we need to manually set the background for click feedback because the spannable
                            // absorbs the click on the background
                            if (!holder.preventNextClick) {
                                holder.background.getBackground()
                                        .setState(new int[] { android.R.attr.state_pressed });
                                new Handler().postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        holder.background.getBackground()
                                                .setState(new int[] { android.R.attr.state_empty });
                                    }
                                }, 25);
                            }

                            holder.background.performClick();
                        }
                    }
                });

                holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            holder.background.performLongClick();
                            holder.preventNextClick = true;
                        }
                        return false;
                    }
                });

                if (holder.retweeter.getVisibility() == View.VISIBLE) {
                    holder.retweeter.setSoundEffectsEnabled(false);
                    holder.retweeter.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                if (!holder.preventNextClick) {
                                    holder.background.getBackground()
                                            .setState(new int[] { android.R.attr.state_pressed });
                                    new Handler().postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            holder.background.getBackground()
                                                    .setState(new int[] { android.R.attr.state_empty });
                                        }
                                    }, 25);
                                }

                                holder.background.performClick();
                            }
                        }
                    });

                    holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                holder.background.performLongClick();
                                holder.preventNextClick = true;
                            }
                            return false;
                        }
                    });
                }

                TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
                TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
            }
        }
    }, 400);
    currHandler++;

    if (currHandler == 10) {
        currHandler = 0;
    }

    if (openFirst && position == 0) {
        holder.background.performClick();
    }
}

From source file:com.klinker.android.twitter.adapters.UserListMembersArrayAdapter.java

License:Apache License

@Override
public void bindView(final View view, int position, final User user) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    final long id = user.getId();
    holder.userId = id;/*from  w ww .j a  va  2  s  .c  o m*/

    holder.name.setText(user.getName());
    holder.screenName.setText("@" + user.getScreenName());

    final String url = user.getBiggerProfileImageURL();
    if (settings.roundContactImages) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadCircleImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    } else {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (holder.userId == id) {
                    loadImage(context, holder, url, mCache, id);
                }
            }
        }, 500);
    }

    holder.picture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", user.getName());
            viewProfile.putExtra("screenname", user.getScreenName());
            viewProfile.putExtra("proPic", user.getBiggerProfileImageURL());
            //viewProfile.putExtra("tweetid", holder.tweetId);
            viewProfile.putExtra("retweet", false);

            context.startActivity(viewProfile);
        }
    });

    holder.background.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_user))
                    .setMessage(context.getResources().getString(R.string.remove) + " " + user.getName() + " "
                            + context.getResources().getString(R.string.from_list) + "?")
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            try {
                                new RemoveUser().execute(user.getId() + "");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    }).create().show();
        }
    });
}

From source file:com.klinker.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createInteraction(Context context, User source, Status status, int account, int type) {
    ContentValues values = new ContentValues();
    long id;/*from  ww  w.  j  a  v  a2 s  . c  o  m*/
    if (status != null) {
        id = status.getId();
    } else {
        id = 0; // 0 will be used for whenever it is just a follow
    }
    long time = new GregorianCalendar().getTime().getTime(); // current time

    String users = "@" + source.getScreenName() + " ";

    String text = "";

    String title = "";

    switch (type) {
    case TYPE_FAVORITE:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.favorited);
        text = status.getText();
        break;
    case TYPE_RETWEET:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.retweeted);
        text = status.getRetweetedStatus().getText();
        break;
    case TYPE_FOLLOWER:
        title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.followed);
        break;
    }

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.klinker.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void updateInteraction(Context context, User source, Status status, int account, int type) {
    if (type == TYPE_RETWEET) {
        status = status.getRetweetedStatus();
    }//  w w w  .  j  a v a 2 s .  co m
    Cursor cursor = interactionExists(status.getId(), account);

    if (cursor.getCount() > 0) { // it does exist
        // i want to do the updating stuff

        if (cursor.moveToFirst()) {
            String users = cursor.getString(cursor.getColumnIndex(InteractionsSQLiteHelper.COLUMN_USERS));
            String title = "";

            users += "@" + source.getScreenName() + " ";

            String[] x = users.split(" ");

            if (type == TYPE_RETWEET) { // retweet
                title = x.length + " " + context.getResources().getString(R.string.new_retweets);
            } else { // favorite
                title = x.length + " " + context.getResources().getString(R.string.new_favorites);
            }

            ContentValues cv = new ContentValues();
            cv.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
            cv.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
            cv.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);
            cv.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL());
            cv.put(InteractionsSQLiteHelper.COLUMN_TIME, new GregorianCalendar().getTimeInMillis());

            try {
                database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv,
                        InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?",
                        new String[] { status.getId() + "" });
            } catch (Exception e) {
                open();
                database.update(InteractionsSQLiteHelper.TABLE_INTERACTIONS, cv,
                        InteractionsSQLiteHelper.COLUMN_TWEET_ID + " = ?",
                        new String[] { status.getId() + "" });
            }
        }
    } else {
        // this creates the entry
        createInteraction(context, source, status, account, type);
    }
}