use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class SearchedTrendsActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
try {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
} catch (Exception e) {
}
switch(item.getItemId()) {
case R.id.menu_compose_with_search:
Intent compose = new Intent(context, ComposeActivity.class);
compose.putExtra("user", searchQuery.replaceAll("\"", "") + " ");
startActivity(compose);
return super.onOptionsItemSelected(item);
case R.id.menu_save_search:
Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show();
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
twitter.createSavedSearch(searchQuery.replaceAll("\"", ""));
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, getString(R.string.success), Toast.LENGTH_SHORT).show();
}
});
} catch (TwitterException e) {
// something went wrong
}
}
}).start();
return super.onOptionsItemSelected(item);
case R.id.menu_settings:
Intent settings = new Intent(context, SettingsActivity.class);
startActivityForResult(settings, SETTINGS_RESULT);
return true;
case R.id.menu_pic_filter:
listView.setVisibility(View.GONE);
if (!item.isChecked()) {
searchQuery += " filter:links twitter.com";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", "");
item.setChecked(false);
}
doSearch(searchQuery);
return super.onOptionsItemSelected(item);
case R.id.menu_remove_rt:
listView.setVisibility(View.GONE);
if (!item.isChecked()) {
searchQuery += " -RT";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace(" -RT", "");
item.setChecked(false);
}
doSearch(searchQuery);
return super.onOptionsItemSelected(item);
case R.id.menu_show_top_tweets:
if (!item.isChecked()) {
searchQuery += " TOP";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace(" TOP", "");
item.setChecked(false);
}
doSearch(searchQuery);
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class ListsActivity method getLists.
public void getLists() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, settings);
final ResponseList<UserList> lists;
try {
lists = twitter.getUserLists(settings.myScreenName);
} catch (OutOfMemoryError e) {
return;
}
Collections.sort(lists, new Comparator<UserList>() {
public int compare(UserList result1, UserList result2) {
return result1.getName().compareTo(result2.getName());
}
});
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (lists.size() > 0) {
listView.setAdapter(new ListsArrayAdapter(context, lists));
listView.setVisibility(View.VISIBLE);
} else {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
try {
nothing.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
listView.setVisibility(View.GONE);
}
LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
spinner.setVisibility(View.GONE);
}
});
} catch (Exception e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
nothing.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
spinner.setVisibility(View.GONE);
}
});
}
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class LocalTrendsFragment method getTrends.
@Override
protected Trends getTrends() {
try {
Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
Trends trends;
if (sharedPrefs.getBoolean("manually_config_location", false)) {
// chicago to default
trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574));
} else {
mGoogleApiClient.connect();
connected = false;
int i = 0;
while (!connected && i < 5) {
try {
Thread.sleep(1500);
} catch (Exception e) {
}
i++;
}
Location location = mLastLocation;
ResponseList<twitter4j.Location> locations = twitter.getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
}
return trends;
} catch (Exception e) {
return null;
}
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class UserAutoCompleteHelper method search.
private void search(final String screenName) {
new Thread(new Runnable() {
@Override
public void run() {
Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
try {
users = twitter.searchUsers("@" + screenName, 0);
} catch (Exception e) {
}
context.runOnUiThread(new Runnable() {
@Override
public void run() {
userAutoComplete.setAdapter(new AutoCompleteUserArrayAdapter(context, users));
}
});
}
}).start();
}
use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.
the class SearchPager method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
sharedPrefs.edit().putBoolean("should_refresh", false).commit();
onBackPressed();
return true;
case R.id.menu_settings:
Intent settings = new Intent(context, SettingsActivity.class);
startActivityForResult(settings, SETTINGS_RESULT);
return true;
case R.id.menu_save_search:
Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show();
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
twitter.createSavedSearch(searchQuery.replace(" -RT", "").replace(" TOP", ""));
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(context, getString(R.string.success), Toast.LENGTH_SHORT).show();
}
});
} catch (TwitterException e) {
// something went wrong
}
}
}).start();
return super.onOptionsItemSelected(item);
case R.id.menu_compose_with_search:
Intent compose = new Intent(context, ComposeActivity.class);
compose.putExtra("user", searchQuery);
startActivity(compose);
return super.onOptionsItemSelected(item);
case R.id.menu_search:
case R.id.menu_pic_filter:
if (!item.isChecked()) {
searchQuery += " filter:links twitter.com";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", "");
item.setChecked(false);
}
Intent broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
broadcast.putExtra("query", searchQuery);
context.sendBroadcast(broadcast);
return super.onOptionsItemSelected(item);
case R.id.menu_remove_rt:
if (!item.isChecked()) {
searchQuery += " -RT";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace(" -RT", "");
item.setChecked(false);
}
broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
broadcast.putExtra("query", searchQuery);
context.sendBroadcast(broadcast);
return super.onOptionsItemSelected(item);
case R.id.menu_show_top_tweets:
if (!item.isChecked()) {
searchQuery += " TOP";
item.setChecked(true);
} else {
searchQuery = searchQuery.replace(" TOP", "");
item.setChecked(false);
}
broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
broadcast.putExtra("query", searchQuery);
context.sendBroadcast(broadcast);
return super.onOptionsItemSelected(item);
default:
return super.onOptionsItemSelected(item);
}
}
Aggregations