Example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Prototype

int IME_ACTION_SEARCH

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).

Usage

From source file:org.rm3l.ddwrt.tiles.syslog.StatusSyslogTile.java

@Override
public void onLoadFinished(@NotNull Loader<NVRAMInfo> loader, @Nullable NVRAMInfo data) {
    //Set tiles//from   ww  w .ja v a 2 s. co  m
    Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data);

    layout.findViewById(R.id.tile_status_router_syslog_header_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_router_syslog_content_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_router_syslog_state).setVisibility(View.VISIBLE);
    layout.findViewById(R.id.tile_status_router_syslog_content).setVisibility(View.VISIBLE);

    if (data == null) {
        data = new NVRAMInfo().setException(new DDWRTNoDataException("No Data!"));
    }

    @NotNull
    final TextView errorPlaceHolderView = (TextView) this.layout
            .findViewById(R.id.tile_status_router_syslog_error);

    @Nullable
    final Exception exception = data.getException();

    if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {

        if (exception == null) {
            errorPlaceHolderView.setVisibility(View.GONE);
        }

        final String syslogdEnabledPropertyValue = data.getProperty(SYSLOGD_ENABLE);
        final boolean isSyslogEnabled = "1".equals(syslogdEnabledPropertyValue);

        final TextView syslogState = (TextView) this.layout.findViewById(R.id.tile_status_router_syslog_state);

        final View syslogContentView = this.layout.findViewById(R.id.tile_status_router_syslog_content);
        final EditText filterEditText = (EditText) this.layout
                .findViewById(R.id.tile_status_router_syslog_filter);

        syslogState.setText(
                syslogdEnabledPropertyValue == null ? "-" : (isSyslogEnabled ? "Enabled" : "Disabled"));

        syslogState.setVisibility(mDisplayStatus ? View.VISIBLE : View.GONE);

        final TextView logTextView = (TextView) syslogContentView;
        if (isSyslogEnabled) {

            //Highlight textToFind for new log lines
            final String newSyslog = data.getProperty(SYSLOG, EMPTY_STRING);

            //Hide container if no data at all (no existing data, and incoming data is empty too)
            final View scrollView = layout.findViewById(R.id.tile_status_router_syslog_content_scrollview);

            //noinspection ConstantConditions
            Spanned newSyslogSpan = new SpannableString(newSyslog);

            final SharedPreferences sharedPreferences = this.mParentFragmentPreferences;
            final String existingSearch = sharedPreferences != null
                    ? sharedPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null)
                    : null;

            if (!isNullOrEmpty(existingSearch)) {
                if (isNullOrEmpty(filterEditText.getText().toString())) {
                    filterEditText.setText(existingSearch);
                }
                if (!isNullOrEmpty(newSyslog)) {
                    //noinspection ConstantConditions
                    newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch);
                }
            }

            //                if (!(isNullOrEmpty(existingSearch) || isNullOrEmpty(newSyslog))) {
            //                    filterEditText.setText(existingSearch);
            //                    //noinspection ConstantConditions
            //                    newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch);
            //                }

            if (isNullOrEmpty(logTextView.getText().toString()) && isNullOrEmpty(newSyslog)) {
                scrollView.setVisibility(View.INVISIBLE);
            } else {
                scrollView.setVisibility(View.VISIBLE);

                logTextView.setMovementMethod(new ScrollingMovementMethod());

                logTextView.append(
                        new SpannableStringBuilder().append(Html.fromHtml("<br/>")).append(newSyslogSpan));
            }

            filterEditText.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    final int DRAWABLE_LEFT = 0;
                    final int DRAWABLE_TOP = 1;
                    final int DRAWABLE_RIGHT = 2;
                    final int DRAWABLE_BOTTOM = 3;

                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        if (event.getRawX() >= (filterEditText.getRight()
                                - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                            //Reset everything
                            filterEditText.setText(EMPTY_STRING); //this will trigger the TextWatcher, thus disabling the "Find" button
                            //Highlight text in textview
                            final String currentText = logTextView.getText().toString();

                            logTextView.setText(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING)
                                    .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING));

                            if (sharedPreferences != null) {
                                final SharedPreferences.Editor editor = sharedPreferences.edit();
                                editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING);
                                editor.apply();
                            }
                            return true;
                        }
                    }
                    return false;
                }
            });

            filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                        final String textToFind = filterEditText.getText().toString();
                        if (isNullOrEmpty(textToFind)) {
                            //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present
                            return true;
                        }
                        if (sharedPreferences != null) {
                            if (textToFind.equalsIgnoreCase(existingSearch)) {
                                //No need to go further as this is already the string we are looking for
                                return true;
                            }
                            final SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind);
                            editor.apply();
                        }
                        //Highlight text in textview
                        final String currentText = logTextView.getText().toString();

                        logTextView.setText(
                                findAndHighlightOutput(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING)
                                        .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING), textToFind));

                        return true;
                    }
                    return false;
                }
            });

        }
    }

    if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = Throwables.getRootCause(exception);
        errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null"));
        final Context parentContext = this.mParentFragmentActivity;
        errorPlaceHolderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (rootCause != null) {
                    Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
        errorPlaceHolderView.setVisibility(View.VISIBLE);
    }

    doneWithLoaderInstance(this, loader, R.id.tile_status_router_syslog_togglebutton_title,
            R.id.tile_status_router_syslog_togglebutton);

    Log.d(LOG_TAG, "onLoadFinished(): done loading!");
}

