use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class TwitterSearchFragment method findStatus.
public void findStatus(final long statusid) {
listView.setVisibility(View.GONE);
spinner.setVisibility(View.VISIBLE);
hasMore = false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
Status status = twitter.showStatus(statusid);
final ArrayList<Status> statuses = new ArrayList<Status>();
statuses.add(status);
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
TimelineArrayAdapter adapter = new TimelineArrayAdapter(context, statuses, 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);
}
});
hasMore = false;
}
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class TwitterSearchFragment 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);
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();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class UserSearchFragment method getMoreUsers.
public void getMoreUsers(final String mQuery) {
if (hasMore) {
canRefresh = false;
mPullToRefreshLayout.setRefreshing(true);
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
ResponseList<User> result = twitter.searchUsers(mQuery, userPage);
userPage++;
for (User u : result) {
users.add(u);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (peopleAdapter != null) {
peopleAdapter.notifyDataSetChanged();
}
mPullToRefreshLayout.setRefreshing(false);
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
mPullToRefreshLayout.setRefreshing(false);
}
});
hasMore = false;
}
}
}).start();
}
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class UserSearchFragment method doUserSearch.
public void doUserSearch(final String mQuery) {
listView.setVisibility(View.GONE);
spinner.setVisibility(View.VISIBLE);
hasMore = true;
canRefresh = false;
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
ResponseList<User> result = twitter.searchUsers(mQuery, userPage);
userPage++;
if (result.size() < 18) {
hasMore = false;
canRefresh = false;
}
users = new ArrayList<User>();
for (User u : result) {
users.add(u);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
peopleAdapter = new PeopleArrayAdapter(context, users, onlyProfile);
listView.setAdapter(peopleAdapter);
listView.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
canRefresh = true;
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
spinner.setVisibility(View.GONE);
}
});
hasMore = false;
canRefresh = true;
}
}
}).start();
}
use of twitter4j.Twitter in project twitter4j by yusuke.
the class GetRateLimitStatus method main.
/**
* Usage: java twitter4j.examples.account.GetRateLimitStatus
*
* @param args message
*/
public static void main(String[] args) {
try {
Twitter twitter = new TwitterFactory().getInstance();
Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();
for (String endpoint : rateLimitStatus.keySet()) {
RateLimitStatus status = rateLimitStatus.get(endpoint);
System.out.println("Endpoint: " + endpoint);
System.out.println(" Limit: " + status.getLimit());
System.out.println(" Remaining: " + status.getRemaining());
System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds());
System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset());
}
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get rate limit status: " + te.getMessage());
System.exit(-1);
}
}
Aggregations