当前位置: 首页>>代码示例>>Java>>正文


Java TtsSpan类代码示例

本文整理汇总了Java中android.text.style.TtsSpan的典型用法代码示例。如果您正苦于以下问题:Java TtsSpan类的具体用法?Java TtsSpan怎么用?Java TtsSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TtsSpan类属于android.text.style包,在下文中一共展示了TtsSpan类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getView

import android.text.style.TtsSpan; //导入依赖的package包/类
@Override
public View getView(final LayoutInflater inflater, ViewGroup container, Context context) {
    View view = inflater.inflate(R.layout.test_tts_span, container, false);
    ListView list = (ListView) view.findViewById(R.id.test_tts_span_list);

    TtsSpan[] ttsSpans = initTtsSpans();
    String[] spanTypes = container.getResources()
            .getStringArray(R.array.test_tts_span_type_array);
    String[] texts = context.getResources().getStringArray(R.array.test_tts_span_text_array);

    TTSSpanTestAdapter adapter = new TTSSpanTestAdapter(context,
            ttsSpans, spanTypes, texts);

    list.setAdapter(adapter);

    return view;
}
 
开发者ID:google,项目名称:talkback,代码行数:18,代码来源:TTSSpanTest.java

示例2: initTtsSpans

import android.text.style.TtsSpan; //导入依赖的package包/类
private TtsSpan[] initTtsSpans() {
    TtsSpan[] ttsSpans = new TtsSpan[7];
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ttsSpans[0] = new TtsSpan.CardinalBuilder("1234").build();
        ttsSpans[1] = new TtsSpan.DateBuilder().setYear(1998).setMonth(9).setDay(4).build();
        ttsSpans[2] = new TtsSpan.DecimalBuilder().setArgumentsFromDouble(Math.PI, 0, 5)
                .build();
        ttsSpans[3] = new TtsSpan.DigitsBuilder().setDigits("2048").build();
        ttsSpans[4] = new TtsSpan.MoneyBuilder().setCurrency("USD").setIntegerPart(3057000)
                .build();
        ttsSpans[5] = new TtsSpan.OrdinalBuilder().setNumber(21).build();
        ttsSpans[6] = new TtsSpan.TextBuilder().setText("Spoken Text").build();
    }
    //TODO add more TtsSpans

    return ttsSpans;
}
 
开发者ID:google,项目名称:talkback,代码行数:18,代码来源:TTSSpanTest.java

示例3: wrapForTts

import android.text.style.TtsSpan; //导入依赖的package包/类
/**
 * Wraps a message with a TTS span, so that a different message is spoken than
 * what is getting displayed.
 * @param msg original message
 * @param ttsMsg message to be spoken
 */
