Android Open Source - formulize-android Connection Util






From Project

Back to project page formulize-android.

License

The source code is released under:

GNU General Public License

If you think the Android project formulize-android 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 ca.formulize.android.util;
/*from  w w  w  . j  a va2  s.  c  o  m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionUtil {

  /**
   * Helper function to convert an entire input stream into a String
   * 
   * @param in
   * @return String representation of the input stream
   */
  static public String readInputToString(InputStreamReader in) {
    BufferedReader reader = new BufferedReader(in);
    StringBuilder stringBuilder = new StringBuilder();

    try {
      // Read server response
      String line = null;
      while ((line = reader.readLine()) != null) {
        stringBuilder.append(line + "\n");
      }
      reader.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return stringBuilder.toString();

  }

  /**
   * Check if the user is connected to the Internet.
   * 
   * @param context The current context of the application
   * @return True if the user is connected to the Internet, else false
   */
  static public Boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
  }
}




Java Source Code List

ca.formulize.android.connection.FUserSession.java
ca.formulize.android.connection.LoginRunnable.java
ca.formulize.android.connection.LogoutAsyncTask.java
ca.formulize.android.connection.NetworkStateReceiver.java
ca.formulize.android.data.ConnectionInfo.java
ca.formulize.android.data.FormulizeApplication.java
ca.formulize.android.data.FormulizeDBContract.java
ca.formulize.android.data.FormulizeDBHelper.java
ca.formulize.android.data.FormulizeLink.java
ca.formulize.android.ui.AddConnectionActivity.java
ca.formulize.android.ui.ApplicationListActivity.java
ca.formulize.android.ui.ConnectionActivity.java
ca.formulize.android.ui.LoginDialogFragment.java
ca.formulize.android.ui.LogoutDialogFragment.java
ca.formulize.android.ui.NoNetworkDialogFragment.java
ca.formulize.android.ui.ScreenListActivity.java
ca.formulize.android.ui.ScreenWebActivity.java
ca.formulize.android.util.ConnectionUtil.java