FileDocCategorySizeDatePackage
StreamingTextView.javaAPI DocAndroid 5.1 API9969Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.widget

StreamingTextView

public class StreamingTextView extends android.widget.EditText
Shows the recognized text as a continuous stream of words.

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
Constructors Summary
public StreamingTextView(android.content.Context context, android.util.AttributeSet attrs)


         
        super(context, attrs);
    
public StreamingTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
    
Methods Summary
private voidaddColorSpan(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 voidaddDottySpans(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 voidcancelStreamAnimation()

        if (mStreamingAnimation != null) {
            mStreamingAnimation.cancel();
        }
    
private android.graphics.BitmapgetScaledBitmap(int resourceId, float scaled)

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
        return Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * scaled),
                (int) (bitmap.getHeight() * scaled), false);
    
private intgetStreamPosition()

        return mStreamPosition;
    
public static booleanisLayoutRtl(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 voidonFinishInflate()

        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 voidonInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
This is required to make the View findable by uiautomator

        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(StreamingTextView.class.getCanonicalName());
    
public voidreset()

        if (DEBUG) Log.d(TAG, "#reset");

        mStreamPosition = -1;
        cancelStreamAnimation();
        setText("");
    
public voidsetFinalRecognizedText(java.lang.CharSequence finalText)
Sets the final, non changing, full text result. This should only happen at the very end of a recognition.

param
finalText to the view to.

        if (DEBUG) Log.d(TAG, "setFinalRecognizedText(" + finalText + ")");

        updateText(finalText);
    
private voidsetStreamPosition(int streamPosition)

        mStreamPosition = streamPosition;
        invalidate();
    
private voidstartStreamAnimation()

        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 voidupdateRecognizedText(java.lang.String stableText, java.util.List rmsValues)

public voidupdateRecognizedText(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 voidupdateText(java.lang.CharSequence displayText)

        setText(displayText);
        bringPointIntoView(length());