Package ej.net.util.connectivity
Class SimpleNetworkCallbackAdapter
- java.lang.Object
-
- android.net.ConnectivityManager.NetworkCallback
-
- ej.net.util.connectivity.SimpleNetworkCallbackAdapter
-
- All Implemented Interfaces:
SimpleNetworkCallback
public class SimpleNetworkCallbackAdapter extends ConnectivityManager.NetworkCallback implements SimpleNetworkCallback
A simple network call back adapter. It can be extended or used with a listener.
-
-
Constructor Summary
Constructors Constructor Description SimpleNetworkCallbackAdapter()Instantiates aSimpleNetworkCallback.SimpleNetworkCallbackAdapter(SimpleNetworkCallback listener)Instantiates aSimpleNetworkCallback.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleNetworkCallbackgetListener()Gets the listener to call back on state change.booleanhasInternet()Checks whether the call back had been called for Internet.booleanisConnected()Checks whether the call back had been called for connection.voidonAvailable(Network network)Called when the framework connects and has declared new network ready for use.voidonCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities)Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need.voidonConnectivity(boolean isConnected)Called when the connectivity state changes.voidonInternet(boolean hasInternet)Called when the Internet state change.voidonLost(Network network)Called when the framework has a hard loss of the network or when the graceful failure ends.voidsetListener(SimpleNetworkCallback listener)Sets the listener to call back on state change.
-
-
-
Constructor Detail
-
SimpleNetworkCallbackAdapter
public SimpleNetworkCallbackAdapter()
Instantiates aSimpleNetworkCallback.
-
SimpleNetworkCallbackAdapter
public SimpleNetworkCallbackAdapter(@Nullable SimpleNetworkCallback listener)
Instantiates aSimpleNetworkCallback.- Parameters:
listener- the listener to call onstate change.
-
-
Method Detail
-
getListener
public SimpleNetworkCallback getListener()
Gets the listener to call back on state change.- Returns:
- the listener,
nullif none.
-
setListener
public void setListener(@Nullable SimpleNetworkCallback listener)
Sets the listener to call back on state change.- Parameters:
listener- the listener to set.
-
onAvailable
public void onAvailable(Network network)
Description copied from class:ConnectivityManager.NetworkCallbackCalled when the framework connects and has declared new network ready for use. This callback may be called more than once if theNetworkthat is satisfying the request changes.- Overrides:
onAvailablein classConnectivityManager.NetworkCallback- Parameters:
network- TheNetworkof the satisfying network.
-
onLost
public void onLost(Network network)
Description copied from class:ConnectivityManager.NetworkCallbackCalled when the framework has a hard loss of the network or when the graceful failure ends.- Overrides:
onLostin classConnectivityManager.NetworkCallback- Parameters:
network- TheNetworklost.
-
onCapabilitiesChanged
public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities)
Description copied from class:ConnectivityManager.NetworkCallbackCalled when the network the framework connected to for this request changes capabilities but still satisfies the stated need.- Overrides:
onCapabilitiesChangedin classConnectivityManager.NetworkCallback- Parameters:
network- TheNetworkof the satisfying network.networkCapabilities- NetworkCapabilities: The newNetworkCapabilitiesfor this network.
-
onInternet
public void onInternet(boolean hasInternet)
Called when the Internet state change.- Specified by:
onInternetin interfaceSimpleNetworkCallback- Parameters:
hasInternet-trueif Internet access is available.- See Also:
onCapabilitiesChanged(Network, NetworkCapabilities)
-
onConnectivity
public void onConnectivity(boolean isConnected)
Called when the connectivity state changes.- Specified by:
onConnectivityin interfaceSimpleNetworkCallback- Parameters:
isConnected-trueif a network is available.- See Also:
ConnectivityManager.NetworkCallback.onAvailable(Network),ConnectivityManager.NetworkCallback.onLost(Network)
-
hasInternet
public boolean hasInternet()
Checks whether the call back had been called for Internet.- Returns:
trueif the last call ofonInternet(boolean)had Internet.
-
isConnected
public boolean isConnected()
Checks whether the call back had been called for connection.- Returns:
trueif the last call ofonConnectivity(boolean)was connected.
-
-