WarnOfStorageLimitsActivity.java revision 22cff11251c42263fe452b59c8df3d7be252511e
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
20f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport com.android.mms.R;
21f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
2222cff11251c42263fe452b59c8df3d7be252511eTom Taylorimport com.android.internal.app.AlertController;
2322cff11251c42263fe452b59c8df3d7be252511eTom Taylor
246be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorimport android.app.Activity;
25f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.app.AlertDialog;
26f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.content.DialogInterface;
27f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.content.Intent;
28f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.os.Bundle;
29f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.util.Log;
306be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorimport android.view.KeyEvent;
31f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylorimport android.view.View;
32f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
33f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor/**
34f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor * This is the UI for telling the user about the storage limit setting.
35f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor */
366be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylorpublic class WarnOfStorageLimitsActivity extends Activity implements DialogInterface,
376be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor                    DialogInterface.OnClickListener {
386be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
396be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * The model for the alert.
406be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     *
416be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlertParams
426be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
4322cff11251c42263fe452b59c8df3d7be252511eTom Taylor    protected AlertController mAlert;
446be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
456be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
466be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * The parameters for the alert.
476be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
4822cff11251c42263fe452b59c8df3d7be252511eTom Taylor    protected AlertController.AlertParams mAlertParams;
496be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
50f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    private static final String LOG_TAG = "WarnOfStorageLimitsActivity";
51f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
52f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    private static final int POSITIVE_BUTTON = AlertDialog.BUTTON1;
53f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
54f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    @Override
55f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    protected void onCreate(Bundle savedInstanceState) {
56f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // Can't set this theme in the manifest. The resource compiler complains the
57f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // resource is internal and not visible. Without setting this theme, the window
58f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // gets a double window outline.
59f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        this.setTheme(com.android.internal.R.style.Theme_Dialog_Alert);
60f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
61f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        super.onCreate(savedInstanceState);
62f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
6322cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert = new AlertController(this, this, getWindow());
6422cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams = new AlertController.AlertParams(this);
6522cff11251c42263fe452b59c8df3d7be252511eTom Taylor
6622cff11251c42263fe452b59c8df3d7be252511eTom Taylor        // Set up the "dialog"
6722cff11251c42263fe452b59c8df3d7be252511eTom Taylor        final AlertController.AlertParams p = mAlertParams;
6822cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mTitle = getString(R.string.storage_limits_title);
6922cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mMessage = getString(R.string.storage_limits_message);
7022cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonText = getString(R.string.storage_limits_setting);
7122cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mNegativeButtonText = getString(R.string.storage_limits_setting_dismiss);
7222cff11251c42263fe452b59c8df3d7be252511eTom Taylor        p.mPositiveButtonListener = this;
73f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        setupAlert();
74f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
75f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
76f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    /**
77f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     * {@inheritDoc}
78f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor     */
79f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    public void onClick(DialogInterface dialog, int which) {
80f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
81f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        if (which == POSITIVE_BUTTON) {
82f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            Intent intent = new Intent(this,
83f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor                    MessagingPreferenceActivity.class);
84f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor            startActivity(intent);
85f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        }
86f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
87f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        // No matter what, finish the activity
88f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor        finish();
89f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor    }
90f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor
916be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void cancel() {
926be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        finish();
936be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
946be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
956be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public void dismiss() {
966be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // This is called after the click, since we finish when handling the
976be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        // click, don't do that again here.
986be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        if (!isFinishing()) {
996be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor            finish();
1006be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        }
1016be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1026be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1036be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    /**
1046be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * Sets up the alert, including applying the parameters to the alert model,
1056be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * and installing the alert's content.
1066be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     *
1076be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlert
1086be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     * @see #mAlertParams
1096be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor     */
1106be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    protected void setupAlert() {
11122cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlertParams.apply(mAlert);
11222cff11251c42263fe452b59c8df3d7be252511eTom Taylor        mAlert.installContent();
1136be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1146be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1156be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1166be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyDown(int keyCode, KeyEvent event) {
11722cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyDown(keyCode, event)) return true;
1186be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyDown(keyCode, event);
1196be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1206be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
1216be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    @Override
1226be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    public boolean onKeyUp(int keyCode, KeyEvent event) {
12322cff11251c42263fe452b59c8df3d7be252511eTom Taylor        if (mAlert.onKeyUp(keyCode, event)) return true;
1246be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor        return super.onKeyUp(keyCode, event);
1256be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor    }
1266be18bedb5b87dbbcdb54f37d5a0945bd0f71377Tom Taylor
127f766f33b774cfb6dd4100a6522ffa23c0a0dae35Tom Taylor}
128