예제 #1
0
    @Override
    public ContextMenuSubject getSubject() {
      // Use the history id in order to allow removing history entries
      int id = mCursor.getInt(mCursor.getColumnIndexOrThrow(Combined.HISTORY_ID));

      String keyword = null;
      int keywordCol = mCursor.getColumnIndex(URLColumns.KEYWORD);
      if (keywordCol != -1) keyword = mCursor.getString(keywordCol);

      final String url = mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.URL));

      Bitmap bitmap = Favicons.getInstance().getFaviconFromMemCache(url);
      byte[] favicon = null;

      if (bitmap != null) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        favicon = stream.toByteArray();
      }

      return new ContextMenuSubject(
          id,
          url,
          favicon,
          mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.TITLE)),
          keyword,
          mCursor.getInt(mCursor.getColumnIndexOrThrow(Combined.DISPLAY)));
    }
예제 #2
0
  /* Favicon methods */
  private void loadFavicon(final Tab tab) {
    maybeCancelFaviconLoad(tab);

    long id =
        Favicons.getInstance()
            .loadFavicon(
                tab.getURL(),
                tab.getFaviconURL(),
                !tab.isPrivate(),
                new Favicons.OnFaviconLoadedListener() {

                  public void onFaviconLoaded(String pageUrl, Bitmap favicon) {
                    // Leave favicon UI untouched if we failed to load the image
                    // for some reason.
                    if (favicon == null) return;

                    // The tab might be pointing to another URL by the time the
                    // favicon is finally loaded, in which case we simply ignore it.
                    if (!tab.getURL().equals(pageUrl)) return;

                    tab.updateFavicon(favicon);
                    tab.setFaviconLoadId(Favicons.NOT_LOADING);

                    if (Tabs.getInstance().isSelectedTab(tab))
                      mBrowserToolbar.setFavicon(tab.getFavicon());

                    Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.FAVICON);
                  }
                });

    tab.setFaviconLoadId(id);
  }
예제 #3
0
  public void storeFaviconsInMemCache(Cursor c) {
    try {
      if (c == null || !c.moveToFirst()) return;

      do {
        final String url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
        final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Combined.FAVICON));
        if (b == null) continue;

        Bitmap favicon = BitmapFactory.decodeByteArray(b, 0, b.length);
        if (favicon == null || favicon.getWidth() <= 0 || favicon.getHeight() <= 0) continue;

        favicon = Favicons.getInstance().scaleImage(favicon);
        Favicons.getInstance().putFaviconInMemCache(url, favicon);
      } while (c.moveToNext());
    } finally {
      if (c != null) c.close();
    }
  }
예제 #4
0
  private void maybeCancelFaviconLoad(Tab tab) {
    long faviconLoadId = tab.getFaviconLoadId();

    if (faviconLoadId == Favicons.NOT_LOADING) return;

    // Cancel pending favicon load task
    Favicons.getInstance().cancelFaviconLoad(faviconLoadId);

    // Reset favicon load state
    tab.setFaviconLoadId(Favicons.NOT_LOADING);
  }
예제 #5
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;
  }
예제 #6
0
    @Override
    public View getChildView(
        int groupPosition,
        int childPosition,
        boolean isLastChild,
        View convertView,
        ViewGroup parent) {
      AwesomeEntryViewHolder viewHolder = null;

      if (convertView == null) {
        convertView = getInflater().inflate(R.layout.awesomebar_row, null);

        viewHolder = new AwesomeEntryViewHolder();
        viewHolder.titleView = (TextView) convertView.findViewById(R.id.title);
        viewHolder.urlView = (TextView) convertView.findViewById(R.id.url);
        viewHolder.faviconView = (ImageView) convertView.findViewById(R.id.favicon);
        viewHolder.bookmarkIconView = (ImageView) convertView.findViewById(R.id.bookmark_icon);

        convertView.setTag(viewHolder);
      } else {
        viewHolder = (AwesomeEntryViewHolder) convertView.getTag();
      }

      HistoryListAdapter adapter = getCursorAdapter();
      if (adapter == null) return null;

      @SuppressWarnings("unchecked")
      Map<String, Object> historyItem =
          (Map<String, Object>) adapter.getChild(groupPosition, childPosition);

      String title = (String) historyItem.get(URLColumns.TITLE);
      String url = (String) historyItem.get(URLColumns.URL);

      if (TextUtils.isEmpty(title)) title = url;

      viewHolder.titleView.setText(title);
      viewHolder.urlView.setText(url);

      byte[] b = (byte[]) historyItem.get(URLColumns.FAVICON);
      Bitmap favicon = null;

      if (b != null) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
        if (bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
          favicon = Favicons.getInstance().scaleImage(bitmap);
        }
      }
      updateFavicon(viewHolder.faviconView, favicon);

      Integer bookmarkId = (Integer) historyItem.get(Combined.BOOKMARK_ID);
      Integer display = (Integer) historyItem.get(Combined.DISPLAY);

      // The bookmark id will be 0 (null in database) when the url
      // is not a bookmark. Reading list items are irrelevant in history
      // tab. We should never show any sign or them.
      int visibility =
          (bookmarkId != 0 && display != Combined.DISPLAY_READER ? View.VISIBLE : View.GONE);

      viewHolder.bookmarkIconView.setVisibility(visibility);
      viewHolder.bookmarkIconView.setImageResource(R.drawable.ic_awesomebar_star);

      return convertView;
    }
예제 #7
0
 private void displayFavicon(AwesomeEntryViewHolder viewHolder) {
   final String url = viewHolder.urlView.getText().toString();
   Bitmap bitmap = Favicons.getInstance().getFaviconFromMemCache(url);
   updateFavicon(viewHolder.faviconView, bitmap);
 }