Android Open Source - WeatherBar Connection






From Project

Back to project page WeatherBar.

License

The source code is released under:

MIT License

If you think the Android project WeatherBar listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.cjbarker.wb.receiver;
// w w w . j a  v a2s.c  o m
import com.cjbarker.wb.Prefs;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

public class Connection extends BroadcastReceiver {
  
  private static final String TAG = "Connection";
  
  private boolean isConnected;
  private boolean isWiFi;

  public static boolean isNetworkConnected(Context ctx) {
    if (ctx == null) {
      return false;
    }
    ConnectivityManager cm =
            (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return ( activeNetwork != null && activeNetwork.isConnectedOrConnecting() );
  }
  
  public boolean isWiFiConnection() {
    return isWiFi;
  }
  
  @Override
  public void onReceive(Context ctx, Intent intent) {
    Log.i(TAG, "Intent received: " + intent.getAction());
    
    isConnected = isNetworkConnected(ctx);
    
    if (isConnected) {
      ConnectivityManager cm =
              (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
      isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
    }
    else {
      isWiFi = false;
    }
    
    // okay - no battery drain searching for radio
    if (isWiFi) {
      Prefs.getInstance().setOkayToQuery(true);
    }
  }
}




Java Source Code List

com.cjbarker.wb.Main.java
com.cjbarker.wb.Notifier.java
com.cjbarker.wb.Prefs.java
com.cjbarker.wb.Util.java
com.cjbarker.wb.receiver.BatteryLevel.java
com.cjbarker.wb.receiver.Connection.java
com.cjbarker.wb.receiver.Screen.java
com.cjbarker.wb.ws.ClientRequestTest.java
com.cjbarker.wb.ws.ClientRequest.java
com.cjbarker.wb.ws.ClientResponse.java
com.cjbarker.wb.ws.OpenWeatherTest.java
com.cjbarker.wb.ws.OpenWeather.java
com.cjbarker.wb.ws.WeatherTest.java
com.cjbarker.wb.ws.Weather.java