1 /*
2  * Copyright 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 
17 package com.example.android.activenotifications;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.os.Bundle;
24 import android.os.PersistableBundle;
25 
26 public class ActiveNotificationsActivity extends MainActivity {
27 
28     private ActiveNotificationsFragment mFragment;
29 
30     protected static final String ACTION_NOTIFICATION_DELETE
31             = "com.example.android.activenotifications.delete";
32 
33     private BroadcastReceiver mDeleteReceiver = new BroadcastReceiver() {
34         @Override
35         public void onReceive(Context context, Intent intent) {
36             if (mFragment == null) {
37                 findFragment();
38             }
39             mFragment.updateNumberOfNotifications();
40         }
41     };
42 
43     @Override
onCreate(Bundle savedInstanceState, PersistableBundle persistentState)44     public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
45         super.onCreate(savedInstanceState, persistentState);
46         findFragment();
47         mFragment.updateNumberOfNotifications();
48     }
49 
findFragment()50     private void findFragment() {
51         mFragment = (ActiveNotificationsFragment) getSupportFragmentManager()
52                 .findFragmentById(R.id.sample_content_fragment);
53     }
54 
55     @Override
onResume()56     protected void onResume() {
57         super.onResume();
58         registerReceiver(mDeleteReceiver, new IntentFilter(ACTION_NOTIFICATION_DELETE));
59     }
60 
61     @Override
onPause()62     protected void onPause() {
63         super.onPause();
64         unregisterReceiver(mDeleteReceiver);
65     }
66 }
67