use of androidx.appcompat.widget.SearchView in project collect by opendatakit.
the class AppListActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.list_menu, menu);
final MenuItem sortItem = menu.findItem(R.id.menu_sort);
final MenuItem searchItem = menu.findItem(R.id.menu_filter);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setQueryHint(getResources().getString(R.string.search));
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
filterText = query;
updateAdapter();
searchView.clearFocus();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
filterText = newText;
updateAdapter();
return false;
}
});
MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
sortItem.setVisible(false);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
sortItem.setVisible(true);
return true;
}
});
if (isSearchBoxShown) {
searchItem.expandActionView();
searchView.setQuery(savedFilterText, false);
}
return super.onCreateOptionsMenu(menu);
}
use of androidx.appcompat.widget.SearchView in project Taskbar by farmerbb.
the class StartMenuController method drawStartMenu.
private void drawStartMenu(UIHost host) {
IconCache.getInstance(context).clearCache();
final SharedPreferences pref = U.getSharedPreferences(context);
boolean shouldShowSearchBox = shouldShowSearchBox(pref, hasHardwareKeyboard);
// Initialize layout params
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
// Determine where to show the start menu on screen
String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
int layoutId = getStartMenuLayoutId(taskbarPosition);
params.gravity = getStartMenuGravity(taskbarPosition);
// Initialize views
layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
layout.setAlpha(0);
startMenu = layout.findViewById(R.id.start_menu);
if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
layout.viewHandlesBackButton();
boolean scrollbar = pref.getBoolean(PREF_SCROLLBAR, false);
startMenu.setFastScrollEnabled(scrollbar);
startMenu.setFastScrollAlwaysVisible(scrollbar);
startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
startMenu.setBackgroundColor(0);
if (pref.getBoolean(PREF_VISUAL_FEEDBACK, true))
startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
int columns = context.getResources().getInteger(R.integer.tb_start_menu_columns);
boolean isGrid = pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid");
if (isGrid) {
ViewGroup.LayoutParams startMenuParams = startMenu.getLayoutParams();
startMenuParams.width = (int) (startMenuParams.width * (columns / 3f));
startMenu.setLayoutParams(startMenuParams);
}
searchView = layout.findViewById(R.id.search);
searchViewClicked = false;
int backgroundTint = U.getBackgroundTint(context);
FrameLayout startMenuFrame = layout.findViewById(R.id.start_menu_frame);
FrameLayout searchViewLayout = layout.findViewById(R.id.search_view_layout);
startMenuFrame.setBackgroundColor(backgroundTint);
searchViewLayout.setBackgroundColor(backgroundTint);
if (shouldShowSearchBox) {
if (!hasHardwareKeyboard)
searchView.setIconifiedByDefault(true);
searchView.setOnTouchListener((v, event) -> {
searchViewClicked = true;
return false;
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!hasSubmittedQuery) {
ListAdapter adapter = startMenu.getAdapter();
if (adapter != null) {
hasSubmittedQuery = true;
if (adapter.getCount() > 0) {
View view = adapter.getView(0, null, startMenu);
LinearLayout layout = view.findViewById(R.id.entry);
layout.performClick();
} else {
if (U.shouldCollapse(context, true)) {
U.sendBroadcast(context, ACTION_HIDE_TASKBAR);
} else {
hideStartMenu(true);
}
Intent intent = generateQueryWebSearchIntent(query);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
} else {
intent = generateQueryGoogleIntent(query);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ignored) {
}
}
}
}
}
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
searchView.setIconified(false);
View closeButton = searchView.findViewById(R.id.search_close_btn);
if (closeButton != null)
closeButton.setVisibility(View.GONE);
refreshApps(newText, false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
U.newHandler().postDelayed(() -> {
EditText editText = searchView.findViewById(R.id.search_src_text);
if (editText != null) {
editText.requestFocus();
editText.setSelection(editText.getText().length());
}
}, 50);
}
return true;
}
});
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
LinearLayout powerButton = layout.findViewById(R.id.power_button);
powerButton.setOnClickListener(view -> {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
});
powerButton.setOnGenericMotionListener((view, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
}
return false;
});
searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));
startMenu.setOnItemClickListener((viewParent, view, position, id) -> {
hideStartMenu(true);
AppEntry entry = (AppEntry) viewParent.getAdapter().getItem(position);
U.launchApp(context, entry, null, false, false, view);
});
View childLayout = layout.findViewById(R.id.search_view_child_layout);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
childLayout.setBackgroundColor(0);
if (isGrid) {
ViewGroup.LayoutParams childLayoutParams = childLayout.getLayoutParams();
childLayoutParams.width = (int) (childLayoutParams.width * (columns / 3f));
childLayout.setLayoutParams(childLayoutParams);
}
} else
searchViewLayout.setVisibility(View.GONE);
applyMarginFix(host, layout, params);
textView = layout.findViewById(R.id.no_apps_found);
U.registerReceiver(context, toggleReceiver, ACTION_TOGGLE_START_MENU);
U.registerReceiver(context, hideReceiver, ACTION_HIDE_START_MENU);
U.registerReceiver(context, hideReceiverNoReset, ACTION_HIDE_START_MENU_NO_RESET);
U.registerReceiver(context, showSpaceReceiver, ACTION_SHOW_START_MENU_SPACE);
U.registerReceiver(context, hideSpaceReceiver, ACTION_HIDE_START_MENU_SPACE);
U.registerReceiver(context, resetReceiver, ACTION_RESET_START_MENU);
handler = U.newHandler();
refreshApps(true);
host.addView(layout, params);
}
use of androidx.appcompat.widget.SearchView in project IITB-App by wncc.
the class RecyclerViewFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_view_menu, menu);
MenuItem item = menu.findItem(R.id.action_search);
SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext());
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItem.SHOW_AS_ACTION_IF_ROOM);
item.setActionView(sv);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
performSearch(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
searchQuery = null;
updateData();
showLoader = true;
return true;
} else if (newText.length() >= 3) {
performSearch(newText);
return true;
}
return false;
}
});
}
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);
}
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;
});
}
Aggregations