Ejemplo n.º 1
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      int type = getItemViewType(position);
      if (type == ROW_SEARCH || type == ROW_SUGGEST) {
        SearchEntryViewHolder viewHolder = null;

        if (convertView == null || !(convertView.getTag() instanceof SearchEntryViewHolder)) {
          convertView =
              getInflater().inflate(R.layout.awesomebar_suggestion_row, getListView(), false);

          viewHolder = new SearchEntryViewHolder();
          viewHolder.suggestionView = (FlowLayout) convertView.findViewById(R.id.suggestion_layout);
          viewHolder.iconView = (ImageView) convertView.findViewById(R.id.suggestion_icon);
          viewHolder.userEnteredView =
              (LinearLayout) convertView.findViewById(R.id.suggestion_user_entered);
          viewHolder.userEnteredTextView =
              (TextView) convertView.findViewById(R.id.suggestion_text);

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

        bindSearchEngineView(mSearchEngines.get(getEngineIndex(position)), viewHolder);
      } else {
        AwesomeEntryViewHolder viewHolder = null;

        if (convertView == null || !(convertView.getTag() instanceof AwesomeEntryViewHolder)) {
          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();
        }

        position -= getSuggestEngineCount();
        Cursor cursor = getCursor();
        if (!cursor.moveToPosition(position))
          throw new IllegalStateException("Couldn't move cursor to position " + position);

        updateTitle(viewHolder.titleView, cursor);
        updateUrl(viewHolder.urlView, cursor);
        updateBookmarkIcon(viewHolder.bookmarkIconView, cursor);
        displayFavicon(viewHolder);
      }

      return convertView;
    }
Ejemplo n.º 2
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;
    }