Android Open Source - bodyapps-android Sync User






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/*from  w w  w  .ja va2s  . c o m*/
 */

package fossasia.valentina.bodyapp.sync;

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

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Handles the Sync of users
 */
public class SyncUser extends Sync {

  private static String json;
  private static final String URL = "http://192.168.1.2:8020/user";
  private static String result;
  private static final int CON_TIMEOUT=5000;
  private static final int SOC_TIMEOUT=5000;
  

  /**
   * Get the user ID of the given user from web application
   * 
   * @param email
   * @param name
   * @return
   */
  public static String getUserID(String email, String name) {
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.accumulate("name", name);
      jsonObject.accumulate("age", "22");
      jsonObject.accumulate("dob", "12/10/1990");
      jsonObject.accumulate("emailId", email);
      json = jsonObject.toString();
    } catch (JSONException e) {
      e.printStackTrace();
    }
    
    SyncUser su=new SyncUser();

    result = su.POST(URL, json, CON_TIMEOUT,SOC_TIMEOUT);
    return result;
  }
  
  @Override
  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("\"", "");
    JSONObject jObject;
    String out=null;
    try {
      jObject = new JSONObject(result);
      out= jObject.getString("user_id");
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    
    return out;

  }
  

}




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