Example usage for twitter4j Twitter createSavedSearch

List of usage examples for twitter4j Twitter createSavedSearch

Introduction

In this page you can find the example usage for twitter4j Twitter createSavedSearch.

Prototype

SavedSearch createSavedSearch(String query) throws TwitterException;

Source Link

Document

Creates a saved search for the authenticated user.

Usage

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

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    try {/*  w  ww  .j ava2  s . co  m*/
        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);
    }
}

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

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        onBackPressed();//from ww w  . jav  a2  s.c  o  m
        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:
        //overridePendingTransition(0,0);
        //finish();
        //overridePendingTransition(0,0);
        //return super.onOptionsItemSelected(item);

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

From source file:com.klinker.android.twitter.ui.search.SearchPager.java

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        onBackPressed();/*from   w  ww.j  a  va2  s . co m*/
        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);

                    ((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:
        //overridePendingTransition(0,0);
        //finish();
        //overridePendingTransition(0,0);
        //return super.onOptionsItemSelected(item);

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

From source file:com.mothsoft.integration.twitter.TwitterServiceImpl.java

License:Apache License

public void createSavedSearch(final String query) {
    try {//from w ww  . j a v a  2 s.c o m
        final Twitter twitter = factory.getInstance();
        twitter.createSavedSearch(query);
    } catch (TwitterException e) {
        throw wrapException(e);
    }
}

From source file:twitter4j.examples.savedsearches.CreateSavedSearch.java

License:Apache License

/**
 * Usage: java twitter4j.examples.savedsearches.CreateSavedSearch [query]
 *
 * @param args message//from   w  w w . j  a  v  a  2 s .c  om
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.savedsearches.CreateSavedSearch [query]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        SavedSearch savedSearch = twitter.createSavedSearch(args[0]);
        System.out.println("Successfully created saved search [name:" + savedSearch.getName() + " query:"
                + savedSearch.getQuery() + " id:" + savedSearch.getId() + "]");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to create a saved search: " + te.getMessage());
        System.exit(-1);
    }
}