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.onebusaway.android.report.ui.InfrastructureIssueActivity.java

/**
 * Initialize UI components/*from ww w.  j  a va  2 s.  co m*/
 */
private void setupViews() {
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mServicesSpinnerFrameLayout = (FrameLayout) findViewById(R.id.ri_spinnerView);

    mAddressEditText = (EditText) findViewById(R.id.ri_address_editText);
    mAddressEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                searchAddress();
                return true;
            }
            return false;
        }
    });

    CustomScrollView mainScrollView = (CustomScrollView) findViewById(R.id.ri_scrollView);
    mainScrollView.addInterceptScrollView(findViewById(R.id.ri_frame_map_view));

    mServicesSpinner = (Spinner) findViewById(R.id.ri_spinnerServices);
    mServicesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {

            if (mShowCategories) {
                mShowCategories = false;
                return;
            }

            SpinnerItem spinnerItem = (SpinnerItem) mServicesSpinner.getSelectedItem();
            if (!spinnerItem.isHint() && !spinnerItem.isSection()) {

                Service service = ((ServiceSpinnerItem) spinnerItem).getService();
                onSpinnerItemSelected(service);
            } else if (spinnerItem.isHint()) {
                clearReportingFragments(false);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
        }
    });

    mBusStopHeader = (RelativeLayout) findViewById(R.id.bus_stop_header);
}

From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java

public ActionBarMenuItem setIsSearchField(boolean value) {
    if (parentMenu == null) {
        return this;
    }//from w  w  w .j  av  a 2  s. c  o  m
    if (value && searchContainer == null) {
        searchContainer = new FrameLayout(getContext());
        parentMenu.addView(searchContainer, 0);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) searchContainer.getLayoutParams();
        layoutParams.weight = 1;
        layoutParams.width = 0;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.leftMargin = AndroidUtilities.dp(6);
        searchContainer.setLayoutParams(layoutParams);
        searchContainer.setVisibility(GONE);

        searchField = new EditText(getContext());
        searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        searchField.setHintTextColor(0x88ffffff);
        searchField.setTextColor(0xffffffff);
        searchField.setSingleLine(true);
        searchField.setBackgroundResource(0);
        searchField.setPadding(0, 0, 0, 0);
        int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        searchField.setInputType(inputType);
        searchField.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {

            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
        searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (/*actionId == EditorInfo.IME_ACTION_SEARCH || */event != null
                        && (event.getAction() == KeyEvent.ACTION_UP
                                && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH
                                || event.getAction() == KeyEvent.ACTION_DOWN
                                        && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    AndroidUtilities.hideKeyboard(searchField);
                    if (listener != null) {
                        listener.onSearchPressed(searchField);
                    }
                }
                return false;
            }
        });
        searchField.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) {
                if (listener != null) {
                    listener.onTextChanged(searchField);
                }
                if (clearButton != null) {
                    clearButton.setAlpha(s == null || s.length() == 0 ? 0.6f : 1.0f);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        try {
            Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
            mCursorDrawableRes.setAccessible(true);
            mCursorDrawableRes.set(searchField, R.drawable.search_carret);
        } catch (Exception e) {
            //nothing to do
        }
        searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
        searchField.setTextIsSelectable(false);
        searchContainer.addView(searchField);
        FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) searchField.getLayoutParams();
        layoutParams2.width = LayoutHelper.MATCH_PARENT;
        layoutParams2.gravity = Gravity.CENTER_VERTICAL;
        layoutParams2.height = AndroidUtilities.dp(36);
        layoutParams2.rightMargin = AndroidUtilities.dp(48);
        searchField.setLayoutParams(layoutParams2);

        clearButton = new ImageView(getContext());
        clearButton.setImageResource(R.drawable.ic_close_white);
        clearButton.setScaleType(ImageView.ScaleType.CENTER);
        clearButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                searchField.setText("");
                searchField.requestFocus();
                AndroidUtilities.showKeyboard(searchField);
            }
        });
        searchContainer.addView(clearButton);
        layoutParams2 = (FrameLayout.LayoutParams) clearButton.getLayoutParams();
        layoutParams2.width = AndroidUtilities.dp(48);
        layoutParams2.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
        layoutParams2.height = LayoutHelper.MATCH_PARENT;
        clearButton.setLayoutParams(layoutParams2);
    }
    isSearchField = value;
    return this;
}

