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 android.app.Activity;
     21 import android.app.AlertDialog;
     22 import android.content.DialogInterface;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.view.KeyEvent;
     26 
     27 import com.android.internal.app.AlertController;
     28 import com.android.mms.R;
     29 
     30 /**
     31  * This is the UI for telling the user about the storage limit setting.
     32  */
     33 public class WarnOfStorageLimitsActivity extends Activity implements DialogInterface,
     34                     DialogInterface.OnClickListener {
     35     /**
     36      * The model for the alert.
     37      *
     38      * @see #mAlertParams
     39      */
     40     protected AlertController mAlert;
     41 
     42     /**
     43      * The parameters for the alert.
     44      */
     45     protected AlertController.AlertParams mAlertParams;
     46 
     47     private static final String LOG_TAG = "WarnOfStorageLimitsActivity";
     48 
     49     private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE;
     50 
     51     @Override
     52     protected void onCreate(Bundle savedInstanceState) {
     53         // Can't set this theme in the manifest. The resource compiler complains the
     54         // resource is internal and not visible. Without setting this theme, the window
     55         // gets a double window outline.
     56         this.setTheme(com.android.internal.R.style.Theme_Dialog_Alert);
     57 
     58         super.onCreate(savedInstanceState);
     59 
     60         mAlert = new AlertController(this, this, getWindow());
     61         mAlertParams = new AlertController.AlertParams(this);
     62 
     63         // Set up the "dialog"
     64         final AlertController.AlertParams p = mAlertParams;
     65         p.mMessage = getString(R.string.storage_limits_message);
     66         p.mPositiveButtonText = getString(R.string.storage_limits_setting);
     67         p.mNegativeButtonText = getString(R.string.storage_limits_setting_dismiss);
     68         p.mPositiveButtonListener = this;
     69         setupAlert();
     70     }
     71 
     72     /**
     73      * {@inheritDoc}
     74      */
     75     public void onClick(DialogInterface dialog, int which) {
     76 
     77         if (which == POSITIVE_BUTTON) {
     78             Intent intent = new Intent(this,
     79                     MessagingPreferenceActivity.class);
     80             startActivity(intent);
     81         }
     82         dialog.dismiss();
     83 
     84         // No matter what, finish the activity
     85         finish();
     86     }
     87 
     88     public void cancel() {
     89         finish();
     90     }
     91 
     92     public void dismiss() {
     93         // This is called after the click, since we finish when handling the
     94         // click, don't do that again here.
     95         if (!isFinishing()) {
     96             finish();
     97         }
     98     }
     99 
    100     /**
    101      * Sets up the alert, including applying the parameters to the alert model,
    102      * and installing the alert's content.
    103      *
    104      * @see #mAlert
    105      * @see #mAlertParams
    106      */
    107     protected void setupAlert() {
    108         mAlertParams.apply(mAlert);
    109         mAlert.installContent();
    110     }
    111 
    112     @Override
    113     public boolean onKeyDown(int keyCode, KeyEvent event) {
    114         if (mAlert.onKeyDown(keyCode, event)) return true;
    115         return super.onKeyDown(keyCode, event);
    116     }
    117 
    118     @Override
    119     public boolean onKeyUp(int keyCode, KeyEvent event) {
    120         if (mAlert.onKeyUp(keyCode, event)) return true;
    121         return super.onKeyUp(keyCode, event);
    122     }
    123 
    124 }
    125