Example usage for twitter4j QueryResult hasNext

List of usage examples for twitter4j QueryResult hasNext

Introduction

In this page you can find the example usage for twitter4j QueryResult hasNext.

Prototype

boolean hasNext();

Source Link

Document

test if there is next page

Usage

From source file:com.daiv.android.twitter.ui.drawer_activities.discover.NearbyTweets.java

License:Apache License

public void getTweets() {

    canRefresh = false;//w w w  .ja  v a 2  s  .  c o m

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);

                boolean manualLoc = sharedPrefs.getBoolean("manually_config_location", false);

                int i = 0;
                while (!connected && i < 5 && !manualLoc) {
                    try {
                        Thread.sleep(1500);
                    } catch (Exception e) {

                    }

                    i++;
                }

                double latitude = -1;
                double longitude = -1;

                if (manualLoc) {
                    // need to query yahoos api for the location...
                    double[] loc = getLocationFromYahoo(sharedPrefs.getInt("woeid", 2379574));
                    latitude = loc[0];
                    longitude = loc[1];
                } else {
                    // set it from the location client
                    Location location = mLastLocation;
                    latitude = location.getLatitude();
                    longitude = location.getLongitude();
                }

                query = new Query();
                query.setGeoCode(new GeoLocation(latitude, longitude), 10, Query.MILES);

                QueryResult result = twitter.search(query);

                if (result.hasNext()) {
                    hasMore = true;
                    query = result.nextQuery();
                } else {
                    hasMore = false;
                }

                for (Status s : result.getTweets()) {
                    statuses.add(s);
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, statuses);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);

                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Throwable e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Toast.makeText(context, getString(R.string.error), Toast.LENGTH_SHORT).show();
                        } catch (IllegalStateException e) {
                            // not attached to activity
                        }
                    }
                });
            }

            canRefresh = true;
        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.drawer_activities.discover.NearbyTweets.java

License:Apache License

public void getMore() {
    if (hasMore) {
        canRefresh = false;//from  ww  w .  j  a v a  2 s  .c  o m
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, settings);
                    QueryResult result = twitter.search(query);

                    for (twitter4j.Status status : result.getTweets()) {
                        statuses.add(status);
                    }

                    if (result.hasNext()) {
                        query = result.nextQuery();
                        hasMore = true;
                    } else {
                        hasMore = false;
                    }

                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adapter.notifyDataSetChanged();
                            canRefresh = true;
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            canRefresh = false;
                        }
                    });
                }
            }
        }).start();
    }
}

From source file:com.daiv.android.twitter.ui.profile_viewer.fragments.sub_fragments.ProfileMentionsFragment.java

License:Apache License

public void doSearch() {
    spinner.setVisibility(View.VISIBLE);

    new Thread(new Runnable() {
        @Override/*  ww w.j a v a  2  s.  c  o  m*/
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                query = new Query("@" + screenName + " -RT");
                query.sinceId(1);
                QueryResult result = twitter.search(query);

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, tweets);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);

                        spinner.setVisibility(View.GONE);
                        canRefresh = true;

                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;

                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });

            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;

                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            }

        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.profile_viewer.fragments.sub_fragments.ProfileMentionsFragment.java

License:Apache License

public void getMore() {
    canRefresh = false;/*from   ww w .  j  av a  2  s.  co m*/

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                QueryResult result = twitter.search(query);

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter.notifyDataSetChanged();
                        canRefresh = true;

                        if (!hasMore) {
                            View footer = inflater.inflate(R.layout.mentions_footer, null);
                            listView.addFooterView(footer);
                            listView.setFooterDividersEnabled(false);
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        canRefresh = false;
                        hasMore = false;
                    }
                });

            }

        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.search.TwitterSearchFragment.java

License:Apache License

