Fields Summary |
---|
private static final boolean | DEBUG |
private static final String | TAG |
private static final float | TEXT_DOT_SCALE |
private static final boolean | DOTS_FOR_STABLE |
private static final boolean | DOTS_FOR_PENDING |
private static final boolean | ANIMATE_DOTS_FOR_PENDING |
private static final long | STREAM_UPDATE_DELAY_MILLIS |
private static final Pattern | SPLIT_PATTERN |
private static final android.util.Property | STREAM_POSITION_PROPERTY |
private final Random | mRandom |
private android.graphics.Bitmap | mOneDot |
private android.graphics.Bitmap | mTwoDot |
private int | mStreamPosition |
private android.animation.ObjectAnimator | mStreamingAnimation |
Methods Summary |
---|
private void | addColorSpan(android.text.SpannableStringBuilder displayText, int color, java.lang.String text, int textStart)
ForegroundColorSpan span = new ForegroundColorSpan(color);
int start = textStart;
int end = textStart + text.length();
displayText.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
private void | addDottySpans(android.text.SpannableStringBuilder displayText, java.lang.String text, int textStart)
Matcher m = SPLIT_PATTERN.matcher(text);
while (m.find()) {
int wordStart = textStart + m.start();
int wordEnd = textStart + m.end();
DottySpan span = new DottySpan(text.charAt(m.start()), wordStart);
displayText.setSpan(span, wordStart, wordEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
|
private void | cancelStreamAnimation()
if (mStreamingAnimation != null) {
mStreamingAnimation.cancel();
}
|
private android.graphics.Bitmap | getScaledBitmap(int resourceId, float scaled)
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
return Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * scaled),
(int) (bitmap.getHeight() * scaled), false);
|
private int | getStreamPosition()
return mStreamPosition;
|
public static boolean | isLayoutRtl(android.view.View view)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
return View.LAYOUT_DIRECTION_RTL == view.getLayoutDirection();
} else {
return false;
}
|
protected void | onFinishInflate()
super.onFinishInflate();
mOneDot = getScaledBitmap(R.drawable.lb_text_dot_one, TEXT_DOT_SCALE);
mTwoDot = getScaledBitmap(R.drawable.lb_text_dot_two, TEXT_DOT_SCALE);
reset();
|
public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)This is required to make the View findable by uiautomator
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(StreamingTextView.class.getCanonicalName());
|
public void | reset()
if (DEBUG) Log.d(TAG, "#reset");
mStreamPosition = -1;
cancelStreamAnimation();
setText("");
|
public void | setFinalRecognizedText(java.lang.CharSequence finalText)Sets the final, non changing, full text result. This should only happen at the very end of
a recognition.
if (DEBUG) Log.d(TAG, "setFinalRecognizedText(" + finalText + ")");
updateText(finalText);
|
private void | setStreamPosition(int streamPosition)
mStreamPosition = streamPosition;
invalidate();
|
private void | startStreamAnimation()
cancelStreamAnimation();
int pos = getStreamPosition();
int totalLen = length();
int animLen = totalLen - pos;
if (animLen > 0) {
if (mStreamingAnimation == null) {
mStreamingAnimation = new ObjectAnimator();
mStreamingAnimation.setTarget(this);
mStreamingAnimation.setProperty(STREAM_POSITION_PROPERTY);
}
mStreamingAnimation.setIntValues(pos, totalLen);
mStreamingAnimation.setDuration(STREAM_UPDATE_DELAY_MILLIS * animLen);
mStreamingAnimation.start();
}
|
public void | updateRecognizedText(java.lang.String stableText, java.util.List rmsValues)
|
public void | updateRecognizedText(java.lang.String stableText, java.lang.String pendingText)
if (DEBUG) Log.d(TAG, "updateText(" + stableText + "," + pendingText + ")");
if (stableText == null) {
stableText = "";
}
SpannableStringBuilder displayText = new SpannableStringBuilder(stableText);
if (DOTS_FOR_STABLE) {
addDottySpans(displayText, stableText, 0);
}
if (pendingText != null) {
int pendingTextStart = displayText.length();
displayText.append(pendingText);
if (DOTS_FOR_PENDING) {
addDottySpans(displayText, pendingText, pendingTextStart);
} else {
int pendingColor = getResources().getColor(
R.color.lb_search_plate_hint_text_color);
addColorSpan(displayText, pendingColor, pendingText, pendingTextStart);
}
}
// Start streaming in dots from beginning of partials, or current position,
// whichever is larger
mStreamPosition = Math.max(stableText.length(), mStreamPosition);
// Copy the text and spans to a SpannedString, since editable text
// doesn't redraw in invalidate() when hardware accelerated
// if the text or spans havent't changed. (probably a framework bug)
updateText(new SpannedString(displayText));
if (ANIMATE_DOTS_FOR_PENDING) {
startStreamAnimation();
}
|
private void | updateText(java.lang.CharSequence displayText)
setText(displayText);
bringPointIntoView(length());
|