WarnOfStorageLimitsActivity.java revision d64419030e1fec1e751695dab3bd7236e2fb0214
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
47f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    private static final String LOG_TAG = "WarnOfStorageLimitsActivity";
48f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
49f725654f44ad56db2212a6318d89c8b50bf2d0dcChristian Mehlmauer    private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
50f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
51f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    @Override
52f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    protected void onCreate(Bundle savedInstanceState) {
53f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // Can't set this theme in the manifest. The resource compiler complains the
54f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // resource is internal and not visible. Without setting this theme, the window
55f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // gets a double window outline.
56f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        this.setTheme(com.android.internal.R.style.Theme_Dialog_Alert);
57f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
58f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        super.onCreate(savedInstanceState);
59f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
6022cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert = new AlertController(this, this, getWindow());
6122cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams = new AlertController.AlertParams(this);
6222cff11251c42263fe452b59c8df3d7be252511eTom Taylor
6322cff11251c42263fe452b59c8df3d7be252511eTom Taylor        // Set up the "dialog"
6422cff11251c42263fe452b59c8df3d7be252511eTom Taylor        final AlertController.AlertParams p = mAlertParams;
6522cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mMessage = getString(R.string.storage_limits_message);
6622cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonText = getString(R.string.storage_limits_setting);
6722cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mNegativeButtonText = getString(R.string.storage_limits_setting_dismiss);
6822cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonListener = this;
69f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        setupAlert();
70f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
71f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
72f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    /**
73f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     * {@inheritDoc}
74f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     */
75f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    public void onClick(DialogInterface dialog, int which) {
76f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
77f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        if (which == POSITIVE_BUTTON) {
78f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            Intent intent = new Intent(this,
79f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor                    MessagingPreferenceActivity.class);
80f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            startActivity(intent);
81f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        }
82c4a34a0ccd414e2bba937e8abd105a0383afff35Tom Taylor        dialog.dismiss();
83f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
84f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // No matter what, finish the activity
85f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        finish();
86f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
87f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
886be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void cancel() {
896be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        finish();
906be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
916be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
926be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void dismiss() {
936be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // This is called after the click, since we finish when handling the
946be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // click, don't do that again here.
956be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        if (!isFinishing()) {
966be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor            finish();
976be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        }
986be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
996be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1006be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
1016be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * Sets up the alert, including applying the parameters to the alert model,
1026be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * and installing the alert's content.
1036be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     *
1046be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlert
1056be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlertParams
1066be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
1076be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    protected void setupAlert() {
10822cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams.apply(mAlert);
10922cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert.installContent();
1106be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1116be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1126be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1136be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyDown(int keyCode, KeyEvent event) {
11422cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyDown(keyCode, event)) return true;
1156be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyDown(keyCode, event);
1166be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1176be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1186be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1196be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyUp(int keyCode, KeyEvent event) {
12022cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyUp(keyCode, event)) return true;
1216be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyUp(keyCode, event);
1226be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1236be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
124f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor}
125