public void onRefreshStarted() {
    new Thread(new Runnable() {
        @Override/*  w  w w.java  2 s .c o m*/
        public void run() {
            final long topId;
            if (tweets.size() > 0) {
                topId = tweets.get(0).getId();
            } else {
                topId = 0;
            }

            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                query = new Query(searchQuery);
                if (topTweets) {
                    query.setResultType(Query.POPULAR);
                } else {
                    query.setResultType(null);
                }
                QueryResult result = twitter.search(query);

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        int top = 0;
                        for (int i = 0; i < tweets.size(); i++) {
                            if (tweets.get(i).getId() == topId) {
                                top = i;
                                break;
                            }
                        }

                        adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        listView.setSelection(top);

                        spinner.setVisibility(View.GONE);

                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            }
        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.search.TwitterSearchFragment.java

License:Apache License

public void doSearch(final String mQuery) {
    spinner.setVisibility(View.VISIBLE);

    if (listView.getVisibility() != View.GONE) {
        listView.setVisibility(View.GONE);
    }/*  www. j  a  v a2  s  .  c  om*/

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Log.v("Test_searching", "query in frag: " + mQuery);
                query = new Query(mQuery);
                if (topTweets) {
                    query.setResultType(Query.ResultType.popular);
                } else {
                    query.setResultType(null);
                }
                QueryResult result = twitter.search(query);

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);

                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            }
        }
    }).start();
}

From source file:com.daiv.android.twitter.ui.search.TwitterSearchFragment.java

License:Apache License

public void getMore() {
    if (hasMore) {
        canRefresh = false;// w  w w . j  a v a  2  s . c  o m
        mPullToRefreshLayout.setRefreshing(true);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, settings);
                    QueryResult result = twitter.search(query);

                    for (twitter4j.Status status : result.getTweets()) {
                        tweets.add(status);
                    }

                    if (result.hasNext()) {
                        query = result.nextQuery();
                        hasMore = true;
                    } else {
                        hasMore = false;
                    }

                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adapter.notifyDataSetChanged();
                            mPullToRefreshLayout.setRefreshing(false);
                            canRefresh = true;
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mPullToRefreshLayout.setRefreshing(false);
                            canRefresh = true;
                        }
                    });
                }
            }
        }).start();
    }
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

License:Apache License

public void onRefreshStarted() {
    new Thread(new Runnable() {
        @Override/*from w  ww . j  ava2s .  c  om*/
        public void run() {

            final long topId;
            if (tweets.size() > 0) {
                topId = tweets.get(0).getId();
            } else {
                topId = 0;
            }

            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                query = new Query(searchQuery);
                QueryResult result = twitter.search(query);

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        int top = 0;
                        for (int i = 0; i < tweets.size(); i++) {
                            if (tweets.get(i).getId() == topId) {
                                top = i;
                                break;
                            }
                        }

                        adapter = new TimelineArrayAdapter(context, tweets);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);
                        listView.setSelection(top);

                        spinner.setVisibility(View.GONE);

                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        mPullToRefreshLayout.setRefreshing(false);
                    }
                });
            }
        }
    }).start();
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

License:Apache License

public void doSearch(final String mQuery) {
    spinner.setVisibility(View.VISIBLE);

    new Thread(new Runnable() {
        @Override//from   w  w w  . j av  a 2 s .  c  om
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);

                Log.v("talon_search", "search query: " + mQuery);
                query = new Query();

                if (mQuery.contains(" TOP")) {
                    query.setResultType(Query.ResultType.popular);
                }

                query.setQuery(mQuery.replace(" TOP", ""));
                QueryResult result;
                try {
                    result = twitter.search(query);
                } catch (OutOfMemoryError e) {
                    return;
                }

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, tweets);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);

                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });

            }
        }
    }).start();
}

From source file:com.klinker.android.twitter.activities.search.TwitterSearchFragment.java

License:Apache License

public void doSearch(final String mQuery) {
    spinner.setVisibility(View.VISIBLE);

    if (listView.getVisibility() != View.GONE) {
        listView.setVisibility(View.GONE);
    }/* w ww.j  a v a2 s  .c  o  m*/

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                Log.v("talon_searching", "query in frag: " + mQuery);
                query = new Query(mQuery);
                if (topTweets) {
                    query.setResultType(Query.ResultType.popular);
                } else {
                    query.setResultType(null);
                }
                QueryResult result = twitter.search(query);

                tweets.clear();

                for (twitter4j.Status status : result.getTweets()) {
                    tweets.add(status);
                }

                if (result.hasNext()) {
                    query = result.nextQuery();
                    hasMore = true;
                } else {
                    hasMore = false;
                }

                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        adapter = new TimelineArrayAdapter(context, tweets, onlyStatus);
                        listView.setAdapter(adapter);
                        listView.setVisibility(View.VISIBLE);

                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            }
        }
    }).start();
}