Java Code Examples for android.view.MenuItem#expandActionView()

The following examples show how to use android.view.MenuItem#expandActionView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Toolbar.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    final SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    final Menu menu = mMenuView != null ? mMenuView.peekMenu() : null;
    if (ss.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && menu != null) {
        final MenuItem item = menu.findItem(ss.expandedMenuItemId);
        if (item != null) {
            item.expandActionView();
        }
    }

    if (ss.isOverflowOpen) {
        postShowOverflowMenu();
    }
}
 
Example 2
Source File: UserSearchActivity.java    From GithubUsersSearchApp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_user_search, menu);
    final MenuItem searchActionMenuItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) searchActionMenuItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!searchView.isIconified()) {
                searchView.setIconified(true);
            }
            userSearchPresenter.search(query);
            toolbar.setTitle(query);
            searchActionMenuItem.collapseActionView();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
    searchActionMenuItem.expandActionView();
    return true;
}
 
Example 3
Source File: FragmentContacts.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_contacts, menu);

    MenuItem menuSearch = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) menuSearch.getActionView();
    searchView.setQueryHint(getString(R.string.title_search));

    if (!TextUtils.isEmpty(searching)) {
        menuSearch.expandActionView();
        searchView.setQuery(searching, true);
    }

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            searching = newText;
            adapter.search(newText);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            searching = query;
            adapter.search(query);
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 4
Source File: NavigationDrawerFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void initNavigationView(View rootView) {
    NavigationView navigationView = rootView.findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this::onOptionsItemSelected);
    MenuItem menuItem = navigationView.getMenu().findItem(R.id.menu_gun);
    NavigationMenuView menuView = (NavigationMenuView) navigationView.getChildAt(0);
    menuView.setVerticalScrollBarEnabled(false);
    View actionView = getLayoutInflater().inflate(R.layout.nav_menu_action_view_gun, null);
    menuItem.setActionView(actionView);
    menuItem.expandActionView();
    mReplyCountView = actionView.findViewById(R.id.reply_count);
    mHeaderView = navigationView.getHeaderView(0).findViewById(R.id.viewFlipper);
    updateHeaderView();
}
 
Example 5
Source File: ActivityMain.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public void updateMenu(Menu menu) {
    // Search
    MenuItem menuSearch = menu.findItem(R.id.menu_search);
    final SearchView searchView = (SearchView) menuSearch.getActionView();
    if (searchView != null) {
        String pkg = getIntent().getStringExtra(EXTRA_SEARCH_PACKAGE);
        if (pkg != null) {
            Log.i(TAG, "Search pkg=" + pkg);
            menuSearch.expandActionView();
            searchView.setQuery(pkg, true);
        }
    }
}
 
Example 6
Source File: TaskEditActivity.java    From Kandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case android.R.id.home:
            onBackPressed();
            return true;
        case R.id.action_save:
            ownerId = spinnerProjectUsers.getSelectedItemPosition();
            if (spinnerProjectUsers.getSelectedItemPosition() != 0) {
                for (Enumeration<Integer> iter = projectUsers.keys(); iter.hasMoreElements();) {
                    Integer key = iter.nextElement();
                    if (projectUsers.get(key).contentEquals((String) spinnerProjectUsers.getSelectedItem())) {
                        ownerId = key;
                        break;
                    }
                }
            }
            if (isNewTask) {
                kanboardAPI.createTask(editTextTitle.getText().toString(), projectid, colorId != null ? colorId : defaultColor, columnId, ownerId, null, dueDate, editTextDescription.getText().toString(), null, null, swimlaneId, null, null, null, null, null, null, null, startDate);

            } else {
                kanboardAPI.updateTask(task.getId(), editTextTitle.getText().toString(), colorId != null ? colorId : defaultColor, ownerId, dueDate, editTextDescription.getText().toString(), null, null, null, null, null, null, null, null, null, startDate);
            }
            ProgressBar prog = new ProgressBar(TaskEditActivity.this);
            prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY);
            item.setActionView(prog);
            item.expandActionView();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 7
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != State.MODE_GRID);
    list.setVisible(mState.derivedMode != State.MODE_LIST);
    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        sort.setVisible(false);
        search.expandActionView();
        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();
        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }
    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);
    search.setVisible(true);
    createDir.setVisible(true);
    return true;
}
 
