Android Open Source - GroupSmart-Android Service Handler






From Project

Back to project page GroupSmart-Android.

License

The source code is released under:

Copyright (C) <2014> <Derek Argueta - Hunter Kehoe> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ...

If you think the Android project GroupSmart-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 com.dargueta.groupsmart;
// w  w  w  .j a  v  a  2  s  .  c  o  m
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

/**
 * 
 * @author Hunter Kehoe
 * 
 * This class handles the remote server calls.
 *
 */
public class ServiceHandler {
  static String response = null;
  public final static int GET = 1;
  public final static int POST = 2;
  
  public ServiceHandler() {
    
  }
  
  public String makeServiceCall(String url, int method) {
    
    return this.makeServiceCall(url, method, null);
  }
  
  public String makeServiceCall(String url, int method, List<NameValuePair> params) {
    
    try {
      
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpEntity httpEntity = null;
      HttpResponse httpResponse = null;
      
      if (method == POST) {
        
      } else if (method == GET) {
        
        if (params != null) {
          
          String paramString = URLEncodedUtils.format(params, "utf-8");
          url += "?" + paramString;
        }
        
        HttpGet httpGet = new HttpGet(url);
        httpResponse = httpClient.execute(httpGet);
      }
      
      httpEntity = httpResponse.getEntity();
      response = EntityUtils.toString(httpEntity);
      
    } catch (UnsupportedEncodingException e) {
      
      e.printStackTrace();
      
    } catch (ClientProtocolException e) {
      
      e.printStackTrace();
      
    } catch (IOException e) {
      
      e.printStackTrace();
    }
    
    return response;
  }
}




Java Source Code List

com.dargueta.groupsmart.ChangePassword.java
com.dargueta.groupsmart.Constants.java
com.dargueta.groupsmart.CourseSelect.java
com.dargueta.groupsmart.CreateGroup.java
com.dargueta.groupsmart.Feedback.java
com.dargueta.groupsmart.FindGroup.java
com.dargueta.groupsmart.GroupInfo.java
com.dargueta.groupsmart.Login.java
com.dargueta.groupsmart.Main.java
com.dargueta.groupsmart.MajorSelect.java
com.dargueta.groupsmart.Profile.java
com.dargueta.groupsmart.Register.java
com.dargueta.groupsmart.ServiceHandler.java
com.dargueta.groupsmart.Settings.java
com.dargueta.groupsmart.UpdateGroup.java
com.dargueta.groupsmart.UpdateProfile.java