From source file:io.plaidapp.ui.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  va 2  s  .c  om
        public boolean onQueryTextSubmit(String query) {
            searchFor(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus && confirmSaveContainer.getVisibility() == View.VISIBLE) {
                hideSaveConfimation();
            }
        }
    });
}

From source file:com.hannesdorfmann.search.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);
  }//from  ww  w . java  2 s. com

From source file:babbq.com.searchplace.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/*from ww  w .  jav a2 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;
        }
    });
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus && confirmSaveContainer.getVisibility() == View.VISIBLE) {
                hideSaveConfimation();
            }
        }
    });
}

From source file:com.liuwei1995.red.fragment.presenter.EyeFragmentPresenter.java

/**
 * :?//from   w w  w .ja va 2  s .c o  m
 */
private void watchSearch() {
    if (type == H_TYPE_ONE)
        actv_license_plate_number.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    // ??
                    ((InputMethodManager) actv_license_plate_number.getContext()
                            .getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                                    ((Activity) mContext).getCurrentFocus().getWindowToken(),
                                    InputMethodManager.HIDE_NOT_ALWAYS);
                    // ???...
                    search();
                    return true;
                }
                return false;
            }
        });
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * SearchView initialization. It's a little complex because it's not using SearchManager but is implementing on its
 * own./*  ww  w  . jav a  2s .c om*/
 */
@SuppressLint("NewApi")
private void initSearchView(final Menu menu) {

    // Prevents some mysterious NullPointer on app fast-switching
    if (mainActivity == null)
        return;

    // Save item as class attribute to make it collapse on drawer opening
    searchMenuItem = menu.findItem(R.id.menu_search);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) mainActivity.getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(mainActivity.getComponentName()));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

    // Expands the widget hiding other actionbar icons
    searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> setActionItemsVisibility(menu, hasFocus));

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {

        boolean searchPerformed = false;

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Reinitialize notes list to all notes when search is collapsed
            searchQuery = null;
            if (searchLayout.getVisibility() == View.VISIBLE) {
                toggleSearchLabel(false);
            }
            mainActivity.getIntent().setAction(Intent.ACTION_MAIN);
            initNotesList(mainActivity.getIntent());
            mainActivity.supportInvalidateOptionsMenu();
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {

            searchView.setOnQueryTextListener(new OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String arg0) {

                    return prefs.getBoolean("settings_instant_search", false);
                }

                @Override
                public boolean onQueryTextChange(String pattern) {

                    if (prefs.getBoolean("settings_instant_search", false) && searchLayout != null
                            && searchPerformed && mFragment.isAdded()) {
                        searchTags = null;
                        searchQuery = pattern;
                        NoteLoaderTask.getInstance().execute("getNotesByPattern", pattern);
                        return true;
                    } else {
                        searchPerformed = true;
                        return false;
                    }
                }
            });
            return true;
        }
    });
}

From source file:im.vector.fragments.VectorRoomDetailsMembersFragment.java

/**
 * Finalize the fragment initialization.
 *//*w  ww .j av a 2 s .  c  o  m*/
