Search in sources :

Example 56 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_pj_p6.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_pj_p6(final OnNetworkCallback_PJ_P6 listener, int member_id, int ex61, int ex62, int ex63, int ex64, int ex65, int ex66) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataPJP6(member_id, ex61, ex62, ex63, ex64, ex65, ex66);
    call.enqueue(new Callback<POJO_PJ_P6>() {

        @Override
        public void onResponse(Call<POJO_PJ_P6> call, Response<POJO_PJ_P6> response) {
            try {
                POJO_PJ_P6 assessmentstu6 = (POJO_PJ_P6) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(assessmentstu6);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_PJ_P6> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) POJO_PJ_P6(com.example.user.dvectn.POJO.POJO_PJ_P6) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Example 57 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServerLogin.

public void callServerLogin(final OnNetworkCallbackLoginListener listener, String username, String password) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.loginHandle(username, password);
    call.enqueue(new Callback<POJO_login>() {

        @Override
        public void onResponse(Call<POJO_login> call, Response<POJO_login> response) {
            try {
                POJO_login loginRes = (POJO_login) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(loginRes);
                }
            } catch (Exception e) {
                Log.e("Network connect error", e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_login> call, Throwable t) {
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) POJO_login(com.example.user.dvectn.POJO.POJO_login)

Example 58 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_pj_p4.

// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_pj_p4(final OnNetworkCallback_PJ_P4 listener, int member_id, int ex41, int ex42, int ex43, int ex44, int ex45, int ex46, int ex47) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataPJP4(member_id, ex41, ex42, ex43, ex44, ex45, ex46, ex47);
    call.enqueue(new Callback<POJO_PJ_P4>() {

        @Override
        public void onResponse(Call<POJO_PJ_P4> call, Response<POJO_PJ_P4> response) {
            try {
                POJO_PJ_P4 assessmentstu4 = (POJO_PJ_P4) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(assessmentstu4);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_PJ_P4> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) POJO_PJ_P4(com.example.user.dvectn.POJO.POJO_PJ_P4)

Example 59 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_pj_p2.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_pj_p2(final OnNetworkCallback_PJ_P2 listener, int member_id, int ex21, int ex22, int ex23, int ex24, int ex25, int ex26, int ex27, int ex28) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataPJP2(member_id, ex21, ex22, ex23, ex24, ex25, ex26, ex27, ex28);
    call.enqueue(new Callback<POJO_PJ_P2>() {

        @Override
        public void onResponse(Call<POJO_PJ_P2> call, Response<POJO_PJ_P2> response) {
            try {
                POJO_PJ_P2 assessmentstu2 = (POJO_PJ_P2) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(assessmentstu2);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_PJ_P2> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) POJO_PJ_P2(com.example.user.dvectn.POJO.POJO_PJ_P2)

Example 60 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_test1_in_ag.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// public void callServer_bt_d1(final OnNetworkCallback_BT_D1 listener, int member_id, String  app_name, int app_date, String  app_detai) {
// 
// Gson gson = new GsonBuilder()
// .setLenient()
// .create();
// 
// final Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(Fragment_login.BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .build();
// 
// APISERVER callapi = retrofit.create(APISERVER.class);
// 
// Call call = callapi.getDatadaily(member_id, app_name, app_date, app_detai);
// call.enqueue(new Callback<POJO_Checkdaily>() {
// 
// 
// @Override
// public void onResponse(Call<POJO_Checkdaily> call, Response<POJO_Checkdaily> response) {
// //                Log.e("onResponse",""+response.body());
// 
// try {
// 
// POJO_Checkdaily Checkdaily = (POJO_Checkdaily) response.body();
// 
// if (response.code() != 200) {
// //                        Log.e("Network connected","Response code = "+response.code());
// 
// ResponseBody responseBody = response.errorBody();
// 
// if (responseBody != null) {
// listener.onBodyError(responseBody);
// } else if (responseBody == null) {
// listener.onBodyErrorIsNull();
// }
// 
// //                        Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
// //                        Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
// } else {
// listener.onResponse(Checkdaily);
// }
// 
// } catch (Exception e) {
// //                    Log.e("Network connect error",e.getMessage());
// }
// }
// 
// @Override
// public void onFailure(Call<POJO_Checkdaily> call, Throwable t) {
// Log.e("NT", t.getMessage());
// try {
// 
// listener.onFailure(t);
// 
// } catch (Exception e) {
// 
// listener.onFailure(t);
// //                    Log.e("Network connectLogin",t.getMessage());
// }
// 
// }
// });
// }
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_test1_in_ag(final OnNetworkCallback_test1_in_ag listener, int member_id) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDatatest1(member_id);
    call.enqueue(new Callback<POJO_test1_in_ag>() {

        @Override
        public void onResponse(Call<POJO_test1_in_ag> call, Response<POJO_test1_in_ag> response) {
            try {
                POJO_test1_in_ag test1 = (POJO_test1_in_ag) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(test1);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_test1_in_ag> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) POJO_test1_in_ag(com.example.user.dvectn.POJO.POJO_test1_in_ag) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1067 Gson (com.google.gson.Gson)803 IOException (java.io.IOException)185 Test (org.junit.Test)141 ArrayList (java.util.ArrayList)101 JsonObject (com.google.gson.JsonObject)90 File (java.io.File)80 JsonElement (com.google.gson.JsonElement)78 HashMap (java.util.HashMap)67 List (java.util.List)62 Map (java.util.Map)59 Retrofit (retrofit2.Retrofit)56 Type (java.lang.reflect.Type)52 FileNotFoundException (java.io.FileNotFoundException)42 TypeToken (com.google.gson.reflect.TypeToken)40 ResponseBody (okhttp3.ResponseBody)39 FileOutputStream (java.io.FileOutputStream)38 Call (retrofit2.Call)38 JsonSyntaxException (com.google.gson.JsonSyntaxException)37 JsonParser (com.google.gson.JsonParser)36