Search in sources :

Example 1 with SpzWarning

use of itor.topnetwork.com.dxditor.bean.SpzWarning in project Dxditor by kimi2009.

the class SpzModel method getWarningData.

@Override
public void getWarningData(final ValueCallBack<ArrayList<SpzWarning>> callBack) {
    if (Constants.testData) {
        ArrayList<SpzWarning> temp = new ArrayList<SpzWarning>();
        temp.add(new SpzWarning("", "京津线03号桥梁声屏障(2米处)声屏障位移", "120", "", "mm"));
        temp.add(new SpzWarning("", "丰沙线11号桥梁声屏障(0.9米处)声屏障位移", "80", "", "mm"));
        temp.add(new SpzWarning("", "京包线19号桥梁声屏障(2.4米处)声屏障位移", "74", "", "mm"));
        spzWarnings = temp;
        callBack.onSuccess(spzWarnings);
    } else {
        /*//Form表单格式的参数传递
        FormBody formBody = new FormBody
                .Builder()
                .add("bridgeCode", Constants.BRIDGECODE)//设置参数名称和参数值
                .build();*/
        Request request = new Request.Builder().url(Constants.getAppSoundBarrierNewOneAlarm).build();
        okHttpClient.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                System.out.println("getAppSoundBarrierNewOneAlarm:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        spzWarnings = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SpzWarning>>() {
                        }.getType());
                        callBack.onSuccess(spzWarnings);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) SpzWarning(itor.topnetwork.com.dxditor.bean.SpzWarning) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 SpzWarning (itor.topnetwork.com.dxditor.bean.SpzWarning)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Call (okhttp3.Call)1 Callback (okhttp3.Callback)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 JSONObject (org.json.JSONObject)1