package cc.mvdan.libaccesspointexample;

import android.app.Activity;
import android.os.Bundle;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.widget.TextView;
import android.content.Context;

import java.lang.StringBuilder;

import cc.mvdan.libaccesspoint.WifiApControl;

public class MainActivity extends Activity {

	private WifiApControl apControl;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
		apControl = WifiApControl.getApControl(wm);
	}

	@Override
	public void onResume() {
		super.onResume();
		refreshStatus();
	}

	private static String stateString(int state) {
		switch (state) {
			case WifiApControl.STATE_FAILED:
				return "FAILED";
			case WifiApControl.STATE_DISABLED:
				return "DISABLED";
			case WifiApControl.STATE_DISABLING:
				return "DISABLING";
			case WifiApControl.STATE_ENABLED:
				return "ENABLED";
			case WifiApControl.STATE_ENABLING:
				return "ENABLING";
			default:
				return "UNKNOWN!";
		}
	}

	private void refreshStatus() {
		TextView tv = (TextView) findViewById(R.id.text1);
		StringBuilder sb = new StringBuilder();
		if (!WifiApControl.isSupported()) {
			sb.append("Warning: Wifi AP mode not supported!\n");
			sb.append("You should get unknown or zero values below.\n");
			sb.append("If you don't, isSupported() is probably buggy!\n");
		}
		int state = apControl.getState();
		sb.append("State: ").append(stateString(state)).append('\n');
		sb.append("Enabled: ");
		if (apControl.isEnabled()) {
			sb.append("YES\n");
		} else {
			sb.append("NO\n");
		}
		final WifiConfiguration wifiConfig = apControl.getConfiguration();
		sb.append("WifiConfiguration:");
		if (wifiConfig == null) {
			sb.append(" null\n");
		} else {
			sb.append("\n");
			sb.append("   SSID: \"").append(wifiConfig.SSID).append("\"\n");
			sb.append("   preSharedKey: \"").append(wifiConfig.preSharedKey).append("\"\n");
		}
		tv.setText(sb.toString());
	}
}

@@ -82,17 +82,23 @@
 oid.
-os.Bundle
+content.Context
 ;%0Aim
@@ -175,16 +175,42 @@
 anager;%0A
+import android.os.Bundle;%0A
 import a
@@ -236,40 +236,8 @@
 iew;
-%0Aimport android.content.Context;
 %0A%0Aim
@@ -265,16 +265,45 @@
 Builder;
+%0Aimport java.net.InetAddress;
 %0A%0Aimport
@@ -2087,16 +2087,210 @@
 %22);%0A%09%09%7D%0A
+%09%09final InetAddress addr = WifiApControl.getInetAddress();%0A%09%09sb.append(%22InetAddress: %22);%0A%09%09if (addr == null) %7B%0A%09%09%09sb.append(%22null%5Cn%22);%0A%09%09%7D else %7B%0A%09%09%09sb.append(addr.toString()).append('%5Cn');%0A%09%09%7D%0A
 %09%09tv.set

Add InetAddress example section