Search in sources :

Example 11 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 12 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 13 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)

Example 14 with SearchView

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

the class CameraContactSelectionFragment method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
    requireActivity().getMenuInflater().inflate(R.menu.camera_contacts, menu);
    MenuItem searchViewItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchViewItem.getActionView();
    SearchView.OnQueryTextListener queryListener = new SearchView.OnQueryTextListener() {

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

        @Override
        public boolean onQueryTextChange(String query) {
            contactViewModel.onQueryUpdated(query);
            return true;
        }
    };
    searchViewItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            searchView.setOnQueryTextListener(queryListener);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            searchView.setOnQueryTextListener(null);
            contactViewModel.onSearchClosed();
            return true;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem)

Example 15 with SearchView

use of androidx.appcompat.widget.SearchView in project PocketMaps by junjunguo.

the class DownloadMapActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_maps, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search_filter);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(this);
    searchView.setOnSearchClickListener(createHideMenuListener(menu));
    searchView.setOnCloseListener(createShowMenuListener(menu));
    return true;
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem)

Aggregations

SearchView (androidx.appcompat.widget.SearchView)39 MenuItem (android.view.MenuItem)29 View (android.view.View)7 Bundle (android.os.Bundle)5 SearchManager (android.app.SearchManager)4 Intent (android.content.Intent)4 Drawable (android.graphics.drawable.Drawable)4 SpannableString (android.text.SpannableString)4 MenuInflater (android.view.MenuInflater)4 LinearLayout (android.widget.LinearLayout)4 TextView (android.widget.TextView)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 SuppressLint (android.annotation.SuppressLint)3 TargetApi (android.annotation.TargetApi)3 Activity (android.app.Activity)3 Context (android.content.Context)3 Uri (android.net.Uri)3 Handler (android.os.Handler)3 Menu (android.view.Menu)3 ViewTreeObserver (android.view.ViewTreeObserver)3