private void finalizeInit() {
    MXMediasCache mxMediasCache = mSession.getMediasCache();

    mAddMembersFloatingActionButton = mViewHierarchy.findViewById(R.id.add_participants_create_view);

    mAddMembersFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // pop to the home activity
            Intent intent = new Intent(getActivity(), VectorRoomInviteMembersActivity.class);
            intent.putExtra(VectorRoomInviteMembersActivity.EXTRA_MATRIX_ID, mSession.getMyUserId());
            intent.putExtra(VectorRoomInviteMembersActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
            getActivity().startActivityForResult(intent, INVITE_USER_REQUEST_CODE);
        }
    });

    // search room members management
    mPatternToSearchEditText = (EditText) mViewHierarchy.findViewById(R.id.search_value_edit_text);
    mClearSearchImageView = (ImageView) mViewHierarchy.findViewById(R.id.clear_search_icon_image_view);
    mSearchNoResultTextView = (TextView) mViewHierarchy.findViewById(R.id.search_no_results_text_view);

    // add IME search action handler
    mPatternToSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (actionId == EditorInfo.IME_ACTION_GO)
                    || (actionId == EditorInfo.IME_ACTION_DONE)) {
                String previousPattern = mPatternValue;
                mPatternValue = mPatternToSearchEditText.getText().toString();

                if (TextUtils.isEmpty(mPatternValue.trim())) {
                    // Prevent empty patterns to be launched and restore previous valid pattern to properly manage inter tab switch
                    mPatternValue = previousPattern;
                } else {
                    refreshRoomMembersList(mPatternValue, REFRESH_NOT_FORCED);
                }
                return true;
            }
            return false;
        }
    });

    mClearSearchImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // clear search pattern to restore no filtered room members list
            mPatternToSearchEditText.setText("");
            mPatternValue = null;
            refreshRoomMembersList(mPatternValue, REFRESH_NOT_FORCED);
            forceListInExpandingState();
        }
    });

    mProgressView = mViewHierarchy.findViewById(R.id.add_participants_progress_view);
    mParticipantsListView = (ExpandableListView) mViewHierarchy
            .findViewById(R.id.room_details_members_exp_list_view);
    mAdapter = new VectorRoomDetailsMembersAdapter(getActivity(), R.layout.adapter_item_vector_add_participants,
            R.layout.adapter_item_vector_recent_header, mSession, mRoom.getRoomId(), mxMediasCache);
    mParticipantsListView.setAdapter(mAdapter);
    // the group indicator is managed in the adapter (group view creation)
    mParticipantsListView.setGroupIndicator(null);

    mParticipantsListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            refreshMemberPresences();
        }
    });

    // set all the listener handlers called from the adapter
    mAdapter.setOnParticipantsListener(new VectorRoomDetailsMembersAdapter.OnParticipantsListener() {
        @Override
        public void onClick(final ParticipantAdapterItem participantItem) {
            Intent memberDetailsIntent = new Intent(getActivity(), VectorMemberDetailsActivity.class);
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MEMBER_ID, participantItem.mUserId);
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MATRIX_ID,
                    mSession.getCredentials().userId);
            getActivity().startActivityForResult(memberDetailsIntent, GET_MENTION_REQUEST_CODE);
        }

        @Override
        public void onSelectUserId(String userId) {
            ArrayList<String> userIds = mAdapter.getSelectedUserIds();

            if (0 != userIds.size()) {
                setActivityTitle(userIds.size() + " "
                        + getActivity().getResources().getString(R.string.room_details_selected));
            } else {
                resetActivityTitle();
            }
        }

        @Override
        public void onRemoveClick(final ParticipantAdapterItem participantItem) {
            String text = getActivity().getString(R.string.room_participants_remove_prompt_msg,
                    participantItem.mDisplayName);

            // The user is trying to leave with unsaved changes. Warn about that
            new AlertDialog.Builder(VectorApp.getCurrentActivity())
                    .setTitle(R.string.room_participants_remove_prompt_title).setMessage(text)
                    .setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();

                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    ArrayList<String> userIds = new ArrayList<>();
                                    userIds.add(participantItem.mUserId);

                                    kickUsers(userIds, 0);
                                }
                            });
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }

        @Override
        public void onLeaveClick() {
            // The user is trying to leave with unsaved changes. Warn about that
            new AlertDialog.Builder(VectorApp.getCurrentActivity())
                    .setTitle(R.string.room_participants_leave_prompt_title)
                    .setMessage(getActivity().getString(R.string.room_participants_leave_prompt_msg))
                    .setPositiveButton(R.string.leave, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();

                            mProgressView.setVisibility(View.VISIBLE);

                            mRoom.leave(new ApiCallback<Void>() {
                                @Override
                                public void onSuccess(Void info) {
                                    if (null != getActivity()) {
                                        getActivity().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                getActivity().finish();
                                            }
                                        });
                                    }
                                }

                                private void onError(final String errorMessage) {
                                    if (null != getActivity()) {
                                        getActivity().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                mProgressView.setVisibility(View.GONE);
                                                Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT)
                                                        .show();
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onNetworkError(Exception e) {
                                    onError(e.getLocalizedMessage());
                                }

                                @Override
                                public void onMatrixError(MatrixError e) {
                                    onError(e.getLocalizedMessage());
                                }

                                @Override
                                public void onUnexpectedError(Exception e) {
                                    onError(e.getLocalizedMessage());
                                }
                            });

                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }

        @Override
        public void onGroupCollapsedNotif(int aGroupPosition) {
            if (null != mIsListViewGroupExpandedMap) {
                mIsListViewGroupExpandedMap.put(aGroupPosition, CommonActivityUtils.GROUP_IS_COLLAPSED);
            }
        }

        @Override
        public void onGroupExpandedNotif(int aGroupPosition) {
            if (null != mIsListViewGroupExpandedMap) {
                mIsListViewGroupExpandedMap.put(aGroupPosition, CommonActivityUtils.GROUP_IS_EXPANDED);
            }
        }
    });
}

