/*
 * Copyright 2014 Regional Adult Education Program of Lee, Scott, Wise, and Norton Public Schools
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package edu.mecc.race2ged.helpers;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Utils class includes commonly used methods often relating to system information such
 * as network states or date and time.
 *
 * @author Bryan Smith
 */
public class Utils {

    /**
     * Network States
     */
    public static int NO_CONNECTION = 0;
    public static int WIFI = 1;
    public static int MOBILE_DATA = 2;

    private static Typeface sRobotoThin;

    /**
     * Returns the current system date.
     */
    public static String getDateAndTime() {
        return new SimpleDateFormat("yyyy-MM-dd.HH.mm.ss").format(new Date(System
                .currentTimeMillis()));
    }

    /**
     * Are we connected to WiFi, Mobile Data, or nothing?
     * @return The devices current network state.
     */
    public static int getNetworkStatus(Context context) {
        final ConnectivityManager connMgr = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (wifi != null && wifi.isAvailable() && wifi.isConnected()) return WIFI;
        else if (mobile != null && mobile.isAvailable() && mobile.isConnected()) return MOBILE_DATA;
        return NO_CONNECTION;
    }

    /**
     * Displays a Toast Message on the UI Thread
     * @param context The context of the activity.
     * @param resourceId The resource ID of the text to display in the message.
     */
    public static void showToastOnUiThread(final Context context, final int resourceId) {
        ((Activity) context).runOnUiThread(new Runnable() {

            public void run() {
                Toast.makeText(context, resourceId, Toast.LENGTH_LONG).show();
            }
        });
    }

    /**
     * Displays a Toast Message on the UI Thread
     * @param context The context of the activity.
     * @param string The string to display in the message.
     */
    public static void showToastOnUiThread(final Context context, final String string) {
        ((Activity) context).runOnUiThread(new Runnable() {
            public void run() {
                Toast.makeText(context, string, Toast.LENGTH_LONG).show();
            }
        });
    }

    /**
     * Sets the font of a view to Roboto-Light
     * @param context The context of the activity.
     * @param view The view that will use Roboto-Light
     */
    public static void setRobotoThin(Context context, View view) {
        if (sRobotoThin == null) {
            sRobotoThin = Typeface.createFromAsset(context.getAssets(), "Roboto-Light.ttf");
        }
        setFont(view, sRobotoThin);
    }

    /**
     * Sets the font of a view.
     * @param view The view that will use defined Typeface
     * @param robotoTypeFace The font typeface to use.
     */
    private static void setFont(View view, Typeface robotoTypeFace) {
        if (view instanceof ViewGroup) {
            int count = ((ViewGroup) view).getChildCount();
            for (int i = 0; i < count; i++) {
                setFont(((ViewGroup) view).getChildAt(i), robotoTypeFace);
            }
        } else if (view instanceof TextView) {
            ((TextView) view).setTypeface(robotoTypeFace);
        }
    }
}
@@ -781,16 +781,47 @@
 ontext;%0A
+import android.content.Intent;%0A
 import a
@@ -2405,32 +2405,819 @@
 NECTION;%0A    %7D%0A%0A
+    /**%0A     * Send an email with supplied address, subject, and content.%0A     * @param emailAddress To: Email Address%0A     * @param emailSubject Email Subject%0A     * @param emailBody Email Body Content%0A     */%0A    public void sendEmail(Context context,String emailAddress, String emailSubject, String emailBody) %7B%0A        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);%0A        emailIntent.setType(%22plain/html%22);%0A        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String%5B%5D %7BemailAddress%7D);%0A        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);%0A        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody);%0A        context.startActivity(Intent.createChooser(emailIntent, %22Sending email...%22));%0A    %7D%0A%0A
     /**%0A     * D

Add send email method.