Example usage for android.app SearchManager USER_QUERY

List of usage examples for android.app SearchManager USER_QUERY

Introduction

In this page you can find the example usage for android.app SearchManager USER_QUERY.

Prototype

String USER_QUERY

To view the source code for android.app SearchManager USER_QUERY.

Click Source Link

Document

Intent extra data key: Use this key with android.content.Intent#getStringExtra content.Intent.getStringExtra() to obtain the query string typed in by the user.

Usage

From source file:com.deliciousdroid.activity.FragmentBaseActivity.java

@Override
@TargetApi(14)//w ww.  ja va  2  s  .  c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    mAccountManager = AccountManager.get(this);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    loadSettings();
    init();

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        getActionBar().setHomeButtonEnabled(true);
    }

    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(this, MainSearchResults.class);
            i.putExtras(intent.getExtras());
            startActivity(i);
            finish();
        } else {
            onSearchRequested();
        }
    } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) {
        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);
            startActivity(i);
            finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            Intent viewBookmark = new Intent(this, ViewBookmark.class);
            viewBookmark.setAction(Intent.ACTION_VIEW);
            viewBookmark.setData(data);
            viewBookmark.removeExtra(SearchManager.USER_QUERY);
            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(this, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            finish();
        }
    }
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

private void performSearch(String query) {
    final Intent intent = new Intent(this, SearchActivity.class);
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, query);
    SearchProfile selected = (SearchProfile) mSpinnerProfiles.getSelectedItem();
    if ((selected != null) && (selected.facets != null)) {
        intent.putExtra(SearchManager.USER_QUERY, selected.facets);
    }/* w  w w  .j a v  a  2  s.co  m*/
    this.startActivity(intent);
}

From source file:ca.rmen.android.poetassistant.main.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    Log.d(TAG, "onNewIntent() called with: " + "intent = [" + intent + "]");
    setIntent(intent);/* ww  w  . j a  v  a 2  s.  co  m*/
    // The user entered a search term either by typing or by voice
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getDataString();
        if (TextUtils.isEmpty(query)) {
            query = intent.getStringExtra(SearchManager.QUERY);
        }
        if (TextUtils.isEmpty(query)) {
            CharSequence userQuery = intent.getCharSequenceExtra(SearchManager.USER_QUERY);
            if (!TextUtils.isEmpty(userQuery))
                query = userQuery.toString();
        }
        if (TextUtils.isEmpty(query))
            return;
        mSearch.addSuggestions(query);
        mSearch.search(query);
    }
    // We got here from a deep link
    else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri data = getIntent().getData();
        handleDeepLink(data);
    }
    // Play some text in the tts tab
    else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        mBinding.viewPager.setCurrentItem(mPagerAdapter.getPositionForTab(Tab.READER));
        String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
        ReaderFragment readerFragment = (ReaderFragment) mPagerAdapter.getFragment(mBinding.viewPager,
                Tab.READER);
        readerFragment.setText(sharedText);
    }
}

From source file:com.songcode.materialnotes.ui.NoteEditActivity.java

private boolean initActivityState(Intent intent) {
    /**/*from  w w w  . j a v  a2  s.c o  m*/
     * If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
     * then jump to the NotesListActivity
     */
    mWorkingNote = null;
    if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
        long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
        mUserQuery = "";

        /**
         * Starting from the searched result
         */
        if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
            noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
            mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
        }

        if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
            Intent jump = new Intent(this, NotesListActivity.class);
            startActivity(jump);
            showToast(R.string.error_note_not_exist);
            finish();
            return false;
        } else {
            mWorkingNote = WorkingNote.load(this, noteId);
            if (mWorkingNote == null) {
                Log.e(TAG, "load note failed with note id" + noteId);
                finish();
                return false;
            }
        }
    } else if (TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
        // New note
        long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
        int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, Notes.TYPE_WIDGET_INVALIDE);
        int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, ResourceParser.getDefaultBgId(this));

        // Parse call-record note
        String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
        if (callDate != 0 && phoneNumber != null) {
            if (TextUtils.isEmpty(phoneNumber)) {
                Log.w(TAG, "The call record number is null");
            }
            long noteId = 0;
            if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), phoneNumber,
                    callDate)) > 0) {
                mWorkingNote = WorkingNote.load(this, noteId);
                if (mWorkingNote == null) {
                    Log.e(TAG, "load call note failed with note id" + noteId);
                    finish();
                    return false;
                }
            } else {
                mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType, bgResId);
                mWorkingNote.convertToCallNote(phoneNumber, callDate);
            }
        } else {
            mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType, bgResId);
        }
    } else {
        Log.e(TAG, "Intent not specified action, should not support");
        finish();
        return false;
    }

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    mWorkingNote.setOnSettingStatusChangedListener(this);
    return true;
}

From source file:com.pindroid.activity.Main.java

