Android Open Source - bodyapps-android Sync






From Project

Back to project page bodyapps-android.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project bodyapps-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

/*
 * Copyright (c) 2014, Fashiontec (http://fashiontec.org)
 * Licensed under LGPL, Version 3// w  w  w .  j av a2s .co m
 */

package fossasia.valentina.bodyapp.sync;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.util.Log;

/**
 * Class to handle main sync methods
 */
public class Sync {
  
  /**
   * Method which makes all the POST calls
   * 
   * @param url
   * @param json
   * @return
   */
  public String POST(String url, String json, int conTimeOut, int socTimeOut) {

    InputStream inputStream = null;
    String result = "";
    try {

      HttpParams httpParameters = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(httpParameters,conTimeOut);
      HttpConnectionParams.setSoTimeout(httpParameters, socTimeOut);
      HttpClient httpclient = new DefaultHttpClient(httpParameters);
      HttpPost httpPost = new HttpPost(url);
      StringEntity se = new StringEntity(json);
      httpPost.setEntity(se);
      httpPost.setHeader("Accept", "application/json");
      httpPost.setHeader("Content-type", "application/json");
      HttpResponse httpResponse = httpclient.execute(httpPost);
      inputStream = httpResponse.getEntity().getContent();

      if (inputStream != null)
        result = convertInputStreamToString(inputStream);
      else
        result = "Did not work!";
      System.out.println(result + "result");

    } catch (Exception e) {
      Log.d("InputStream", e.getLocalizedMessage());
    }

    return result;
  }

  /**
   * Converts the given input stream to a string.
   * @param inputStream
   * @return
   * @throws IOException
   */
  public String convertInputStreamToString(InputStream inputStream)
      throws IOException {
    BufferedReader bufferedReader = new BufferedReader(
        new InputStreamReader(inputStream));
    String line = "";
    String result = "";
    while ((line = bufferedReader.readLine()) != null)
      result += line;

    inputStream.close();
    result = result.replaceAll("\"", "");
    return result;

  }
}




Java Source Code List

fossasia.valentina.bodyapp.db.DBContract.java
fossasia.valentina.bodyapp.db.DatabaseHandler.java
fossasia.valentina.bodyapp.main.CreateActivity.java
fossasia.valentina.bodyapp.main.GridAdapter.java
fossasia.valentina.bodyapp.main.MainActivity.java
fossasia.valentina.bodyapp.main.MeasurementActivity.java
fossasia.valentina.bodyapp.main.SavedActivity.java
fossasia.valentina.bodyapp.main.SavedAdapter.java
fossasia.valentina.bodyapp.main.SettingsActivity.java
fossasia.valentina.bodyapp.managers.MeasurementManager.java
fossasia.valentina.bodyapp.managers.PersonManager.java
fossasia.valentina.bodyapp.managers.UserManager.java
fossasia.valentina.bodyapp.models.MeasurementListModel.java
fossasia.valentina.bodyapp.models.Measurement.java
fossasia.valentina.bodyapp.models.Person.java
fossasia.valentina.bodyapp.models.User.java
fossasia.valentina.bodyapp.sync.SyncMeasurement.java
fossasia.valentina.bodyapp.sync.SyncUser.java
fossasia.valentina.bodyapp.sync.Sync.java