From source file:com.bydavy.card.receipts.activities.ReceiptListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.activity_receipt_list, menu);
    final MenuItem searchItem = menu.findItem(R.id.menu_search);
    mSearch = (EditText) searchItem.getActionView();
    mSearch.setOnEditorActionListener(new OnEditorActionListener() {
        @Override/*  w ww  . jav  a 2s .  c  o m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((EditorInfo.IME_ACTION_SEARCH == actionId)
                    || ((event != null) && (KeyEvent.KEYCODE_ENTER == event.getKeyCode()))) {
                search(v.getText().toString());
                return true;
            }
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:org.chromium.chrome.browser.widget.selection.SelectableListToolbar.java

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        UiUtils.hideKeyboard(v);//w ww  . jav a2 s . c  om
    }
    return false;
}

From source file:com.ichi2.anki2.CardBrowser.java

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

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);/* ww  w.  j av  a2s .  c o m*/
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java

@Override
public void startSearchMode(boolean animate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (animate) {
            final View actionMenuView = toolbar.getChildAt(1);
            final ViewGroup actionMenuViewGroup = (ViewGroup) actionMenuView;
            final View addButton = actionMenuViewGroup.getChildAt(0);

            searchButtonCenter = new Point(
                    (int) (addButton.getX() + actionMenuView.getX() + addButton.getWidth() / 2),
                    (int) (addButton.getY() + actionMenuView.getY() + addButton.getHeight() / 2));

            final Animator animator = ViewAnimationUtils.createCircularReveal(searchToolbar,
                    searchButtonCenter.x, searchButtonCenter.y, 0, searchToolbar.getWidth());
            animator.setDuration(revealStatusBarDuration);
            animator.addListener(new StartSearchModeAnimationListener(toolbar));
            searchToolbar.setVisibility(View.VISIBLE);
            animator.start();/* w  w w.  j  av a  2s.  com*/
        } else {
            searchToolbar.setVisibility(View.VISIBLE);
        }

        setSupportActionBar(searchToolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(tintedBackArrow);
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setCustomView(R.layout.toolbar_search);
        }
    } else {
        toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.background));

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(tintedBackArrow);
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setCustomView(R.layout.toolbar_search);
        }

        invalidateOptionsMenu();
    }

    searchInput = (EditText) findViewById(R.id.search_input);
    searchInput.requestFocus();
    searchInputSub = RxTextView.textChangeEvents(searchInput)
            .debounce(searchInputDebounceDuration, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread()).subscribe(textViewTextChangeEvent -> {
                presenter.onSearchInputChanged(textViewTextChangeEvent.text().toString());
            });
    searchInputLengthSub = RxTextView.textChangeEvents(searchInput).observeOn(AndroidSchedulers.mainThread())
            .subscribe(textViewTextChangeEvent -> {
                presenter.onSearchInputLengthChanged(textViewTextChangeEvent.text().toString(),
                        textViewTextChangeEvent.count());
            });
    searchInput.setOnEditorActionListener((textView, actionId, keyEvent) -> {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            Utils.hideKeyboard(ShowComicsActivity.this);
            return true;
        }
        return false;
    });

    Utils.showKeyboard(this);

    searchResults.setVisibility(View.VISIBLE);
    if (animate) {
        searchResults.animate().alpha(1).setDuration(crossfadeViewPagerSearchDuration).setListener(null);

        viewPager.animate().alpha(0).setDuration(crossfadeViewPagerSearchDuration)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        viewPager.setVisibility(View.GONE);
                    }
                });
    } else {
        searchResults.setAlpha(1);
        viewPager.setAlpha(0);
        viewPager.setVisibility(View.GONE);
    }
}

From source file:com.hichinaschool.flashcards.anki.CardBrowser.java

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

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//from w w w .  j  a  v a2  s.co  m
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "sfld", "deck", "flags" },
            new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:org.goodev.material.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*w  w w  .  j  a v  a  2  s .c o m*/
        public boolean onQueryTextSubmit(String query) {
            searchFor(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });

}

