package com.cooler.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Net utils: contains some network utils.
 * 
 * @author Vincent Cheung
 * @since  Nov. 05, 2014
 */
public class NetUtils {
	/**
	 * To check if the network is available.
	 * 
	 * @param  context context
	 * @return true if available, otherwise return false
	 */
	public static boolean isNetAvailable(Context context) {
		if (context == null) {
			return false;
		}
		
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = manager.getActiveNetworkInfo();
		if (info == null) {
			return false;
		}
		
		return info.isAvailable();
	}
	
	/**
	 * Ping the specified IP.
	 * 
	 * @param ip IP address
	 */
	public static String ping(String ip) {
		try {
			/* ping 3 times */
			Process process = Runtime.getRuntime().exec("ping -c 2 -w 100 " + ip);
			int status = process.waitFor();
			if (status != 0) {
				return "N/A";
			}
			
			InputStream is = process.getInputStream();
			BufferedReader bf = new BufferedReader(new InputStreamReader(is));
			StringBuffer buffer = new StringBuffer();
			String content = "";
			while ((content = bf.readLine()) != null) {
				buffer.append(content);
				buffer.append("\n");
			}
			
			return buffer.toString();
		} catch (IOException | InterruptedException e) {
			return "N/A";
		}
	}
}

@@ -19,16 +19,176 @@
 .util;%0A%0A
+import android.content.Context;%0Aimport android.content.Intent;%0Aimport android.net.ConnectivityManager;%0Aimport android.net.NetworkInfo;%0Aimport android.net.Uri;%0A%0A
 import j
@@ -305,113 +305,8 @@
 r;%0A%0A
-import android.content.Context;%0Aimport android.net.ConnectivityManager;%0Aimport android.net.NetworkInfo;%0A%0A
 /**%0A
@@ -844,22 +844,26 @@
 Info();%0A
+%0A
 %09%09
-if (
+return 
 info == 
@@ -870,62 +870,349 @@
 null
-) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09return info.isAvailable(
+ ? false : info.isAvailable();%0A%09%7D%0A%0A%09/**%0A%09 * Open default browser with url.%0A%09 *%0A%09 * @param context context%0A%09 * @param url     url to open%0A%09 */%0A%09public static void openBrowser(Context context, String url) %7B%0A%09%09Intent intent = new Intent();%0A%09%09intent.setAction(Intent.ACTION_VIEW);%0A%09%09intent.setData(Uri.parse(url));%0A%09%09context.startActivity(intent
 );%0A%09
@@ -1692,13 +1692,8 @@
 tent
- = %22%22
 ;%0A%09%09

add open browser in NetUtils