Search in sources :

Example 1 with SearchView

use of androidx.appcompat.widget.SearchView in project materialistic by hidroh.

the class BaseListActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mIsMultiPane) {
        getMenuInflater().inflate(R.menu.menu_item_compact, menu);
    }
    if (isSearchable()) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        MenuItem menuSearch = menu.findItem(R.id.menu_search);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setQuery("", false);
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(androidx.appcompat.widget.SearchView) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) ComponentName(android.content.ComponentName)

Example 2 with SearchView

use of androidx.appcompat.widget.SearchView in project materialistic by hidroh.

the class FavoriteFragment method createSearchView.

private void createSearchView(MenuItem menuSearch) {
    final SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
    searchView.setQueryHint(getString(R.string.hint_search_saved_stories));
    searchView.setSearchableInfo(((SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE)).getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconified(!mSearchViewExpanded);
    searchView.setQuery(mFilter, false);
    searchView.setOnSearchClickListener(v -> {
        mSearchViewExpanded = true;
        v.requestFocus();
    });
    searchView.setOnCloseListener(() -> {
        // trigger a dummy empty search intent, as empty query does not get submitted
        searchView.setQuery(FavoriteActivity.EMPTY_QUERY, true);
        return false;
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView)

Example 3 with SearchView

use of androidx.appcompat.widget.SearchView in project RSAndroidApp by RailwayStations.

the class MainActivity method onCreateOptionsMenu.

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

        @Override
        public boolean onQueryTextSubmit(final String s) {
            Log.d(TAG, "onQueryTextSubmit: " + s);
            searchString = s;
            updateStationList();
            return false;
        }

        @Override
        public boolean onQueryTextChange(final String s) {
            Log.d(TAG, "onQueryTextChange: " + s);
            searchString = s;
            updateStationList();
            return false;
        }
    });
    final UpdatePolicy updatePolicy = baseApplication.getUpdatePolicy();
    menu.findItem(updatePolicy.getId()).setChecked(true);
    return true;
}
Also used : UpdatePolicy(de.bahnhoefe.deutschlands.bahnhofsfotos.model.UpdatePolicy) SearchView(androidx.appcompat.widget.SearchView) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) TargetApi(android.annotation.TargetApi)

Example 4 with SearchView

use of androidx.appcompat.widget.SearchView in project Signal-Android by WhisperSystems.

the class SearchToolbar method initialize.

private void initialize() {
    inflate(getContext(), R.layout.search_toolbar, this);
    setOrientation(VERTICAL);
    Toolbar toolbar = findViewById(R.id.toolbar);
    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow_left_24);
    toolbar.setNavigationIcon(drawable);
    toolbar.setCollapseIcon(drawable);
    toolbar.inflateMenu(R.menu.conversation_list_search);
    this.searchItem = toolbar.getMenu().findItem(R.id.action_filter_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    EditText searchText = searchView.findViewById(R.id.search_src_text);
    searchView.setSubmitButtonEnabled(false);
    if (searchText != null)
        searchText.setHint(R.string.SearchToolbar_search);
    else
        searchView.setQueryHint(getResources().getString(R.string.SearchToolbar_search));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (listener != null)
                listener.onSearchTextChange(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return onQueryTextSubmit(newText);
        }
    });
    searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            hide();
            return true;
        }
    });
    toolbar.setNavigationOnClickListener(v -> hide());
}
Also used : EditText(android.widget.EditText) SearchView(androidx.appcompat.widget.SearchView) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) Toolbar(androidx.appcompat.widget.Toolbar)

Example 5 with SearchView

