Search in sources :

Example 61 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class SavedSearchesActivity method getSearches.

public static void getSearches() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                final ResponseList<SavedSearch> searches = twitter.getSavedSearches();
                Collections.sort(searches, new Comparator<SavedSearch>() {

                    public int compare(SavedSearch result1, SavedSearch result2) {
                        return result1.getQuery().compareTo(result2.getQuery());
                    }
                });
                final ArrayList<String> searchNames = new ArrayList<String>();
                for (SavedSearch sear : searches) {
                    searchNames.add(sear.getQuery());
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (searchNames.size() > 0) {
                            adapter = new SavedSearchArrayAdapter(context, searchNames);
                            listView.setAdapter(adapter);
                            listView.setVisibility(View.VISIBLE);
                        } else {
                            try {
                                nothing.setVisibility(View.VISIBLE);
                            } catch (Exception e) {
                            }
                            listView.setVisibility(View.GONE);
                        }
                        spinner.setVisibility(View.GONE);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                    }
                });
            }
        }
    }).start();
}
Also used : SavedSearch(twitter4j.SavedSearch) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) Activity(android.app.Activity) SavedSearchArrayAdapter(com.klinker.android.twitter.adapters.SavedSearchArrayAdapter)

Example 62 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class NearbyTweets method getTweets.

public void getTweets() {
    canRefresh = false;
    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();
}
Also used : Status(twitter4j.Status) Query(twitter4j.Query) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) QueryResult(twitter4j.QueryResult) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) GeoLocation(twitter4j.GeoLocation) LinearLayout(android.widget.LinearLayout) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Example 63 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class CategoryFragment method getSuggestions.

public void getSuggestions() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
                int i = 0;
                final ResponseList<Category> categories = twitter.getSuggestedUserCategories();
                Collections.sort(categories, new Comparator<Category>() {

                    public int compare(Category result1, Category result2) {
                        return result1.getName().compareTo(result2.getName());
                    }
                });
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        listView.setAdapter(new CategoriesArrayAdapter(context, categories));
                        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() {
                        Toast.makeText(context, getResources().getString(R.string.no_location), Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();
}
Also used : Category(twitter4j.Category) CategoriesArrayAdapter(com.klinker.android.twitter.adapters.CategoriesArrayAdapter) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) LinearLayout(android.widget.LinearLayout)

Example 64 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class SearchedTrendsActivity method onRefreshStarted.

public void onRefreshStarted() {
    new Thread(new Runnable() {

        @Override
        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();
}
Also used : QueryResult(twitter4j.QueryResult) Query(twitter4j.Query) Status(twitter4j.Status) Twitter(twitter4j.Twitter) ComposeActivity(com.klinker.android.twitter.activities.compose.ComposeActivity) SettingsActivity(com.klinker.android.twitter.settings.SettingsActivity) Activity(android.app.Activity) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) TwitterException(twitter4j.TwitterException)

Example 65 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class WorldTrends method getTrends.

public void getTrends() {
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                twitter4j.Trends trends = twitter.getPlaceTrends(1);
                final ArrayList<String> currentTrends = new ArrayList<String>();
                for (Trend t : trends.getTrends()) {
                    String name = t.getName();
                    currentTrends.add(name);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (currentTrends != null) {
                            listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
                        }
                        listView.setVisibility(View.VISIBLE);
                        LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
                        spinner.setVisibility(View.GONE);
                    }
                });
                HashtagDataSource source = HashtagDataSource.getInstance(context);
                for (String s : currentTrends) {
                    if (s.contains("#")) {
                        // we want to add it to the userAutoComplete
                        Log.v("talon_hashtag", "adding: " + s);
                        // could be much more efficient by querying and checking first, but I
                        // just didn't feel like it when there is only ever 10 of them here
                        source.deleteTag(s);
                        // add it to the userAutoComplete database
                        source.createTag(s);
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }).start();
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) Trend(twitter4j.Trend) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) TrendsArrayAdapter(com.klinker.android.twitter.adapters.TrendsArrayAdapter) LinearLayout(android.widget.LinearLayout)

Aggregations

Twitter (twitter4j.Twitter)127 TwitterException (twitter4j.TwitterException)76 TwitterFactory (twitter4j.TwitterFactory)60 Status (twitter4j.Status)44 Activity (android.app.Activity)35 QueryResult (twitter4j.QueryResult)17 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)16 Intent (android.content.Intent)13 ArrayList (java.util.ArrayList)13 User (twitter4j.User)12 Query (twitter4j.Query)11 IDs (twitter4j.IDs)8 LinearLayout (android.widget.LinearLayout)7 IOException (java.io.IOException)7 Context (android.content.Context)6 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)6 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)5 GeoLocation (twitter4j.GeoLocation)5 Paging (twitter4j.Paging)5