Android Open Source - AndroidRestWS Rest Call Task






From Project

Back to project page AndroidRestWS.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidRestWS 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.alaintxu.restws.WS;
//from  ww w  .j  a  v a 2  s.co  m
import android.os.AsyncTask;
import android.util.Log;


import com.alaintxu.restws.MainActivity;

import org.json.JSONObject;

/**
 * Created by aperez on 20/05/14.
 */
public class RestCallTask extends AsyncTask<JSONObject,Integer,JSONObject> {
    //possible actions
    public static final int CHECK_KEY   = 1;
    public static final int GET_DATA    = 2;
    public static final int SAVE_DATA   = 3;

    private RestWS rest_ws;

    private int action =   -1;
    private MainActivity myActivity;

    public RestCallTask(){
        super();
        rest_ws = new RestWS();
    }

    public RestCallTask(String ws_url){
        super();
        rest_ws = new RestWS(ws_url);
    }

    @Override
    protected JSONObject doInBackground(JSONObject... jsonObjects) {
        JSONObject jsonOutput =   null;
        try {
            JSONObject jsonInput    =   jsonObjects[0];
            action = jsonInput.getInt("action");
            jsonOutput = rest_ws.makePostQuery(jsonInput);
        }catch (Exception e) {
            action = -1;
            Log.e("RestCallTask","doInBackground() - "+e.toString());
        }

        return jsonOutput;
    }

    public void setMyActivity(MainActivity myActivity) {
        this.myActivity = myActivity;
    }

    /*protected void onProgressUpdate(Integer... progress){
        setProgressPercent(progress[0]);
    }*/

    protected void onPostExecute(JSONObject jsonOutput){
        switch (action){
            case CHECK_KEY:
                myActivity.setCheckKeyResponse(jsonOutput);
                break;
            case GET_DATA:
                myActivity.setGetDataResponse(jsonOutput);
                break;
            case SAVE_DATA:
                myActivity.setSaveDataResponse(jsonOutput);
                break;
            default:
                Log.e("RestThread","run() - Undefined Action: "+action);
        }
    }
}




Java Source Code List

com.alaintxu.restws.MainActivity.java
com.alaintxu.restws.NavigationDrawerFragment.java
com.alaintxu.restws.Settings.SettingsActivity.java
com.alaintxu.restws.Settings.SettingsFunctions.java
com.alaintxu.restws.WS.MySSLSocketFactory.java
com.alaintxu.restws.WS.RestCallTask.java
com.alaintxu.restws.WS.RestWS.java
com.alaintxu.restws.dummy.DummyContent.java