use of androidx.appcompat.widget.SearchView in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    GroupActiveState groupActiveState = groupViewModel.getGroupActiveState().getValue();
    boolean isActiveGroup = groupActiveState != null && groupActiveState.isActiveGroup();
    boolean isActiveV2Group = groupActiveState != null && groupActiveState.isActiveV2Group();
    boolean isInActiveGroup = groupActiveState != null && !groupActiveState.isActiveGroup();
    if (isInMessageRequest() && recipient != null && !recipient.get().isBlocked()) {
        if (isActiveGroup) {
            inflater.inflate(R.menu.conversation_message_requests_group, menu);
        }
        super.onCreateOptionsMenu(menu, inflater);
    }
    if (isSecureText) {
        if (recipient.get().getExpiresInSeconds() > 0) {
            if (!isInActiveGroup) {
                inflater.inflate(R.menu.conversation_expiring_on, menu);
            }
            titleView.showExpiring(recipient);
        } else {
            if (!isInActiveGroup) {
                inflater.inflate(R.menu.conversation_expiring_off, menu);
            }
            titleView.clearExpiring();
        }
    }
    if (isSingleConversation()) {
        if (isSecureText)
            inflater.inflate(R.menu.conversation_callable_secure, menu);
        else if (!recipient.get().isReleaseNotes())
            inflater.inflate(R.menu.conversation_callable_insecure, menu);
    } else if (isGroupConversation()) {
        if (isActiveV2Group && Build.VERSION.SDK_INT > 19) {
            inflater.inflate(R.menu.conversation_callable_groupv2, menu);
            if (groupCallViewModel != null && Boolean.TRUE.equals(groupCallViewModel.hasActiveGroupCall().getValue())) {
                hideMenuItem(menu, R.id.menu_video_secure);
            }
            showGroupCallingTooltip();
        }
        inflater.inflate(R.menu.conversation_group_options, menu);
        if (!isPushGroupConversation()) {
            inflater.inflate(R.menu.conversation_mms_group_options, menu);
            if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
                menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
            } else {
                menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
            }
        }
        inflater.inflate(R.menu.conversation_active_group_options, menu);
    }
    inflater.inflate(R.menu.conversation, menu);
    if (isSingleConversation() && !isSecureText && !recipient.get().isReleaseNotes()) {
        inflater.inflate(R.menu.conversation_insecure, menu);
    }
    if (recipient != null && recipient.get().isMuted())
        inflater.inflate(R.menu.conversation_muted, menu);
    else
        inflater.inflate(R.menu.conversation_unmuted, menu);
    if (isSingleConversation() && getRecipient().getContactUri() == null && !recipient.get().isReleaseNotes()) {
        inflater.inflate(R.menu.conversation_add_to_contacts, menu);
    }
    if (recipient != null && recipient.get().isSelf()) {
        if (isSecureText) {
            hideMenuItem(menu, R.id.menu_call_secure);
            hideMenuItem(menu, R.id.menu_video_secure);
        } else {
            hideMenuItem(menu, R.id.menu_call_insecure);
        }
        hideMenuItem(menu, R.id.menu_mute_notifications);
    }
    if (recipient != null && recipient.get().isBlocked()) {
        if (isSecureText) {
            hideMenuItem(menu, R.id.menu_call_secure);
            hideMenuItem(menu, R.id.menu_video_secure);
            hideMenuItem(menu, R.id.menu_expiring_messages);
            hideMenuItem(menu, R.id.menu_expiring_messages_off);
        } else {
            hideMenuItem(menu, R.id.menu_call_insecure);
        }
        hideMenuItem(menu, R.id.menu_mute_notifications);
    }
    if (recipient != null && recipient.get().isReleaseNotes()) {
        hideMenuItem(menu, R.id.menu_add_shortcut);
    }
    hideMenuItem(menu, R.id.menu_group_recipients);
    if (isActiveV2Group) {
        hideMenuItem(menu, R.id.menu_mute_notifications);
        hideMenuItem(menu, R.id.menu_conversation_settings);
    } else if (isGroupConversation()) {
        hideMenuItem(menu, R.id.menu_conversation_settings);
    }
    hideMenuItem(menu, R.id.menu_create_bubble);
    viewModel.canShowAsBubble().observe(getViewLifecycleOwner(), canShowAsBubble -> {
        MenuItem item = menu.findItem(R.id.menu_create_bubble);
        if (item != null) {
            item.setVisible(canShowAsBubble && !isInBubble());
        }
    });
    if (threadId == -1L) {
        hideMenuItem(menu, R.id.menu_view_media);
    }
    searchViewItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchViewItem.getActionView();
    SearchView.OnQueryTextListener queryListener = new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchViewModel.onQueryUpdated(query, threadId, true);
            searchNav.showLoading();
            viewModel.setSearchQuery(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            searchViewModel.onQueryUpdated(query, threadId, false);
            searchNav.showLoading();
            viewModel.setSearchQuery(query);
            return true;
        }
    };
    searchViewItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            searchView.setOnQueryTextListener(queryListener);
            searchViewModel.onSearchOpened();
            searchNav.setVisibility(View.VISIBLE);
            searchNav.setData(0, 0);
            inputPanel.setHideForSearch(true);
            for (int i = 0; i < menu.size(); i++) {
                if (!menu.getItem(i).equals(searchViewItem)) {
                    menu.getItem(i).setVisible(false);
                }
            }
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            searchView.setOnQueryTextListener(null);
            isSearchRequested = false;
            searchViewModel.onSearchClosed();
            searchNav.setVisibility(View.GONE);
            inputPanel.setHideForSearch(false);
            viewModel.setSearchQuery(null);
            setBlockedUserState(recipient.get(), isSecureText, isDefaultSms);
            invalidateOptionsMenu();
            return true;
        }
    });
    if (isSearchRequested) {
        if (searchViewItem.expandActionView()) {
            searchViewModel.onSearchOpened();
        }
    }
    super.onCreateOptionsMenu(menu, inflater);
}
Also used : SearchView(androidx.appcompat.widget.SearchView) GroupActiveState(org.thoughtcrime.securesms.conversation.ConversationGroupViewModel.GroupActiveState) MenuItem(android.view.MenuItem) SpannableString(android.text.SpannableString)

Aggregations

SearchView (androidx.appcompat.widget.SearchView)32 MenuItem (android.view.MenuItem)24 View (android.view.View)5 SearchManager (android.app.SearchManager)4 Drawable (android.graphics.drawable.Drawable)4 SpannableString (android.text.SpannableString)4 EditText (android.widget.EditText)4 TargetApi (android.annotation.TargetApi)3 Activity (android.app.Activity)3 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 MenuInflater (android.view.MenuInflater)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 SuppressLint (android.annotation.SuppressLint)2 ComponentName (android.content.ComponentName)2 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 Uri (android.net.Uri)2