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;
  }
  private void _defineSearchView(Menu menu) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Theme the SearchView's AutoCompleteTextView drop down. For some reason this wasn't working in
    // styles.xml
    SearchView.SearchAutoComplete autoCompleteTextView =
        (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

    if (autoCompleteTextView != null) {
      autoCompleteTextView.setDropDownBackgroundResource(android.R.color.white);
      // set Enable Spelling Suggestions
      autoCompleteTextView.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
      int color = Color.parseColor("#ffffffff");
      Drawable drawable = autoCompleteTextView.getDropDownBackground();
      drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);

      autoCompleteTextView.setDropDownBackgroundDrawable(drawable);
      autoCompleteTextView.setTextColor(
          getResources().getColor(R.color.auto_complete_text_view_text_color));
    }

    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new MenuItemCompat.OnActionExpandListener() {

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            Log.d(TAG, "onMenuItemActionCollapse");
            return true;
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            Log.d(TAG, "onMenuItemActionExpand");
            return true;
          }
        });
    searchView.setOnSuggestionListener(
        new SearchView.OnSuggestionListener() {
          @Override
          public boolean onSuggestionSelect(int position) {
            Log.d(TAG, "onSuggestionSelect:" + position);
            return false;
          }

          @Override
          public boolean onSuggestionClick(int position) {
            Log.d(TAG, "onSuggestionClick:" + position);
            try {
              CursorAdapter c = searchView.getSuggestionsAdapter();
              if (c != null) {
                Cursor cur = c.getCursor();
                cur.moveToPosition(position);

                String cardID = cur.getString(cur.getColumnIndex(BaseColumns._ID));
                Log.d(TAG, "cardID:" + cardID);
                String query =
                    cur.getString(cur.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
                Log.d(TAG, "query:" + query);
                int insertSuggesstionResults = learnApiImplements._insertSuggesstion(cardID);
                Log.d(
                    TAG,
                    "insertSuggesstionResults "
                        + ((insertSuggesstionResults == -1) ? " OK" : " Fails"));
                _displayCard(cardID);

                // call back actionbar
                searchItem.collapseActionView();
              } else {
                Log.d(TAG, "NUll searchView.getSuggestionsAdapter()");
              }
            } catch (Exception e) {
              LazzyBeeShare.showErrorOccurred(context, "_defineSearchView", e);
            }
            return true;
          }
        });
  }
Ejemplo n.º 3
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);
  }