Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * */
      5 
      6 package com.android.mms.ui;
      7 
      8 import com.android.mms.R;
      9 
     10 import android.app.Activity;
     11 import android.app.AlertDialog;
     12 import android.content.DialogInterface;
     13 import android.content.SharedPreferences;
     14 import android.os.Bundle;
     15 import android.preference.PreferenceManager;
     16 import android.view.View;
     17 
     18 /**
     19  * This activity is used by 3rd party apps to allow the user to turn on/off notifications in
     20  * the Messaging app.
     21  */
     22 public class MiniPreferenceActivity extends Activity {
     23     public static String DISABLE_NOTIFICATIONS_INTENT =
     24         "com.android.mms.intent.action.MESSAGING_APP_NOTIFICATIONS";
     25 
     26     @Override
     27     protected void onCreate(Bundle icicle) {
     28         super.onCreate(icicle);
     29 
     30         boolean notificationsEnabled = MessagingPreferenceActivity.getNotificationEnabled(this);
     31 
     32         if (!notificationsEnabled) {
     33             setResult(RESULT_OK);
     34             finish();
     35         }
     36 
     37         AlertDialog.Builder builder = new AlertDialog.Builder(this);
     38         AlertDialog dialog = builder.setMessage(getResources()
     39                 .getString(R.string.disable_notifications_dialog_message))
     40             .setCancelable(true)
     41             .setPositiveButton(R.string.yes, mDialogButtonListener)
     42             .setNegativeButton(R.string.no, mDialogButtonListener)
     43             .show();
     44 
     45         dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
     46             public void onDismiss(DialogInterface dialog) {
     47                 if (!MiniPreferenceActivity.this.isFinishing()) {
     48                     finish();
     49                 }
     50             }
     51         });
     52     }
     53 
     54     private DialogInterface.OnClickListener mDialogButtonListener =
     55         new DialogInterface.OnClickListener() {
     56             public void onClick(DialogInterface dialog, int which) {
     57                 if (which == DialogInterface.BUTTON_POSITIVE) {
     58                     // turn off Messaging notifications
     59                     MessagingPreferenceActivity.enableNotifications(false,
     60                             MiniPreferenceActivity.this);
     61                     setResult(RESULT_OK);
     62                 } else {
     63                     setResult(RESULT_CANCELED);
     64                 }
     65                 finish();
     66             }
     67     };
     68 }
     69