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