public static CharSequence wrapForTts(CharSequence msg, String ttsMsg) {
    SpannableString spanned = new SpannableString(msg);
    spanned.setSpan(new TtsSpan.TextBuilder(ttsMsg).build(),
            0, spanned.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return spanned;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:13,代码来源:Utilities.java

示例4: prepareSpans

import android.text.style.TtsSpan; //导入依赖的package包/类
/**
 * Ensures that a {@link CategorySpan} is in {@param textToSpannify} if required.
 * Will firstly remove all existing category spans, and then add back one if neccesary.
 * In addition, also adds a {@link TtsSpan} to indicate to screen readers that the category
 * span has semantic meaning representing a category.
 */
@TargetApi(21)
private void prepareSpans(Editable textToSpannify) {
    if (textToSpannify == null) {
        return;
    }

    removeSpans(textToSpannify, CategorySpan.class);
    if (Build.VERSION.SDK_INT >= 21) {
        removeSpans(textToSpannify, TtsSpan.class);
    }

    int colonIndex = textToSpannify.toString().indexOf(':');
    if (colonIndex > 0) {
        CategorySpan span = new CategorySpan(context);
        textToSpannify.setSpan(span, 0, colonIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        if (Build.VERSION.SDK_INT >= 21) {
            // For accessibility reasons, make this more clear to screen readers that the
            // span we just added semantically represents a category.
            CharSequence categoryName = textToSpannify.subSequence(0, colonIndex);
            TtsSpan ttsSpan = new TtsSpan.TextBuilder(context.getString(R.string.tts_category_name,
                    categoryName)).build();
            textToSpannify.setSpan(ttsSpan, 0, 0, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:33,代码来源:CategoryTextWatcher.java

示例5: wrapForTts

import android.text.style.TtsSpan; //导入依赖的package包/类
/**
 * Wraps a message with a TTS span, so that a different message is spoken than
 * what is getting displayed.
 * @param msg original message
 * @param ttsMsg message to be spoken
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static CharSequence wrapForTts(CharSequence msg, String ttsMsg) {
    if (Utilities.ATLEAST_LOLLIPOP) {
        SpannableString spanned = new SpannableString(msg);
        spanned.setSpan(new TtsSpan.TextBuilder(ttsMsg).build(),
                0, spanned.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        return spanned;
    } else {
        return msg;
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:18,代码来源:Utilities.java

示例6: obtainVerbatim

import android.text.style.TtsSpan; //导入依赖的package包/类
static final CharSequence obtainVerbatim(String text) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new SpannableStringBuilder().append(text,
                new TtsSpan.VerbatimBuilder(text).build(), 0);
    } else {
        return text;
    }
}
 
开发者ID:Gericop,项目名称:DateTimePicker,代码行数:9,代码来源:TimePickerClockDelegate.java

示例7: obtainVerbatim

import android.text.style.TtsSpan; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private CharSequence obtainVerbatim(String text) {
    return (SUtils.isApi_21_OrHigher()) ?
            new SpannableStringBuilder().append(text,
                    new TtsSpan.VerbatimBuilder(text).build(), 0)
            : text;
}
 
开发者ID:andela-kogunde,项目名称:CheckSmarter,代码行数:8,代码来源:SublimeTimePicker.java

示例8: TTSSpanTestAdapter

import android.text.style.TtsSpan; //导入依赖的package包/类
public TTSSpanTestAdapter(Context context, TtsSpan[] ttsSpans,
                          String[] spanTypes, String[] texts) {
    mContext = context;
    mTtsSpans = ttsSpans;
    mSpanTypes = spanTypes;
    mTexts = texts;
}
 
开发者ID:google,项目名称:talkback,代码行数:8,代码来源:TTSSpanTestAdapter.java

示例9: onCreate

import android.text.style.TtsSpan; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set preferences to use device-protected storage.
    if (BuildCompat.isAtLeastN()) {
        getPreferenceManager().setStorageDeviceProtected();
    }

    mService = TalkBackService.getInstance();

    // Compose preference keys from a key prefix and accessibility event types.
    for (int id : DUMP_A11Y_EVENT_IDS) {
        mDumpEventPrefKeys.add(getString(R.string.pref_dump_event_key_prefix, id));
    }

    addPreferencesFromResource(R.xml.dump_events_preferences);
    PreferenceScreen screen = getPreferenceScreen();

    for (int i = 0; i < DUMP_A11Y_EVENT_IDS.length; i++) {
        CheckBoxPreference preference = new CheckBoxPreference(
                getActivity().getApplicationContext());
        preference.setKey(mDumpEventPrefKeys.get(i));

        String title = AccessibilityEvent.eventTypeToString(DUMP_A11Y_EVENT_IDS[i]);
        // Add TtsSpan to the titles to improve readability.
        SpannableString spannableString = new SpannableString(title);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            TtsSpan ttsSpan = new TtsSpan.TextBuilder(title.replaceAll("_", " ")).build();
            spannableString.setSpan(ttsSpan, 0, title.length(), 0 /* no flag */);
        }
        preference.setTitle(spannableString);

        screen.addPreference(preference);
        preference.setOnPreferenceChangeListener(this);
    }
}
 
开发者ID:google,项目名称:talkback,代码行数:38,代码来源:TalkBackDumpAccessibilityEventActivity.java

示例10: obtainVerbatim

import android.text.style.TtsSpan; //导入依赖的package包/类
private static final CharSequence obtainVerbatim(String text) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return new SpannableStringBuilder().append(text,
                new TtsSpan.VerbatimBuilder(text).build(), 0);
    } else {
        return text;
    }
}
 
开发者ID:TR4Android,项目名称:AppCompat-Extension-Library,代码行数:9,代码来源:AppCompatTimePickerDelegate.java


注:本文中的android.text.style.TtsSpan类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。