From source file:im.neon.fragments.VectorRoomDetailsMembersFragment.java

/**
 * Finalize the fragment initialization.
 *///from  www  .  j  a va 2  s .c  om
private void finalizeInit() {
    MXMediasCache mxMediasCache = mSession.getMediasCache();

    mAddMembersFloatingActionButton = mViewHierarchy.findViewById(R.id.add_participants_create_view);

    mAddMembersFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // pop to the home activity
            Intent intent = new Intent(getActivity(), VectorRoomInviteMembersActivity.class);
            intent.putExtra(VectorRoomInviteMembersActivity.EXTRA_MATRIX_ID, mSession.getMyUserId());
            intent.putExtra(VectorRoomInviteMembersActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
            intent.putExtra(VectorRoomInviteMembersActivity.EXTRA_ADD_CONFIRMATION_DIALOG, true);
            getActivity().startActivityForResult(intent, INVITE_USER_REQUEST_CODE);
        }
    });

    // search room members management
    mPatternToSearchEditText = (EditText) mViewHierarchy.findViewById(R.id.search_value_edit_text);
    mClearSearchImageView = (ImageView) mViewHierarchy.findViewById(R.id.clear_search_icon_image_view);
    mSearchNoResultTextView = (TextView) mViewHierarchy.findViewById(R.id.search_no_results_text_view);

    // add IME search action handler
    mPatternToSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (actionId == EditorInfo.IME_ACTION_GO)
                    || (actionId == EditorInfo.IME_ACTION_DONE)) {
                String previousPattern = mPatternValue;
                mPatternValue = mPatternToSearchEditText.getText().toString();

                if (TextUtils.isEmpty(mPatternValue.trim())) {
                    // Prevent empty patterns to be launched and restore previous valid pattern to properly manage inter tab switch
                    mPatternValue = previousPattern;
                } else {
                    refreshRoomMembersList(mPatternValue, REFRESH_NOT_FORCED);
                }
                return true;
            }
            return false;
        }
    });

    mClearSearchImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // clear search pattern to restore no filtered room members list
            mPatternToSearchEditText.setText("");
            mPatternValue = null;
            refreshRoomMembersList(mPatternValue, REFRESH_NOT_FORCED);
            forceListInExpandingState();
        }
    });

    mProgressView = mViewHierarchy.findViewById(R.id.add_participants_progress_view);
    mParticipantsListView = (ExpandableListView) mViewHierarchy
            .findViewById(R.id.room_details_members_exp_list_view);
    mAdapter = new VectorRoomDetailsMembersAdapter(getActivity(), R.layout.adapter_item_vector_add_participants,
            R.layout.adapter_item_vector_recent_header, mSession, mRoom.getRoomId(), mxMediasCache);
    mParticipantsListView.setAdapter(mAdapter);
    // the group indicator is managed in the adapter (group view creation)
    mParticipantsListView.setGroupIndicator(null);

    mParticipantsListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            refreshMemberPresences();
        }
    });

    // set all the listener handlers called from the adapter
    mAdapter.setOnParticipantsListener(new VectorRoomDetailsMembersAdapter.OnParticipantsListener() {
        @Override
        public void onClick(final ParticipantAdapterItem participantItem) {
            Intent memberDetailsIntent = new Intent(getActivity(), VectorMemberDetailsActivity.class);
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MEMBER_ID, participantItem.mUserId);
            memberDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MATRIX_ID,
                    mSession.getCredentials().userId);
            getActivity().startActivityForResult(memberDetailsIntent, GET_MENTION_REQUEST_CODE);
        }

        @Override
        public void onSelectUserId(String userId) {
            ArrayList<String> userIds = mAdapter.getSelectedUserIds();

            if (0 != userIds.size()) {
                setActivityTitle(userIds.size() + " "
                        + getActivity().getResources().getString(R.string.room_details_selected));
            } else {
                resetActivityTitle();
            }
        }

        @Override
        public void onRemoveClick(final ParticipantAdapterItem participantItem) {
            String text = getActivity().getString(R.string.room_participants_remove_prompt_msg,
                    participantItem.mDisplayName);

            // The user is trying to leave with unsaved changes. Warn about that
            new AlertDialog.Builder(VectorApp.getCurrentActivity()).setTitle(R.string.dialog_title_confirmation)
                    .setMessage(text).setPositiveButton(R.string.remove, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();

                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    kickUsers(Arrays.asList(participantItem.mUserId), 0);
                                }
                            });
                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }

        @Override
        public void onLeaveClick() {
            // The user is trying to leave with unsaved changes. Warn about that
            new AlertDialog.Builder(VectorApp.getCurrentActivity())
                    .setTitle(R.string.room_participants_leave_prompt_title)
                    .setMessage(getActivity().getString(R.string.room_participants_leave_prompt_msg))
                    .setPositiveButton(R.string.leave, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();

                            mProgressView.setVisibility(View.VISIBLE);

                            mRoom.leave(new ApiCallback<Void>() {
                                @Override
                                public void onSuccess(Void info) {
                                    if (null != getActivity()) {
                                        getActivity().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                getActivity().finish();
                                            }
                                        });
                                    }
                                }

                                private void onError(final String errorMessage) {
                                    if (null != getActivity()) {
                                        getActivity().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                mProgressView.setVisibility(View.GONE);
                                                Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT)
                                                        .show();
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onNetworkError(Exception e) {
                                    onError(e.getLocalizedMessage());
                                }

                                @Override
                                public void onMatrixError(MatrixError e) {
                                    onError(e.getLocalizedMessage());
                                }

                                @Override
                                public void onUnexpectedError(Exception e) {
                                    onError(e.getLocalizedMessage());
                                }
                            });

                        }
                    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }

        @Override
        public void onGroupCollapsedNotif(int aGroupPosition) {
            if (null != mIsListViewGroupExpandedMap) {
                mIsListViewGroupExpandedMap.put(aGroupPosition, CommonActivityUtils.GROUP_IS_COLLAPSED);
            }
        }

        @Override
        public void onGroupExpandedNotif(int aGroupPosition) {
            if (null != mIsListViewGroupExpandedMap) {
                mIsListViewGroupExpandedMap.put(aGroupPosition, CommonActivityUtils.GROUP_IS_EXPANDED);
            }
        }
    });
}

