1 /* 2 * Copyright (C) 2012 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.app.Activity; 20 import android.app.AlertDialog; 21 import android.content.DialogInterface; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.util.Log; 25 26 /** 27 * Container activity for CMAS opt-in/opt-out alert dialog. 28 */ 29 public class CellBroadcastOptOutActivity extends Activity { 30 private static final String TAG = "CellBroadcastOptOutActivity"; 31 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 Log.d(TAG, "created activity"); 36 showOptOutDialog(this); 37 } 38 39 /** 40 * Show the opt-out dialog. Uses the CellBroadcastAlertDialog activity unless the device is 41 * in restricted keyguard mode, in which case we create a new CellBroadcastOptOutActivity 42 * so that the dialog appears underneath the lock screen. The user must unlock the device 43 * to configure the settings, so we don't want to show the opt-in dialog before then. 44 */ showOptOutDialog(final Activity activity)45 static void showOptOutDialog(final Activity activity) { 46 AlertDialog.Builder builder = new AlertDialog.Builder(activity); 47 builder.setMessage(R.string.cmas_opt_out_dialog_text) 48 .setPositiveButton(R.string.cmas_opt_out_button_yes, 49 new DialogInterface.OnClickListener() { 50 @Override 51 public void onClick(DialogInterface dialog, int which) { 52 Log.d(TAG, "User clicked Yes"); 53 activity.finish(); 54 } 55 }) 56 .setNegativeButton(R.string.cmas_opt_out_button_no, 57 new DialogInterface.OnClickListener() { 58 @Override 59 public void onClick(DialogInterface dialog, int which) { 60 Log.d(TAG, "User clicked No"); 61 Intent intent = new Intent(activity, CellBroadcastSettings.class); 62 activity.startActivity(intent); 63 activity.finish(); 64 } 65 }) 66 .setOnCancelListener( 67 new DialogInterface.OnCancelListener() { 68 @Override 69 public void onCancel(DialogInterface dialog) { 70 Log.d(TAG, "User cancelled"); 71 // If the user presses the back button, make sure we dismiss the 72 // emergency alert's dialog as well. 73 activity.finish(); 74 } 75 }) 76 .create().show(); 77 } 78 } 79