Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2008 Esmertec AG.
      3  * Copyright (C) 2008 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mms.ui;
     19 
     20 import com.android.mms.R;
     21 
     22 import com.android.internal.app.AlertController;
     23 
     24 import android.app.Activity;
     25 import android.app.AlertDialog;
     26 import android.content.DialogInterface;
     27 import android.content.Intent;
     28 import android.os.Bundle;
     29 import android.view.KeyEvent;
     30 
     31 /**
     32  * This is the UI for telling the user about the storage limit setting.
     33  */
     34 public class WarnOfStorageLimitsActivity extends Activity implements DialogInterface,
     35                     DialogInterface.OnClickListener {
     36     /**
     37      * The model for the alert.
     38      *
     39      * @see #mAlertParams
     40      */
     41     protected AlertController mAlert;
     42 
     43     /**
     44      * The parameters for the alert.
     45      */
     46     protected AlertController.AlertParams mAlertParams;
     47 
     48     private static final String LOG_TAG = "WarnOfStorageLimitsActivity";
     49 
     50     private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
     51 
     52     @Override
     53     protected void onCreate(Bundle savedInstanceState) {
     54         // Can't set this theme in the manifest. The resource compiler complains the
     55         // resource is internal and not visible. Without setting this theme, the window
     56         // gets a double window outline.
     57         this.setTheme(com.android.internal.R.style.Theme_Dialog_Alert);
     58 
     59         super.onCreate(savedInstanceState);
     60 
     61         mAlert = new AlertController(this, this, getWindow());
     62         mAlertParams = new AlertController.AlertParams(this);
     63 
     64         // Set up the "dialog"
     65         final AlertController.AlertParams p = mAlertParams;
     66         p.mTitle = getString(R.string.storage_limits_title);
     67         p.mMessage = getString(R.string.storage_limits_message);
     68         p.mPositiveButtonText = getString(R.string.storage_limits_setting);
     69         p.mNegativeButtonText = getString(R.string.storage_limits_setting_dismiss);
     70         p.mPositiveButtonListener = this;
     71         setupAlert();
     72     }
     73 
     74     /**
     75      * {@inheritDoc}
     76      */
     77     public void onClick(DialogInterface dialog, int which) {
     78 
     79         if (which == POSITIVE_BUTTON) {
     80             Intent intent = new Intent(this,
     81                     MessagingPreferenceActivity.class);
     82             startActivity(intent);
     83         }
     84         dialog.dismiss();
     85 
     86         // No matter what, finish the activity
     87         finish();
     88     }
     89 
     90     public void cancel() {
     91         finish();
     92     }
     93 
     94     public void dismiss() {
     95         // This is called after the click, since we finish when handling the
     96         // click, don't do that again here.
     97         if (!isFinishing()) {
     98             finish();
     99         }
    100     }
    101 
    102     /**
    103      * Sets up the alert, including applying the parameters to the alert model,
    104      * and installing the alert's content.
    105      *
    106      * @see #mAlert
    107      * @see #mAlertParams
    108      */
    109     protected void setupAlert() {
    110         mAlertParams.apply(mAlert);
    111         mAlert.installContent();
    112     }
    113 
    114     @Override
    115     public boolean onKeyDown(int keyCode, KeyEvent event) {
    116         if (mAlert.onKeyDown(keyCode, event)) return true;
    117         return super.onKeyDown(keyCode, event);
    118     }
    119 
    120     @Override
    121     public boolean onKeyUp(int keyCode, KeyEvent event) {
    122         if (mAlert.onKeyUp(keyCode, event)) return true;
    123         return super.onKeyUp(keyCode, event);
    124     }
    125 
    126 }
    127