• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.android.cellbroadcastreceiver;
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.telephony.CellBroadcastMessage;
25 
26 /**
27  * Custom alert dialog with optional flashing warning icon.
28  * Alert audio and text-to-speech handled by {@link CellBroadcastAlertAudio}.
29  * Keyguard handling based on {@code AlarmAlert} class from DeskClock app.
30  */
31 public class CellBroadcastAlertDialog extends CellBroadcastAlertFullScreen {
32 
33     private BroadcastReceiver mScreenOffReceiver;
34 
35     private class ScreenOffReceiver extends BroadcastReceiver {
36         @Override
onReceive(Context context, Intent intent)37         public void onReceive(Context context, Intent intent) {
38             handleScreenOff();
39         }
40     }
41 
42     @Override
onCreate(Bundle icicle)43     protected void onCreate(Bundle icicle) {
44         super.onCreate(icicle);
45 
46         // Listen for the screen turning off so that when the screen comes back
47         // on, the user does not need to unlock the phone to dismiss the alert.
48         CellBroadcastMessage msg = getLatestMessage();
49         if (msg != null && msg.isEmergencyAlertMessage()) {
50             mScreenOffReceiver = new ScreenOffReceiver();
51             registerReceiver(mScreenOffReceiver,
52                     new IntentFilter(Intent.ACTION_SCREEN_OFF));
53         }
54     }
55 
56     @Override
onDestroy()57     public void onDestroy() {
58         super.onDestroy();
59         if (mScreenOffReceiver != null) {
60             unregisterReceiver(mScreenOffReceiver);
61         }
62     }
63 
64     @Override
onBackPressed()65     public void onBackPressed() {
66         // stop animating warning icon, stop playing alert sound, mark broadcast as read
67         dismiss();
68     }
69 
70     @Override
getLayoutResId()71     protected int getLayoutResId() {
72         return R.layout.cell_broadcast_alert;
73     }
74 
handleScreenOff()75     private void handleScreenOff() {
76         // Launch the full screen activity but do not turn the screen on.
77         Intent i = new Intent(this, CellBroadcastAlertFullScreen.class);
78         i.putParcelableArrayListExtra(CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA, mMessageList);
79         i.putExtra(SCREEN_OFF_EXTRA, true);
80         startActivity(i);
81         finish();
82     }
83 }
84