Android Open Source - face_rec_android Send C S Response






From Project

Back to project page face_rec_android.

License

The source code is released under:

GNU General Public License

If you think the Android project face_rec_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 in.amolgupta.helpingfaceless.services;
//from  w  w w. j  a v a 2s .  c o  m
import in.amolgupta.helpingfaceless.common.Constants;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;
import android.util.Log;

import com.google.gson.JsonObject;
import com.squareup.okhttp.OkHttpClient;

public class SendCSResponse extends AsyncTask<Void, Void, Boolean> {
  String taskId, auth, feedback;
  OkHttpClient client = new OkHttpClient();

  public SendCSResponse(String taskId, String auth, String feedback) {
    super();
    this.taskId = taskId;
    this.auth = auth;
    this.feedback = feedback;

  }

  String createRequestJSON() {
    String input = new String();
    JsonObject inputTaskObject = new JsonObject();
    inputTaskObject.addProperty("id", taskId);
    JsonObject inputUserObject = new JsonObject();
    inputUserObject.addProperty("similarity", feedback);

    JsonObject inputObject = new JsonObject();
//    inputObject.addProperty("access_token", "e2ad9723-b938-457b-8377-6e42f01f6697");
    inputObject.addProperty("task", taskId);
    inputObject.addProperty("user", inputUserObject.toString());
    Log.d("HF_API",inputObject.toString());
//    return inputObject.toString();
    return "task="+taskId+"&selected="+feedback;
  }
  List<NameValuePair> getNameValuePairs(){
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("task", taskId));
        nameValuePairs.add(new BasicNameValuePair("selected", feedback));
        return nameValuePairs;
  }
  @Override
  protected Boolean doInBackground(Void... params) {
    try {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost(Constants.mFeedBackURL);
          httppost.setEntity(new UrlEncodedFormEntity(getNameValuePairs()));
//      httppost.setHeader("Accept", "application/json");
//      httppost.setHeader("Content-type", "application/json");
      HttpResponse response = httpclient.execute(httppost);
      Log.d("HF_API", response.getStatusLine().toString());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return false;
    }
    return true;
  }

}




Java Source Code List

in.amolgupta.helpingfaceless.Views.Fragment.DashboardFragment.java
in.amolgupta.helpingfaceless.activities.HFBaseActivity.java
in.amolgupta.helpingfaceless.activities.HelpActivity.java
in.amolgupta.helpingfaceless.activities.HelpItemFragment.java
in.amolgupta.helpingfaceless.activities.HomeActivity.java
in.amolgupta.helpingfaceless.activities.ImageFragment.java
in.amolgupta.helpingfaceless.activities.PledgeFragment.java
in.amolgupta.helpingfaceless.activities.SetupActivity.java
in.amolgupta.helpingfaceless.activities.SigningActivity.java
in.amolgupta.helpingfaceless.activities.UploadForm.java
in.amolgupta.helpingfaceless.common.App.java
in.amolgupta.helpingfaceless.common.Constants.java
in.amolgupta.helpingfaceless.entities.ImageData.java
in.amolgupta.helpingfaceless.entities.NavItem.java
in.amolgupta.helpingfaceless.entities.TaskDetails.java
in.amolgupta.helpingfaceless.parser.CrowsourceDataParser.java
in.amolgupta.helpingfaceless.services.SendCSResponse.java
in.amolgupta.helpingfaceless.utils.ET.java
in.amolgupta.helpingfaceless.utils.LocationRequestData.java
in.amolgupta.helpingfaceless.utils.RequestUtils.java