summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java134
1 files changed, 67 insertions, 67 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
index 85695ec6c9..7c37569ae2 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
@@ -7,90 +7,90 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.annotation.NonNull;
-import android.util.Log;
-import com.mapbox.mapboxsdk.MapboxAccountManager;
+import com.mapbox.mapboxsdk.Mapbox;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import timber.log.Timber;
+
/**
* Interface definition for a callback to be invoked when connectivity changes.
* Not public api.
*/
public class ConnectivityReceiver extends BroadcastReceiver {
- private static final String TAG = ConnectivityReceiver.class.getSimpleName();
- private static ConnectivityReceiver INSTANCE;
-
- /**
- * Get or create the singleton instance
- */
- public static synchronized ConnectivityReceiver instance(Context context) {
- if (INSTANCE == null) {
- //Register new instance
- INSTANCE = new ConnectivityReceiver();
- context.registerReceiver(INSTANCE, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
-
- //Add default listeners
- INSTANCE.addListener(new NativeConnectivityListener());
- }
-
- return INSTANCE;
+ private static ConnectivityReceiver INSTANCE;
+
+ /**
+ * Get or create the singleton instance
+ */
+ public static synchronized ConnectivityReceiver instance(Context context) {
+ if (INSTANCE == null) {
+ //Register new instance
+ INSTANCE = new ConnectivityReceiver();
+ context.registerReceiver(INSTANCE, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
+
+ //Add default listeners
+ INSTANCE.addListener(new NativeConnectivityListener());
}
- private List<ConnectivityListener> listeners = new CopyOnWriteArrayList<>();
+ return INSTANCE;
+ }
- private ConnectivityReceiver() {
- }
+ private List<ConnectivityListener> listeners = new CopyOnWriteArrayList<>();
- /**
- * @see BroadcastReceiver#onReceive(Context, Intent)
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- boolean connected = isConnected(context);
- Log.v(TAG, "Connected: " + connected);
-
- //Loop over listeners
- for (ConnectivityListener listener : listeners) {
- listener.onNetworkStateChanged(connected);
- }
- }
+ private ConnectivityReceiver() {
+ }
- /**
- * Add a listener to be notified
- *
- * @param listener the listener to add
- */
- public void addListener(@NonNull ConnectivityListener listener) {
- listeners.add(listener);
- }
+ /**
+ * @see BroadcastReceiver#onReceive(Context, Intent)
+ */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ boolean connected = isConnected(context);
+ Timber.v("Connected: " + connected);
- /**
- * Remove a listener
- *
- * @param listener the listener to remove
- */
- public void removeListener(@NonNull ConnectivityListener listener) {
- listeners.remove(listener);
+ //Loop over listeners
+ for (ConnectivityListener listener : listeners) {
+ listener.onNetworkStateChanged(connected);
}
-
- /**
- * Get current connectivity state
- *
- * @param context current Context
- * @return true if connected
- */
- public boolean isConnected(Context context) {
- Boolean connected = MapboxAccountManager.getInstance().isConnected();
- if (connected != null) {
- // Connectivity state overridden by app
- return connected;
- }
-
- ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
- return (activeNetwork != null && activeNetwork.isConnected());
+ }
+
+ /**
+ * Add a listener to be notified
+ *
+ * @param listener the listener to add
+ */
+ public void addListener(@NonNull ConnectivityListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Remove a listener
+ *
+ * @param listener the listener to remove
+ */
+ public void removeListener(@NonNull ConnectivityListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Get current connectivity state
+ *
+ * @param context current Context
+ * @return true if connected
+ */
+ public boolean isConnected(Context context) {
+ Boolean connected = Mapbox.isConnected();
+ if (connected != null) {
+ // Connectivity state overridden by app
+ return connected;
}
+ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
+ return (activeNetwork != null && activeNetwork.isConnected());
+ }
+
}