1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| package cryptiris.IrisSerenite;
import java.lang.Thread;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
public class AndroSereniteActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// --- Plein écran
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
// --- Création et affichage du navigateur
final WebView webview = new WebView(this);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.loadUrl("http://........php");
// --- Maintien de l'écran brillant
setContentView(webview);
// --- Utilisation du Wifi et test de la connectivité
String service = Context.WIFI_SERVICE;
final WifiManager wifi = (WifiManager)getSystemService(service);
WifiInfo info = wifi.getConnectionInfo();
// --- Récupération des informations de connexion
int strenght = WifiManager.calculateSignalLevel(info.getRssi(),5);
int speed = info.getLinkSpeed();
String units = WifiInfo.LINK_SPEED_UNITS;
String ssid = info.getSSID();
int ipAddress = info.getIpAddress(); // @ip en int ...
// --- transforme l'@IP au format reconnu
String ip = String.format("%d.%d.%d.%d",
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff));
// --- Message qui sera délivré
String cSummary;
Builder builder = new AlertDialog.Builder(this);
if (ipAddress == 0)
{
builder.setTitle("WIFI non connecté au réseau");
cSummary = String.format("Pas de connexion à %s . Vous n'est peut etre plus à porté du Wifi\nAppuyer sur 'Suivant' pour tenter de vous connecter\nCela prendra moins de 10s", ssid);
builder.setMessage(cSummary);
builder.setPositiveButton("Suivant", new DialogInterface.OnClickListener()
{ // --- On définit l'action pour le oui
public void onClick(DialogInterface dialog, int id)
{
// --- Activation de wifi si besoin avec délai de 1.5s pour le faire
boolean connect_wifi = true;
if (!wifi.isWifiEnabled())
if (wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLING)
{
connect_wifi = wifi.setWifiEnabled(true);
try {
Thread.sleep(1500);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
// --- Tentative de connexion au wifi avec un delai de 5s
boolean test_connexion = wifi.reconnect();
try {
Thread.sleep(5000);
}
catch (InterruptedException exception) {
exception.printStackTrace();
}
webview.reload(); // --- Rafraichissement de la page web
String cSummary = String.format("Activation du Wifi : %s\nRésultat du test de la connexion : %s", connect_wifi, test_connexion);
Toast.makeText(getBaseContext(), cSummary, Toast.LENGTH_LONG).show();
}
});
}
else
{
builder.setTitle("WIFI connecté");
cSummary = String.format("Connecté à %s à %s%s. Force %s/5 \nL'adresse IP est %s", ssid, speed, units, strenght, ip);
builder.setMessage(cSummary);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{ // --- On définit l'action pour le "OK" ...On affiche simplement un message (2s)
public void onClick(DialogInterface dialog, int id)
{
Toast.makeText(getBaseContext(), "La surveillance est active ", Toast.LENGTH_LONG).show(); }
});
}
builder.show(); // --- On lance la boite de dialogue
}
} |
Partager