From source file:com.nit.vicky.CardBrowser.java

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

    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);//  w w  w. j  a v a  2 s.  c  o m
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();

    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);

    mBackground = Themes.getCardBrowserBackground();

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);

    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);

    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item,
            new String[] { "word", "sfld", "deck", "flags" },
            new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize,
            sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });

    //mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);

    mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview);
    mCardsGridView.setAdapter(mGridAdapter);
    mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() {
        @Override
        public void onItemClick(StaggeredGridView parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class);
            //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
            String imgURL = getImgURL(sCardBrowserCard);
            Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show();
        }
    });
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearch();
        }
    });

    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

    mSelectedTags = new HashSet<String>();

    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void initView() {
    setTitleText(R.string.select_school);

    swipeLayout = (RefreshLayout) findViewById(R.id.enroll_school_swipe_container);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
            android.R.color.holo_orange_light, android.R.color.holo_red_light);

    schoolListView = (ListView) findViewById(R.id.enroll_select_school_listview);
    swipeLayout.setChildScroll(new MOnScrollListener() {

        @Override//ww  w. j a va 2s . c o  m
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
            LogUtil.print("scrolling--->" + schoolListView.getFirstVisiblePosition());
            switch (scrollState) {
            // ?
            case OnScrollListener.SCROLL_STATE_IDLE:// ??
                scrollFlag = false;
                // 
                if (schoolListView.getLastVisiblePosition() == (schoolListView.getCount() - 1)) {
                    // toTopBtn.setVisibility(View.VISIBLE);
                }
                // 
                if (schoolListView.getFirstVisiblePosition() == 0) {
                    // toTopBtn.setVisibility(View.GONE);
                }

                break;
            case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:// 
                scrollFlag = true;

                break;
            case OnScrollListener.SCROLL_STATE_FLING:// ???
                scrollFlag = false;
                break;
            }
        }

        /**
         * firstVisibleItem??ID0
         * visibleItemCount???? totalItemCount
         */
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            lastId = firstVisibleItem;
        }

        @SuppressLint("NewApi")
        @Override
        public void downPull() {
            if (lastId == 0) {
                LogUtil.print("scrolling---2222>" + schoolListView.getPivotX());
                searchSchool.setVisibility(View.VISIBLE);
                schoolListView.scrollListBy(0);
                LogUtil.print("scrolling---4444>" + schoolListView.getPivotX());
            }

        }
    });
    // schoolListView.setPullRefreshEnable(false);
    // schoolListView.setPullLoadEnable(false);

    selectSchool = (SchoolVO) getIntent().getSerializableExtra("school");

    // if (app.userVO != null
    // && app.userVO.getApplystate().equals(
    // EnrollResult.SUBJECT_NONE.getValue())) {
    // showTitlebarText(BaseActivity.SHOW_RIGHT_TEXT);
    // setText(0, R.string.finish);
    // } else {
    showTitlebarText(BaseActivity.SHOW_RIGHT_TEXT);
    if (currCity != null) {
        currCity = currCity.replace("", "");
        setRightText(currCity);

    }
    // }

    View headerView = View.inflate(mContext, R.layout.enroll_school_header, null);

    schoolListView.addHeaderView(headerView);

    // ?
    llSearch = (LinearLayout) headerView.findViewById(R.id.enroll_school_select_ll);

    adLayout = (RelativeLayout) headerView.findViewById(R.id.enroll_school_top_headpic_im);
    topViewPager = (InfiniteViewPager) headerView.findViewById(R.id.enroll_school_top_viewpager);
    dotLayout = (LinearLayout) headerView.findViewById(R.id.enroll_school_top_dotlayout);
    defaultImage = (ImageView) headerView.findViewById(R.id.enroll_school_top_defaultimage);
    searchSchool = (EditText) headerView.findViewById(R.id.enroll_school_search_et);

    classSelect = (TextView) findViewById(R.id.enroll_school_class_select_tv);
    distanceSelect = (TextView) findViewById(R.id.enroll_school_distance_select_tv);
    commentSelect = (TextView) findViewById(R.id.enroll_school_comment_select_tv);
    priceSelect = (TextView) findViewById(R.id.enroll_school_price_select_tv);
    arrow1 = (ImageView) findViewById(R.id.enroll_school_arrow1_iv);
    arrow2 = (ImageView) findViewById(R.id.enroll_school_arrow2_iv);
    arrow3 = (ImageView) findViewById(R.id.enroll_school_arrow3_iv);
    arrow4 = (ImageView) findViewById(R.id.enroll_school_arrow4_iv);

    searchSchool.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    RelativeLayout.LayoutParams headParams = (RelativeLayout.LayoutParams) adLayout.getLayoutParams();
    headParams.width = screenWidth;
    int height = (int) ((screenWidth - 16 * screenDensity) / 3 + (screenWidth - 12 * screenDensity) * 2 / 3
            + statusbarHeight);
    height += (63 * screenDensity);

    headParams.height = screenHeight - height;
    viewPagerHeight = headParams.height;
    setViewPager();

}

From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java

private void setupSearchView() {
      SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
      mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
      // hint, inputType & ime options seem to be ignored from XML! Set in code
      mSearchView.setQueryHint(getString(R.string.search_hint));
      mSearchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
      mSearchView.setImeOptions(mSearchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
              | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
      mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
          @Override/*from w  ww .  j a  va  2  s  .co  m*/
          public boolean onQueryTextSubmit(String query) {
              searchFor(query);
              return true;
          }

          @Override
          public boolean onQueryTextChange(String query) {
              if (TextUtils.isEmpty(query)) {
                  clearResults();
              }
              return true;
          }
      });
      mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {

          }
      });
  }