use of androidx.appcompat.widget.SearchView in project Signal-Android by signalapp.
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());
}
use of androidx.appcompat.widget.SearchView in project Signal-Android by signalapp.
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);
}
use of androidx.appcompat.widget.SearchView in project android by nextcloud.
the class FileDisplayActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_file_display, menu);
menu.findItem(R.id.action_select_all).setVisible(false);
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
searchMenuItem.setVisible(false);
mSearchText.setOnClickListener(v -> {
showSearchView();
searchView.setIconified(false);
});
ThemeToolbarUtils.themeSearchView(searchView, this);
// populate list of menu items to show/hide when drawer is opened/closed
mDrawerMenuItemstoShowHideList = new ArrayList<>(1);
mDrawerMenuItemstoShowHideList.add(searchMenuItem);
// focus the SearchView
if (!TextUtils.isEmpty(searchQuery)) {
searchView.post(() -> {
searchView.setIconified(false);
searchView.setQuery(searchQuery, true);
searchView.clearFocus();
});
}
final View mSearchEditFrame = searchView.findViewById(androidx.appcompat.R.id.search_edit_frame);
searchView.setOnCloseListener(() -> {
if (TextUtils.isEmpty(searchView.getQuery().toString())) {
searchView.onActionViewCollapsed();
// order matters
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mDrawerToggle.syncState();
OCFileListFragment ocFileListFragment = getListOfFilesFragment();
if (ocFileListFragment != null) {
ocFileListFragment.setSearchFragment(false);
ocFileListFragment.refreshDirectory();
}
} else {
searchView.post(() -> searchView.setQuery("", true));
}
return true;
});
ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int oldVisibility = -1;
@Override
public void onGlobalLayout() {
int currentVisibility = mSearchEditFrame.getVisibility();
if (currentVisibility != oldVisibility) {
if (currentVisibility == View.VISIBLE) {
setDrawerIndicatorEnabled(false);
}
oldVisibility = currentVisibility;
}
}
});
return super.onCreateOptionsMenu(menu);
}
use of androidx.appcompat.widget.SearchView in project android by nextcloud.
the class ExtendedListFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
final MenuItem item = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(item);
closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(this);
ThemeToolbarUtils.themeSearchView(searchView, requireContext());
SearchView.SearchAutoComplete theTextArea = searchView.findViewById(R.id.search_src_text);
theTextArea.setHighlightColor(ThemeColorUtils.primaryAccentColor(getContext()));
final Handler handler = new Handler();
DisplayMetrics displaymetrics = new DisplayMetrics();
Activity activity;
if ((activity = getActivity()) != null) {
activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
searchView.setMaxWidth((int) (width * 0.4));
} else {
if (activity instanceof FolderPickerActivity) {
searchView.setMaxWidth((int) (width * 0.8));
} else {
searchView.setMaxWidth(width);
}
}
}
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> handler.post(() -> {
if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity) && !(getActivity() instanceof UploadFilesActivity)) {
if (getActivity() instanceof FileDisplayActivity) {
Fragment fragment = ((FileDisplayActivity) getActivity()).getLeftFragment();
if (fragment instanceof OCFileListFragment) {
((OCFileListFragment) fragment).setFabVisible(!hasFocus);
}
}
if (TextUtils.isEmpty(searchView.getQuery())) {
closeButton.setVisibility(View.INVISIBLE);
}
}
}));
// On close -> empty field, show keyboard and
closeButton.setOnClickListener(view -> {
searchView.setQuery("", true);
searchView.requestFocus();
searchView.onActionViewExpanded();
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
}
});
final View mSearchEditFrame = searchView.findViewById(androidx.appcompat.R.id.search_edit_frame);
ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int oldVisibility = -1;
@Override
public void onGlobalLayout() {
int currentVisibility = mSearchEditFrame.getVisibility();
if (currentVisibility != oldVisibility) {
if (currentVisibility == View.VISIBLE) {
setEmptyListMessage(SearchType.REGULAR_FILTER);
} else {
if (MainApp.isOnlyOnDevice()) {
setMessageForEmptyList(R.string.file_list_empty_headline, R.string.file_list_empty_on_device, R.drawable.ic_list_empty_folder, true);
} else {
setEmptyListMessage(SearchType.NO_SEARCH);
}
}
oldVisibility = currentVisibility;
}
}
});
LinearLayout searchBar = searchView.findViewById(R.id.search_bar);
searchBar.setLayoutTransition(new LayoutTransition());
}
use of androidx.appcompat.widget.SearchView in project android by nextcloud.
the class ThemeToolbarUtils method themeSearchView.
/**
* Theme search view
*
* @param searchView searchView to be changed
* @param context the app's context
*/
public static void themeSearchView(SearchView searchView, Context context) {
// hacky as no default way is provided
int fontColor = ThemeColorUtils.appBarPrimaryFontColor(context);
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
editText.setTextSize(16);
ThemeTextInputUtils.setEditTextColor(context, editText, fontColor);
editText.setHintTextColor(ThemeColorUtils.appBarSecondaryFontColor(context));
ImageView closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
closeButton.setColorFilter(fontColor);
ImageView searchButton = searchView.findViewById(androidx.appcompat.R.id.search_button);
searchButton.setColorFilter(fontColor);
}
Aggregations