Search in sources :

Example 6 with SearchRecentSuggestions

use of android.provider.SearchRecentSuggestions in project Talon-for-Twitter by klinker24.

the class ProfilePager method getUser.

public void getUser() {
    Thread getUser = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                thisUser = twitter.showUser(screenName);
            } catch (Exception e) {
                thisUser = null;
            }
            if (thisUser != null) {
                try {
                    FollowersDataSource.getInstance(context).createUser(thisUser, sharedPrefs.getInt("current_account", 1));
                } catch (Exception e) {
                // the user already exists. don't know if this is more efficient than querying the db or not.
                }
                final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
                suggestions.saveRecentQuery("@" + thisUser.getScreenName(), null);
            }
            new GetActionBarInfo().execute();
        }
    });
    getUser.setPriority(Thread.MAX_PRIORITY);
    getUser.start();
}
Also used : Twitter(twitter4j.Twitter) SearchRecentSuggestions(android.provider.SearchRecentSuggestions) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 7 with SearchRecentSuggestions

use of android.provider.SearchRecentSuggestions in project ActionBarSherlock by JakeWharton.

the class Issue659 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, Issue659SuggestionsProvider.AUTHORITY, Issue659SuggestionsProvider.MODE);
        suggestions.saveRecentQuery(query, null);
        Toast.makeText(this, "Search called with: " + query, Toast.LENGTH_SHORT).show();
    }
}
Also used : Intent(android.content.Intent) SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Example 8 with SearchRecentSuggestions

use of android.provider.SearchRecentSuggestions in project Varis-Android by dkhmelenko.

the class MainActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = null;
    if (searchItem != null) {
        mSearchView = (SearchView) searchItem.getActionView();
    }
    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                boolean submitProhibited = true;
                if (query.length() > SEARCH_LIMIT) {
                    // save search query to history
                    SearchRecentSuggestions suggestionsProvider = new SearchRecentSuggestions(MainActivity.this, SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
                    suggestionsProvider.saveRecentQuery(query, null);
                    submitProhibited = false;
                }
                return submitProhibited;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                reloadSearchHistoryAdapter(newText);
                return true;
            }
        });
        mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {

            @Override
            public boolean onSuggestionClick(int position) {
                mSearchView.setQuery(mQueryItems.get(position), true);
                return true;
            }

            @Override
            public boolean onSuggestionSelect(int position) {
                return true;
            }
        });
        reloadSearchHistoryAdapter("");
        // restore query if it was
        if (!TextUtils.isEmpty(mSavedQuery)) {
            mSearchView.setQuery(mSavedQuery, false);
            mSearchView.setIconified(false);
        }
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Example 9 with SearchRecentSuggestions

use of android.provider.SearchRecentSuggestions in project materialistic by hidroh.

the class SearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (getIntent().hasExtra(SearchManager.QUERY)) {
        mQuery = getIntent().getStringExtra(SearchManager.QUERY);
    }
    super.onCreate(savedInstanceState);
    if (!TextUtils.isEmpty(mQuery)) {
        getSupportActionBar().setSubtitle(mQuery);
        SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchRecentSuggestionsProvider.PROVIDER_AUTHORITY, SearchRecentSuggestionsProvider.MODE) {

            @Override
            public void saveRecentQuery(String queryString, String line2) {
                truncateHistory(getContentResolver(), MAX_RECENT_SUGGESTIONS - 1);
                super.saveRecentQuery(queryString, line2);
            }
        };
        suggestions.saveRecentQuery(mQuery, null);
    }
}
Also used : SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Example 10 with SearchRecentSuggestions

use of android.provider.SearchRecentSuggestions in project Talon-for-Twitter by klinker24.

the class PrefFragment method setUpMemManagementSettings.

