// Path: src/main/java/com/opentaxi/android/utils/MessageEvent.java
// public class MessageEvent {
//     public final String message;
// 
//     public MessageEvent(String message) {
//         this.message = message;
//     }
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import com.opentaxi.android.utils.MessageEvent;
import com.opentaxi.rest.RestClient;
import de.greenrobot.event.EventBus;
package com.opentaxi.android;


/**
 * Created with IntelliJ IDEA.
 * User: stanimir
 * Date: 11/8/13
 * Time: 12:16 PM
 * developer STANIMIR MARINOV
 */
public class NetworkStateReceiver extends BroadcastReceiver {
    /**
     * if (bandwidth > 16) Code for large items
     * if (bandwidth <= 16 && bandwidth > 8) Code for medium items
     * else Code for small items
     */
    public void onReceive(Context context, Intent intent) {

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

        if (activeNetInfo != null) {
            if (activeNetInfo.isConnected()) {
                StringBuilder network = new StringBuilder();
                if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                    network.append(activeNetInfo.getTypeName()).append(" ").append(wm.getConnectionInfo().getLinkSpeed()).append("Mbps");
                } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    network.append(activeNetInfo.getTypeName()).append(" ").append(getNetworkTypeName(tm.getNetworkType()));
                } //else RestClient.getInstance().setBandwidth(0);

                onConnected(network.toString());

            } else onDisconnected();

        } else onDisconnected();
    }

    private void onConnected(String typeName) {
        RestClient.getInstance().setHaveConnection(true);
// Path: src/main/java/com/opentaxi/android/utils/MessageEvent.java
// public class MessageEvent {
//     public final String message;
// 
//     public MessageEvent(String message) {
//         this.message = message;
//     }
// }


// Path: src/main/java/com/opentaxi/android/NetworkStateReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import com.opentaxi.android.utils.MessageEvent;
import com.opentaxi.rest.RestClient;
import de.greenrobot.event.EventBus;

package com.opentaxi.android;


/**
 * Created with IntelliJ IDEA.
 * User: stanimir
 * Date: 11/8/13
 * Time: 12:16 PM
 * developer STANIMIR MARINOV
 */
public class NetworkStateReceiver extends BroadcastReceiver {
    /**
     * if (bandwidth > 16) Code for large items
     * if (bandwidth <= 16 && bandwidth > 8) Code for medium items
     * else Code for small items
     */
    public void onReceive(Context context, Intent intent) {

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

        if (activeNetInfo != null) {
            if (activeNetInfo.isConnected()) {
                StringBuilder network = new StringBuilder();
                if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                    network.append(activeNetInfo.getTypeName()).append(" ").append(wm.getConnectionInfo().getLinkSpeed()).append("Mbps");
                } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    network.append(activeNetInfo.getTypeName()).append(" ").append(getNetworkTypeName(tm.getNetworkType()));
                } //else RestClient.getInstance().setBandwidth(0);

                onConnected(network.toString());

            } else onDisconnected();

        } else onDisconnected();
    }

    private void onConnected(String typeName) {
        RestClient.getInstance().setHaveConnection(true);
        EventBus.getDefault().postSticky(new MessageEvent(typeName));