Commit 9cb21884 authored by Toni Beier's avatar Toni Beier

Handle WIFI and connectivity changes

parent 882cab3d
Pipeline #22853 passed with stages
in 3 minutes and 48 seconds
......@@ -75,6 +75,8 @@ public class MainActivity extends AppCompatActivity {
boolean inInstall = false, canLeaveInstall = false;
int useCache = 0; // <0 - false ; 0 - undefined ; >0 - true
private NetworkChangeReciever networkChangeReciever = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -141,6 +143,14 @@ public class MainActivity extends AppCompatActivity {
super.onResume();
recomputeLayout();
IntentFilter networkChangeRecieverIntentFilter = new IntentFilter();
networkChangeRecieverIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
networkChangeRecieverIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
this.networkChangeReciever = new NetworkChangeReciever();
Log.d("network_change_broadcast", "register receiver");
this.registerReceiver(this.networkChangeReciever, networkChangeRecieverIntentFilter);
}
private void recomputeLayout() {
......@@ -172,6 +182,14 @@ public class MainActivity extends AppCompatActivity {
}
}
@Override
protected void onPause() {
super.onPause();
Log.d("network_change_broadcast", "unregister receiver");
this.unregisterReceiver(this.networkChangeReciever);
}
private void recomputeLayoutStatus() {
ticks_status = Helper.getNetworkStatus(MainActivity.this, "\"eduroam\"");
......@@ -806,4 +824,17 @@ public class MainActivity extends AppCompatActivity {
params.setMargins((subentry ? 50 : 0), 0, 0, 10);
return params;
}
}
private class NetworkChangeReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.d("network_change_broadcast", "Get action: " + intent.getAction());
recomputeLayout();
} catch (Exception exception) {
Log.d("network_change_broadcast", "Error while recompute ticklist", exception);
}
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment