in app/src/main/java/com/google/reviewit/widget/UnifiedDiffView.java [484:555]
private TextView createLineWithIntralineDiffs(
String line, LineChangeType changeType, Intraline intraline,
int textSizeSp) {
SpannableStringBuilder b = new SpannableStringBuilder(line);
boolean invert = intraline != null && intraline.isHighlightNewline();
int lineBackgroundColorId = -1;
switch (changeType) {
case ADD:
lineBackgroundColorId = invert
? R.color.lineAddedIntraline
: R.color.lineAdded;
break;
case DELETE:
lineBackgroundColorId = invert
? R.color.lineDeletedIntraline
: R.color.lineDeleted;
break;
case NO_CHANGE:
default:
break;
}
if (intraline != null) {
try {
List<Range> ranges = invert
? intraline.getInvertedRanges()
: intraline.getRanges();
for (Range range : ranges) {
switch (changeType) {
case ADD:
BackgroundColorSpan addedSpan =
new BackgroundColorSpan(widgetUtil.color(
invert
? R.color.lineAdded
: R.color.lineAddedIntraline));
b.setSpan(addedSpan, range.from, range.to,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
break;
case DELETE:
BackgroundColorSpan deletedSpan =
new BackgroundColorSpan(widgetUtil.color(
invert
? R.color.lineDeleted
: R.color.lineDeletedIntraline));
b.setSpan(deletedSpan, range.from, range.to,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
break;
case NO_CHANGE:
default:
break;
}
}
} catch (Throwable t) {
Log.e(TAG, "Failed to render intraline diff " + intraline
+ " for line '" + line + "'", t);
}
}
TextView textView = new TextView(getContext());
textView.setLayoutParams(wrapTableRowLayout());
textView.setText(b);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSizeSp);
textView.setTypeface(Typeface.MONOSPACE);
if (lineBackgroundColorId != -1) {
textView.setBackgroundColor(widgetUtil.color(lineBackgroundColorId));
}
return textView;
}