Search in sources :

Example 31 with Callback

use of zipkin2.Callback in project Dxditor by kimi2009.

the class SpzModel method getTrendData.

@Override
public void getTrendData(final ValueCallBack<String> callBack, int position) {
    spzTrends = new ArrayList<SpzTrend>();
    if (Constants.testData) {
        SpzEchartsBean spzBean = new SpzEchartsBean();
        if (position == 0) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("10" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 1) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("8" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 2) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("7" + i), "03-2" + i + " 08:00"));
            }
        }
        List<String> time = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            time.add(spzTrends.get(i).getStorageTime());
        }
        spzBean.xData = time;
        List<Float> lineDatas = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            lineDatas.add(spzTrends.get(i).getTypeData());
        }
        spzBean.seriesData = lineDatas;
        callBack.onSuccess(gson.toJson(spzBean));
    } else {
        // Form表单格式的参数传递
        FormBody formBody = new FormBody.Builder().add("bridgeCode", spzWarnings.get(position).getBridgeCode()).add("type", spzWarnings.get(position).getType()).add("storageTime", Constants.MONTH).build();
        Request request = new Request.Builder().post(formBody).url(Constants.getAppSoundBarrierInfo).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("getAppSoundBarrierInfo:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        spzTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SpzTrend>>() {
                        }.getType());
                        SpzEchartsBean spzBean = new SpzEchartsBean();
                        // bridgeBean.initValue =;
                        List<String> time = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            time.add(spzTrends.get(i).getStorageTime());
                        }
                        spzBean.xData = time;
                        List<Float> lineDatas = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            lineDatas.add(spzTrends.get(i).getTypeData());
                        }
                        spzBean.seriesData = lineDatas;
                        callBack.onSuccess(gson.toJson(spzBean));
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) SpzEchartsBean(itor.topnetwork.com.dxditor.hybrid.bean.spz.SpzEchartsBean) ArrayList(java.util.ArrayList) List(java.util.List) SpzTrend(itor.topnetwork.com.dxditor.bean.SpzTrend)

Example 32 with Callback

use of zipkin2.Callback in project Dxditor by kimi2009.

the class EchartsDataBean method ztLiveEcharts.

public void ztLiveEcharts(String code) {
    FormBody formBody = new FormBody.Builder().add("weightsCode", // 设置参数名称和参数值
    code).build();
    Request request = new Request.Builder().post(formBody).url(Constants.getAppWeightsTrendInfo).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("res:"+res);
            try {
                JSONObject js = new JSONObject(res);
                if (js.getBoolean("success")) {
                    ArrayList<ZtLiveBean> ZtLiveBeans = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<ZtLiveBean>>() {
                    }.getType());
                    System.out.println("ZtLiveBeans.size():" + ZtLiveBeans.size());
                    ArrayList<String> xdata = new ArrayList<String>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        String time = ZtLiveBeans.get(i).getTimeStamp().replace("T", " ");
                        xdata.add(time);
                    }
                    ztLiveEchartsBean.xData = xdata;
                    /*ArrayList<Float> seriesdata = new ArrayList<Float>();
                        for (int i = 0; i < ZtLiveBeans.size(); i++) {
                            Float h = ZtLiveBeans.get(i).getbValue() + ZtLiveBeans.get(i).getWeightsHeight();
                            seriesdata.add(h);
                        }
                        ztLiveEchartsBean.seriesData = seriesdata;*/
                    ArrayList<Float> aValues = new ArrayList<Float>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        aValues.add(ZtLiveBeans.get(i).getaValue());
                    }
                    ztLiveEchartsBean.aValues = aValues;
                    ArrayList<Float> bValues = new ArrayList<Float>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        bValues.add(ZtLiveBeans.get(i).getbValue());
                    }
                    ztLiveEchartsBean.bValues = bValues;
                    ArrayList<Integer> temps = new ArrayList<Integer>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        temps.add(ZtLiveBeans.get(i).getTemperature());
                    }
                    ztLiveEchartsBean.temps = temps;
                    ztLiveEchartsBean.startValue = ZtLiveBeans.size() - 50;
                    ztLiveEchartsBean.endValue = ZtLiveBeans.size();
                } else {
                }
                ei.refresh(gson.toJson(ztLiveEchartsBean));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Call(okhttp3.Call) FormBody(okhttp3.FormBody) Request(okhttp3.Request) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject)

Example 33 with Callback

use of zipkin2.Callback in project SmartMesh_Android by SmartMeshFoundation.

the class TransactionDetailActivity method getTranscationBlock.

/**
 * Get the block number of the transaction hash
 */
