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