Example usage for android.provider SearchRecentSuggestions SearchRecentSuggestions

List of usage examples for android.provider SearchRecentSuggestions SearchRecentSuggestions

Introduction

In this page you can find the example usage for android.provider SearchRecentSuggestions SearchRecentSuggestions.

Prototype

public SearchRecentSuggestions(Context context, String authority, int mode) 

Source Link

Document

Although provider utility classes are typically static, this one must be constructed because it needs to be initialized using the same values that you provided in your android.content.SearchRecentSuggestionsProvider .

Usage

From source file:com.klinker.android.twitter.ui.drawer_activities.DrawerActivity.java

private void logoutFromTwitter() {

    context.sendBroadcast(new Intent("com.klinker.android.STOP_PUSH_SERVICE"));

    int currentAccount = sharedPrefs.getInt("current_account", 1);
    boolean login1 = sharedPrefs.getBoolean("is_logged_in_1", false);
    boolean login2 = sharedPrefs.getBoolean("is_logged_in_2", false);

    // Delete the data for the logged out account
    SharedPreferences.Editor e = sharedPrefs.edit();
    e.remove("authentication_token_" + currentAccount);
    e.remove("authentication_token_secret_" + currentAccount);
    e.remove("is_logged_in_" + currentAccount);
    e.remove("new_notification");
    e.remove("new_retweets");
    e.remove("new_favorites");
    e.remove("new_follows");
    e.remove("current_position_" + currentAccount);
    e.commit();//from  ww w  .j  a va  2  s  .  c o m

    HomeDataSource homeSources = HomeDataSource.getInstance(context);
    homeSources.deleteAllTweets(currentAccount);

    MentionsDataSource mentionsSources = MentionsDataSource.getInstance(context);
    mentionsSources.deleteAllTweets(currentAccount);

    DMDataSource dmSource = DMDataSource.getInstance(context);
    dmSource.deleteAllTweets(currentAccount);

    FavoriteUsersDataSource favs = FavoriteUsersDataSource.getInstance(context);
    favs.deleteAllUsers(currentAccount);

    InteractionsDataSource inters = InteractionsDataSource.getInstance(context);
    inters.deleteAllInteractions(currentAccount);

    try {
        long account1List1 = sharedPrefs.getLong("account_" + currentAccount + "_list_1", 0l);
        long account1List2 = sharedPrefs.getLong("account_" + currentAccount + "_list_2", 0l);

        ListDataSource list = ListDataSource.getInstance(context);
        list.deleteAllTweets(account1List1);
        list.deleteAllTweets(account1List2);
    } catch (Exception x) {

    }

    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionsProvider.AUTHORITY,
            MySuggestionsProvider.MODE);
    suggestions.clearHistory();

    AppSettings.invalidate();

    if (currentAccount == 1 && login2) {
        e.putInt("current_account", 2).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else if (currentAccount == 2 && login1) {
        e.putInt("current_account", 1).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else { // only the one account
        e.putInt("current_account", 1).commit();
        finish();
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    }

}

From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java

private void logoutFromTwitter() {

    context.sendBroadcast(new Intent("com.klinker.android.STOP_PUSH_SERVICE"));

    int currentAccount = sharedPrefs.getInt("current_account", 1);
    boolean login1 = sharedPrefs.getBoolean("is_logged_in_1", false);
    boolean login2 = sharedPrefs.getBoolean("is_logged_in_2", false);

    // Delete the data for the logged out account
    SharedPreferences.Editor e = sharedPrefs.edit();
    e.remove("authentication_token_" + currentAccount);
    e.remove("authentication_token_secret_" + currentAccount);
    e.remove("is_logged_in_" + currentAccount);
    e.remove("new_notification");
    e.remove("new_retweets");
    e.remove("new_favorites");
    e.remove("new_follows");
    e.remove("current_position_" + currentAccount);
    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();//from  w w w. j  av  a  2  s .co m

    HomeDataSource homeSources = HomeDataSource.getInstance(context);
    homeSources.deleteAllTweets(currentAccount);

    MentionsDataSource mentionsSources = MentionsDataSource.getInstance(context);
    mentionsSources.deleteAllTweets(currentAccount);

    DMDataSource dmSource = DMDataSource.getInstance(context);
    dmSource.deleteAllTweets(currentAccount);

    FavoriteUsersDataSource favs = FavoriteUsersDataSource.getInstance(context);
    favs.deleteAllUsers(currentAccount);

    InteractionsDataSource inters = InteractionsDataSource.getInstance(context);
    inters.deleteAllInteractions(currentAccount);

    ActivityDataSource activity = ActivityDataSource.getInstance(context);
    activity.deleteAll(currentAccount);

    FavoriteTweetsDataSource favTweets = FavoriteTweetsDataSource.getInstance(context);
    favTweets.deleteAllTweets(currentAccount);

    try {
        long account1List1 = sharedPrefs.getLong("account_" + currentAccount + "_list_1", 0l);
        long account1List2 = sharedPrefs.getLong("account_" + currentAccount + "_list_2", 0l);

        ListDataSource list = ListDataSource.getInstance(context);
        list.deleteAllTweets(account1List1);
        list.deleteAllTweets(account1List2);
    } catch (Exception x) {

    }

    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionsProvider.AUTHORITY,
            MySuggestionsProvider.MODE);
    suggestions.clearHistory();

    AppSettings.invalidate();

    if (currentAccount == 1 && login2) {
        e.putInt("current_account", 2).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else if (currentAccount == 2 && login1) {
        e.putInt("current_account", 1).commit();
        finish();
        Intent next = new Intent(context, MainActivity.class);
        startActivity(next);
    } else { // only the one account
        e.putInt("current_account", 1).commit();
        finish();
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    }

}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 *//*from w  w  w  . j a v  a2s  .  c  om*/
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newinstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setCustomDimension(Analytics.CD_INDEX_ACCOUNT_TYPE,
                    AnalyticsUtils.getAccountTypeForAccount(mAccount.getEmailAddress()));
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = (Uri) intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions.
            final String query = intent.getStringExtra(SearchManager.QUERY);
            final String authority = mContext.getString(R.string.suggestions_authority);
            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext, authority,
                    SuggestionsProvider.MODE);
            suggestions.saveRecentQuery(query, null);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