private void getTranscationBlock() {
    try {
        NetRequestUtils.getInstance().getTxBlockNumber(TransactionDetailActivity.this, transVo.getTx(), new Callback() {

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

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                try {
                    String jsonString = response.body().string();
                    JSONObject object = new JSONObject(jsonString);
                    if (object.optInt("errcod") == 0) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(0);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 1;
                        mHandler.sendMessage(message);
                    } else if (object.optInt("errcod") == 1001222) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(0);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 1;
                        mHandler.sendMessage(message);
                    } else if (object.optInt("errcod") == 1001221) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(2);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 2;
                        mHandler.sendMessage(message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) Message(android.os.Message) JSONException(org.json.JSONException) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Example 34 with Callback

use of zipkin2.Callback in project BaseProject by wareine.

the class UploadFileManager method upLoadFile.

/**
 *上传文件
 * @param actionUrl 接口地址
 * @param paramsMap 参数
 * @param callBack 回调
 * @param <T>
 */
public <T> void upLoadFile(String actionUrl, HashMap<String, Object> paramsMap, final ReqCallBack<T> callBack) {
    try {
        // 补全请求地址
        String requestUrl = String.format("%s/%s", BASE_URL, actionUrl);
        MultipartBody.Builder builder = new MultipartBody.Builder();
        // 设置类型
        builder.setType(MultipartBody.FORM);
        // 追加参数
        for (String key : paramsMap.keySet()) {
            Object object = paramsMap.get(key);
            if (!(object instanceof File)) {
                builder.addFormDataPart(key, object.toString());
            } else {
                File file = (File) object;
                builder.addFormDataPart(key, file.getName(), RequestBody.create(null, file));
            }
        }
        // 创建RequestBody
        RequestBody body = builder.build();
        // 创建Request
        final Request request = new Request.Builder().url(requestUrl).post(body).build();
        // 单独设置参数 比如读取超时时间
        final Call call = mOkHttpClient.newBuilder().writeTimeout(50, TimeUnit.SECONDS).build().newCall(request);
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                Log.e(TAG, e.toString());
                failedCallBack("上传失败", callBack);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String string = response.body().string();
                    Log.e(TAG, "response ----->" + string);
                    successCallBack((T) string, callBack);
                } else {
                    failedCallBack("上传失败", callBack);
                }
            }
        });
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) MultipartBody(okhttp3.MultipartBody) File(java.io.File) RequestBody(okhttp3.RequestBody)

Example 35 with Callback

use of zipkin2.Callback in project BaseProject by wareine.

the class UploadFileManager method upLoadFile.

/**
 *上传文件
 * @param actionUrl 接口地址
 * @param paramsMap 参数
 * @param callBack 回调
 * @param <T>
 */
public <T> void upLoadFile(String actionUrl, HashMap<String, Object> paramsMap, final ReqProgressCallBack<T> callBack) {
    try {
        // 补全请求地址
        String requestUrl = String.format("%s/%s", BASE_URL, actionUrl);
        MultipartBody.Builder builder = new MultipartBody.Builder();
        // 设置类型
        builder.setType(MultipartBody.FORM);
        // 追加参数
        for (String key : paramsMap.keySet()) {
            Object object = paramsMap.get(key);
            if (!(object instanceof File)) {
                builder.addFormDataPart(key, object.toString());
            } else {
                File file = (File) object;
                builder.addFormDataPart(key, file.getName(), createProgressRequestBody(MEDIA_OBJECT_STREAM, file, callBack));
            }
        }
        // 创建RequestBody
        RequestBody body = builder.build();
        // 创建Request
        final Request request = new Request.Builder().url(requestUrl).post(body).build();
        final Call call = mOkHttpClient.newBuilder().writeTimeout(50, TimeUnit.SECONDS).build().newCall(request);
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                Log.e(TAG, e.toString());
                failedCallBack("上传失败", callBack);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String string = response.body().string();
                    Log.e(TAG, "response ----->" + string);
                    successCallBack((T) string, callBack);
                } else {
                    failedCallBack("上传失败", callBack);
                }
            }
        });
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) MultipartBody(okhttp3.MultipartBody) File(java.io.File) RequestBody(okhttp3.RequestBody)

Aggregations

Callback (okhttp3.Callback)173 IOException (java.io.IOException)137 Call (okhttp3.Call)132 Response (okhttp3.Response)132 Request (okhttp3.Request)110 Callback (retrofit2.Callback)42 Call (retrofit2.Call)41 Test (org.junit.Test)39 Response (retrofit2.Response)39 RequestBody (okhttp3.RequestBody)37 OkHttpClient (okhttp3.OkHttpClient)34 File (java.io.File)27 Context (android.content.Context)24 JSONObject (org.json.JSONObject)20 FormBody (okhttp3.FormBody)19 ArrayList (java.util.ArrayList)18 View (android.view.View)16 Intent (android.content.Intent)14 TextView (android.widget.TextView)14 GsonBuilder (com.google.gson.GsonBuilder)14