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