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.hybris.mobile.app.commerce.fragment.CatalogContentFragmentBase.java

/**
 * Return true if we come from a search request
 *
 * @return/*from  ww  w  .j  av a2s  .  co  m*/
 */
protected boolean isSearchRequest() {
    Intent intent = getActivity().getIntent();

    return (intent != null && StringUtils.equals(Intent.ACTION_SEARCH, intent.getAction())
            && intent.hasExtra(SearchManager.QUERY)) || StringUtils.isNotBlank(mCurrentSearchText);
}

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
    IconCache.getInstance(this).clearCache();

    final SharedPreferences pref = U.getSharedPreferences(this);
    final boolean hasHardwareKeyboard = getResources()
            .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;

    switch (pref.getString("show_search_bar", "keyboard")) {
    case "always":
        shouldShowSearchBox = true;/*from w ww .ja v a  2  s .  c o  m*/
        break;
    case "keyboard":
        shouldShowSearchBox = hasHardwareKeyboard;
        break;
    case "never":
        shouldShowSearchBox = false;
        break;
    }

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            shouldShowSearchBox ? 0
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);

    // Determine where to show the start menu on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.start_menu_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_right":
        layoutId = R.layout.start_menu_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "top_left":
        layoutId = R.layout.start_menu_top_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_right":
        layoutId = R.layout.start_menu_top_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    case "top_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    }

    // Initialize views
    int theme = 0;

    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    startMenu = (GridView) layout.findViewById(R.id.start_menu);

    if ((shouldShowSearchBox && !hasHardwareKeyboard)
            || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();

    boolean scrollbar = pref.getBoolean("scrollbar", false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);

    if (pref.getBoolean("transparent_start_menu", false))
        startMenu.setBackgroundColor(0);

    searchView = (SearchView) layout.findViewById(R.id.search);

    int backgroundTint = U.getBackgroundTint(this);

    FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame);
    FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);

    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (!hasSubmittedQuery) {
                    ListAdapter adapter = startMenu.getAdapter();
                    if (adapter != null) {
                        hasSubmittedQuery = true;

                        if (adapter.getCount() > 0) {
                            View view = adapter.getView(0, null, startMenu);
                            LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry);
                            layout.performClick();
                        } else {
                            if (pref.getBoolean("hide_taskbar", true)
                                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
                            else
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

                            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                            intent.putExtra(SearchManager.QUERY, query);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            if (intent.resolveActivity(getPackageManager()) != null)
                                startActivity(intent);
                            else {
                                Uri uri = new Uri.Builder().scheme("https").authority("www.google.com")
                                        .path("search").appendQueryParameter("q", query).build();

                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                    /* Gracefully fail */ }
                            }
                        }
                    }
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                searchView.setIconified(false);

                View closeButton = searchView.findViewById(R.id.search_close_btn);
                if (closeButton != null)
                    closeButton.setVisibility(View.GONE);

                refreshApps(newText, false);

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                    new Handler().postDelayed(() -> {
                        EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }

                return true;
            }
        });

        searchView.setOnQueryTextFocusChangeListener((view, b) -> {
            if (!hasHardwareKeyboard) {
                ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
                params1.height = getResources().getDimensionPixelSize(b
                        && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService")
                                ? R.dimen.start_menu_height_half
                                : R.dimen.start_menu_height);
                startMenu.setLayoutParams(params1);
            }

            if (!b) {
                if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
                    LocalBroadcastManager.getInstance(StartMenuService.this)
                            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        });

        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);

        LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button);
        powerButton.setOnClickListener(view -> {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(location);
        });

        powerButton.setOnGenericMotionListener((view, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                openContextMenu(location);
            }
            return false;
        });

        searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));

        startMenu.setOnItemClickListener((parent, view, position, id) -> {
            hideStartMenu();

            AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
            U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(),
                    entry.getUserId(StartMenuService.this), null, false, false);
        });

        if (pref.getBoolean("transparent_start_menu", false))
            layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
    } else
        searchViewLayout.setVisibility(View.GONE);

    textView = (TextView) layout.findViewById(R.id.no_apps_found);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));

    handler = new Handler();
    refreshApps(true);

    windowManager.addView(layout, params);
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        //use the query to search your data somehow
    }/*from w  w  w  .  jav  a 2  s  . c om*/
}

