@Override public View getView(int position, View convertView, ViewGroup group) { if (convertView == null) { convertView = View.inflate(getActivity(), R.layout.buffer_line, null); } BufferEvent event = getItem(position); BufferEvent prevEvent = (position > 0) ? getItem(position - 1) : null; BufferEventItem firstItem = event.getFirstItem(); BufferEventMessage firstItemMessage = firstItem.getMessage(); boolean isNewDay = ((prevEvent != null) && (!firstItem.isSameDay(prevEvent.getFirstItem()))); TextView dayView = (TextView) convertView.findViewById(R.id.day); dayView.setVisibility(isNewDay ? View.VISIBLE : View.GONE); if (isNewDay) { dayView.setText(mDateFormat.format(firstItemMessage.getDate())); } TextView timestampView = (TextView) convertView.findViewById(R.id.timestamp); TextView textView = (TextView) convertView.findViewById(R.id.text); Date date = firstItemMessage.getDate(); if (date != null) { timestampView.setText(new SimpleDateFormat("h:mm aa").format(date)); timestampView.setVisibility(View.VISIBLE); } else { timestampView.setVisibility(View.GONE); } CharSequence text = mRenderer.renderEvent(event); if ((!(mBuffer instanceof ConsoleBuffer)) && (!(text instanceof SpannableString))) { SpannableString span = new SpannableString(text); span.setSpan( new StyleSpan(Typeface.ITALIC), 0, span.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); span.setSpan( new ForegroundColorSpan(Color.GRAY), 0, span.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); textView.setText(span); } else { textView.setText(text); } boolean highlight = firstItem.isHighlight() && (mBuffer instanceof ChannelBuffer); convertView .findViewById(R.id.inner) .setBackgroundColor(highlight ? mHighlightBgColor : Color.TRANSPARENT); return convertView; }
@Override public void onListItemClick(ListView l, View v, int position, long id) { final BufferEvent event = ((BufferEventListAdapter) getListAdapter()).getItem(position); List<ContextMenuItem> menuItems = Lists.newArrayList(); if (event.getItems().size() == 1) { populateMenuItems(menuItems, event.getFirstItem()); } else { populateMenuItems(menuItems, event.getItems()); } showContextMenu(menuItems); }