• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.android.messaging.receiver;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 
22 import com.android.messaging.datamodel.BugleNotifications;
23 import com.android.messaging.datamodel.action.MarkAsSeenAction;
24 import com.android.messaging.ui.UIIntents;
25 import com.android.messaging.util.ConversationIdSet;
26 import com.android.messaging.util.LogUtil;
27 
28 // NotificationReceiver is used to handle delete intents from notifications. When a user
29 // clears all notifications or swipes a bugle notification away, the intent we pass in as
30 // the delete intent will get handled here.
31 public class NotificationReceiver extends BroadcastReceiver {
32     // Logging
33     public static final String TAG = LogUtil.BUGLE_TAG;
34     public static final boolean VERBOSE = false;
35 
36     @Override
onReceive(final Context context, final Intent intent)37     public void onReceive(final Context context, final Intent intent) {
38         if (VERBOSE) {
39             LogUtil.v(TAG, "NotificationReceiver.onReceive: intent " + intent);
40         }
41         if (intent.getAction().equals(UIIntents.ACTION_RESET_NOTIFICATIONS)) {
42             final String conversationIdSetString =
43                     intent.getStringExtra(UIIntents.UI_INTENT_EXTRA_CONVERSATION_ID_SET);
44             final int notificationTargets = intent.getIntExtra(
45                     UIIntents.UI_INTENT_EXTRA_NOTIFICATIONS_UPDATE, BugleNotifications.UPDATE_ALL);
46             if (conversationIdSetString == null) {
47                 BugleNotifications.markAllMessagesAsSeen();
48             } else {
49                 for (final String conversationId :
50                         ConversationIdSet.createSet(conversationIdSetString)) {
51                     MarkAsSeenAction.markAsSeen(conversationId);
52                     BugleNotifications.resetLastMessageDing(conversationId);
53                 }
54             }
55         }
56     }
57 }