Search in sources :

Example 26 with SearchView

use of android.support.v7.widget.SearchView in project Rocket.Chat.Android by RocketChat.

the class SidebarMainFragment method onSetupView.

@SuppressLint("RxLeakedSubscription")
@Override
protected void onSetupView() {
    setupUserActionToggle();
    setupUserStatusButtons();
    setupLogoutButton();
    setupVersionInfo();
    adapter = new RoomListAdapter();
    adapter.setOnItemClickListener(new RoomListAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(Room room) {
            searchView.clearFocus();
            presenter.onRoomSelected(room);
        }

        @Override
        public void onItemClick(SpotlightRoom spotlightRoom) {
            searchView.setQuery(null, false);
            searchView.clearFocus();
            methodCallHelper.joinRoom(spotlightRoom.getId()).onSuccessTask(task -> {
                presenter.onSpotlightRoomSelected(spotlightRoom);
                return null;
            });
        }
    });
    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.room_list_container);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
    recyclerView.setAdapter(adapter);
    searchView = (SearchView) rootView.findViewById(R.id.search);
    RxSearchView.queryTextChanges(searchView).compose(bindToLifecycle()).debounce(300, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).switchMap(it -> {
        if (it.length() == 0) {
            adapter.setMode(RoomListAdapter.MODE_ROOM);
            return Observable.just(Collections.<SpotlightRoom>emptyList());
        }
        adapter.setMode(RoomListAdapter.MODE_SPOTLIGHT_ROOM);
        final String queryString = it.toString();
        methodCallHelper.searchSpotlightRooms(queryString);
        return realmSpotlightRoomRepository.getSuggestionsFor(queryString, SortDirection.DESC, 10).toObservable();
    }).subscribe(this::showSearchSuggestions, Logger::report);
}
Also used : Bundle(android.os.Bundle) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) DialogFragment(android.support.v4.app.DialogFragment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RealmSpotlightRoomRepository(chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository) RocketChatAvatar(chat.rocket.android.widget.RocketChatAvatar) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) DirectMessageRoomListHeader(chat.rocket.android.layouthelper.chatroom.roomlist.DirectMessageRoomListHeader) View(android.view.View) TextUtils(chat.rocket.android.helper.TextUtils) AbsoluteUrlHelper(chat.rocket.android.helper.AbsoluteUrlHelper) User(chat.rocket.core.models.User) RocketChatAbsoluteUrl(chat.rocket.android.fragment.chatroom.RocketChatAbsoluteUrl) RealmServerInfoRepository(chat.rocket.persistence.realm.repositories.RealmServerInfoRepository) RoomListAdapter(chat.rocket.android.layouthelper.chatroom.roomlist.RoomListAdapter) RxSearchView(com.jakewharton.rxbinding2.support.v7.widget.RxSearchView) UserRenderer(chat.rocket.android.renderer.UserRenderer) SessionInteractor(chat.rocket.core.interactors.SessionInteractor) List(java.util.List) TextView(android.widget.TextView) RealmSessionRepository(chat.rocket.persistence.realm.repositories.RealmSessionRepository) Room(chat.rocket.core.models.Room) BuildConfig(chat.rocket.android.BuildConfig) ChannelRoomListHeader(chat.rocket.android.layouthelper.chatroom.roomlist.ChannelRoomListHeader) Nullable(android.support.annotation.Nullable) RxCompoundButton(com.jakewharton.rxbinding2.widget.RxCompoundButton) AbstractFragment(chat.rocket.android.fragment.AbstractFragment) RocketChatCache(chat.rocket.android.RocketChatCache) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) Observable(io.reactivex.Observable) R(chat.rocket.android.R) RealmRoomRepository(chat.rocket.persistence.realm.repositories.RealmRoomRepository) AddDirectMessageDialogFragment(chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment) AddChannelDialogFragment(chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment) FavoriteRoomListHeader(chat.rocket.android.layouthelper.chatroom.roomlist.FavoriteRoomListHeader) CompoundButton(android.widget.CompoundButton) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Logger(chat.rocket.android.helper.Logger) UnreadRoomListHeader(chat.rocket.android.layouthelper.chatroom.roomlist.UnreadRoomListHeader) RoomInteractor(chat.rocket.core.interactors.RoomInteractor) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) SpotlightRoom(chat.rocket.core.models.SpotlightRoom) RealmUserRepository(chat.rocket.persistence.realm.repositories.RealmUserRepository) RoomListHeader(chat.rocket.android.layouthelper.chatroom.roomlist.RoomListHeader) SortDirection(chat.rocket.core.SortDirection) Collections(java.util.Collections) RoomListAdapter(chat.rocket.android.layouthelper.chatroom.roomlist.RoomListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Logger(chat.rocket.android.helper.Logger) Room(chat.rocket.core.models.Room) SpotlightRoom(chat.rocket.core.models.SpotlightRoom) SpotlightRoom(chat.rocket.core.models.SpotlightRoom) SuppressLint(android.annotation.SuppressLint)

Example 27 with SearchView

use of android.support.v7.widget.SearchView in project RSAndroidApp by RailwayStations.

the class MainActivity method onCreateOptionsMenu.

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();
    search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            Log.d(TAG, "onQueryTextSubmit ");
            try {
                cursor = dbAdapter.getBahnhofsListByKeyword(s, false);
                if (cursor == null) {
                    Toast.makeText(MainActivity.this, "No records found!", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this, cursor.getCount() + " records found!", Toast.LENGTH_LONG).show();
                }
                customAdapter.swapCursor(cursor);
            } catch (Exception e) {
                Log.e(TAG, "Unhandled Exception in onQueryTextSubmit", e);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            Log.d(TAG, "onQueryTextChange ");
            try {
                cursor = dbAdapter.getBahnhofsListByKeyword(s, false);
                if (cursor != null) {
                    customAdapter.swapCursor(cursor);
                }
            } catch (Exception e) {
                Log.e(TAG, "Unhandled Exception in onQueryTextSubmit", e);
            }
            return false;
        }
    });
    return true;
}
Also used : SearchView(android.support.v7.widget.SearchView) SearchManager(android.app.SearchManager) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TargetApi(android.annotation.TargetApi)

