Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mFragmentManager = getSupportFragmentManager();
    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mFilterDrawerFragment =
        (FilterDrawerFragment) getFragmentManager().findFragmentById(R.id.filter_drawer);

    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
    // Set up the filter drawer.
    mFilterDrawerFragment.setUp(
        R.id.filter_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
  }
Пример #2
0
  @Override
  public boolean onCreateOptionsMenu(final Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()
    //                && !mFilterDrawerFragment.isDrawerOpen()
    ) {
      // Only show items in the action bar relevant to this screen
      // if the drawer is not showing. Otherwise, let the drawer
      // decide what to show in the action bar.
      getMenuInflater().inflate(R.menu.main, menu);
      mGlobalMenu = menu;
      // Associate searchable configuration with the SearchView
      SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
      MenuItem searchItem = menu.findItem(R.id.action_search);
      assert searchItem != null;
      final SearchView searchView = (SearchView) searchItem.getActionView();
      assert searchView != null;
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

      searchView.setQueryHint("Search contact");
      searchView.setSubmitButtonEnabled(false);

      searchView.setOnCloseListener(
          new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
              Log.d("SEARCH_VIEW", "setOnCloseListener()::onClose()");
              return false;
            }
          });

      searchView.setOnQueryTextFocusChangeListener(
          new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              Log.d(
                  "SEARCH_VIEW",
                  "setOnQueryTextFocusChangeListener()::onFocusChange():: v="
                      + v.toString()
                      + " hasFocus="
                      + hasFocus);
              if (!hasFocus) {
                //                        menu.findItem(R.id.action_search).collapseActionView();
                //                        searchView.onActionViewCollapsed();
                //                        searchView.setQuery("",false);
              }
            }
          });

      searchView.setOnQueryTextListener(
          new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
              Log.d(
                  "SEARCH_VIEW", "setOnQueryTextListener()::onQueryTextSubmit():: query=" + query);
              return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
              Log.d(
                  "SEARCH_VIEW",
                  "setOnQueryTextListener()::onQueryTextChange():: newText=" + newText);
              if (mFragmentManager.findFragmentById(R.id.container) instanceof ContactsFragment) {
                ((ContactsAdapter)
                        ((ContactsFragment) mFragmentManager.findFragmentById(R.id.container))
                            .getList()
                            .getAdapter())
                    .getFilter()
                    .filter(
                        newText,
                        new Filter.FilterListener() {
                          @Override
                          public void onFilterComplete(int count) {
                            Log.d(
                                "SEARCH_VIEW",
                                "setOnQueryTextListener()::onQueryTextChange()::onFilterComplete():: count="
                                    + count);
                          }
                        });
              }
              return true;
            }
          });

      searchView.setOnSearchClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              Log.d("SEARCH_VIEW", "setOnSearchClickListener()::onClick():: v=" + v.toString());
            }
          });

      searchView.setOnSuggestionListener(
          new SearchView.OnSuggestionListener() {
            @Override
            public boolean onSuggestionSelect(int position) {
              Log.d(
                  "SEARCH_VIEW",
                  "setOnSuggestionListener()::onSuggestionSelect():: position=" + position);
              return true;
            }

            @Override
            public boolean onSuggestionClick(int position) {
              Log.d(
                  "SEARCH_VIEW",
                  "setOnSuggestionListener()::onSuggestionClick():: position=" + position);
              return true;
            }
          });

      restoreActionBar();
      return true;
    }
    //        getActionBar().setDisplayShowCustomEnabled(false);
    return super.onCreateOptionsMenu(menu);
  }