//Copyright (c) 2011 Kenneth Evans
//
//Permission is hereby granted, free of charge, to any person obtaining
//a copy of this software and associated documentation files (the
//"Software"), to deal in the Software without restriction, including
//without limitation the rights to use, copy, modify, merge, publish,
//distribute, sublicense, and/or sell copies of the Software, and to
//permit persons to whom the Software is furnished to do so, subject to
//the following conditions:
//
//The above copyright notice and this permission notice shall be included
//in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
//MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
//IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
//CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
//TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
//SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package net.kenevans.android.misc;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;

public class Utils implements IConstants {
	/**
	 * General alert dialog.
	 * 
	 * @param context
	 * @param title
	 * @param msg
	 */
	public static void alert(Context context, String title, String msg) {
		try {
			AlertDialog alertDialog = new AlertDialog.Builder(context)
					.setTitle(title)
					.setMessage(msg)
					.setPositiveButton("OK",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.cancel();
								}
							}).create();
			alertDialog.show();
		} catch (Throwable t) {
			Log.e(getContextTag(context), "Error using " + title
					+ "AlertDialog\n" + t + "\n" + t.getMessage());
		}
	}

	/**
	 * Error message dialog.
	 * 
	 * @param context
	 * @param msg
	 */
	public static void errMsg(Context context, String msg) {
		Log.e(TAG, getContextTag(context) + msg);
		alert(context, "Error", msg);
	}

	/**
	 * Error message dialog.
	 * 
	 * @param context
	 * @param msg
	 */
	public static void warnMsg(Context context, String msg) {
		Log.w(TAG, getContextTag(context) + msg);
		alert(context, "Warning", msg);
	}

	/**
	 * Info message dialog.
	 * 
	 * @param context
	 * @param msg
	 */
	public static void infoMsg(Context context, String msg) {
		Log.i(TAG, getContextTag(context) + msg);
		alert(context, "Information", msg);
	}

	/**
	 * Exception message dialog. Displays message plus the exception and
	 * exception message.
	 * 
	 * @param context
	 * @param msg
	 * @param t
	 */
	public static void excMsg(Context context, String msg, Throwable t) {
		String fullMsg = msg += "\n" + "Exception: " + t + "\n"
				+ t.getMessage();
		Log.e(TAG, getContextTag(context) + msg);
		alert(context, "Exception", fullMsg);
	}

	/**
	 * Utility method to get a tag representing the Context to associate with a
	 * log message.
	 * 
	 * @param context
	 * @return
	 */
	public static String getContextTag(Context context) {
		if (context == null) {
			return "<Unknown>: ";
		}
		return "Utils: " + context.getClass().getSimpleName() + ": ";
	}

}

@@ -1646,12 +1646,36 @@
 ton(
-%22OK%22
+context.getText(R.string.ok)
 ,%0D%0A%09
@@ -2236,15 +2236,50 @@
 xt, 
-%22Error%22
+context.getText(R.string.error).toString()
 , ms
@@ -2496,17 +2496,52 @@
 xt, 
-%22Warning%22
+context.getText(R.string.warning).toString()
 , ms
@@ -2757,21 +2757,49 @@
 xt, 
-%22Information%22
+context.getText(R.string.info).toString()
 , ms
@@ -3078,41 +3078,86 @@
 %22%5Cn%22
- + %22Exception: %22 + t + %22%5Cn%22%0D%0A%09%09%09%09
+%0D%0A%09%09%09%09+ context.getText(R.string.exception).toString() + %22: %22 + t%0D%0A%09%09%09%09+ %22%5Cn%22 
 + t.
@@ -3237,19 +3237,54 @@
 xt, 
-%22Exception%22
+context.getText(R.string.exception).toString()
 , fu
@@ -3543,15 +3543,11 @@
 n %22%3C
-Unknown
+???
 %3E: %22

Localized strings in Utils.