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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations