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.openintents.safe.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.search_fragment, null);

    frontdoor = new Intent(getActivity(), Safe.class);
    frontdoor.setAction(CryptoIntents.ACTION_AUTOLOCK);
    restartTimerIntent = new Intent(CryptoIntents.ACTION_RESTART_TIMER);

    etSearchCriteria = (EditText) root.findViewById(R.id.search_criteria);
    results = new ArrayList<SearchEntry>();

    Button goButton = (Button) root.findViewById(R.id.go_button);
    goButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            searchCriteria = etSearchCriteria.getText().toString().trim().toLowerCase();
            searchThreadStart();/* w  w  w  .  j  av  a  2  s.c  o  m*/
        }
    });

    etSearchCriteria.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // Sadly with Jelly Bean actionId can equal 0 instead of IME_ACTION_SEARCH,
            // so the hack event==null is used
            if (actionId == EditorInfo.IME_ACTION_SEARCH || event == null) {
                // hide the soft keyboard
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, 0);
                searchCriteria = etSearchCriteria.getText().toString().trim().toLowerCase();
                searchThreadStart();
                return true;
            }
            return false;
        }
    });

    return root;
}

From source file:tv.acfun.video.fragment.SearchFragment.java

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH
            || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        startSearch(v.getText().toString(), 1);
    }/*from   ww w.  jav a  2s .c  om*/
    return false;
}

From source file:org.akvo.rsr.up.ProjectListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //employment can for now only change at login, so assign it for life of activity
    mEmployed = SettingsUtil.getAuthUser(this).getOrgIds().size() > 0;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_project_list);

    projCountLabel = (TextView) findViewById(R.id.projcountlabel);
    inProgress = (LinearLayout) findViewById(R.id.projlistprogress);
    inProgress1 = (ProgressBar) findViewById(R.id.progressBar1);
    inProgress2 = (ProgressBar) findViewById(R.id.progressBar2);
    inProgress3 = (ProgressBar) findViewById(R.id.progressBar3);

    mList = (ListView) findViewById(R.id.list_projects);
    mEmptyText = (TextView) findViewById(R.id.list_empty_text);
    mFirstTimeText = (TextView) findViewById(R.id.first_time_text);
    mUnemployedText = (TextView) findViewById(R.id.unemployed_text);
    mList.setOnItemClickListener(new OnItemClickListener() {

        @Override//ww w. jav a2 s  .  c o m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(view.getContext(), ProjectDetailActivity.class);
            i.putExtra(ConstantUtil.PROJECT_ID_KEY, ((Long) view.getTag(R.id.project_id_tag)).toString());
            startActivity(i);
        }
    });

    searchButton = (Button) findViewById(R.id.btn_projsearch);
    searchButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            //toggle visibility. When invisible, clear search string
            if (searchField.getVisibility() == View.VISIBLE) {
                searchField.setVisibility(View.GONE);
                searchField.setText("");
                // show magnifying glass
                searchButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0);
                getData();
            } else {
                searchField.setVisibility(View.VISIBLE);
                //show X instead of magnifying glass
                searchButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_close_normal, 0, 0, 0);
                searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
                searchField.requestFocus();
                showSoftKeyBoard(searchField);
            }
        }
    });

    searchField = (EditText) findViewById(R.id.txt_projsearch);
    searchField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            hideSoftKeyBoard();
            // update list with new search string
            getData();
            return true;
        }
    });

    //Create db
    ad = new RsrDbAdapter(this);
    Log.d(TAG, "Opening DB during create");
    ad.open();

    //register a listener for completion broadcasts
    IntentFilter f = new IntentFilter(ConstantUtil.PROJECTS_FETCHED_ACTION);
    f.addAction(ConstantUtil.PROJECTS_PROGRESS_ACTION);
    broadRec = new ResponseReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(broadRec, f);

    //in case we came back here during a refresh
    if (GetProjectDataService.isRunning(this)) {
        inProgress.setVisibility(View.VISIBLE);
    }
}

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

private void initData() {
    searchCoach.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchCoach.setOnEditorActionListener(new OnEditorActionListener() {

        @Override/*from   ww  w  . j a  v a2s  . c  om*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // ??
                ((InputMethodManager) searchCoach.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(SearchCoachActivity.this.getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);

                // ?
                LogUtil.print("?");
                coachname = searchCoach.getText().toString().trim();
                searchcoach(true);
                return true;
            }
            return false;
        }

    });
}

From source file:com.mobicage.rogerthat.plugins.friends.ServiceSearchActivity.java

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

    setContentView(R.layout.service_search);

    mSearchCategoryLabels = (LinearLayout) findViewById(R.id.search_category);
    mSearchCategoryViewFlipper = (SafeViewFlipper) findViewById(R.id.search_result_lists);

    mSearchInfoByCategory = new HashMap<String, ServiceSearchActivity.SearchInfo>();
    mSearchInfoByListView = new HashMap<AbsListView, ServiceSearchActivity.SearchInfo>();

    mGestureScanner = new GestureDetector(new ViewFlipperSlider(mOnSwipeLeft, mOnSwipeRight));

    final Context ctx = this;
    final EditText editText = (EditText) findViewById(R.id.search_text);
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override//from w  w w  . j a  v  a  2  s .  c  o m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                if (!TextUtils.isEmptyOrWhitespace(mSearchString)) {
                    UIUtils.hideKeyboard(ServiceSearchActivity.this, v);
                    launchFindServiceCall();
                    return true;
                }
            }
            return false;
        }
    });
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            mSearchString = s.toString();
            clearSearches();
        }
    });

    findViewById(R.id.search_button).setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            if (TextUtils.isEmptyOrWhitespace(mSearchString)) {
                mSearchString = "";
            }
            UIUtils.hideKeyboard(ctx, editText);
            clearSearches();
            launchFindServiceCall();
        }
    });
}

From source file:com.wanderingcan.persistentsearch.PersistentSearchView.java

@SuppressWarnings("deprecation")
private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
    mNavIcon = new ImageButton(context);
    mEndIcon = new ImageButton(context);
    mSearchText = new EditText(context);
    mSearchMenuView = new SearchMenuView(context);
    mDivider = new View(context);
    mDivider.setVisibility(GONE);/* w ww . j  a  v  a 2  s. c  o  m*/

    mPresenter = new SearchMenuPresenter(context, new SearchMenuListener());

    mSearchMenuView.setAdapter(mPresenter.mAdapter);
    mSearchMenuView.addItemDecoration(new DividerItemDecoration(context, attrs));

    int[] attr = { android.R.attr.listDivider };
    TypedArray ta = context.obtainStyledAttributes(attr);
    Drawable divider = ta.getDrawable(0);
    ta.recycle();

    mOpened = false;
    mShowClearDrawable = false;
    mShowMenu = true;

    //Set up CardView
    setUseCompatPadding(true);
    setFocusable(true);
    setFocusableInTouchMode(true);

    //Set up TextView
    if (Build.VERSION.SDK_INT >= 16) {
        mSearchText.setBackground(null);
        mNavIcon.setBackground(null);
        mEndIcon.setBackground(null);
        mDivider.setBackground(divider);
    } else {
        mSearchText.setBackgroundDrawable(null);
        mNavIcon.setBackgroundDrawable(null);
        mEndIcon.setBackgroundDrawable(null);
        mDivider.setBackgroundDrawable(divider);
    }
    mSearchText.setSingleLine();
    mHintVisible = false;
    mSearchText.setOnFocusChangeListener(new SearchFocusListener());
    mSearchText.setOnEditorActionListener(new EditTextEditorAction());
    mSearchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    mSearchText.addTextChangedListener(new EditTextTextWatcher());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersistentSearchView, defStyleAttr, 0);
    Drawable drawable = a.getDrawable(R.styleable.PersistentSearchView_navSrc);
    setNavigationDrawable(drawable);
    mNavIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mNavIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mIconListener != null) {
                mIconListener.OnNavigationIconClick();
            }
        }
    });

    drawable = a.getDrawable(R.styleable.PersistentSearchView_endSrc);
    setEndDrawable(drawable);
    mClearDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_cancel);
    mEndIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mEndIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mShowClearDrawable) {
                //Clears the text
                mSearchText.setText(EMPTY);
            } else {
                if (mIconListener != null) {
                    mIconListener.OnEndIconClick();
                }
            }
        }
    });

    mHint = a.getText(R.styleable.PersistentSearchView_hint);
    mHintAlwaysVisible = a.getBoolean(R.styleable.PersistentSearchView_hintAlwaysActive, false);
    if (mHintAlwaysVisible) {
        mSearchText.setHint(mHint);
    }
    a.recycle();

    Resources res = context.getResources();
    int imageDimen = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_dimen);
    mImageMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_side_margin);
    int imageTopMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_image_top_margin);

    //Sets all of the locations of the views
    CardView.LayoutParams lpNav = generateDefaultLayoutParams();
    lpNav.width = lpNav.height = imageDimen;

    CardView.LayoutParams lpEnd = (LayoutParams) generateLayoutParams(lpNav);

    lpNav.gravity = Gravity.START;
    lpEnd.gravity = Gravity.END;

    if (Build.VERSION.SDK_INT >= 17) {
        mNavIcon.setPaddingRelative(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPaddingRelative(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    } else {
        mNavIcon.setPadding(mImageMargin, imageTopMargin, mImageMargin / 2, imageTopMargin);
        mEndIcon.setPadding(mImageMargin / 2, imageTopMargin, mImageMargin, imageTopMargin);
    }

    CardView.LayoutParams lpText = generateDefaultLayoutParams();
    lpText.gravity = Gravity.TOP;
    lpText.height = lpNav.topMargin + lpNav.height;
    mTextMargin = res.getDimensionPixelSize(R.dimen.persistent_search_view_text_margin);
    if (Build.VERSION.SDK_INT >= 17) {
        lpText.setMarginStart(mTextMargin);
        lpText.setMarginEnd(mTextMargin);
    } else {
        lpText.leftMargin = lpText.rightMargin = mTextMargin;
    }
    lpText = setupSearchTextMargin(lpText);

    CardView.LayoutParams lpMenu = generateDefaultLayoutParams();
    lpMenu.topMargin = lpNav.topMargin + lpNav.height;
    lpMenu.height = RecyclerView.LayoutParams.WRAP_CONTENT;

    CardView.LayoutParams lpDivider = generateDefaultLayoutParams();
    if (divider != null) {
        lpDivider.height = divider.getIntrinsicHeight();
    }
    lpDivider.topMargin = lpNav.topMargin + lpNav.height;

    //Adds the views to the PersistentSearchView
    addView(mNavIcon, lpNav);
    addView(mEndIcon, lpEnd);
    addView(mSearchText, lpText);
    addView(mSearchMenuView, lpMenu);
    addView(mDivider, lpDivider);
}

From source file:de.appetites.android.menuItemSearchAction.MenuItemSearchAction.java

private void createMenuItem(Menu menu, Drawable drawable, final LinearLayout list) {
    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    setLayoutParams(layoutParams);/* w  ww  .j a v  a 2 s.  co m*/

    setHint(R.string.menu_item_search_action_hint);

    searchItem = menu.add(R.string.menu_item_search_action_menu_text).setIcon(drawable);
    searchItem.setActionView(this).setTitle("Search");
    searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // open keyboard
            list.setVisibility(View.VISIBLE);
            MenuItemSearchAction.this.setText("");
            MenuItemSearchAction.this.requestFocus();

            MenuItemSearchAction.this.postDelayed(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) context
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                }
            }, 200);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // close keyboard
            list.setVisibility(View.GONE);
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(MenuItemSearchAction.this.getWindowToken(), 0);

            return true;
        }
    });

    setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // perform Search
                searchPerformListener.performSearch(MenuItemSearchAction.this.getText().toString());

                searchItem.collapseActionView();
                return true;
            }
            return false;
        }
    });
}

