/talkback_preics/src/com/google/android/marvin/talkback/formatter/tv/CnbcStockQuoteFormatter.java

http://eyes-free.googlecode.com/ · Java · 51 lines · 25 code · 5 blank · 21 comment · 2 complexity · faffa61ff6acac107cbdded1c20d1ad3 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 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. package com.google.android.marvin.talkback.formatter.tv;
  17. import com.google.android.marvin.talkback.Formatter;
  18. import com.google.android.marvin.talkback.R;
  19. import com.google.android.marvin.talkback.TalkBackService;
  20. import com.google.android.marvin.talkback.Utterance;
  21. import android.content.Context;
  22. import android.view.accessibility.AccessibilityEvent;
  23. /**
  24. * Formatter that returns an utterance to announce a stock quote in
  25. * the CNBC application.
  26. *
  27. * @author svetoslavganov@google.com (Svetoslav R. Ganov)
  28. */
  29. public final class CnbcStockQuoteFormatter implements Formatter {
  30. @Override
  31. public void format(AccessibilityEvent event, Context context, Utterance utterance,
  32. Object args) {
  33. CharSequence abbreviation = event.getText().get(0);
  34. if (abbreviation.charAt(0) == '.') {
  35. abbreviation = abbreviation.subSequence(1, abbreviation.length());
  36. abbreviation = TalkBackService.getInstance().cleanUpString(abbreviation.toString());
  37. }
  38. CharSequence description = event.getText().get(2);
  39. CharSequence lastValue = event.getText().get(3);
  40. CharSequence absoluteChange = event.getText().get(4);
  41. CharSequence relativeChange = event.getText().get(5);
  42. String formattedText = context.getString(R.string.template_googletv_stock_quote,
  43. abbreviation, description, lastValue, absoluteChange, relativeChange);
  44. utterance.getText().append(formattedText);
  45. }
  46. }