Search in sources :

Example 6 with SearchView

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);
}
Also used : MenuItemCompat(androidx.core.view.MenuItemCompat) SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem)

Example 7 with SearchView

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);
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) PackageManager(android.content.pm.PackageManager) TaskbarPosition(com.farmerbb.taskbar.util.TaskbarPosition) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) IconCache(com.farmerbb.taskbar.util.IconCache) Patterns(android.util.Patterns) TopApps(com.farmerbb.taskbar.util.TopApps) Handler(android.os.Handler) View(android.view.View) TargetApi(android.annotation.TargetApi) InvisibleActivityAlt(com.farmerbb.taskbar.activity.InvisibleActivityAlt) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) SearchView(androidx.appcompat.widget.SearchView) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) LauncherApps(android.content.pm.LauncherApps) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) List(java.util.List) TextView(android.widget.TextView) MenuHelper(com.farmerbb.taskbar.helper.MenuHelper) ListAdapter(android.widget.ListAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) Intent(android.content.Intent) InvisibleActivity(com.farmerbb.taskbar.activity.InvisibleActivity) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) Blacklist(com.farmerbb.taskbar.util.Blacklist) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) StartMenuLayout(com.farmerbb.taskbar.widget.StartMenuLayout) UserHandle(android.os.UserHandle) Build(android.os.Build) Collator(java.text.Collator) UserManager(android.os.UserManager) URLUtil(android.webkit.URLUtil) R(com.farmerbb.taskbar.R) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) StartMenuAdapter(com.farmerbb.taskbar.adapter.StartMenuAdapter) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) EditText(android.widget.EditText) Constants(com.farmerbb.taskbar.util.Constants) EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager) SearchView(androidx.appcompat.widget.SearchView) AppEntry(com.farmerbb.taskbar.util.AppEntry) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) ListAdapter(android.widget.ListAdapter) LinearLayout(android.widget.LinearLayout)

Example 8 with SearchView

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;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem) MainActivity(app.insti.activity.MainActivity)

Example 9 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 10 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)

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