示例#1
0
  protected void refineSuggestion(SuggestionsAdapter<?> adapter, long id) {
    if (DBG) Log.d(TAG, "query refine clicked, pos " + id);
    SuggestionPosition suggestion = getCurrentSuggestions(adapter, id);
    if (suggestion == null) {
      return;
    }
    String query = suggestion.getSuggestionQuery();
    if (TextUtils.isEmpty(query)) {
      return;
    }

    // Log refine click
    getLogger()
        .logSuggestionClick(
            id,
            suggestion.getCursor(),
            getCurrentIncludedCorpora(),
            Logger.SUGGESTION_CLICK_TYPE_REFINE);

    // Put query + space in query text view
    String queryWithSpace = query + ' ';
    setQuery(queryWithSpace, false);
    updateSuggestions();
    mSearchActivityView.focusQueryTextView();
  }
示例#2
0
 @Override
 protected void onStop() {
   if (DBG) Log.d(TAG, "onStop()");
   if (!mTookAction) {
     // TODO: This gets logged when starting other activities, e.g. by opening the search
     // settings, or clicking a notification in the status bar.
     // TODO we should log both sets of suggestions in 2-pane mode
     getLogger().logExit(getCurrentSuggestions(), getQuery().length());
   }
   // Close all open suggestion cursors. The query will be redone in onResume()
   // if we come back to this activity.
   mSearchActivityView.clearSuggestions();
   getQsbApplication().getShortcutRefresher().reset();
   mSearchActivityView.onStop();
   super.onStop();
 }
示例#3
0
 @Override
 protected void onResume() {
   if (DBG) Log.d(TAG, "onResume()");
   super.onResume();
   updateSuggestionsBuffered();
   mSearchActivityView.onResume();
   if (mTraceStartUp) Debug.stopMethodTracing();
 }
示例#4
0
 @Override
 protected void onDestroy() {
   if (DBG) Log.d(TAG, "onDestroy()");
   getCorpora().unregisterDataSetObserver(mCorporaObserver);
   mSearchActivityView.destroy();
   super.onDestroy();
   if (mDestroyListener != null) {
     mDestroyListener.onDestroyed();
   }
 }
示例#5
0
 protected void launchIntent(Intent intent) {
   if (DBG) Log.d(TAG, "launchIntent " + intent);
   if (intent == null) {
     return;
   }
   try {
     startActivity(intent);
     mSearchActivityView.considerHidingInputMethod();
   } catch (RuntimeException ex) {
     // Since the intents for suggestions specified by suggestion providers,
     // guard against them not being handled, not allowed, etc.
     Log.e(TAG, "Failed to start " + intent.toUri(0), ex);
   }
 }
示例#6
0
  private void setupFromIntent(Intent intent) {
    if (DBG) Log.d(TAG, "setupFromIntent(" + intent.toUri(0) + ")");
    String corpusName = getCorpusNameFromUri(intent.getData());
    String query = intent.getStringExtra(SearchManager.QUERY);
    Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
    boolean selectAll = intent.getBooleanExtra(SearchManager.EXTRA_SELECT_QUERY, false);

    setCorpus(corpusName);
    setQuery(query, selectAll);
    mAppSearchData = appSearchData;

    if (startedIntoCorpusSelectionDialog()) {
      mSearchActivityView.showCorpusSelectionDialog();
    }
  }
示例#7
0
 protected Set<Corpus> getCurrentIncludedCorpora() {
   Suggestions suggestions = mSearchActivityView.getSuggestions();
   return suggestions == null ? null : suggestions.getIncludedCorpora();
 }
示例#8
0
 protected SuggestionCursor getCurrentSuggestions() {
   return mSearchActivityView.getCurrentPromotedSuggestions();
 }
示例#9
0
 protected Corpus getSearchCorpus() {
   return mSearchActivityView.getSearchCorpus();
 }
示例#10
0
 protected void setQuery(String query, boolean selectAll) {
   mSearchActivityView.setQuery(query, selectAll);
 }
示例#11
0
 @Override
 protected void onPause() {
   if (DBG) Log.d(TAG, "onPause()");
   mSearchActivityView.onPause();
   super.onPause();
 }
示例#12
0
 private void setCorpus(String name) {
   mSearchActivityView.setCorpus(name);
 }
示例#13
0
 private String getCorpusName() {
   return mSearchActivityView.getCorpusName();
 }
示例#14
0
 private Corpus getCorpus() {
   return mSearchActivityView.getCorpus();
 }
示例#15
0
 protected void showSuggestions(Suggestions suggestions) {
   mSearchActivityView.setSuggestions(suggestions);
 }
示例#16
0
 protected String getQuery() {
   return mSearchActivityView.getQuery();
 }
示例#17
0
 public void run() {
   mSearchActivityView.showInputMethodForQuery();
 }
示例#18
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    mTraceStartUp = getIntent().hasExtra(INTENT_EXTRA_TRACE_START_UP);
    if (mTraceStartUp) {
      String traceFile = new File(getDir("traces", 0), "qsb-start.trace").getAbsolutePath();
      Log.i(TAG, "Writing start-up trace to " + traceFile);
      Debug.startMethodTracing(traceFile);
    }
    recordStartTime();
    if (DBG) Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceState);

    // This forces the HTTP request to check the users domain to be
    // sent as early as possible.
    QsbApplication.get(this).getSearchBaseUrlHelper();

    mSearchActivityView = setupContentView();

    if (getConfig().showScrollingSuggestions()) {
      mSearchActivityView.setMaxPromotedSuggestions(getConfig().getMaxPromotedSuggestions());
    } else {
      mSearchActivityView.limitSuggestionsToViewHeight();
    }
    if (getConfig().showScrollingResults()) {
      mSearchActivityView.setMaxPromotedResults(getConfig().getMaxPromotedResults());
    } else {
      mSearchActivityView.limitResultsToViewHeight();
    }

    mSearchActivityView.setSearchClickListener(
        new SearchActivityView.SearchClickListener() {
          public boolean onSearchClicked(int method) {
            return SearchActivity.this.onSearchClicked(method);
          }
        });

    mSearchActivityView.setQueryListener(
        new SearchActivityView.QueryListener() {
          public void onQueryChanged() {
            updateSuggestionsBuffered();
          }
        });

    mSearchActivityView.setSuggestionClickListener(new ClickHandler());

    mSearchActivityView.setVoiceSearchButtonClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            onVoiceSearchClicked();
          }
        });

    View.OnClickListener finishOnClick =
        new View.OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        };
    mSearchActivityView.setExitClickListener(finishOnClick);

    // First get setup from intent
    Intent intent = getIntent();
    setupFromIntent(intent);
    // Then restore any saved instance state
    restoreInstanceState(savedInstanceState);

    // Do this at the end, to avoid updating the list view when setSource()
    // is called.
    mSearchActivityView.start();

    mCorporaObserver = new CorporaObserver();
    getCorpora().registerDataSetObserver(mCorporaObserver);
    recordOnCreateDone();
  }