PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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