PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/talkback_preics/src/com/google/android/marvin/talkback/formatter/calendar/DayViewWindowStateChangedFormatter.java

http://eyes-free.googlecode.com/
Java | 93 lines | 54 code | 17 blank | 22 comment | 5 complexity | c19fadabde40794022a57c51937650d9 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.calendar;
18
19import com.google.android.marvin.talkback.Formatter;
20import com.google.android.marvin.talkback.R;
21import com.google.android.marvin.talkback.Utterance;
22
23import android.content.Context;
24import android.os.Build;
25import android.os.Bundle;
26import android.view.accessibility.AccessibilityEvent;
27
28import java.util.regex.Pattern;
29
30/**
31 * This class is a custom formatter for the Day/Weekly/Monthly
32 * view of the Google Calendar application.
33 *
34 * @author svetoslavganov@google.com (Svetoslav R. Ganov)
35 *
36 */
37public class DayViewWindowStateChangedFormatter implements Formatter {
38
39    private static final int SDK_INT = Build.VERSION.SDK_INT;
40    
41    private static final int GINGERBREAD = 9;
42    
43    private static final int HONEYCOMB = 10;
44    
45    private static final char SPACE = ' ';
46
47    private static final char PERIOD = '.';
48
49    private static final char COMMA = ',';
50
51    private static final String KEY_SHOWN_DAY_COUNT = "shownDayCount";
52
53    private static final int WEEK_DAY_COUNT = 7;
54
55    private final Pattern mWeekSplitPattern = Pattern.compile(" \u2013 ");
56
57    @Override
58    public void format(AccessibilityEvent event, Context context, Utterance utterance,
59            Object args) {
60        StringBuilder textBuilder = utterance.getText();
61
62        CharSequence eventText = event.getText().get(0).toString();
63        switch (SDK_INT) {
64            case GINGERBREAD:
65                textBuilder.append(context.getString(R.string.template_announce_day, eventText));
66                break;
67            case HONEYCOMB:
68                Bundle bundle = (Bundle) event.getParcelableData();
69                int shownDayCount = bundle.getInt(KEY_SHOWN_DAY_COUNT);
70                if (shownDayCount == WEEK_DAY_COUNT) {
71                    String[] rangeFragments = mWeekSplitPattern.split(eventText);
72                    String fromDate = rangeFragments[0];
73                    String toDate = rangeFragments[1];
74                    textBuilder.append(context.getString(R.string.template_announce_week, fromDate,
75                            toDate));
76                } else {
77                    textBuilder.append(context.getString(R.string.template_announce_day, eventText));
78                }
79                break;
80        }
81
82        int todayEventCount = event.getAddedCount();
83        if (todayEventCount > 0) {
84            textBuilder.append(COMMA);
85            textBuilder.append(SPACE);
86            textBuilder.append(todayEventCount);
87            textBuilder.append(SPACE);
88            textBuilder.append(context.getResources().getQuantityString(R.plurals.plural_event,
89                    todayEventCount));
90        }
91        textBuilder.append(PERIOD);
92    }
93}