From source file:com.jefftharris.passwdsafe.PasswdSafe.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    PasswdSafeUtil.dbginfo(TAG, "onNewIntent: %s", intent);
    switch (intent.getAction()) {
    case PasswdSafeUtil.VIEW_INTENT:
    case Intent.ACTION_VIEW: {
        final Uri openUri = PasswdSafeApp.getOpenUriFromIntent(intent);
        final ObjectHolder<Boolean> reopen = new ObjectHolder<>(true);
        itsFileDataFrag.useFileData(new PasswdFileDataUser() {
            @Override//from   w  ww  .j a  va  2  s  . co  m
            public void useFileData(@NonNull PasswdFileData fileData) {
                reopen.set(!fileData.getUri().getUri().equals(openUri));
            }
        });
        Boolean reopenVal = reopen.get();
        if ((reopenVal != null) && reopenVal) {
            // Close and reopen the new file
            itsFileDataFrag.setFileData(null);
            doUpdateView(ViewMode.INIT, new PasswdLocation());
            changeInitialView();
            changeFileOpenView(intent);
        }
        break;
    }
    case Intent.ACTION_SEARCH: {
        setRecordQueryFilter(intent.getStringExtra(SearchManager.QUERY));
        break;
    }
    default: {
        FragmentManager fragMgr = getSupportFragmentManager();
        Fragment frag = fragMgr.findFragmentById(R.id.content);
        if (frag instanceof PasswdSafeOpenFileFragment) {
            ((PasswdSafeOpenFileFragment) frag).onNewIntent(intent);
        }
        break;
    }
    }
}

From source file:com.akop.bach.fragment.playstation.GamesFragment.java

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();

    if (info.targetView.getTag() instanceof ViewHolder) {
        ViewHolder vh = (ViewHolder) info.targetView.getTag();

        switch (menuItem.getItemId()) {
        case R.id.menu_google_trophies:
            Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH);
            searchIntent.putExtra(SearchManager.QUERY,
                    getString(R.string.google_trophies_f, vh.title.getText()));

            startActivity(searchIntent);
            return true;
        }/*www .j a va2  s  .co m*/
    }

    return super.onContextItemSelected(menuItem);
}

From source file:org.yammp.fragment.ArtistFragment.java

private void doSearch(String artist, String album) {

    CharSequence title = null;/*from ww  w  .j a v  a2  s. c  o m*/
    String query = null;

    boolean isUnknownArtist = artist == null || MediaStore.UNKNOWN_STRING.equals(artist);
    boolean isUnknownAlbum = album == null || MediaStore.UNKNOWN_STRING.equals(album);
    if (isUnknownArtist && isUnknownAlbum)
        return;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = album != null ? album : artist;
    query = album != null ? album : artist;

    if (!isUnknownArtist) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    if (!isUnknownAlbum) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    setIntent(intent);//  w  w w. j  a  va  2s .co  m
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        args.putString("query", query);
        if (EAN13CheckDigit.EAN13_CHECK_DIGIT.isValid(query) && (!query.substring(0, 3).contains("977")
                || !query.substring(0, 3).contains("978") || !query.substring(0, 3).contains("979"))) {
            mPresenter.loadProduct(query);
        } else {
            mSearchView.clearFocus();
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, SearchFragment.newInstance(args), SearchFragment.TAG)
                    .commit();
        }
    }
}

From source file:com.android.music.ArtistAlbumBrowserFragment.java

void doSearch() {
    CharSequence title = null;/*from   ww w  .  ja  v a 2  s  .c o m*/
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (mCurrentArtistId != null) {
        title = mCurrentArtistName;
        query = mCurrentArtistName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    } else {
        if (mIsUnknownAlbum) {
            title = query = mCurrentArtistNameForAlbum;
        } else {
            title = query = mCurrentAlbumName;
            if (!mIsUnknownArtist) {
                query = query + " " + mCurrentArtistNameForAlbum;
            }
        }
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE);
    }
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:babbq.com.searchplace.SearchActivity.java

@Override
protected void onNewIntent(Intent intent) {
    if (intent.hasExtra(SearchManager.QUERY)) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (!TextUtils.isEmpty(query)) {
            searchView.setQuery(query, false);
            searchFor(query);//from w  w  w .j  a v  a 2 s  .  c o  m
        }
    }
}

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

@Override
public boolean onLongClick(View v) {

    // TODO search media info

    String track = getTitle().toString();
    String artist = "";// mArtistNameView.getText().toString();
    String album = "";// mAlbumNameView.getText().toString();

    CharSequence title = getString(R.string.mediasearch, track);
    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track);

    String query = track;//ww  w.  j  a va  2 s  . co  m
    if (!getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    } else if (getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = album + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    } else if (!getString(R.string.unknown_artist).equals(artist)
            && getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    i.putExtra(SearchManager.QUERY, query);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    startActivity(Intent.createChooser(i, title));
    return true;
}