1f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor/*
2f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * Copyright (C) 2008 Esmertec AG.
3f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * Copyright (C) 2008 The Android Open Source Project
4f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor *
5f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * Licensed under the Apache License, Version 2.0 (the "License");
6f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * you may not use this file except in compliance with the License.
7f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * You may obtain a copy of the License at
8f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor *
9f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor *      http://www.apache.org/licenses/LICENSE-2.0
10f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor *
11f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * Unless required by applicable law or agreed to in writing, software
12f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * distributed under the License is distributed on an "AS IS" BASIS,
13f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * See the License for the specific language governing permissions and
15f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * limitations under the License.
16f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor */
17f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
18f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorpackage com.android.mms.ui;
19f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
206be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorimport android.app.Activity;
21f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.app.AlertDialog;
22f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.content.DialogInterface;
23f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.content.Intent;
24f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.os.Bundle;
256be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorimport android.view.KeyEvent;
26f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
27d64419030e1fec1e751695dab3bd7236e2fb0214Roger Chenimport com.android.internal.app.AlertController;
28d64419030e1fec1e751695dab3bd7236e2fb0214Roger Chenimport com.android.mms.R;
29d64419030e1fec1e751695dab3bd7236e2fb0214Roger Chen
30f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor/**
31f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * This is the UI for telling the user about the storage limit setting.
32f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor */
336be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorpublic class WarnOfStorageLimitsActivity extends Activity implements DialogInterface,
346be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor                    DialogInterface.OnClickListener {
356be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
366be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * The model for the alert.
376be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     *
386be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlertParams
396be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
4022cff11251c42263fe452b59c8df3d7be252511eTom Taylor    protected AlertController mAlert;
416be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
426be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
436be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * The parameters for the alert.
446be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
4522cff11251c42263fe452b59c8df3d7be252511eTom Taylor    protected AlertController.AlertParams mAlertParams;
466be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
47f725654f44ad56db2212a6318d89c8b50bf2d0dcChristian Mehlmauer    private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
48f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
49f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    @Override
50f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    protected void onCreate(Bundle savedInstanceState) {
51f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // Can't set this theme in the manifest. The resource compiler complains the
52f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // resource is internal and not visible. Without setting this theme, the window
53f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // gets a double window outline.
54f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        this.setTheme(com.android.internal.R.style.Theme_Dialog_Alert);
55f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
56f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        super.onCreate(savedInstanceState);
57f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
5822cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert = new AlertController(this, this, getWindow());
5922cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams = new AlertController.AlertParams(this);
6022cff11251c42263fe452b59c8df3d7be252511eTom Taylor
6122cff11251c42263fe452b59c8df3d7be252511eTom Taylor        // Set up the "dialog"
6222cff11251c42263fe452b59c8df3d7be252511eTom Taylor        final AlertController.AlertParams p = mAlertParams;
6322cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mMessage = getString(R.string.storage_limits_message);
6422cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonText = getString(R.string.storage_limits_setting);
6522cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mNegativeButtonText = getString(R.string.storage_limits_setting_dismiss);
6622cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonListener = this;
67f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        setupAlert();
68f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
69f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
70f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    /**
71f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     * {@inheritDoc}
72f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     */
73f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    public void onClick(DialogInterface dialog, int which) {
74f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
75f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        if (which == POSITIVE_BUTTON) {
76f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            Intent intent = new Intent(this,
77f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor                    MessagingPreferenceActivity.class);
78f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            startActivity(intent);
79f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        }
80c4a34a0ccd414e2bba937e8abd105a0383afff35Tom Taylor        dialog.dismiss();
81f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
82f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // No matter what, finish the activity
83f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        finish();
84f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
85f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
866be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void cancel() {
876be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        finish();
886be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
896be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
906be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void dismiss() {
916be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // This is called after the click, since we finish when handling the
926be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // click, don't do that again here.
936be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        if (!isFinishing()) {
946be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor            finish();
956be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        }
966be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
976be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
986be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
996be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * Sets up the alert, including applying the parameters to the alert model,
1006be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * and installing the alert's content.
1016be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     *
1026be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlert
1036be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlertParams
1046be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
1056be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    protected void setupAlert() {
10622cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams.apply(mAlert);
10722cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert.installContent();
1086be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1096be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1106be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1116be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyDown(int keyCode, KeyEvent event) {
11222cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyDown(keyCode, event)) return true;
1136be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyDown(keyCode, event);
1146be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1156be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1166be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1176be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyUp(int keyCode, KeyEvent event) {
11822cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyUp(keyCode, event)) return true;
1196be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyUp(keyCode, event);
1206be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1216be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
122f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor}
123