FileDocCategorySizeDatePackage
StatusBarNotifier.javaAPI DocAndroid 1.5 API12358Wed May 06 22:42:46 BST 2009com.android.im.service

StatusBarNotifier

public class StatusBarNotifier extends Object

Fields Summary
private static final boolean
DBG
private static final long
SUPPRESS_SOUND_INTERVAL_MS
static final long[]
VIBRATE_PATTERN
private android.content.Context
mContext
private android.app.NotificationManager
mNotificationManager
private HashMap
mSettings
private android.os.Handler
mHandler
private HashMap
mNotificationInfos
private long
mLastSoundPlayedMs
Constructors Summary
public StatusBarNotifier(android.content.Context context)


       
        mContext = context;
        mNotificationManager = (NotificationManager) context.getSystemService(
                Context.NOTIFICATION_SERVICE);
        mSettings = new HashMap<Long, Im.ProviderSettings.QueryMap>();
        mHandler = new Handler();
        mNotificationInfos = new HashMap<Long, NotificationInfo>();
    
Methods Summary
public voiddismissChatNotification(long providerId, java.lang.String username)

        NotificationInfo info;
        boolean removed;
        synchronized (mNotificationInfos) {
            info = mNotificationInfos.get(providerId);
            if (info == null) {
                return;
            }
            removed = info.removeItem(username);
        }

        if (removed) {
            if (info.getMessage() == null) {
                if (DBG) log("dismissChatNotification: removed notification for " + providerId);
                mNotificationManager.cancel(info.computeNotificationId());
            } else {
                if (DBG) {
                    log("cancelNotify: new notification" +
                            " mTitle=" + info.getTitle() +
                            " mMessage=" + info.getMessage() +
                            " mIntent=" + info.getIntent());
                }
                mNotificationManager.notify(info.computeNotificationId(),
                        info.createNotification("", true));
            }
        }
    
public voiddismissNotifications(long providerId)

        synchronized (mNotificationInfos) {
            NotificationInfo info = mNotificationInfos.get(providerId);
            if (info != null) {
                mNotificationManager.cancel(info.computeNotificationId());
                mNotificationInfos.remove(providerId);
            }
        }
    
private Im.ProviderSettings.QueryMapgetProviderSettings(long providerId)

        Im.ProviderSettings.QueryMap res = mSettings.get(providerId);
        if (res == null) {
            res = new Im.ProviderSettings.QueryMap(mContext.getContentResolver(),
                    providerId, true, mHandler);
            mSettings.put(providerId, res);
        }
        return res;
    
private booleanisNotificationEnabled(long providerId)

        Im.ProviderSettings.QueryMap settings = getProviderSettings(providerId);
        return settings.getEnableNotification();
    
private static voidlog(java.lang.String msg)

        Log.d(RemoteImService.TAG, "[StatusBarNotify] " + msg);
    
private voidnotify(java.lang.String sender, java.lang.String title, java.lang.String tickerText, java.lang.String message, long providerId, long accountId, android.content.Intent intent, boolean lightWeightNotify)

        NotificationInfo info;
        synchronized (mNotificationInfos) {
            info = mNotificationInfos.get(providerId);
            if (info == null) {
                info = new NotificationInfo(providerId, accountId);
                mNotificationInfos.put(providerId, info);
            }
            info.addItem(sender, title, message, intent);
        }

        mNotificationManager.notify(info.computeNotificationId(),
                info.createNotification(tickerText, lightWeightNotify));
    
public voidnotifyChat(long providerId, long accountId, long chatId, java.lang.String username, java.lang.String nickname, java.lang.String msg, boolean lightWeightNotify)

        if (!isNotificationEnabled(providerId)) {
            if (DBG) log("notification for chat " + username + " is not enabled");
            return;
        }

        String title = nickname;
        String snippet = nickname + ": " + msg;
        Intent intent = new Intent(Intent.ACTION_VIEW,
                ContentUris.withAppendedId(Im.Chats.CONTENT_URI, chatId));
        intent.addCategory(com.android.im.app.ImApp.IMPS_CATEGORY);
        notify(username, title, snippet, msg, providerId, accountId, intent, lightWeightNotify);
    
public voidnotifyGroupInvitation(long providerId, long accountId, long invitationId, java.lang.String username)


        Intent intent = new Intent(Intent.ACTION_VIEW,
                ContentUris.withAppendedId(Im.Invitation.CONTENT_URI, invitationId));

        String title = mContext.getString(R.string.notify_groupchat_label);
        String message = mContext.getString(
                R.string.group_chat_invite_notify_text, username);
        notify(username, title, message, message, providerId, accountId, intent, false);
    
public voidnotifySubscriptionRequest(long providerId, long accountId, long contactId, java.lang.String username, java.lang.String nickname)

        if (!isNotificationEnabled(providerId)) {
            if (DBG) log("notification for subscription request " + username + " is not enabled");
            return;
        }
        String title = nickname;
        String message = mContext.getString(R.string.subscription_notify_text, nickname);
        Intent intent = new Intent(ImServiceConstants.ACTION_MANAGE_SUBSCRIPTION,
                ContentUris.withAppendedId(Im.Contacts.CONTENT_URI, contactId));
        intent.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, providerId);
        intent.putExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS, username);
        notify(username, title, message, message, providerId, accountId, intent, false);
    
public voidonServiceStop()

        for(Im.ProviderSettings.QueryMap queryMap : mSettings.values()) {
            queryMap.close();
        }
    
private voidsetRinger(long providerId, android.app.Notification notification)

        Im.ProviderSettings.QueryMap settings = getProviderSettings(providerId);
        String ringtoneUri = settings.getRingtoneURI();
        boolean vibrate = settings.getVibrate();

        notification.sound = TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri);
        if (notification.sound != null) {
            mLastSoundPlayedMs = SystemClock.elapsedRealtime();
        }

        if (DBG) log("setRinger: notification.sound = " + notification.sound);

        if (vibrate) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
            if (DBG) log("setRinger: defaults |= vibrate");
        }
    
private booleanshouldSuppressSoundNotification()

        return (SystemClock.elapsedRealtime() - mLastSoundPlayedMs < SUPPRESS_SOUND_INTERVAL_MS);