From source file:com.popdeem.sdk.uikit.fragment.PDUITagFriendsFragment.java

@Nullable
@Override/*  w  ww  . j  a v  a 2 s .  com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_pd_tag_friends, container, false);

    mTaggedNames = getArguments().getStringArrayList("names");
    mTaggedIds = getArguments().getStringArrayList("ids");

    mProgress = (ProgressBar) view.findViewById(R.id.pd_progress_bar);
    mTaggedFriendsTextView = (TextView) view.findViewById(R.id.pd_tagged_friends_text_view);

    view.findViewById(R.id.pd_tagged_friends_text_view).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mConfirmCallback.taggedFriendsUpdated(mTaggedNames, mTaggedIds);
            getActivity().getSupportFragmentManager().popBackStack(PDUITagFriendsFragment.class.getSimpleName(),
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
    });

    final EditText searchEditText = (EditText) view.findViewById(R.id.pd_tag_friends_search_edit_text);
    searchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mAdapter.getFilter().filter(s);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {
                PDUIUtils.hideKeyboard(getActivity(), searchEditText);
                return true;
            }
            return false;
        }
    });

    mAdapter = new PDUITaggableFriendsListViewAdapter(getActivity(), R.layout.item_pd_taggable_friend, friends);
    mAdapter.setCallback(mFriendsCheckBoxChangedCallback);

    ListView listView = (ListView) view.findViewById(R.id.pd_tag_friends_list_view);
    listView.setAdapter(mAdapter);

    updateTaggedFriendsButton();
    makeTaggableFriendsRequest();

    return view;
}

From source file:com.ran.pics.activity.fragment.ImageClassifiGridFragment.java

private void initView(LayoutInflater inflater) {
    rootView = inflater.inflate(R.layout.fragment_classifi_grid, null);
    etSearch = (EditText) rootView.findViewById(R.id.etSearch);
    gvRefresh = (RecyclerView) rootView.findViewById(R.id.gvRefresh);
    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
    etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override// w w  w .j  av  a 2  s . c o  m
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                if (etSearch.getText().toString().trim().equals("")) {
                    ToastUtil.showShort(rootView, "");
                    return false;
                }
                UILApplication.missKeyBoard(getActivity());
                ImageSearchResultActivity.startImageSearchResultActivity(getActivity(),
                        etSearch.getText().toString().trim());
                return true;
            }
            return false;
        }
    });
}

From source file:com.miz.mizuu.fragments.SearchWebMoviesFragment.java

@Override
public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    mToolbar = (Toolbar) v.findViewById(R.id.toolbar);
    ((MizActivity) getActivity()).setSupportActionBar(mToolbar);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
    v.findViewById(R.id.spinner1).setVisibility(View.GONE);

    mListView = (ListView) v.findViewById(R.id.listView1);
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from  w w w  . j a  va2 s. c om*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            showMovie(arg2);
        }
    });
    mListView.setEmptyView(v.findViewById(R.id.no_results));
    v.findViewById(R.id.no_results).setVisibility(View.GONE);

    // Both the ProgressBar and ListView have been set, so let's hide the ProgressBar
    hideProgressBar();

    mSearchField = (EditText) v.findViewById(R.id.editText1);
    mSearchField.setSelection(mSearchField.length());
    mSearchField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.toString().length() > 0)
                searchForMovies();
            else {
                mSearchTask.cancel(true);
                mResults.clear();
                mAdapter.notifyDataSetChanged();
            }
        }
    });
    mSearchField.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    || actionId == EditorInfo.IME_ACTION_SEARCH)
                searchForMovies();
            return true;
        }
    });
}