From source file:com.tct.mail.ui.AbstractActivityController.java

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 *///w ww . j  a v  a  2  s .c  om
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newInstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setCustomDimension(Analytics.CD_INDEX_ACCOUNT_TYPE,
                    AnalyticsUtils.getAccountTypeForAccount(mAccount.getEmailAddress()));
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_S
        } else if (intent.getData() != null) {
            folderUri = intent.getData();
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_E
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        // Check if we should load all conversations instead of using
        // the default behavior which loads an initial subset.
        mIgnoreInitialConversationLimit = intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT,
                false);

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_S
            mToastBar.hide(false, false);
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_E
            // Save this search query for future suggestions.
            final String query = intent.getStringExtra(SearchManager.QUERY);
            final String authority = mContext.getString(R.string.suggestions_authority);
            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext, authority,
                    SuggestionsProvider.MODE);
            suggestions.saveRecentQuery(query, null);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
            /** TCT: init the list context for remote search, except folder. @{ */
            // use a UNINITIALIZED folder temporarily. need update when finish search load.
            Folder folder = Folder.newUnsafeInstance();
            mConvListContext = ConversationListContext.forSearchQuery(mAccount, folder, query);
            mConvListContext
                    .setSearchField(mActivity.getIntent().getStringExtra(SearchParams.BUNDLE_QUERY_FIELD));
            /** @} */
        } else {
            /** TCT: The action is search but no extra account means it's a global search. @{ */
            mGlobalSearch = true;
            LogUtils.logFeature(LogTag.SEARCH_TAG, "Handle ACTION_SEARCH , is mGlobalSearch [%s]",
                    mGlobalSearch);
            // reload conbined inbox folder if needed.
            if (mAccount != null && (mFolder == null || !mFolder.isInitialized())) {
                Bundle args = new Bundle();
                LogUtils.logFeature(LogTag.SEARCH_TAG, " GlobalSearch but without Folder, reload inbox again.");
                args.putParcelable(Utils.EXTRA_FOLDER_URI, mAccount.settings.defaultInbox);
                restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
            }
            /** @} */
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}