Skip to content

Commit

Permalink
#21 fix setSpan with negative index
Browse files Browse the repository at this point in the history
  • Loading branch information
gscdev committed May 3, 2021
1 parent 792c184 commit 5dfe933
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/src/main/java/ai/elimu/vitabu/ui/storybook/CoverFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ public void onRangeStart(String utteranceId, int start, int end, int frame) {
super.onRangeStart(utteranceId, start, end, frame);

Log.i(getClass().getName(), "utteranceId: " + utteranceId + ", start: " + start + ", end: " + end);

// Highlight the word being spoken
Spannable spannable = new SpannableString(audioText);
BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(getResources().getColor(R.color.colorAccent));
spannable.setSpan(backgroundColorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
audioTextView.setText(spannable);

if (start >= 0) {
// Highlight the word being spoken
Spannable spannable = new SpannableString(audioText);
BackgroundColorSpan backgroundColorSpan = new BackgroundColorSpan(getResources().getColor(R.color.colorAccent));
spannable.setSpan(backgroundColorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
audioTextView.setText(spannable);
}
}

@Override
Expand All @@ -130,6 +132,8 @@ public void onDone(String utteranceId) {

if (audioListener != null) {
audioListener.onAudioDone();
} else {
onStop(utteranceId, false);
}
}

Expand Down

0 comments on commit 5dfe933

Please sign in to comment.