Home | History | Annotate | Download | only in cellbroadcastreceiver
      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
     37         public void onReceive(Context context, Intent intent) {
     38             handleScreenOff();
     39         }
     40     }
     41 
     42     @Override
     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         if (CellBroadcastConfigService.isEmergencyAlertMessage(getLatestMessage())) {
     49             mScreenOffReceiver = new ScreenOffReceiver();
     50             registerReceiver(mScreenOffReceiver,
     51                     new IntentFilter(Intent.ACTION_SCREEN_OFF));
     52         }
     53     }
     54 
     55     @Override
     56     public void onDestroy() {
     57         super.onDestroy();
     58         if (mScreenOffReceiver != null) {
     59             unregisterReceiver(mScreenOffReceiver);
     60         }
     61     }
     62 
     63     @Override
     64     public void onBackPressed() {
     65         // stop animating warning icon, stop playing alert sound, mark broadcast as read
     66         dismiss();
     67     }
     68 
     69     @Override
     70     protected int getLayoutResId() {
     71         return R.layout.cell_broadcast_alert;
     72     }
     73 
     74     private void handleScreenOff() {
     75         // Launch the full screen activity but do not turn the screen on.
     76         Intent i = new Intent(this, CellBroadcastAlertFullScreen.class);
     77         i.putParcelableArrayListExtra(CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA, mMessageList);
     78         i.putExtra(SCREEN_OFF_EXTRA, true);
     79         startActivity(i);
     80         finish();
     81     }
     82 }
     83