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