示例#1
0
        public void handleMessage(android.os.Message msg) {
          if (msg.what == 0) {
            mSMenuItem.expandActionView();
            ViewUtils.showKeybord(mSEditText, false);
            clearSearchFocus();
            getSherlockActivity().getSupportActionBar().setIcon(R.drawable.ic_logo);

            mSearchView.setOnSuggestionListener(
                new OnSuggestionListener() {

                  @Override
                  public boolean onSuggestionSelect(int position) {
                    // TODO Auto-generated method stub
                    return false;
                  }

                  @Override
                  public boolean onSuggestionClick(int position) {
                    if (mHistoryAdapter != null) {
                      Cursor s = (Cursor) mHistoryAdapter.getItem(position);
                      if (s.getString(1).equals(HistoryTask.SpecialRow)) {
                        clearHistory();
                      } else {
                        String jjdm = s.getString(2);
                        FundUtils.launchFundDetails(getSherlockActivity(), jjdm, 0, 0);
                        Analytics.onEvent(
                            getActivity(), Analytics.VIEW_FUND_DETAIL, Analytics.KEY_FROM, "历史记录");
                      }
                    }
                    return true;
                  }
                });

            mSMenuItem.setOnActionExpandListener(
                new OnActionExpandListener() {

                  @Override
                  public boolean onMenuItemActionExpand(MenuItem item) {
                    // TODO Auto-generated method stub
                    return false;
                  }

                  @Override
                  public boolean onMenuItemActionCollapse(MenuItem item) {
                    // TODO Auto-generated method stub
                    getActivity().finish();
                    return false;
                  }
                });
          }
        };
示例#2
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getSherlockActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSherlockActivity()
        .getSupportActionBar()
        .setTitle(highlightTitleText(R.string.st_contacts_title));
    getSherlockActivity().getSupportActionBar().setSubtitle(null);

    if (!isLoaded()) {
      return;
    }

    inflater.inflate(R.menu.contacts_menu, menu);

    menu.findItem(R.id.systemContacts).setTitle(highlightMenuText(R.string.st_contacts_menu_book));
    menu.findItem(R.id.addContact)
        .setTitle(highlightMenuText(R.string.st_contacts_menu_add_contact));
    menu.findItem(R.id.allContacts)
        .setTitle(highlightMenuText(R.string.st_contacts_menu_all_contacts));
    menu.findItem(R.id.onlyTContacts).setTitle(highlightMenuText(R.string.st_contacts_menu_only_t));

    MenuItem searchItem = menu.findItem(R.id.searchMenu);

    com.actionbarsherlock.widget.SearchView searchView =
        (com.actionbarsherlock.widget.SearchView) searchItem.getActionView();
    // searchView.setQueryHint(getStringSafe(R.string.st_contacts_filter));
    searchView.setQueryHint("");

    ((ImageView) searchView.findViewById(R.id.abs__search_button))
        .setImageResource(R.drawable.st_bar_ic_search);

    searchView.setOnSuggestionListener(
        new com.actionbarsherlock.widget.SearchView.OnSuggestionListener() {
          @Override
          public boolean onSuggestionSelect(int position) {
            return false;
          }

          @Override
          public boolean onSuggestionClick(int position) {
            return false;
          }
        });

    searchView.setOnQueryTextListener(
        new com.actionbarsherlock.widget.SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            return true;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            doFilter(newText);
            return true;
          }
        });

    searchItem.setOnActionExpandListener(
        new MenuItem.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            doFilter(null);
            return true;
          }
        });

    if (application.getUserSettings().showOnlyTelegramContacts()) {
      menu.findItem(R.id.allContacts).setVisible(true);
      menu.findItem(R.id.onlyTContacts).setVisible(false);
    } else {
      menu.findItem(R.id.allContacts).setVisible(false);
      menu.findItem(R.id.onlyTContacts).setVisible(true);
    }
  }
  /**
   * Adding collapsible search menu item to the menu.
   *
   * @param menu
   * @param isLightTheme - true if use light them for ActionBar, else false
   * @return
   */
  public static MenuItem addSearchMenuItem(
      Menu menu, boolean isLightTheme, final TextWatcher textWatcher) {
    final MenuItem menuItem =
        menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
    menuItem
        .setIcon(
            isLightTheme
                ? R.drawable.ic_action_search_holo_light
                : R.drawable.ic_action_search_holo_dark)
        .setActionView(
            isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark)
        .setShowAsAction(
            MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    final View searchView = menuItem.getActionView();
    final AutoCompleteTextView editText =
        (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
    menuItem.setOnActionExpandListener(
        new OnActionExpandListener() {

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            editText.addTextChangedListener(textWatcher);
            editText.requestFocus();
            showKeyboard(editText);
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            editText.setText(null);
            editText.removeTextChangedListener(textWatcher);
            // editText.clearFocus();
            hideKeyboard(editText);
            return true;
          }
        });

    final View searchPlate = searchView.findViewById(R.id.search_plate);
    editText.setOnFocusChangeListener(
        new OnFocusChangeListener() {

          @Override
          public void onFocusChange(View v, final boolean hasFocus) {
            searchView.post(
                new Runnable() {
                  public void run() {
                    searchPlate
                        .getBackground()
                        .setState(
                            hasFocus
                                ? new int[] {android.R.attr.state_focused}
                                : new int[] {android.R.attr.state_empty});
                    searchView.invalidate();
                  }
                });
          }
        });

    final ImageView closeBtn =
        (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
    closeBtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (!TextUtils.isEmpty(editText.getText())) {
              editText.setText(null);
            } else {
              menuItem.collapseActionView();
            }
          }
        });

    return menuItem;
  }