Example 8
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != State.MODE_GRID);
    list.setVisible(mState.derivedMode != State.MODE_LIST);
    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        sort.setVisible(false);
        search.expandActionView();
        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();
        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }
    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);
    search.setVisible(true);
    createDir.setVisible(true);
    return true;
}
 
Example 9
Source File: ChooseContactActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    final Intent i = getIntent();
    boolean showEnterJid = i != null && i.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
    menu.findItem(R.id.action_scan_qr_code).setVisible(isCameraFeatureAvailable() && showEnterJid);
    MenuItem mMenuSearchView = menu.findItem(R.id.action_search);
    if (startSearching) {
        mMenuSearchView.expandActionView();
    }
    return true;
}
 
Example 10
Source File: ChooseContactActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    final Intent i = getIntent();
    boolean showEnterJid = i != null && i.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
    menu.findItem(R.id.action_scan_qr_code).setVisible(isCameraFeatureAvailable() && showEnterJid);
    MenuItem mMenuSearchView = menu.findItem(R.id.action_search);
    if (startSearching) {
        mMenuSearchView.expandActionView();
    }
    return true;
}
 
Example 11
Source File: MenuItemCompatIcs.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static boolean expandActionView(MenuItem item) {
    return item.expandActionView();
}
 
Example 12
Source File: G.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public static boolean a(MenuItem menuitem)
{
    return menuitem.expandActionView();
}
 
Example 13
Source File: Api14Adapter.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleSearchKey(MenuItem menuItem) {
  menuItem.expandActionView();
  return true;
}
 
Example 14
Source File: MainActivity.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
/**
 * Handles selected item from action bar
 *
 * @param item the selected item from the action bar
 * @return boolean
 */
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    Locale locale = getResources().getConfiguration().locale;

    //noinspection SimplifiableIfStatement
    switch (id) {
        case R.id.action_about:
            DateFormat monthFormat = new SimpleDateFormat("MMMM", locale);
            DateFormat yearFormat = new SimpleDateFormat("yyyy", locale);
            Date date = new Date();

            AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
            alertDialog.setTitle("Teocci");
            alertDialog.setIcon(R.mipmap.ic_launcher);
            alertDialog.setMessage(
                    "Dedicated to the person who gives me a reason to smile even on the dullest of days." + ".\n" +
                    "누리 고마워~ Thanks for been in my life." + "\n\n" +
                    "YiB v" + BuildConfig.VERSION_NAME + "\n\[email protected]\n\n" +
                            monthFormat.format(date) + " " + yearFormat.format(date) + ".\n"
            );
            alertDialog.setButton(
                    AlertDialog.BUTTON_NEUTRAL,
                    "OK",
                    (dialog, which) -> dialog.dismiss()
            );
            alertDialog.show();

            return true;
        case R.id.action_clear_list:
            YouTubeSqlDb.getInstance()
                    .videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED)
                    .deleteAll();
            recentlyPlayedFragment.clearRecentlyPlayedList();
            return true;
        case R.id.action_remove_account:
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
            String chosenAccountName = sp.getString(ACCOUNT_NAME, null);

            if (chosenAccountName != null) {
                sp.edit().remove(ACCOUNT_NAME).apply();
            }
            return true;
        case R.id.action_search:
            item.expandActionView();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 15
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public void updateMenuItems(Menu menu){
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    if(isTelevision()) {
        menu.findItem(R.id.menu_create_dir).setVisible(showActionMenu());
        menu.findItem(R.id.menu_create_file).setVisible(showActionMenu());
    }
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem settings = menu.findItem(R.id.menu_settings);

    // Open drawer means we hide most actions
    if (isRootsDrawerOpen()) {
        search.setVisible(false);
        sort.setVisible(false);
        grid.setVisible(false);
        list.setVisible(false);
        mIgnoreNextCollapse = true;
        search.collapseActionView();
        return;
    }

    sort.setVisible(cwd != null);
    grid.setVisible(!RootInfo.isOtherRoot(getCurrentRoot()) && mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        //sort.setVisible(false);

        search.expandActionView();

        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();

        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
        searchVisible = false;

        // No display options in recent directories
        if (cwd == null) {
            grid.setVisible(false);
            list.setVisible(false);
        }
        if (mState.action == State.ACTION_CREATE) {
            if (null != SaveFragment.get(fm))
                SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());
        }
    } else {
        searchVisible = root != null
                && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
        // TODO: Is this useful?
        if(null != SaveFragment.get(fm))
            SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());

        if(null != MoveFragment.get(fm))
            MoveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isMoveSupported());
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    settings.setVisible(mState.action != ACTION_MANAGE);
}
 