From source file:com.push.app.HomeActivity.java

private void handleMenuSearch() {

    ActionBar action = getSupportActionBar(); //get the actionbar

    if (isSearchOpened) { //test if the search is open
        updateViews(false);// w w w  .  ja  va 2s  . c  om

        //hides the keyboard
        imm.hideSoftInputFromWindow(editSearch.getWindowToken(), 0);
        showDefaultActionBar();
    } else { //open the search entry

        updateViews(true);

        if (((ObservableListView) findViewById(R.id.searchList)).getAdapter() != null
                && !((ObservableListView) findViewById(R.id.searchList)).getAdapter().isEmpty()) {
            ((TextView) findViewById(R.id.searchResults)).setText(getString(R.string.recent_results));
        }

        action.setDisplayShowCustomEnabled(true); //enable it to display a
        View view = getLayoutInflater().inflate(R.layout.search_bar, null);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                ActionBar.LayoutParams.MATCH_PARENT);
        action.setCustomView(view, layoutParams);//add the custom view
        action.setDisplayShowTitleEnabled(false); //hide the title
        Toolbar parent = (Toolbar) view.getParent();
        parent.setContentInsetsAbsolute(0, 0);
        editSearch = (EditText) action.getCustomView().findViewById(R.id.edtSearch); //the text editor

        //this is a listener to do a search when the user clicks on search button
        editSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    imm.hideSoftInputFromWindow(editSearch.getWindowToken(), 0);
                    doSearch(editSearch.getText().toString());
                    editSearch.setText("");
                    return true;
                }

                return false;
            }
        });

        editSearch.requestFocus();
        //open the keyboard focused in the edtSearch
        imm.showSoftInput(editSearch, InputMethodManager.SHOW_IMPLICIT);

        //add the close icon
        mSearchAction.setIcon(getResources().getDrawable(R.mipmap.ic_action_cancel));
        isSearchOpened = true;
    }
}