/talkback_preics/src/com/google/android/marvin/talkback/formatter/phone/NotificationFormatter.java

http://eyes-free.googlecode.com/ · Java · 67 lines · 35 code · 8 blank · 24 comment · 7 complexity · 743fdb39187efb5ce7f08ddf2053e9b3 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 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.phone;
  17. import com.google.android.marvin.talkback.Formatter;
  18. import com.google.android.marvin.talkback.NotificationType;
  19. import com.google.android.marvin.talkback.Utils;
  20. import com.google.android.marvin.talkback.Utterance;
  21. import android.app.Notification;
  22. import android.content.Context;
  23. import android.os.Parcelable;
  24. import android.view.accessibility.AccessibilityEvent;
  25. /**
  26. * Formatter that returns an utterance to announce text replacement.
  27. *
  28. * @author svetoslavganov@google.conm (Svetoslav R. Ganov)
  29. */
  30. public final class NotificationFormatter implements Formatter {
  31. private static final String SPACE = " ";
  32. @Override
  33. public void format(AccessibilityEvent event, Context context, Utterance utterance, Object args) {
  34. StringBuilder utteranceText = utterance.getText();
  35. StringBuilder eventText = Utils.getEventText(context, event);
  36. NotificationType type;
  37. Parcelable parcelable = event.getParcelableData();
  38. if (parcelable instanceof Notification) {
  39. int icon = ((Notification) parcelable).icon;
  40. // special case since the notification appears several
  41. // times while the phone call goes through different phases
  42. // resulting in multiple announcement of the fact that a phone
  43. // call is in progress which the user is already aware of
  44. if (icon == NotificationType.ICON_PHONE_CALL) {
  45. type = null; // ignore this notification
  46. } else {
  47. type = NotificationType.getNotificationTypeFromIcon(icon);
  48. }
  49. } else {
  50. type = null;
  51. }
  52. if (type != null) {
  53. CharSequence typeText = context.getResources().getString(type.getValue());
  54. utteranceText.append(typeText);
  55. utteranceText.append(SPACE);
  56. }
  57. utteranceText.append(eventText);
  58. }
  59. }