Example 16
Source File: MenuItemCompatIcs.java    From guideshow with MIT License 4 votes vote down vote up
public static boolean expandActionView(MenuItem item) {
    return item.expandActionView();
}
 
Example 17
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public void updateMenuItems(Menu menu){
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    if(isTelevision()) {
        menu.findItem(R.id.menu_create_dir).setVisible(showActionMenu());
        menu.findItem(R.id.menu_create_file).setVisible(showActionMenu());
    }
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem settings = menu.findItem(R.id.menu_settings);

    // Open drawer means we hide most actions
    if (isRootsDrawerOpen()) {
        search.setVisible(false);
        sort.setVisible(false);
        grid.setVisible(false);
        list.setVisible(false);
        mIgnoreNextCollapse = true;
        search.collapseActionView();
        return;
    }

    sort.setVisible(cwd != null);
    grid.setVisible(!RootInfo.isOtherRoot(getCurrentRoot()) && mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        //sort.setVisible(false);

        search.expandActionView();

        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();

        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
        searchVisible = false;

        // No display options in recent directories
        if (cwd == null) {
            grid.setVisible(false);
            list.setVisible(false);
        }
        if (mState.action == State.ACTION_CREATE) {
            if (null != SaveFragment.get(fm))
                SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());
        }
    } else {
        searchVisible = root != null
                && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
        // TODO: Is this useful?
        if(null != SaveFragment.get(fm))
            SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());

        if(null != MoveFragment.get(fm))
            MoveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isMoveSupported());
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    settings.setVisible(mState.action != ACTION_MANAGE);
}
 
Example 18
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public void updateMenuItems(Menu menu){
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    if(isTelevision()) {
        menu.findItem(R.id.menu_create_dir).setVisible(showActionMenu());
        menu.findItem(R.id.menu_create_file).setVisible(showActionMenu());
    }
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem settings = menu.findItem(R.id.menu_settings);

    // Open drawer means we hide most actions
    if (isRootsDrawerOpen()) {
        search.setVisible(false);
        sort.setVisible(false);
        grid.setVisible(false);
        list.setVisible(false);
        mIgnoreNextCollapse = true;
        search.collapseActionView();
        return;
    }

    sort.setVisible(cwd != null);
    grid.setVisible(!RootInfo.isOtherRoot(getCurrentRoot()) && mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        //sort.setVisible(false);

        search.expandActionView();

        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();

        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
        searchVisible = false;

        // No display options in recent directories
        if (cwd == null) {
            grid.setVisible(false);
            list.setVisible(false);
        }
        if (mState.action == State.ACTION_CREATE) {
            if (null != SaveFragment.get(fm))
                SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());
        }
    } else {
        searchVisible = root != null
                && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
        // TODO: Is this useful?
        if(null != SaveFragment.get(fm))
            SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());

        if(null != MoveFragment.get(fm))
            MoveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isMoveSupported());
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    settings.setVisible(mState.action != ACTION_MANAGE);
}
 
