|
| 1 | +/* |
| 2 | + * Copyright (C) 2011 wordpress.org |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.wordpress.android.util; |
| 18 | + |
| 19 | +import android.app.AlertDialog; |
| 20 | +import android.app.Dialog; |
| 21 | +import android.content.Context; |
| 22 | +import android.content.DialogInterface; |
| 23 | + |
| 24 | +public class AlertUtil { |
| 25 | + /** |
| 26 | + * Show Alert Dialog |
| 27 | + * @param context |
| 28 | + * @param titleId |
| 29 | + * @param messageId |
| 30 | + */ |
| 31 | + public static void showAlert(Context context, int titleId, int messageId) { |
| 32 | + Dialog dlg = new AlertDialog.Builder(context) |
| 33 | + .setTitle(titleId) |
| 34 | + .setPositiveButton(android.R.string.ok, null) |
| 35 | + .setMessage(messageId) |
| 36 | + .create(); |
| 37 | + |
| 38 | + dlg.show(); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Show Alert Dialog |
| 43 | + * @param context |
| 44 | + * @param titleId |
| 45 | + * @param messageId |
| 46 | + */ |
| 47 | + public static void showAlert(Context context, int titleId, String message) { |
| 48 | + Dialog dlg = new AlertDialog.Builder(context) |
| 49 | + .setTitle(titleId) |
| 50 | + .setPositiveButton(android.R.string.ok, null) |
| 51 | + .setMessage(message) |
| 52 | + .create(); |
| 53 | + |
| 54 | + dlg.show(); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Show Alert Dialog |
| 59 | + * @param context |
| 60 | + * @param titleId |
| 61 | + * @param messageId |
| 62 | + * @param positiveButtontxt |
| 63 | + * @param positiveListener |
| 64 | + * @param negativeButtontxt |
| 65 | + * @param negativeListener |
| 66 | + */ |
| 67 | + public static void showAlert(Context context, int titleId, int messageId, |
| 68 | + CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener, |
| 69 | + CharSequence negativeButtontxt, DialogInterface.OnClickListener negativeListener) { |
| 70 | + Dialog dlg = new AlertDialog.Builder(context) |
| 71 | + .setTitle(titleId) |
| 72 | + .setPositiveButton(positiveButtontxt, positiveListener) |
| 73 | + .setNegativeButton(negativeButtontxt, negativeListener) |
| 74 | + .setMessage(messageId) |
| 75 | + .setCancelable(false) |
| 76 | + .create(); |
| 77 | + |
| 78 | + dlg.show(); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Show Alert Dialog |
| 83 | + * @param context |
| 84 | + * @param titleId |
| 85 | + * @param messageId |
| 86 | + * @param positiveButtontxt |
| 87 | + * @param positiveListener |
| 88 | + */ |
| 89 | + public static void showAlert(Context context, int titleId, String message, |
| 90 | + CharSequence positiveButtontxt, DialogInterface.OnClickListener positiveListener) { |
| 91 | + Dialog dlg = new AlertDialog.Builder(context) |
| 92 | + .setTitle(titleId) |
| 93 | + .setPositiveButton(positiveButtontxt, positiveListener) |
| 94 | + .setMessage(message) |
| 95 | + .setCancelable(false) |
| 96 | + .create(); |
| 97 | + |
| 98 | + dlg.show(); |
| 99 | + } |
| 100 | +} |
| 101 | + |
0 commit comments