private void processIntent(Intent intent) {
    String action = intent.getAction();
    String path = intent.getData() != null ? intent.getData().getPath() : "";
    String lastPath = (intent.getData() != null && intent.getData().getLastPathSegment() != null)
            ? intent.getData().getLastPathSegment()
            : "";
    String intentUsername = (intent.getData() != null && intent.getData().getUserInfo() != null)
            ? intent.getData().getUserInfo()
            : "";

    if (!intentUsername.equals("") && !app.getUsername().equals(intentUsername)) {
        setAccount(intentUsername);/*from   ww  w . j  a  v  a  2 s  .  com*/
    }

    if (Intent.ACTION_VIEW.equals(action)) {
        if (lastPath.equals("bookmarks")) {
            if (intent.getData().getQueryParameter("unread") != null
                    && intent.getData().getQueryParameter("unread").equals("1")) {
                onMyUnreadSelected();
            } else {
                onMyBookmarksSelected(intent.getData().getQueryParameter("tagname"));
            }
        } else if (lastPath.equals("notes")) {
            onMyNotesSelected();
        }
    } else if (Intent.ACTION_SEND.equals(action)) {
        Bookmark b = loadBookmarkFromShareIntent();
        b = findExistingBookmark(b);
        onBookmarkAdd(b);
    } else if (Constants.ACTION_SEARCH_SUGGESTION_VIEW.equals(action)) {
        if (path.contains("bookmarks") && TextUtils.isDigitsOnly(lastPath)
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            try {
                String defaultAction = SettingsHelper.getDefaultAction(this);
                BookmarkViewType viewType = null;
                try {
                    viewType = BookmarkViewType.valueOf(defaultAction.toUpperCase(Locale.US));
                } catch (Exception e) {
                    viewType = BookmarkViewType.VIEW;
                }

                onBookmarkSelected(BookmarkManager.GetById(Integer.parseInt(lastPath), this), viewType);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (ContentNotFoundException e) {
                e.printStackTrace();
            }
        } else if (path.contains("bookmarks") && intent.hasExtra(SearchManager.USER_QUERY)) {
            if (intent.getData() != null && intent.getData().getQueryParameter("tagname") != null)
                onTagSelected(intent.getData().getQueryParameter("tagname"), true);
        } else if (path.contains("notes") && TextUtils.isDigitsOnly(lastPath)
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            try {
                onNoteView(NoteManager.GetById(Integer.parseInt(lastPath), this));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (ContentNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java

private void handleIntent(Intent intent) {
    String query = null;/*from w  ww.j a v  a2s  .c  o  m*/
    String[] qf = null;
    if (intent != null) {

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            query = intent.getStringExtra(SearchManager.QUERY);
            qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY));
        } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage msg = (NdefMessage) parcelables[0];
            Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload()));
            query = uri.getQueryParameter("query");
            qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            query = intent.getDataString();
            if (!TextUtils.isEmpty(query)) {
                if (StringUtils.contains(query, "europeana.eu/")) {
                    Uri uri = Uri.parse(query);
                    query = uri.getQueryParameter("query");
                    qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
                }
            }
        } else {
            // no search action recognized? end this activity...
            closeSearchActivity();
        }
        if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) {
            runningSearch = query;
            if (StringArrayUtils.isNotBlank(qf)) {
                searchController.newSearch(this, query, qf);
            } else {
                searchController.newSearch(this, query);
            }
            getSupportActionBar().setTitle(searchController.getSearchTitle(this));
        }
    }
}

From source file:android.support.v7.widget.SearchView.java

/**
 * Constructs an intent from the given information and the search dialog state.
 *
 * @param action Intent action./*from  www  .jav  a 2  s  . c o  m*/
 * @param data Intent data, or <code>null</code>.
 * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>.
 * @param query Intent query, or <code>null</code>.
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other activities
    // on top of the one we want. We don't want to do this in in-app search though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    if (IS_AT_LEAST_FROYO) {
        intent.setComponent(mSearchable.getSearchActivity());
    }
    return intent;
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

/**
 * Constructs an intent from the given information and the search dialog state.
 *
 * @param action Intent action.//from www.ja va 2s.com
 * @param data Intent data, or <code>null</code>.
 * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>.
 * @param query Intent query, or <code>null</code>.
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other activities
    // on top of the one we want. We don't want to do this in in-app search though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    intent.setComponent(mSearchable.getSearchActivity());
    return intent;
}

From source file:com.example.navigationsearchview.NavigationSearchView.java

/**
 * Constructs an intent from the given information and the search dialog
 * state./*w  ww  .  jav a2s.  c  o m*/
 *
 * @param action
 *            Intent action.
 * @param data
 *            Intent data, or <code>null</code>.
 * @param extraData
 *            Data for {@link SearchManager#EXTRA_DATA_KEY} or
 *            <code>null</code>.
 * @param query
 *            Intent query, or <code>null</code>.
 * @param actionKey
 *            The key code of the action key that was pressed, or
 *            {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg
 *            The message for the action key that was pressed, or
 *            <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other
    // activities
    // on top of the one we want. We don't want to do this in in-app search
    // though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    if (IS_AT_LEAST_FROYO) {
        intent.setComponent(mSearchable.getSearchActivity());
    }
    return intent;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

/**
 * Constructs an intent from the given information and the search dialog
 * state.//w ww .ja va2s  .c o m
 * 
 * @param action
 *            Intent action.
 * @param data
 *            Intent data, or <code>null</code>.
 * @param extraData
 *            Data for {@link SearchManager#EXTRA_DATA_KEY} or
 *            <code>null</code>.
 * @param query
 *            Intent query, or <code>null</code>.
 * @param actionKey
 *            The key code of the action key that was pressed, or
 *            {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg
 *            The message for the action key that was pressed, or
 *            <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey,
        String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other
    // activities
    // on top of the one we want. We don't want to do this in in-app search
    // though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    intent.setComponent(mSearchable.getSearchActivity());
    return intent;
}