public void setUpMemManagementSettings() {
    final SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    Preference clearSearch = findPreference("clear_searches");
    clearSearch.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
            suggestions.clearHistory();
            return false;
        }
    });
    Preference backup = findPreference("backup");
    backup.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.backup_settings_dialog)).setMessage(context.getResources().getString(R.string.backup_settings_dialog_summary)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    File des = new File(Environment.getExternalStorageDirectory() + "/Talon/backup.prefs");
                    IOUtils.saveSharedPreferencesToFile(des, context);
                    Toast.makeText(context, context.getResources().getString(R.string.backup_success), Toast.LENGTH_LONG).show();
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).create().show();
            return false;
        }
    });
    Preference restore = findPreference("restore");
    restore.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            File des = new File(Environment.getExternalStorageDirectory() + "/Talon/backup.prefs");
            String authenticationToken1 = sharedPrefs.getString("authentication_token_1", "none");
            String authenticationTokenSecret1 = sharedPrefs.getString("authentication_token_secret_1", "none");
            String myScreenName1 = sharedPrefs.getString("twitter_screen_name_1", "");
            String myName1 = sharedPrefs.getString("twitter_users_name_1", "");
            String myBackgroundUrl1 = sharedPrefs.getString("twitter_background_url_1", "");
            String myProfilePicUrl1 = sharedPrefs.getString("profile_pic_url_1", "");
            long lastTweetId1 = sharedPrefs.getLong("last_tweet_id_1", 0);
            long secondLastTweetId1 = sharedPrefs.getLong("second_last_tweet_id_1", 0);
            long lastMentionId1 = sharedPrefs.getLong("last_mention_id_1", 0);
            long lastDMId1 = sharedPrefs.getLong("last_dm_id_1", 0);
            long twitterId1 = sharedPrefs.getLong("twitter_id_1", 0);
            boolean isloggedin1 = sharedPrefs.getBoolean("is_logged_in_1", false);
            String authenticationToken2 = sharedPrefs.getString("authentication_token_2", "none");
            String authenticationTokenSecret2 = sharedPrefs.getString("authentication_token_secret_2", "none");
            String myScreenName2 = sharedPrefs.getString("twitter_screen_name_2", "");
            String myName2 = sharedPrefs.getString("twitter_users_name_2", "");
            String myBackgroundUrl2 = sharedPrefs.getString("twitter_background_url_2", "");
            String myProfilePicUrl2 = sharedPrefs.getString("profile_pic_url_2", "");
            long lastTweetId2 = sharedPrefs.getLong("last_tweet_id_2", 0);
            long secondLastTweetId2 = sharedPrefs.getLong("second_last_tweet_id_2", 0);
            long lastMentionId2 = sharedPrefs.getLong("last_mention_id_2", 0);
            long lastDMId2 = sharedPrefs.getLong("last_dm_id_2", 0);
            long twitterId2 = sharedPrefs.getLong("twitter_id_2", 0);
            boolean isloggedin2 = sharedPrefs.getBoolean("is_logged_in_2", false);
            IOUtils.loadSharedPreferencesFromFile(des, context);
            Toast.makeText(context, context.getResources().getString(R.string.restore_success), Toast.LENGTH_LONG).show();
            SharedPreferences.Editor e = sharedPrefs.edit();
            e.putString("authentication_token_1", authenticationToken1);
            e.putString("authentication_token_secret_1", authenticationTokenSecret1);
            e.putString("twitter_screen_name_1", myScreenName1);
            e.putString("twitter_users_name_1", myName1);
            e.putString("twitter_background_url_1", myBackgroundUrl1);
            e.putString("profile_pic_url_1", myProfilePicUrl1);
            e.putString("favorite_user_names_1", "");
            e.putLong("last_tweet_id_1", lastTweetId1);
            e.putLong("second_last_tweet_id_1", secondLastTweetId1);
            e.putLong("last_mention_id_1", lastMentionId1);
            e.putLong("last_dm_id_1", lastDMId1);
            e.putLong("twitter_id_1", twitterId1);
            e.putBoolean("is_logged_in_1", isloggedin1);
            e.putString("authentication_token_2", authenticationToken2);
            e.putString("authentication_token_secret_2", authenticationTokenSecret2);
            e.putString("twitter_screen_name_2", myScreenName2);
            e.putString("twitter_users_name_2", myName2);
            e.putString("twitter_background_url_2", myBackgroundUrl2);
            e.putString("profile_pic_url_2", myProfilePicUrl2);
            e.putString("favorite_user_names_2", "");
            e.putLong("last_tweet_id_2", lastTweetId2);
            e.putLong("second_last_tweet_id_2", secondLastTweetId2);
            e.putLong("last_mention_id_2", lastMentionId2);
            e.putLong("last_dm_id_2", lastDMId2);
            e.putLong("twitter_id_2", twitterId2);
            e.putBoolean("is_logged_in_2", isloggedin2);
            e.remove("new_notifications");
            e.remove("new_retweets");
            e.remove("new_favorites");
            e.remove("new_follows");
            int currentAccount = sharedPrefs.getInt("current_account", 1);
            e.remove("last_activity_refresh_" + currentAccount);
            e.remove("original_activity_refresh_" + currentAccount);
            e.remove("activity_follower_count_" + currentAccount);
            e.remove("activity_latest_followers_" + currentAccount);
            e.commit();
            return false;
        }
    });
    final Preference cache = findPreference("delete_cache");
    long size = IOUtils.dirSize(context.getCacheDir());
    cache.setSummary(getResources().getString(R.string.current_cache_size) + ": " + size / 1048576 + " MB");
    cache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.cache_dialog)).setMessage(context.getResources().getString(R.string.cache_dialog_summary)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    try {
                        new TrimCache(cache).execute();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).create().show();
            return false;
        }
    });
    Preference trim = findPreference("trim_now");
    trim.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.trim_dialog)).setMessage(context.getResources().getString(R.string.cache_dialog_summary)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    try {
                        new TrimDatabase().execute();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).create().show();
            return false;
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) SearchRecentSuggestions(android.provider.SearchRecentSuggestions) TwitterException(twitter4j.TwitterException) File(java.io.File)

Aggregations

SearchRecentSuggestions (android.provider.SearchRecentSuggestions)15 TwitterException (twitter4j.TwitterException)2 AlertDialog (android.app.AlertDialog)1 SearchManager (android.app.SearchManager)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 SearchView (android.support.v7.widget.SearchView)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 EventInfo (com.android.calendar.CalendarController.EventInfo)1 MainActivity (com.klinker.android.twitter.activities.MainActivity)1 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)1 HashtagDataSource (com.klinker.android.twitter.data.sq_lite.HashtagDataSource)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Twitter (twitter4j.Twitter)1