Example 28 with SearchView

use of android.support.v7.widget.SearchView in project AndroidChromium by JackyAndroid.

the class UsbChooserPreferences method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.website_preferences_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            // Make search case-insensitive.
            query = query.toLowerCase();
            if (query.equals(mSearch))
                return true;
            mSearch = query;
            getInfo();
            return true;
        }
    };
    mSearchView.setOnQueryTextListener(queryTextListener);
    MenuItem help = menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuItem(android.view.MenuItem)

Example 29 with SearchView

use of android.support.v7.widget.SearchView in project AndroidChromium by JackyAndroid.

the class UsbDevicePreferences method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.website_preferences_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            // Make search case-insensitive.
            query = query.toLowerCase();
            if (query.equals(mSearch))
                return true;
            mSearch = query;
            getInfo();
            return true;
        }
    };
    mSearchView.setOnQueryTextListener(queryTextListener);
    MenuItem help = menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuItem(android.view.MenuItem)

Example 30 with SearchView

use of android.support.v7.widget.SearchView in project UltimateAndroid by cymcsg.

the class DemoOfUiActivity method onCreateOptionsMenu.

//   @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu_layout, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            ToastUtil.show(DemoOfUiActivity.this, "test~", Toast.LENGTH_SHORT);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
    searchView.setOnSearchClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // ToastUtil.show(MainActivity.this,"show~", Toast.LENGTH_SHORT);
        }
    });
    //        }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) SearchView(android.support.v7.widget.SearchView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) ShimmerTextView(com.marshalchen.common.uimodule.shimmer.ShimmerTextView) ListView(android.widget.ListView)

Aggregations

SearchView (android.support.v7.widget.SearchView)74 MenuItem (android.view.MenuItem)47 View (android.view.View)24 SearchManager (android.app.SearchManager)13 MenuItemCompat (android.support.v4.view.MenuItemCompat)13 TextView (android.widget.TextView)13 RecyclerView (android.support.v7.widget.RecyclerView)12 MenuInflater (android.view.MenuInflater)11 ImageView (android.widget.ImageView)11 Toolbar (android.support.v7.widget.Toolbar)9 ListView (android.widget.ListView)8 AdapterView (android.widget.AdapterView)7 MaterialSearchView (com.miguelcatalan.materialsearchview.MaterialSearchView)7 Nullable (android.support.annotation.Nullable)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 SuppressLint (android.annotation.SuppressLint)5 ActionBar (android.support.v7.app.ActionBar)5 ArrayList (java.util.ArrayList)5 Button (android.widget.Button)4 List (java.util.List)4