Example usage for android.app SearchManager QUERY

List of usage examples for android.app SearchManager QUERY

Introduction

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

Prototype

String QUERY

To view the source code for android.app SearchManager 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 from Intent.ACTION_SEARCH.

Usage

From source file:com.vyasware.vaani.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    returnedText = (TextView) findViewById(R.id.textView1);
    outputText = (TextView) findViewById(R.id.textView2);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);

    progressBar.setVisibility(View.INVISIBLE);
    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
    //                "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "hi-IN");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override/*from   www.  j  av a 2  s  .  co  m*/
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                tts.setLanguage(new Locale("hi_IN"));
                tts.setSpeechRate(0.9f);
            }
        }
    });
    returnedText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, returnedText.getText());
            if (intent.resolveActivity(getPackageManager()) != null)
                startActivity(intent);

        }
    });

    toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setIndeterminate(true);
                speech.startListening(recognizerIntent);
                outputText.setText("");
            } else {
                progressBar.setIndeterminate(false);
                progressBar.setVisibility(View.INVISIBLE);
                speech.stopListening();
            }
        }
    });

}

From source file:org.musicmod.android.app.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();/*from   w ww.j  a v a  2 s  .  c om*/

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(getActivity(), list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:com.bukanir.android.activities.SearchActivity.java

private void handleSearchIntent(Intent intent) {
    Log.d(TAG, "handleSearchIntent");
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (Utils.isNetworkAvailable(this)) {
            searchTask = new SearchTask();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                searchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, query);
            } else {
                searchTask.execute(query);
            }/* w ww. java2s.c  o  m*/
        } else {
            Toast.makeText(this, getString(R.string.network_not_available), Toast.LENGTH_LONG).show();
        }
    }
}

From source file:com.saarang.samples.apps.iosched.ui.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    LogUtils.LOGD(TAG, "SearchActivity.onNewIntent: " + intent);
    setIntent(intent);/*from www.j  a v a 2 s . c  o m*/
    String query = intent.getStringExtra(SearchManager.QUERY);
    Bundle args = intentToFragmentArguments(new Intent("com.saarang.samples.apps.iosched.SESSION_VIEW",
            ScheduleContract.Sessions.buildSearchUri(query)));
    LogUtils.LOGD(TAG, "onNewIntent() now reloading sessions fragment with args: " + args);
    mSessionsFragment.reloadFromArguments(args);
    /* [ANALYTICS:EVENT]
     * TRIGGER:   Start a search on the Search Activity
     * CATEGORY:  'Search'
     * ACTION:    'Search'
     * LABEL:     none (we DO NOT log the search query).
     * [/ANALYTICS]
     */
    AnalyticsManager.sendEvent(SCREEN_LABEL, "Search", "");
}

From source file:com.nbonnec.mediaseb.ui.activity.SearchActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        search = intent.getStringExtra(SearchManager.QUERY);
    }
}

From source file:com.rowland.hashtrace.ui.fragments.SearchFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle arguments = getArguments();//from w  w  w.  j av  a2s . c  o m
    if (arguments != null) {
        mQuery = arguments.getString(SearchManager.QUERY);
    }
}

From source file:cm.aptoide.pt.RemoteInSearch.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.list);/* w  w  w .  j a  v  a  2 s.c om*/

    db = new DbHandler(this);

    mPm = getPackageManager();

    getListView().setFastScrollEnabled(true);

    Intent i = getIntent();
    query = i.getStringExtra(SearchManager.QUERY);
    apk_lst = db.getSearch(query, order_lst);
}

From source file:org.openmrs.mobile.activities.FindPatientsSearchActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        mSearching = true;//from w w w  .  j a  v  a2s  .c  om
        mLastSearchId++;
        mEmptyList.setVisibility(View.GONE);
        mPatientsListView.setEmptyView(mSpinner);
        mSearchedPatientsList = new ArrayList<Patient>();
        mAdapter = new PatientArrayAdapter(this, R.layout.find_patients_row, mSearchedPatientsList);
        mPatientsListView.setAdapter(mAdapter);
        mLastQuery = intent.getStringExtra(SearchManager.QUERY);
        new FindPatientsManager()
                .findPatient(FindPatientsHelper.createFindPatientListener(mLastQuery, mLastSearchId, this));

        if (mFindPatientMenuItem != null) {
            MenuItemCompat.collapseActionView(mFindPatientMenuItem);
        }
    }
}

From source file:com.google.samples.apps.iosched.ui.SearchActivity.java

/**
 * As we only ever want one instance of this screen, we set a launchMode of singleTop. This
 * means that instead of re-creating this Activity, a new intent is delivered via this callback.
 * This prevents multiple instances of the search dialog 'stacking up' e.g. if you perform a
 * voice search./* w w  w. jav a2 s.co  m*/
 *
 * See: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
 */
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent.hasExtra(SearchManager.QUERY)) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (!TextUtils.isEmpty(query)) {
            searchFor(query);
            mSearchView.setQuery(query, false);
        }
    }
}

From source file:com.free.underground.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*from w w w . ja  v  a2 s. c o  m*/
    // Handle action buttons
    switch (item.getItemId()) {
    case R.id.action_websearch:
        Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        } else {
            Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}