public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.menu = menu;
    MenuInflater inflater = getMenuInflater();
    if (mode != PRESENT_VIDEOS_MODE && findViewById(R.id.videoitem_detail_container) == null) {
      inflater.inflate(R.menu.videoitem_list, menu);
      MenuItem searchItem = menu.findItem(R.id.action_search);
      SearchView searchView = (SearchView) searchItem.getActionView();
      searchView.setFocusable(false);
      searchView.setOnQueryTextListener(new SearchVideoQueryListener());
      suggestionListAdapter = new SuggestionListAdapter(this);
      searchView.setSuggestionsAdapter(suggestionListAdapter);
      searchView.setOnSuggestionListener(new SearchSuggestionListener(searchView));
      if (!searchQuery.isEmpty()) {
        searchView.setQuery(searchQuery, false);
        searchView.setIconifiedByDefault(false);
      }
    } else if (videoFragment != null) {
      videoFragment.onCreateOptionsMenu(menu, inflater);
    } else {
      inflater.inflate(R.menu.videoitem_two_pannel, menu);
    }

    return true;
  }
示例#2
0
  private void loadHistory(String query) {

    get_list_for_actionbar(query);
    // Cursor
    String[] columns = new String[] {"_id", "text"};
    Object[] temp = new Object[] {0, "default"};

    MatrixCursor cursor = new MatrixCursor(columns);

    for (int i = 0; i < apoList.size(); i++) {

      temp[0] = i;
      temp[1] = apoList.get(i).getPname();

      cursor.addRow(temp);
    }

    // SearchView
    // SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // final SearchView search = (SearchView) menuSearch.getActionView();
    msuggestionAdapter = new SuggestionAdapter(this, cursor, apoList);

    search.setSuggestionsAdapter(msuggestionAdapter);

    search.setOnSuggestionListener(
        new OnSuggestionListener() {

          @Override
          public boolean onSuggestionSelect(int position) {
            Constants.pid = apoList.get(position).getPid();
            Constants.pname = apoList.get(position).getPname();
            Constants.pcost = apoList.get(position).getPcost();

            if (InfoTracker.usersessionid > 0) {

              InfoTracker.resetValuesAtProductLevel();

              InfoTracker.pid = apoList.get(position).getPid();
              InfoTracker.pname = apoList.get(position).getPname();
              InfoTracker.time = System.currentTimeMillis();
            }

            search.clearFocus();
            search.setQuery("", false);
            // menuSearch.collapseActionView();

            Intent intent = new Intent(context, ProductOverView.class);

            context.startActivity(intent);

            return true;
          }

          @Override
          public boolean onSuggestionClick(int position) {

            Constants.pid = apoList.get(position).getPid();
            Constants.pname = apoList.get(position).getPname();
            Constants.pcost = apoList.get(position).getPcost();

            if (InfoTracker.usersessionid > 0) {

              InfoTracker.resetValuesAtProductLevel();

              InfoTracker.pid = apoList.get(position).getPid();
              InfoTracker.pname = apoList.get(position).getPname();
              InfoTracker.time = System.currentTimeMillis();
            }

            search.clearFocus();
            search.setQuery("", false);
            // menuSearch.collapseActionView();

            Intent intent = new Intent(context, ProductOverView.class);

            context.startActivity(intent);

            return true;
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoitem_list);
    StreamingService streamingService = null;

    View bg = findViewById(R.id.mainBG);
    bg.setVisibility(View.VISIBLE);

    try {
      // ------ todo: remove this line when multiservice support is implemented ------
      currentStreamingServiceId = ServiceList.getIdOfService("Youtube");
      streamingService = ServiceList.getService(currentStreamingServiceId);
    } catch (Exception e) {
      e.printStackTrace();
      ErrorActivity.reportError(
          VideoItemListActivity.this,
          e,
          null,
          findViewById(R.id.videoitem_list),
          ErrorActivity.ErrorInfo.make(
              ErrorActivity.SEARCHED,
              ServiceList.getNameOfService(currentStreamingServiceId),
              "",
              R.string.general_error));
    }
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    listFragment =
        (VideoItemListFragment) getSupportFragmentManager().findFragmentById(R.id.videoitem_list);
    listFragment.setStreamingService(streamingService);

    if (savedInstanceState != null && mode != PRESENT_VIDEOS_MODE) {
      searchQuery = savedInstanceState.getString(QUERY);
      currentStreamingServiceId = savedInstanceState.getInt(STREAMING_SERVICE);
      if (!searchQuery.isEmpty()) {
        listFragment.search(searchQuery);
      }
    }

    if (findViewById(R.id.videoitem_detail_container) != null) {
      // The detail container view will be present only in the
      // large-screen layouts (res/values-large and
      // res/values-sw600dp). If this view is present, then the
      // activity should be in two-pane mode.
      mTwoPane = true;

      // In two-pane mode, list items should be given the
      // 'activated' state when touched.

      ((VideoItemListFragment) getSupportFragmentManager().findFragmentById(R.id.videoitem_list))
          .setActivateOnItemClick(true);

      SearchView searchView = (SearchView) findViewById(R.id.searchViewTablet);
      if (mode != PRESENT_VIDEOS_MODE) {
        // Somehow the seticonifiedbydefault property set by the layout xml is not working on
        // the support version on SearchView, so it needs to be set programmatically.
        searchView.setIconifiedByDefault(false);
        searchView.setIconified(false);
        if (!searchQuery.isEmpty()) {
          searchView.setQuery(searchQuery, false);
        }
        searchView.setOnQueryTextListener(new SearchVideoQueryListener());
        suggestionListAdapter = new SuggestionListAdapter(this);
        searchView.setSuggestionsAdapter(suggestionListAdapter);
        searchView.setOnSuggestionListener(new SearchSuggestionListener(searchView));
      } else {
        searchView.setVisibility(View.GONE);
      }
    }

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
  }