TtsSpan.java revision 1d44e0ccecc44cf7f7852e559bf2f9a9aef66064
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.text.style; 18 19import java.text.NumberFormat; 20import java.util.Locale; 21 22import android.os.Parcel; 23import android.os.PersistableBundle; 24import android.text.ParcelableSpan; 25import android.text.TextUtils; 26 27/** 28 * A span that supplies additional meta-data for the associated text intended 29 * for text-to-speech engines. If the text is being processed by a 30 * text-to-speech engine, the engine may use the data in this span in addition 31 * to or instead of its associated text. 32 * 33 * The inner classes are there for convenience and provide builders for each 34 * TtsSpan type. 35 */ 36public class TtsSpan implements ParcelableSpan { 37 private final String mType; 38 private final PersistableBundle mArgs; 39 40 /** 41 * This span type can be used to add morphosyntactic features to the text it 42 * spans over, or synthesize a something else than the spanned text. Use 43 * the argument {@link #ARG_TEXT} to set a different text. 44 * Accepts the arguments {@link #ARG_GENDER}, 45 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 46 * {@link #ARG_CASE}. 47 */ 48 public static final String TYPE_TEXT = "android.type.text"; 49 50 /** 51 * The text associated with this span is a cardinal. Must include the 52 * number to be synthesized with {@link #ARG_NUMBER}. 53 * Also accepts the arguments {@link #ARG_GENDER}, 54 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 55 * {@link #ARG_CASE}. 56 */ 57 public static final String TYPE_CARDINAL = "android.type.cardinal"; 58 59 /** 60 * The text associated with this span is an ordinal. Must include the 61 * number to be synthesized with {@link #ARG_NUMBER}. 62 * Also accepts the arguments {@link #ARG_GENDER}, 63 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 64 * {@link #ARG_CASE}. 65 */ 66 public static final String TYPE_ORDINAL = "android.type.ordinal"; 67 68 /** 69 * The text associated with this span is a decimal number. Must include the 70 * number to be synthesized with {@link #ARG_INTEGER_PART} and 71 * {@link #ARG_FRACTIONAL_PART}. 72 * Also accepts the arguments {@link #ARG_GENDER}, 73 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 74 * {@link #ARG_CASE}. 75 */ 76 public static final String TYPE_DECIMAL = "android.type.decimal"; 77 78 /** 79 * The text associated with this span is a fractional number. Must include 80 * the number to be synthesized with {@link #ARG_NUMERATOR} and 81 * {@link #ARG_DENOMINATOR}. {@link #ARG_INTEGER_PART} is optional 82 * Also accepts the arguments {@link #ARG_GENDER}, 83 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 84 * {@link #ARG_CASE}. 85 */ 86 public static final String TYPE_FRACTION = "android.type.fraction"; 87 88 /** 89 * The text associated with this span is a measure, consisting of a number 90 * and a unit. The number can be a cardinal, decimal or a fraction. Set the 91 * number with the same arguments as {@link #TYPE_CARDINAL}, 92 * {@link #TYPE_DECIMAL} or {@link #TYPE_FRACTION}. The unit can be 93 * specified with {@link #ARG_UNIT}. 94 * Also accepts the arguments {@link #ARG_GENDER}, 95 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 96 * {@link #ARG_CASE}. 97 */ 98 public static final String TYPE_MEASURE = "android.type.measure"; 99 100 /** 101 * The text associated with this span is a time, consisting of a number of 102 * hours and minutes, specified with {@link #ARG_HOURS} and 103 * {@link #ARG_MINUTES}. 104 * Also accepts the arguments {@link #ARG_GENDER}, 105 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 106 * {@link #ARG_CASE}. 107 */ 108 public static final String TYPE_TIME = "android.type.time"; 109 110 /** 111 * The text associated with this span is a date. All arguments are optional, 112 * but at least one has to be provided: {@link #ARG_WEEKDAY}, 113 * {@link #ARG_DAY}, {@link #ARG_MONTH} and {@link #ARG_YEAR}. 114 * Also accepts the arguments {@link #ARG_GENDER}, 115 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 116 * {@link #ARG_CASE}. 117 */ 118 public static final String TYPE_DATE = "android.type.date"; 119 120 /** 121 * The text associated with this span is a telephone number. The argument 122 * {@link #ARG_NUMBER_PARTS} is required. {@link #ARG_COUNTRY_CODE} and 123 * {@link #ARG_EXTENSION} are optional. 124 * Also accepts the arguments {@link #ARG_GENDER}, 125 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 126 * {@link #ARG_CASE}. 127 */ 128 public static final String TYPE_TELEPHONE = "android.type.telephone"; 129 130 131 /** 132 * The text associated with this span is a URI (can be used for URLs and 133 * email addresses). The full schema for URLs, which email addresses can 134 * effectively be seen as a subset of, is: 135 * protocol://username:password@domain:port/path?query_string#fragment_id 136 * Hence populating just username and domain will read as an email address. 137 * All arguments are optional, but at least one has to be provided: 138 * {@link #ARG_PROTOCOL}, {@link #ARG_USERNAME}, {@link #ARG_PASSWORD}, 139 * {@link #ARG_DOMAIN}, {@link #ARG_PORT}, {@link #ARG_PATH}, 140 * {@link #ARG_QUERY_STRING} and {@link #ARG_FRAGMENT_ID}. 141 * Also accepts the arguments {@link #ARG_GENDER}, 142 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 143 * {@link #ARG_CASE}. 144 */ 145 public static final String TYPE_ELECTRONIC = "android.type.electronic"; 146 147 /** 148 * The text associated with this span is an amount of money. Set the amount 149 * with the same arguments as {@link #TYPE_DECIMAL}. 150 * {@link #ARG_CURRENCY} is used to set the currency. {@link #ARG_QUANTITY} 151 * is optional. 152 * Also accepts the arguments {@link #ARG_GENDER}, 153 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 154 * {@link #ARG_CASE}. 155 */ 156 public static final String TYPE_MONEY = "android.type.money"; 157 158 /** 159 * The text associated with this span is a series of digits that have to be 160 * read sequentially. {@link #ARG_DIGITS} is required. 161 * Also accepts the arguments {@link #ARG_GENDER}, 162 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 163 * {@link #ARG_CASE}. 164 */ 165 public static final String TYPE_DIGITS = "android.type.digits"; 166 167 /** 168 * The text associated with this span is a series of characters that have to 169 * be read verbatim. The engine will attempt to ready out any character like 170 * punctuation but excluding whitespace. {@link #ARG_VERBATIM} is required. 171 * Also accepts the arguments {@link #ARG_GENDER}, 172 * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and 173 * {@link #ARG_CASE}. 174 */ 175 public static final String TYPE_VERBATIM = "android.type.verbatim"; 176 177 /** 178 * String argument supplying gender information. Can be any of 179 * {@link #GENDER_NEUTRAL}, {@link #GENDER_MALE} and 180 * {@link #GENDER_FEMALE}. 181 */ 182 public static final String ARG_GENDER = "android.arg.gender"; 183 184 public static final String GENDER_NEUTRAL = "android.neutral"; 185 public static final String GENDER_MALE = "android.male"; 186 public static final String GENDER_FEMALE = "android.female"; 187 188 /** 189 * String argument supplying animacy information. Can be 190 * {@link #ANIMACY_ANIMATE} or 191 * {@link #ANIMACY_INANIMATE} 192 */ 193 public static final String ARG_ANIMACY = "android.arg.animacy"; 194 195 public static final String ANIMACY_ANIMATE = "android.animate"; 196 public static final String ANIMACY_INANIMATE = "android.inanimate"; 197 198 /** 199 * String argument supplying multiplicity information. Can be any of 200 * {@link #MULTIPLICITY_SINGLE}, 201 * {@link #MULTIPLICITY_DUAL} and 202 * {@link #MULTIPLICITY_PLURAL} 203 */ 204 public static final String ARG_MULTIPLICITY = "android.arg.multiplicity"; 205 206 public static final String MULTIPLICITY_SINGLE = "android.single"; 207 public static final String MULTIPLICITY_DUAL = "android.dual"; 208 public static final String MULTIPLICITY_PLURAL = "android.plural"; 209 210 /** 211 * String argument supplying case information. Can be any of 212 * {@link #CASE_NOMINATIVE}, {@link #CASE_ACCUSATIVE}, 213 * {@link #CASE_DATIVE}, {@link #CASE_ABLATIVE}, 214 * {@link #CASE_GENITIVE}, {@link #CASE_VOCATIVE}, 215 * {@link #CASE_LOCATIVE} and 216 * {@link #CASE_INSTRUMENTAL} 217 */ 218 public static final String ARG_CASE = "android.arg.case"; 219 220 public static final String CASE_NOMINATIVE = "android.nomative"; 221 public static final String CASE_ACCUSATIVE = "android.accusative"; 222 public static final String CASE_DATIVE = "android.dative"; 223 public static final String CASE_ABLATIVE = "android.ablative"; 224 public static final String CASE_GENITIVE = "android.genitive"; 225 public static final String CASE_VOCATIVE = "android.vocative"; 226 public static final String CASE_LOCATIVE = "android.locative"; 227 public static final String CASE_INSTRUMENTAL = "android.instrumental"; 228 229 /** 230 * String supplying the text to be synthesized. The synthesizer is free 231 * to decide how to interpret the text. 232 * Can be used with {@link #TYPE_TEXT}. 233 */ 234 public static final String ARG_TEXT = "android.arg.text"; 235 236 /** 237 * Argument used to specify a whole number. The value can be a string of 238 * digits of any size optionally prefixed with a - or +. 239 * Can be used with {@link #TYPE_CARDINAL} and {@link #TYPE_ORDINAL}. 240 */ 241 public static final String ARG_NUMBER = "android.arg.number"; 242 243 /** 244 * Argument used to specify the integer part of a decimal or fraction. The 245 * value can be a string of digits of any size optionally prefixed with 246 * a - or +. 247 * Can be used with {@link #TYPE_DECIMAL} and {@link #TYPE_FRACTION}. 248 */ 249 public static final String ARG_INTEGER_PART = "android.arg.integer_part"; 250 251 /** 252 * Argument used to specify the fractional part of a decimal. The value can 253 * be a string of digits of any size. 254 * Can be used with {@link #TYPE_DECIMAL}. 255 */ 256 public static final String ARG_FRACTIONAL_PART = 257 "android.arg.fractional_part"; 258 259 /** 260 * Argument used to choose the suffix (thousand, million, etc) that is used 261 * to pronounce large amounts of money. For example it can be used to 262 * disambiguate between "two thousand five hundred dollars" and 263 * "two point five thousand dollars". 264 * If implemented, engines should support at least "1000", "1000000", 265 * "1000000000" and "1000000000000". 266 * Example: if the {@link #ARG_INTEGER_PART} argument is "10", the 267 * {@link #ARG_FRACTIONAL_PART} argument is "4", the {@link #ARG_QUANTITY} 268 * argument is "1000" and the {@link #ARG_CURRENCY} argument is "usd", the 269 * TTS engine may pronounce the span as "ten point four thousand dollars". 270 * With the same example but with the quantity set as "1000000" the TTS 271 * engine may pronounce the span as "ten point four million dollars". 272 * Can be used with {@link #TYPE_MONEY}. 273 */ 274 public static final String ARG_QUANTITY = 275 "android.arg.quantity"; 276 277 /** 278 * Argument used to specify the numerator of a fraction. The value can be a 279 * string of digits of any size optionally prefixed with a - or +. 280 * Can be used with {@link #TYPE_FRACTION}. 281 */ 282 public static final String ARG_NUMERATOR = "android.arg.numerator"; 283 284 /** 285 * Argument used to specify the denominator of a fraction. The value can be 286 * a string of digits of any size optionally prefixed with a + or -. 287 * Can be used with {@link #TYPE_FRACTION}. 288 */ 289 public static final String ARG_DENOMINATOR = "android.arg.denominator"; 290 291 /** 292 * Argument used to specify the unit of a measure. The unit should always be 293 * specified in English singular form. Prefixes may be used. Engines will do 294 * their best to pronounce them correctly in the language used. Engines are 295 * expected to at least support the most common ones like "meter", "second", 296 * "degree celcius" and "degree fahrenheit" with some common prefixes like 297 * "milli" and "kilo". 298 * Can be used with {@link #TYPE_MEASURE}. 299 */ 300 public static final String ARG_UNIT = "android.arg.unit"; 301 302 /** 303 * Argument used to specify the hours of a time. The hours should be 304 * provided as an integer in the range from 0 up to and including 24. 305 * Can be used with {@link #TYPE_TIME}. 306 */ 307 public static final String ARG_HOURS = "android.arg.hours"; 308 309 /** 310 * Argument used to specify the minutes of a time. The hours should be 311 * provided as an integer in the range from 0 up to and including 59. 312 * Can be used with {@link #TYPE_TIME}. 313 */ 314 public static final String ARG_MINUTES = "android.arg.minutes"; 315 316 /** 317 * Argument used to specify the weekday of a date. The value should be 318 * provided as an integer and can be any of {@link #WEEKDAY_SUNDAY}, 319 * {@link #WEEKDAY_MONDAY}, {@link #WEEKDAY_TUESDAY}, 320 * {@link #WEEKDAY_WEDNESDAY}, {@link #WEEKDAY_THURSDAY}, 321 * {@link #WEEKDAY_FRIDAY} and {@link #WEEKDAY_SATURDAY}. 322 * Can be used with {@link #TYPE_DATE}. 323 */ 324 public static final String ARG_WEEKDAY = "android.arg.weekday"; 325 326 public static final int WEEKDAY_SUNDAY = 1; 327 public static final int WEEKDAY_MONDAY = 2; 328 public static final int WEEKDAY_TUESDAY = 3; 329 public static final int WEEKDAY_WEDNESDAY = 4; 330 public static final int WEEKDAY_THURSDAY = 5; 331 public static final int WEEKDAY_FRIDAY = 6; 332 public static final int WEEKDAY_SATURDAY = 7; 333 334 /** 335 * Argument used to specify the day of the month of a date. The value should 336 * be provided as an integer in the range from 1 up to and including 31. 337 * Can be used with {@link #TYPE_DATE}. 338 */ 339 public static final String ARG_DAY = "android.arg.day"; 340 341 /** 342 * Argument used to specify the month of a date. The value should be 343 * provided as an integer and can be any of {@link #MONTH_JANUARY}, 344 * {@link #MONTH_FEBRUARY}, {@link #MONTH_MARCH}, {@link #MONTH_APRIL}, 345 * {@link #MONTH_MAY}, {@link #MONTH_JUNE}, {@link #MONTH_JULY}, 346 * {@link #MONTH_AUGUST}, {@link #MONTH_SEPTEMBER}, {@link #MONTH_OCTOBER}, 347 * {@link #MONTH_NOVEMBER} and {@link #MONTH_DECEMBER}. 348 * Can be used with {@link #TYPE_DATE}. 349 */ 350 public static final String ARG_MONTH = "android.arg.month"; 351 352 public static final int MONTH_JANUARY = 0; 353 public static final int MONTH_FEBRUARY = 1; 354 public static final int MONTH_MARCH = 2; 355 public static final int MONTH_APRIL = 3; 356 public static final int MONTH_MAY = 4; 357 public static final int MONTH_JUNE = 5; 358 public static final int MONTH_JULY = 6; 359 public static final int MONTH_AUGUST = 7; 360 public static final int MONTH_SEPTEMBER = 8; 361 public static final int MONTH_OCTOBER = 9; 362 public static final int MONTH_NOVEMBER = 10; 363 public static final int MONTH_DECEMBER = 11; 364 365 /** 366 * Argument used to specify the year of a date. The value should be provided 367 * as a positive integer. 368 * Can be used with {@link #TYPE_DATE}. 369 */ 370 public static final String ARG_YEAR = "android.arg.year"; 371 372 /** 373 * Argument used to specify the country code of a telephone number. Can be 374 * a string of digits optionally prefixed with a "+". 375 * Can be used with {@link #TYPE_TELEPHONE}. 376 */ 377 public static final String ARG_COUNTRY_CODE = "android.arg.country_code"; 378 379 /** 380 * Argument used to specify the main number part of a telephone number. Can 381 * be a string of digits where the different parts of the telephone number 382 * can be separated with a space, '-', '/' or '.'. 383 * Can be used with {@link #TYPE_TELEPHONE}. 384 */ 385 public static final String ARG_NUMBER_PARTS = "android.arg.number_parts"; 386 387 /** 388 * Argument used to specify the extension part of a telephone number. Can be 389 * a string of digits. 390 * Can be used with {@link #TYPE_TELEPHONE}. 391 */ 392 public static final String ARG_EXTENSION = "android.arg.extension"; 393 394 /** 395 * Argument used to specify the protocol of a URI. Examples are "http" and 396 * "ftp". 397 * Can be used with {@link #TYPE_ELECTRONIC}. 398 */ 399 public static final String ARG_PROTOCOL = "android.arg.protocol"; 400 401 /** 402 * Argument used to specify the username part of a URI. Should be set as a 403 * string. 404 * Can be used with {@link #TYPE_ELECTRONIC}. 405 */ 406 public static final String ARG_USERNAME = "android.arg.username"; 407 408 /** 409 * Argument used to specify the password part of a URI. Should be set as a 410 * string. 411 * Can be used with {@link #TYPE_ELECTRONIC}. 412 */ 413 public static final String ARG_PASSWORD = "android.arg.password"; 414 415 /** 416 * Argument used to specify the domain part of a URI. For example 417 * "source.android.com". 418 * Can be used with {@link #TYPE_ELECTRONIC}. 419 */ 420 public static final String ARG_DOMAIN = "android.arg.domain"; 421 422 /** 423 * Argument used to specify the port number of a URI. Should be specified as 424 * an integer. 425 * Can be used with {@link #TYPE_ELECTRONIC}. 426 */ 427 public static final String ARG_PORT = "android.arg.port"; 428 429 /** 430 * Argument used to specify the path part of a URI. For example 431 * "source/index.html". 432 * Can be used with {@link #TYPE_ELECTRONIC}. 433 */ 434 public static final String ARG_PATH = "android.arg.path"; 435 436 /** 437 * Argument used to specify the query string of a URI. For example 438 * "arg=value&argtwo=value". 439 * Can be used with {@link #TYPE_ELECTRONIC}. 440 */ 441 public static final String ARG_QUERY_STRING = "android.arg.query_string"; 442 443 /** 444 * Argument used to specify the fragment id of a URI. Should be specified as 445 * a string. 446 * Can be used with {@link #TYPE_ELECTRONIC}. 447 */ 448 public static final String ARG_FRAGMENT_ID = "android.arg.fragment_id"; 449 450 /** 451 * Argument used to specify the currency. Should be a ISO4217 currency code, 452 * e.g. "USD". 453 * Can be used with {@link #TYPE_MONEY}. 454 */ 455 public static final String ARG_CURRENCY = "android.arg.money"; 456 457 /** 458 * Argument used to specify a string of digits. 459 * Can be used with {@link #TYPE_DIGITS}. 460 */ 461 public static final String ARG_DIGITS = "android.arg.digits"; 462 463 /** 464 * Argument used to specify a string where the characters are read verbatim, 465 * except whitespace. 466 * Can be used with {@link #TYPE_VERBATIM}. 467 */ 468 public static final String ARG_VERBATIM = "android.arg.verbatim"; 469 470 public TtsSpan(String type, PersistableBundle args) { 471 mType = type; 472 mArgs = args; 473 } 474 475 public TtsSpan(Parcel src) { 476 mType = src.readString(); 477 mArgs = src.readPersistableBundle(); 478 } 479 480 /** 481 * Returns the type. 482 * @return The type of this instance. 483 */ 484 public String getType() { 485 return mType; 486 } 487 488 /** 489 * Returns a bundle of the arguments set. 490 * @return The bundle of the arguments set. 491 */ 492 public PersistableBundle getArgs() { 493 return mArgs; 494 } 495 496 @Override 497 public int describeContents() { 498 return 0; 499 } 500 501 @Override 502 public void writeToParcel(Parcel dest, int flags) { 503 dest.writeString(mType); 504 dest.writePersistableBundle(mArgs); 505 } 506 507 @Override 508 public int getSpanTypeId() { 509 return TextUtils.TTS_SPAN; 510 } 511 512 /** 513 * A simple builder for TtsSpans. 514 * This builder can be used directly, but the more specific subclasses of 515 * this builder like {@link TtsSpan.TextBuilder} and 516 * {@link TtsSpan.CardinalBuilder} are likely more useful. 517 * 518 * This class uses generics so methods from this class can return instances 519 * of its child classes, resulting in a fluent API (CRTP pattern). 520 */ 521 public static abstract class Builder<C extends Builder<C>> { 522 // Holds the type of this class. 523 private final String mType; 524 525 // Holds the arguments of this class. It only stores objects of type 526 // String, Integer and Long. 527 private PersistableBundle mArgs = new PersistableBundle(); 528 529 public Builder(String type) { 530 mType = type; 531 } 532 533 /** 534 * Returns a TtsSpan built from the parameters set by the setter 535 * methods. 536 * @return A TtsSpan built with parameters of this builder. 537 */ 538 public TtsSpan build() { 539 return new TtsSpan(mType, mArgs); 540 } 541 542 /** 543 * Sets an argument to a string value. 544 * @param arg The argument name. 545 * @param value The value the argument should be set to. 546 * @return This instance. 547 */ 548 @SuppressWarnings("unchecked") 549 public C setStringArgument(String arg, String value) { 550 mArgs.putString(arg, value); 551 return (C) this; 552 } 553 554 /** 555 * Sets an argument to an int value. 556 * @param arg The argument name. 557 * @param value The value the argument should be set to. 558 */ 559 @SuppressWarnings("unchecked") 560 public C setIntArgument(String arg, int value) { 561 mArgs.putInt(arg, value); 562 return (C) this; 563 } 564 565 /** 566 * Sets an argument to a long value. 567 * @param arg The argument name. 568 * @param value The value the argument should be set to. 569 */ 570 @SuppressWarnings("unchecked") 571 public C setLongArgument(String arg, long value) { 572 mArgs.putLong(arg, value); 573 return (C) this; 574 } 575 } 576 577 /** 578 * A builder for TtsSpans, has setters for morphosyntactic features. 579 * This builder can be used directly, but the more specific subclasses of 580 * this builder like {@link TtsSpan.TextBuilder} and 581 * {@link TtsSpan.CardinalBuilder} are likely more useful. 582 */ 583 public static class SemioticClassBuilder<C extends SemioticClassBuilder<C>> 584 extends Builder<C> { 585 586 public SemioticClassBuilder(String type) { 587 super(type); 588 } 589 590 /** 591 * Sets the gender information for this instance. 592 * @param gender Can any of {@link TtsSpan#GENDER_NEUTRAL}, 593 * {@link TtsSpan#GENDER_MALE} and {@link TtsSpan#GENDER_FEMALE}. 594 * @return This instance. 595 */ 596 public C setGender(String gender) { 597 return setStringArgument(TtsSpan.ARG_GENDER, gender); 598 } 599 600 /** 601 * Sets the animacy information for this instance. 602 * @param animacy Can be any of {@link TtsSpan#ANIMACY_ANIMATE} and 603 * {@link TtsSpan#ANIMACY_INANIMATE}. 604 * @return This instance. 605 */ 606 public C setAnimacy(String animacy) { 607 return setStringArgument(TtsSpan.ARG_ANIMACY, animacy); 608 } 609 610 /** 611 * Sets the multiplicity information for this instance. 612 * @param multiplicity Can be any of 613 * {@link TtsSpan#MULTIPLICITY_SINGLE}, 614 * {@link TtsSpan#MULTIPLICITY_DUAL} and 615 * {@link TtsSpan#MULTIPLICITY_PLURAL}. 616 * @return This instance. 617 */ 618 public C setMultiplicity(String multiplicity) { 619 return setStringArgument(TtsSpan.ARG_MULTIPLICITY, multiplicity); 620 } 621 622 /** 623 * Sets the grammatical case information for this instance. 624 * @param grammaticalCase Can be any of {@link TtsSpan#CASE_NOMINATIVE}, 625 * {@link TtsSpan#CASE_ACCUSATIVE}, {@link TtsSpan#CASE_DATIVE}, 626 * {@link TtsSpan#CASE_ABLATIVE}, {@link TtsSpan#CASE_GENITIVE}, 627 * {@link TtsSpan#CASE_VOCATIVE}, {@link TtsSpan#CASE_LOCATIVE} and 628 * {@link TtsSpan#CASE_INSTRUMENTAL}. 629 * @return This instance. 630 */ 631 public C setCase(String grammaticalCase) { 632 return setStringArgument(TtsSpan.ARG_CASE, grammaticalCase); 633 } 634 } 635 636 /** 637 * A builder for TtsSpans of type {@link TtsSpan #TYPE_TEXT}. 638 */ 639 public static class TextBuilder extends SemioticClassBuilder<TextBuilder> { 640 641 /** 642 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TEXT}. 643 */ 644 public TextBuilder() { 645 super(TtsSpan.TYPE_TEXT); 646 } 647 648 /** 649 * Creates a TtsSpan of type {@link TtsSpan#TYPE_TEXT} and sets the 650 * {@link TtsSpan#ARG_TEXT} argument. 651 * @param text The text to be synthesized. 652 * @see #setText(String) 653 */ 654 public TextBuilder(String text) { 655 this(); 656 setText(text); 657 } 658 659 /** 660 * Sets the {@link TtsSpan#ARG_TEXT} argument, the text to be 661 * synthesized. 662 * @param text The string that will be synthesized. 663 * @return This instance. 664 */ 665 public TextBuilder setText(String text) { 666 return setStringArgument(TtsSpan.ARG_TEXT, text); 667 } 668 } 669 670 /** 671 * A builder for TtsSpans of type {@link TtsSpan #TYPE_CARDINAL}. 672 */ 673 public static class CardinalBuilder 674 extends SemioticClassBuilder<CardinalBuilder> { 675 676 /** 677 * Creates a builder for a TtsSpan of type 678 * {@link TtsSpan#TYPE_CARDINAL}. 679 */ 680 public CardinalBuilder() { 681 super(TtsSpan.TYPE_CARDINAL); 682 } 683 684 /** 685 * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the 686 * {@link TtsSpan#ARG_NUMBER} argument. 687 * @param number The number to synthesize. 688 * @see #setNumber(long) 689 */ 690 public CardinalBuilder(long number) { 691 this(); 692 setNumber(number); 693 } 694 695 /** 696 * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the 697 * {@link TtsSpan#ARG_NUMBER} argument. 698 * @param number The number to synthesize. 699 * @see #setNumber(String) 700 */ 701 public CardinalBuilder(String number) { 702 this(); 703 setNumber(number); 704 } 705 706 /** 707 * Convenience method that converts the number to a String and set it to 708 * the value for {@link TtsSpan#ARG_NUMBER}. 709 * @param number The number that will be synthesized. 710 * @return This instance. 711 */ 712 public CardinalBuilder setNumber(long number) { 713 return setNumber(String.valueOf(number)); 714 } 715 716 /** 717 * Sets the {@link TtsSpan#ARG_NUMBER} argument. 718 * @param number A non-empty string of digits with an optional 719 * leading + or -. 720 * @return This instance. 721 */ 722 public CardinalBuilder setNumber(String number) { 723 return setStringArgument(TtsSpan.ARG_NUMBER, number); 724 } 725 } 726 727 /** 728 * A builder for TtsSpans of type {@link TtsSpan#TYPE_ORDINAL}. 729 */ 730 public static class OrdinalBuilder 731 extends SemioticClassBuilder<OrdinalBuilder> { 732 733 /** 734 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL}. 735 */ 736 public OrdinalBuilder() { 737 super(TtsSpan.TYPE_ORDINAL); 738 } 739 740 /** 741 * Creates a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL} and sets the 742 * {@link TtsSpan#ARG_NUMBER} argument. 743 * @param number The ordinal number to synthesize. 744 * @see #setNumber(long) 745 */ 746 public OrdinalBuilder(long number) { 747 this(); 748 setNumber(number); 749 } 750 751 /** 752 * Creates a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL} and sets the 753 * {@link TtsSpan#ARG_NUMBER} argument. 754 * @param number The number to synthesize. 755 * @see #setNumber(String) 756 */ 757 public OrdinalBuilder(String number) { 758 this(); 759 setNumber(number); 760 } 761 762 /** 763 * Convenience method that converts the number to a String and sets it 764 * to the value for {@link TtsSpan#ARG_NUMBER}. 765 * @param number The ordinal number that will be synthesized. 766 * @return This instance. 767 */ 768 public OrdinalBuilder setNumber(long number) { 769 return setNumber(String.valueOf(number)); 770 } 771 772 /** 773 * Sets the {@link TtsSpan#ARG_NUMBER} argument. 774 * @param number A non-empty string of digits with an optional 775 * leading + or -. 776 * @return This instance. 777 */ 778 public OrdinalBuilder setNumber(String number) { 779 return setStringArgument(TtsSpan.ARG_NUMBER, number); 780 } 781 } 782 783 /** 784 * A builder for TtsSpans of type {@link TtsSpan#TYPE_DECIMAL}. 785 */ 786 public static class DecimalBuilder 787 extends SemioticClassBuilder<DecimalBuilder> { 788 789 /** 790 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL}. 791 */ 792 public DecimalBuilder() { 793 super(TtsSpan.TYPE_DECIMAL); 794 } 795 796 /** 797 * Creates a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL} and sets the 798 * {@link TtsSpan#ARG_INTEGER_PART} and 799 * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments. 800 * @see {@link #setArgumentsFromDouble(double, int, int) 801 */ 802 public DecimalBuilder(double number, 803 int minimumFractionDigits, 804 int maximumFractionDigits) { 805 this(); 806 setArgumentsFromDouble(number, 807 minimumFractionDigits, 808 maximumFractionDigits); 809 } 810 811 /** 812 * Creates a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL} and sets the 813 * {@link TtsSpan#ARG_INTEGER_PART} and 814 * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments. 815 */ 816 public DecimalBuilder(String integerPart, String fractionalPart) { 817 this(); 818 setIntegerPart(integerPart); 819 setFractionalPart(fractionalPart); 820 } 821 822 /** 823 * Convenience method takes a double and a maximum number of fractional 824 * digits, it sets the {@link TtsSpan#ARG_INTEGER_PART} and 825 * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments. 826 * @param number The number to be synthesized. 827 * @param minimumFractionDigits The minimum number of fraction digits 828 * that are pronounced. 829 * @param maximumFractionDigits The maximum number of fraction digits 830 * that are pronounced. If maximumFractionDigits < 831 * minimumFractionDigits then minimumFractionDigits will be assumed 832 * to be equal to maximumFractionDigits. 833 * @return This instance. 834 */ 835 public DecimalBuilder setArgumentsFromDouble( 836 double number, 837 int minimumFractionDigits, 838 int maximumFractionDigits) { 839 // Format double. 840 NumberFormat formatter = NumberFormat.getInstance(Locale.US); 841 formatter.setMinimumFractionDigits(maximumFractionDigits); 842 formatter.setMaximumFractionDigits(maximumFractionDigits); 843 formatter.setGroupingUsed(false); 844 String str = formatter.format(number); 845 846 // Split at decimal point. 847 int i = str.indexOf('.'); 848 if (i >= 0) { 849 setIntegerPart(str.substring(0, i)); 850 setFractionalPart(str.substring(i + 1)); 851 } else { 852 setIntegerPart(str); 853 } 854 return this; 855 } 856 857 /** 858 * Convenience method that converts the number to a String and sets it 859 * to the value for {@link TtsSpan#ARG_INTEGER_PART}. 860 * @param integerPart The integer part of the decimal. 861 * @return This instance. 862 */ 863 public DecimalBuilder setIntegerPart(long integerPart) { 864 return setIntegerPart(String.valueOf(integerPart)); 865 } 866 867 /** 868 * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument. 869 * @param integerPart A non-empty string of digits with an optional 870 * leading + or -. 871 * @return This instance. 872 */ 873 public DecimalBuilder setIntegerPart(String integerPart) { 874 return setStringArgument(TtsSpan.ARG_INTEGER_PART, integerPart); 875 } 876 877 /** 878 * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument. 879 * @param fractionalPart A non-empty string of digits. 880 * @return This instance. 881 */ 882 public DecimalBuilder setFractionalPart(String fractionalPart) { 883 return setStringArgument(TtsSpan.ARG_FRACTIONAL_PART, 884 fractionalPart); 885 } 886 } 887 888 /** 889 * A builder for TtsSpans of type {@link TtsSpan#TYPE_FRACTION}. 890 */ 891 public static class FractionBuilder 892 extends SemioticClassBuilder<FractionBuilder> { 893 894 /** 895 * Creates a builder for a TtsSpan of type 896 * {@link TtsSpan#TYPE_FRACTION}. 897 */ 898 public FractionBuilder() { 899 super(TtsSpan.TYPE_FRACTION); 900 } 901 902 /** 903 * Creates a TtsSpan of type {@link TtsSpan#TYPE_FRACTION} and sets the 904 * {@link TtsSpan#ARG_INTEGER_PART}, {@link TtsSpan#ARG_NUMERATOR}, and 905 * {@link TtsSpan#ARG_DENOMINATOR} arguments. 906 */ 907 public FractionBuilder(long integerPart, 908 long numerator, 909 long denominator) { 910 this(); 911 setIntegerPart(integerPart); 912 setNumerator(numerator); 913 setDenominator(denominator); 914 } 915 916 917 /** 918 * Convenience method that converts the integer to a String and sets the 919 * argument {@link TtsSpan#ARG_NUMBER}. 920 * @param integerPart The integer part. 921 * @return This instance. 922 */ 923 public FractionBuilder setIntegerPart(long integerPart) { 924 return setIntegerPart(String.valueOf(integerPart)); 925 } 926 927 /** 928 * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument. 929 * @param integerPart A non-empty string of digits with an optional 930 * leading + or -. 931 * @return This instance. 932 */ 933 public FractionBuilder setIntegerPart(String integerPart) { 934 return setStringArgument(TtsSpan.ARG_INTEGER_PART, integerPart); 935 } 936 937 /** 938 * Convenience method that converts the numerator to a String and sets 939 * the argument {@link TtsSpan#ARG_NUMERATOR}. 940 * @param numerator The numerator. 941 * @return This instance. 942 */ 943 public FractionBuilder setNumerator(long numerator) { 944 return setNumerator(String.valueOf(numerator)); 945 } 946 947 /** 948 * Sets the {@link TtsSpan#ARG_NUMERATOR} argument. 949 * @param numerator A non-empty string of digits with an optional 950 * leading + or -. 951 * @return This instance. 952 */ 953 public FractionBuilder setNumerator(String numerator) { 954 return setStringArgument(TtsSpan.ARG_NUMERATOR, numerator); 955 } 956 957 /** 958 * Convenience method that converts the denominator to a String and sets 959 * the argument {@link TtsSpan#ARG_DENOMINATOR}. 960 * @param denominator The denominator. 961 * @return This instance. 962 */ 963 public FractionBuilder setDenominator(long denominator) { 964 return setDenominator(String.valueOf(denominator)); 965 } 966 967 /** 968 * Sets the {@link TtsSpan#ARG_DENOMINATOR} argument. 969 * @param denominator A non-empty string of digits with an optional 970 * leading + or -. 971 * @return This instance. 972 */ 973 public FractionBuilder setDenominator(String denominator) { 974 return setStringArgument(TtsSpan.ARG_DENOMINATOR, denominator); 975 } 976 } 977 978 /** 979 * A builder for TtsSpans of type {@link TtsSpan #TYPE_MEASURE}. 980 */ 981 public static class MeasureBuilder 982 extends SemioticClassBuilder<MeasureBuilder> { 983 984 /** 985 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_MEASURE}. 986 */ 987 public MeasureBuilder() { 988 super(TtsSpan.TYPE_MEASURE); 989 } 990 991 /** 992 * Convenience method that converts the number to a String and set it to 993 * the value for {@link TtsSpan#ARG_NUMBER}. 994 * @param number The amount of the measure. 995 * @return This instance. 996 */ 997 public MeasureBuilder setNumber(long number) { 998 return setNumber(String.valueOf(number)); 999 } 1000 1001 /** 1002 * Sets the {@link TtsSpan#ARG_NUMBER} argument. 1003 * @param number A non-empty string of digits with an optional 1004 * leading + or -. 1005 * @return This instance. 1006 */ 1007 public MeasureBuilder setNumber(String number) { 1008 return setStringArgument(TtsSpan.ARG_NUMBER, number); 1009 } 1010 1011 /** 1012 * Convenience method that converts the integer part to a String and set 1013 * it to the value for {@link TtsSpan#ARG_INTEGER_PART}. 1014 * @param integerPart The integer part of a decimal or fraction. 1015 * @return This instance. 1016 */ 1017 public MeasureBuilder setIntegerPart(long integerPart) { 1018 return setNumber(String.valueOf(integerPart)); 1019 } 1020 1021 /** 1022 * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument. 1023 * @param integerPart The integer part of a decimal or fraction; a 1024 * non-empty string of digits with an optional 1025 * leading + or -. 1026 * @return This instance. 1027 */ 1028 public MeasureBuilder setIntegerPart(String integerPart) { 1029 return setStringArgument(TtsSpan.ARG_INTEGER_PART, integerPart); 1030 } 1031 1032 /** 1033 * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument. 1034 * @param fractionalPart The fractional part of a decimal; a non-empty 1035 * string of digits with an optional 1036 * leading + or -. 1037 * @return This instance. 1038 */ 1039 public MeasureBuilder setFractionalPart(String fractionalPart) { 1040 return setStringArgument(TtsSpan.ARG_FRACTIONAL_PART, 1041 fractionalPart); 1042 } 1043 1044 /** 1045 * Convenience method that converts the numerator to a String and set it 1046 * to the value for {@link TtsSpan#ARG_NUMERATOR}. 1047 * @param numerator The numerator of a fraction. 1048 * @return This instance. 1049 */ 1050 public MeasureBuilder setNumerator(long numerator) { 1051 return setNumerator(String.valueOf(numerator)); 1052 } 1053 1054 /** 1055 * Sets the {@link TtsSpan#ARG_NUMERATOR} argument. 1056 * @param numerator The numerator of a fraction; a non-empty string of 1057 * digits with an optional leading + or -. 1058 * @return This instance. 1059 */ 1060 public MeasureBuilder setNumerator(String numerator) { 1061 return setStringArgument(TtsSpan.ARG_NUMERATOR, numerator); 1062 } 1063 1064 /** 1065 * Convenience method that converts the denominator to a String and set 1066 * it to the value for {@link TtsSpan#ARG_DENOMINATOR}. 1067 * @param denominator The denominator of a fraction. 1068 * @return This instance. 1069 */ 1070 public MeasureBuilder setDenominator(long denominator) { 1071 return setDenominator(String.valueOf(denominator)); 1072 } 1073 1074 /** 1075 * Sets the {@link TtsSpan#ARG_DENOMINATOR} argument. 1076 * @param denominator The denominator of a fraction; a non-empty string 1077 * of digits with an optional leading + or -. 1078 * @return This instance. 1079 */ 1080 public MeasureBuilder setDenominator(String denominator) { 1081 return setStringArgument(TtsSpan.ARG_DENOMINATOR, denominator); 1082 } 1083 1084 /** 1085 * Sets the {@link TtsSpan#ARG_UNIT} argument. 1086 * @param unit The unit of the measure. 1087 * @return This instance. 1088 * @see {@link TtsSpan.ARG_UNIT} 1089 */ 1090 public MeasureBuilder setUnit(String unit) { 1091 return setStringArgument(TtsSpan.ARG_UNIT, unit); 1092 } 1093 } 1094 1095 /** 1096 * A builder for TtsSpans of type {@link TtsSpan #TYPE_TIME}. 1097 */ 1098 public static class TimeBuilder 1099 extends SemioticClassBuilder<TimeBuilder> { 1100 1101 /** 1102 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME}. 1103 */ 1104 public TimeBuilder() { 1105 super(TtsSpan.TYPE_TIME); 1106 } 1107 1108 /** 1109 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME} and 1110 * sets the {@link TtsSpan#ARG_HOURS} and {@link TtsSpan#ARG_MINUTES} 1111 * arguments. 1112 */ 1113 public TimeBuilder(int hours, int minutes) { 1114 this(); 1115 setHours(hours); 1116 setMinutes(minutes); 1117 } 1118 1119 /** 1120 * Sets the {@link TtsSpan#ARG_HOURS} argument. 1121 * @param hours The value to be set for hours. See 1122 * {@link TtsSpan#ARG_HOURS}. 1123 * @return This instance. 1124 * @see {@link TtsSpan#ARG_HOURS} 1125 */ 1126 public TimeBuilder setHours(int hours) { 1127 return setIntArgument(TtsSpan.ARG_HOURS, hours); 1128 } 1129 1130 /** 1131 * Sets the {@link TtsSpan#ARG_MINUTES} argument. 1132 * @param minutes The value to be set for minutes. See 1133 * {@link TtsSpan#ARG_MINUTES}. 1134 * @return This instance. 1135 * @see {@link TtsSpan#ARG_MINUTES} 1136 */ 1137 public TimeBuilder setMinutes(int minutes) { 1138 return setIntArgument(TtsSpan.ARG_MINUTES, minutes); 1139 } 1140 } 1141 1142 /** 1143 * A builder for TtsSpans of type {@link TtsSpan #TYPE_DATE}. 1144 */ 1145 public static class DateBuilder 1146 extends SemioticClassBuilder<DateBuilder> { 1147 1148 /** 1149 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DATE}. 1150 */ 1151 public DateBuilder() { 1152 super(TtsSpan.TYPE_DATE); 1153 } 1154 1155 /** 1156 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME} and 1157 * possibly sets the {@link TtsSpan#ARG_WEEKDAY}, 1158 * {@link TtsSpan#ARG_DAY}, {@link TtsSpan#ARG_MONTH} and 1159 * {@link TtsSpan#ARG_YEAR} arguments. Pass null to any argument to 1160 * leave it unset. 1161 */ 1162 public DateBuilder(Integer weekday, 1163 Integer day, 1164 Integer month, 1165 Integer year) { 1166 this(); 1167 if (weekday != null) { 1168 setWeekday(weekday); 1169 } 1170 if (day != null) { 1171 setDay(day); 1172 } 1173 if (month != null) { 1174 setMonth(month); 1175 } 1176 if (year != null) { 1177 setYear(year); 1178 } 1179 } 1180 1181 /** 1182 * Sets the {@link TtsSpan#ARG_WEEKDAY} argument. 1183 * @param weekday The value to be set for weekday. See 1184 * {@link TtsSpan#ARG_WEEKDAY}. 1185 * @return This instance. 1186 * @see {@link TtsSpan#ARG_WEEKDAY} 1187 */ 1188 public DateBuilder setWeekday(int weekday) { 1189 return setIntArgument(TtsSpan.ARG_WEEKDAY, weekday); 1190 } 1191 1192 /** 1193 * Sets the {@link TtsSpan#ARG_DAY} argument. 1194 * @param day The value to be set for day. See 1195 * {@link TtsSpan#ARG_DAY}. 1196 * @return This instance. 1197 * @see {@link TtsSpan#ARG_DAY} 1198 */ 1199 public DateBuilder setDay(int day) { 1200 return setIntArgument(TtsSpan.ARG_DAY, day); 1201 } 1202 1203 /** 1204 * Sets the {@link TtsSpan#ARG_MONTH} argument. 1205 * @param month The value to be set for month. See 1206 * {@link TtsSpan#ARG_MONTH}. 1207 * @return This instance. 1208 * @see {@link TtsSpan#ARG_MONTH} 1209 */ 1210 public DateBuilder setMonth(int month) { 1211 return setIntArgument(TtsSpan.ARG_MONTH, month); 1212 } 1213 1214 /** 1215 * Sets the {@link TtsSpan#ARG_YEAR} argument. 1216 * @param year The value to be set for year. See 1217 * {@link TtsSpan#ARG_YEAR}. 1218 * @return This instance. 1219 * @see {@link TtsSpan#ARG_YEAR} 1220 */ 1221 public DateBuilder setYear(int year) { 1222 return setIntArgument(TtsSpan.ARG_YEAR, year); 1223 } 1224 } 1225 1226 /** 1227 * A builder for TtsSpans of type {@link TtsSpan #TYPE_MONEY}. 1228 */ 1229 public static class MoneyBuilder 1230 extends SemioticClassBuilder<MoneyBuilder> { 1231 1232 /** 1233 * Creates a TtsSpan of type {@link TtsSpan#TYPE_MONEY}. 1234 */ 1235 public MoneyBuilder() { 1236 super(TtsSpan.TYPE_MONEY); 1237 } 1238 1239 /** 1240 * Convenience method that converts the number to a String and set it to 1241 * the value for {@link TtsSpan#ARG_INTEGER_PART}. 1242 * @param integerPart The integer part of the amount. 1243 * @return This instance. 1244 */ 1245 public MoneyBuilder setIntegerPart(long integerPart) { 1246 return setIntegerPart(String.valueOf(integerPart)); 1247 } 1248 1249 /** 1250 * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument. 1251 * @param integerPart A non-empty string of digits with an optional 1252 * leading + or -. 1253 * @return This instance. 1254 */ 1255 public MoneyBuilder setIntegerPart(String integerPart) { 1256 return setStringArgument(TtsSpan.ARG_INTEGER_PART, integerPart); 1257 } 1258 1259 /** 1260 * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument. 1261 * @param fractionalPart Can be a string of digits of any size. 1262 * @return This instance. 1263 */ 1264 public MoneyBuilder setFractionalPart(String fractionalPart) { 1265 return setStringArgument(TtsSpan.ARG_FRACTIONAL_PART, fractionalPart); 1266 } 1267 1268 /** 1269 * Sets the {@link TtsSpan#ARG_CURRENCY} argument. 1270 * @param currency Should be a ISO4217 currency code, e.g. "USD". 1271 * @return This instance. 1272 */ 1273 public MoneyBuilder setCurrency(String currency) { 1274 return setStringArgument(TtsSpan.ARG_CURRENCY, currency); 1275 } 1276 1277 /** 1278 * Sets the {@link TtsSpan#ARG_QUANTITY} argument. 1279 * @param quantity 1280 * @return This instance. 1281 */ 1282 public MoneyBuilder setQuantity(String quantity) { 1283 return setStringArgument(TtsSpan.ARG_QUANTITY, quantity); 1284 } 1285 } 1286 1287 /** 1288 * A builder for TtsSpans of type {@link TtsSpan #TYPE_TELEPHONE}. 1289 */ 1290 public static class TelephoneBuilder 1291 extends SemioticClassBuilder<TelephoneBuilder> { 1292 1293 /** 1294 * Creates a TtsSpan of type {@link TtsSpan#TYPE_TELEPHONE}. 1295 */ 1296 public TelephoneBuilder() { 1297 super(TtsSpan.TYPE_TELEPHONE); 1298 } 1299 1300 /** 1301 * Creates a TtsSpan of type {@link TtsSpan#TYPE_TELEPHONE} and sets the 1302 * {@link TtsSpan#ARG_NUMBER_PARTS} argument. 1303 */ 1304 public TelephoneBuilder(String numberParts) { 1305 this(); 1306 setNumberParts(numberParts); 1307 } 1308 1309 /** 1310 * Sets the {@link TtsSpan#ARG_COUNTRY_CODE} argument. 1311 * @param countryCode The country code can be a series of digits 1312 * optionally prefixed with a "+". 1313 * @return This instance. 1314 */ 1315 public TelephoneBuilder setCountryCode(String countryCode) { 1316 return setStringArgument(TtsSpan.ARG_COUNTRY_CODE, countryCode); 1317 } 1318 1319 /** 1320 * Sets the {@link TtsSpan#ARG_NUMBER_PARTS} argument. 1321 * @param numberParts The main telephone number. Can be a series of 1322 * digits and letters separated by spaces, "/", "-" or ".". 1323 * @return This instance. 1324 */ 1325 public TelephoneBuilder setNumberParts(String numberParts) { 1326 return setStringArgument(TtsSpan.ARG_NUMBER_PARTS, numberParts); 1327 } 1328 1329 /** 1330 * Sets the {@link TtsSpan#ARG_EXTENSION} argument. 1331 * @param extension The extension can be a series of digits. 1332 * @return This instance. 1333 */ 1334 public TelephoneBuilder setExtension(String extension) { 1335 return setStringArgument(TtsSpan.ARG_EXTENSION, extension); 1336 } 1337 } 1338 1339 /** 1340 * A builder for TtsSpans of type {@link TtsSpan #TYPE_ELECTRONIC}. 1341 */ 1342 public static class ElectronicBuilder 1343 extends SemioticClassBuilder<ElectronicBuilder> { 1344 1345 /** 1346 * Creates a TtsSpan of type {@link TtsSpan#TYPE_ELECTRONIC}. 1347 */ 1348 public ElectronicBuilder() { 1349 super(TtsSpan.TYPE_ELECTRONIC); 1350 } 1351 1352 /** 1353 * Sets the {@link TtsSpan#ARG_USERNAME} and {@link TtsSpan#ARG_DOMAIN} 1354 * arguments, representing an email address. 1355 * @param username The part before the @ in the email address. 1356 * @param domain The part after the @ in the email address. 1357 * @return This instance. 1358 */ 1359 public ElectronicBuilder setEmailArguments(String username, 1360 String domain) { 1361 return setDomain(domain).setUsername(username); 1362 } 1363 1364 /** 1365 * Sets the {@link TtsSpan#ARG_PROTOCOL} argument. 1366 * @param protocol The protocol of the URI. Examples are "http" and 1367 * "ftp". 1368 * @return This instance. 1369 */ 1370 public ElectronicBuilder setProtocol(String protocol) { 1371 return setStringArgument(TtsSpan.ARG_PROTOCOL, protocol); 1372 } 1373 1374 /** 1375 * Sets the {@link TtsSpan#ARG_USERNAME} argument. 1376 * @return This instance. 1377 */ 1378 public ElectronicBuilder setUsername(String username) { 1379 return setStringArgument(TtsSpan.ARG_USERNAME, username); 1380 } 1381 1382 /** 1383 * Sets the {@link TtsSpan#ARG_PASSWORD} argument. 1384 * @return This instance. 1385 */ 1386 public ElectronicBuilder setPassword(String password) { 1387 return setStringArgument(TtsSpan.ARG_PASSWORD, password); 1388 } 1389 1390 /** 1391 * Sets the {@link TtsSpan#ARG_DOMAIN} argument. 1392 * @param domain The domain, for example "source.android.com". 1393 * @return This instance. 1394 */ 1395 public ElectronicBuilder setDomain(String domain) { 1396 return setStringArgument(TtsSpan.ARG_DOMAIN, domain); 1397 } 1398 1399 /** 1400 * Sets the {@link TtsSpan#ARG_PORT} argument. 1401 * @return This instance. 1402 */ 1403 public ElectronicBuilder setPort(int port) { 1404 return setIntArgument(TtsSpan.ARG_PORT, port); 1405 } 1406 1407 /** 1408 * Sets the {@link TtsSpan#ARG_PATH} argument. 1409 * @param path For example "source/index.html". 1410 * @return This instance. 1411 */ 1412 public ElectronicBuilder setPath(String path) { 1413 return setStringArgument(TtsSpan.ARG_PATH, path); 1414 } 1415 1416 /** 1417 * Sets the {@link TtsSpan#ARG_QUERY_STRING} argument. 1418 * @param queryString For example "arg=value&argtwo=value". 1419 * @return This instance. 1420 */ 1421 public ElectronicBuilder setQueryString(String queryString) { 1422 return setStringArgument(TtsSpan.ARG_QUERY_STRING, queryString); 1423 } 1424 1425 /** 1426 * Sets the {@link TtsSpan#ARG_FRAGMENT_ID} argument. 1427 * @return This instance. 1428 */ 1429 public ElectronicBuilder setFragmentId(String fragmentId) { 1430 return setStringArgument(TtsSpan.ARG_FRAGMENT_ID, fragmentId); 1431 } 1432 } 1433 1434 /** 1435 * A builder for TtsSpans of type {@link TtsSpan #TYPE_DIGITS}. 1436 */ 1437 public static class DigitsBuilder 1438 extends SemioticClassBuilder<DigitsBuilder> { 1439 1440 /** 1441 * Creates a builder for a TtsSpan of type 1442 * {@link TtsSpan#TYPE_VERBATIM}. 1443 */ 1444 public DigitsBuilder() { 1445 super(TtsSpan.TYPE_DIGITS); 1446 } 1447 1448 /** 1449 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DIGITS} 1450 * and sets the {@link TtsSpan#ARG_DIGITS} argument. 1451 */ 1452 public DigitsBuilder(String digits) { 1453 this(); 1454 setDigits(digits); 1455 } 1456 1457 /** 1458 * Sets the {@link TtsSpan#ARG_DIGITS} argument. 1459 * @param digits A string of digits. 1460 * @return This instance. 1461 */ 1462 public DigitsBuilder setDigits(String digits) { 1463 return setStringArgument(TtsSpan.ARG_DIGITS, digits); 1464 } 1465 } 1466 1467 /** 1468 * A builder for TtsSpans of type {@link TtsSpan #TYPE_VERBATIM}. 1469 */ 1470 public static class VerbatimBuilder 1471 extends SemioticClassBuilder<VerbatimBuilder> { 1472 1473 /** 1474 * Creates a builder for a TtsSpan of type 1475 * {@link TtsSpan#TYPE_VERBATIM}. 1476 */ 1477 public VerbatimBuilder() { 1478 super(TtsSpan.TYPE_VERBATIM); 1479 } 1480 1481 /** 1482 * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_VERBATIM} 1483 * and sets the {@link TtsSpan#ARG_VERBATIM} argument. 1484 */ 1485 public VerbatimBuilder(String verbatim) { 1486 this(); 1487 setVerbatim(verbatim); 1488 } 1489 1490 /** 1491 * Sets the {@link TtsSpan#ARG_VERBATIM} argument. 1492 * @param verbatim A string of characters that will be read verbatim, 1493 * except whitespace. 1494 * @return This instance. 1495 */ 1496 public VerbatimBuilder setVerbatim(String verbatim) { 1497 return setStringArgument(TtsSpan.ARG_VERBATIM, verbatim); 1498 } 1499 } 1500} 1501