Ejemplo n.º 1
0
  public void filter(String searchTerm) {
    AwesomeBarCursorAdapter adapter = getCursorAdapter();
    adapter.filter(searchTerm);

    filterSuggestions(searchTerm);
    if (mSuggestionsOptInPrompt != null) {
      int visibility = TextUtils.isEmpty(searchTerm) ? View.GONE : View.VISIBLE;
      if (mSuggestionsOptInPrompt.getVisibility() != visibility) {
        mSuggestionsOptInPrompt.setVisibility(visibility);
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void destroy() {
    AwesomeBarCursorAdapter adapter = getCursorAdapter();
    unregisterEventListener("SearchEngines:Data");
    if (adapter == null) {
      return;
    }

    Cursor cursor = adapter.getCursor();
    if (cursor != null) cursor.close();

    mHandler.removeMessages(MESSAGE_UPDATE_FAVICONS);
    mHandler.removeMessages(MESSAGE_LOAD_FAVICONS);
    mHandler = null;
  }
Ejemplo n.º 3
0
  protected AwesomeBarCursorAdapter getCursorAdapter() {
    if (mCursorAdapter == null) {
      // Load the list using a custom adapter so we can create the bitmaps
      mCursorAdapter = new AwesomeBarCursorAdapter(mContext);

      mCursorAdapter.setFilterQueryProvider(
          new FilterQueryProvider() {
            @Override
            public Cursor runQuery(CharSequence constraint) {
              long start = SystemClock.uptimeMillis();

              Cursor c = BrowserDB.filter(getContentResolver(), constraint, MAX_RESULTS);
              c.getCount();

              postLoadFavicons();

              long end = SystemClock.uptimeMillis();
              if (!mTelemetrySent && TextUtils.isEmpty(constraint)) {
                int time = (int) (end - start);
                Telemetry.HistogramAdd("FENNEC_AWESOMEBAR_ALLPAGES_EMPTY_TIME", time);
                mTelemetrySent = true;
              }
              return c;
            }
          });
    }
    return mCursorAdapter;
  }
Ejemplo n.º 4
0
  public void destroy() {
    Cursor allPagesCursor = mAllPagesCursorAdapter.getCursor();
    if (allPagesCursor != null) allPagesCursor.close();

    if (mBookmarksAdapter != null) {
      Cursor bookmarksCursor = mBookmarksAdapter.getCursor();
      if (bookmarksCursor != null) bookmarksCursor.close();
    }
  }
Ejemplo n.º 5
0
  private void addAllPagesTab() {
    Log.d(LOGTAG, "Creating All Pages tab");

    addAwesomeTab(ALL_PAGES_TAB, R.string.awesomebar_all_pages_title, R.id.all_pages_list);

    // Load the list using a custom adapter so we can create the bitmaps
    mAllPagesCursorAdapter =
        new AwesomeBarCursorAdapter(
            mContext,
            R.layout.awesomebar_row,
            null,
            new String[] {URLColumns.TITLE, URLColumns.URL, URLColumns.FAVICON},
            new int[] {R.id.title, R.id.url, R.id.favicon});

    mAllPagesCursorAdapter.setViewBinder(new AwesomeCursorViewBinder());

    mAllPagesCursorAdapter.setFilterQueryProvider(
        new FilterQueryProvider() {
          public Cursor runQuery(CharSequence constraint) {
            ContentResolver resolver = mContext.getContentResolver();
            long start = SystemClock.uptimeMillis();

            Cursor c = BrowserDB.filter(resolver, constraint, MAX_RESULTS);
            c.getCount(); // ensure the query runs at least once

            long end = SystemClock.uptimeMillis();
            Log.i(LOGTAG, "Got cursor in " + (end - start) + "ms");

            return c;
          }
        });

    final ListView allPagesList = (ListView) findViewById(R.id.all_pages_list);

    allPagesList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            handleItemClick(allPagesList, position);
          }
        });

    allPagesList.setAdapter(mAllPagesCursorAdapter);
    allPagesList.setOnTouchListener(mListTouchListener);
  }
Ejemplo n.º 6
0
  /** Sets search engines to be shown for user-entered queries. */
  private void setSearchEngines(JSONObject data) {
    try {
      JSONObject suggest = data.getJSONObject("suggest");
      String suggestEngine = suggest.isNull("engine") ? null : suggest.getString("engine");
      String suggestTemplate = suggest.isNull("template") ? null : suggest.getString("template");
      mSuggestionsEnabled = suggest.getBoolean("enabled");
      boolean suggestionsPrompted = suggest.getBoolean("prompted");
      JSONArray engines = data.getJSONArray("searchEngines");

      ArrayList<SearchEngine> searchEngines = new ArrayList<SearchEngine>();
      for (int i = 0; i < engines.length(); i++) {
        JSONObject engineJSON = engines.getJSONObject(i);
        String name = engineJSON.getString("name");
        String iconURI = engineJSON.getString("iconURI");
        Bitmap icon = BitmapUtils.getBitmapFromDataURI(iconURI);
        if (name.equals(suggestEngine) && suggestTemplate != null) {
          // suggest engine should be at the front of the list
          searchEngines.add(0, new SearchEngine(name, icon));

          // The only time Tabs.getInstance().getSelectedTab() should
          // be null is when we're restoring after a crash. We should
          // never restore private tabs when that happens, so it
          // should be safe to assume that null means non-private.
          Tab tab = Tabs.getInstance().getSelectedTab();
          if (tab == null || !tab.isPrivate())
            mSuggestClient =
                new SuggestClient(
                    GeckoApp.mAppContext, suggestTemplate, SUGGESTION_TIMEOUT, SUGGESTION_MAX);
        } else {
          searchEngines.add(new SearchEngine(name, icon));
        }
      }

      mSearchEngines = searchEngines;
      mCursorAdapter.notifyDataSetChanged();

      // show suggestions opt-in if user hasn't been prompted
      if (!suggestionsPrompted && mSuggestClient != null) {
        showSuggestionsOptIn();
      }
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error getting search engine JSON", e);
    }

    filterSuggestions(mSearchTerm);
  }
Ejemplo n.º 7
0
  public void filter(String searchTerm) {
    // Don't let the tab's content steal focus on tab switch
    setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

    // Ensure the 'All Pages' tab is selected
    setCurrentTabByTag(ALL_PAGES_TAB);

    // Restore normal focus behavior on tab host
    setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    // The tabs should only be visible if there's no on-going search
    int tabsVisibility = (searchTerm.length() == 0 ? View.VISIBLE : View.GONE);
    getTabWidget().setVisibility(tabsVisibility);

    // Perform the actual search
    mAllPagesCursorAdapter.filter(searchTerm);
  }
Ejemplo n.º 8
0
  private List<String> getUrlsWithoutFavicon() {
    List<String> urls = new ArrayList<String>();

    Cursor c = mCursorAdapter.getCursor();
    if (c == null || !c.moveToFirst()) return urls;

    do {
      final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));

      // We only want to load favicons from DB if they are not in the
      // memory cache yet.
      if (Favicons.getInstance().getFaviconFromMemCache(url) != null) continue;

      urls.add(url);
    } while (c.moveToNext());

    return urls;
  }