Example 19
Source File: OrdersFragment.java    From mobikul-standalone-pos with MIT License 4 votes vote down vote up
@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        final MenuItem barcodeItem = menu.findItem(R.id.menu_item_scan_barcode);
        barcodeItem.setVisible(false);
        final MenuItem searchItem = menu.findItem(R.id.menu_item_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchItem.setVisible(true);
        searchItem.expandActionView();
        searchView.setQueryHint("Search your order...");
        ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.colorAccent));
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchOrders = new ArrayList<>();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText.length() > 0) {
                    newText = "%" + newText + "%";
                    DataBaseController.getInstanse().getSearchOrders(getActivity(), newText, new DataBaseCallBack() {
                        @Override
                        public void onSuccess(Object responseData, String successMsg) {
                            if (!(searchOrders.toString().equalsIgnoreCase(responseData.toString()))) {
                                if (searchOrders.size() > 0) {
                                    searchOrders.clear();
                                }
                                searchOrders.addAll((List<OrderEntity>) responseData);
                                orderAdapter = new OrderAdapter(getActivity(), searchOrders);
                                binding.orderRv.setAdapter(orderAdapter);
//                                orderAdapter.notifyDataSetChanged();
                            }
                        }

                        @Override
                        public void onFailure(int errorCode, String errorMsg) {

                        }
                    });
                    return true;
                } else {
                    orderAdapter = new OrderAdapter(getActivity(), orders);
                    binding.orderRv.setAdapter(orderAdapter);
                }
                return false;
            }
        });

    }
 
Example 20
Source File: HomeFragment.java    From mobikul-standalone-pos with MIT License 4 votes vote down vote up
@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        final MenuItem searchItem = menu.findItem(R.id.menu_item_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchItem.setVisible(true);
        searchItem.expandActionView();
        searchView.setQueryHint("Search your product...");
        ((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.colorAccent));
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchProduct = new ArrayList<>();

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //perform your click operation hereif (mMainBinding.drawerLayout != null &&
                if (((MainActivity) getActivity()).mMainBinding.drawerLayout.isDrawerOpen(GravityCompat.START))
                    ((MainActivity) getActivity()).mMainBinding.drawerLayout.closeDrawer(GravityCompat.START);

            }
        });

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText.length() > 0) {
                    newText = "%" + newText + "%";
                    DataBaseController.getInstanse().getSearchData(getActivity(), newText, new DataBaseCallBack() {
                        @Override
                        public void onSuccess(Object responseData, String successMsg) {
                            if (!(searchProduct.toString().equalsIgnoreCase(responseData.toString()))) {
                                if (searchProduct.size() > 0) {
                                    searchProduct.clear();
                                }
                                searchProduct.addAll((List<Product>) responseData);
                                productAdapter = new HomePageProductAdapter(getActivity(), searchProduct);
                                binding.productRv.setAdapter(productAdapter);
                            }
                        }

                        @Override
                        public void onFailure(int errorCode, String errorMsg) {

                        }
                    });
                    return true;
                } else {
                    productAdapter = new HomePageProductAdapter(getActivity(), products);
                    binding.productRv.setAdapter(productAdapter);
                }
                return false;
            }
        });

        final MenuItem barCodeItem = menu.findItem(R.id.menu_item_scan_barcode);
        barCodeItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
//                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
//                startActivityForResult(intent, 0);
                Intent intent = new Intent(getActivity(), BarcodeCaptureActivity.class);
                getActivity().startActivityForResult(intent, BARCODE_READER_REQUEST_CODE);
                return false;
            }
        });
    }