private void setupSearchView(SearchView view) {
    searchItem.setShowAsActionFlags(
        MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    view.setSubmitButtonEnabled(true);

    view.setOnQueryTextListener(this);
  }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   final Intent nextIntent = getNextIntent();
   if (nextIntent != null) {
     MenuItem restartItem =
         menu.add(R.string.usi_menu_restart)
             .setIcon(R.drawable.usi_ic_repeat_white_36dp)
             .setOnMenuItemClickListener(
                 new MenuItem.OnMenuItemClickListener() {
                   @Override
                   public boolean onMenuItemClick(MenuItem item) {
                     startActivity(Intent.createChooser(nextIntent, null));
                     return true;
                   }
                 });
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
       restartItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
     }
   }
   MenuItem settingsItem =
       menu.add(R.string.usi_menu_settings)
           .setOnMenuItemClickListener(
               new MenuItem.OnMenuItemClickListener() {
                 @Override
                 public boolean onMenuItemClick(MenuItem item) {
                   startActivity(
                       new Intent(
                           Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                           Uri.parse("package:" + getPackageName())));
                   return true;
                 }
               });
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
     settingsItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER);
   }
   return true;
 }
  private void setupSearchView(MenuItem searchItem) {
    mSearchView.setIconifiedByDefault(false);
    searchItem.setShowAsActionFlags(
        MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
      List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();

      SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
      for (SearchableInfo inf : searchables) {
        if (inf.getSuggestAuthority() != null
            && inf.getSuggestAuthority().startsWith("applications")) {
          info = inf;
        }
      }
      mSearchView.setSearchableInfo(info);
    }

    mSearchView.setOnQueryTextListener(this);
  }
 @Override
 public MenuItem setShowAsActionFlags(int actionEnum) {
   mNativeItem.setShowAsActionFlags(actionEnum);
   return this;
 }
Example #5
0
  private void updateMenu() {
    if (menu != null) {
      if (gridView.getAdapter() instanceof SearchAdapter) return;
      menu.clear();
      getMenuInflater().inflate(R.menu.roster, menu);
      menu.findItem(R.id.add).setEnabled(service.isAuthenticated());
      menu.findItem(R.id.notes).setEnabled(service.isAuthenticated());
      menu.findItem(R.id.disco).setEnabled(service.isAuthenticated());
      menu.findItem(R.id.offline)
          .setTitle(
              prefs.getBoolean("hideOffline", false)
                  ? R.string.ShowOfflineContacts
                  : R.string.HideOfflineContacts);

      MenuItem sound = menu.findItem(R.id.notify);
      sound.setShowAsActionFlags(
          prefs.getBoolean("showSound", false)
              ? MenuItem.SHOW_AS_ACTION_ALWAYS
              : MenuItem.SHOW_AS_ACTION_NEVER);
      if (prefs.getBoolean("soundDisabled", false)) {
        sound.setTitle(R.string.EnableSound);
        sound.setIcon(R.drawable.ic_menu_sound_off);

      } else {
        sound.setTitle(R.string.DisableSound);
        sound.setIcon(R.drawable.ic_menu_sound_on);
      }

      MenuItem.OnActionExpandListener listener =
          new MenuItem.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
              gridView.setAdapter(null);
              searchString = null;
              updateList();
              updateMenu();
              return true;
            }

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
              gridView.setAdapter(searchAdapter);
              searchString = "";
              updateList();
              return true;
            }
          };

      SearchView searchView = new SearchView(this);
      searchView.setQueryHint(getString(android.R.string.search_go));
      searchView.setSubmitButtonEnabled(false);
      searchView.setOnQueryTextListener(
          new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextChange(String newText) {
              searchString = newText;
              updateList();
              return true;
            }

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

      MenuItem item = menu.findItem(R.id.search);
      item.setActionView(searchView);
      item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
      item.setOnActionExpandListener(listener);
      super.onCreateOptionsMenu(menu);
    }
  }