Search in sources :

Example 26 with Callback

use of zipkin2.Callback in project mapbox-events-android by mapbox.

the class TelemetryClientNavigationEventsTest method sendsTheCorrectBodyPostingNavigationArriveEvent.

@Test
public void sendsTheCorrectBodyPostingNavigationArriveEvent() throws Exception {
    TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
    Event.Type arrive = Event.Type.NAV_ARRIVE;
    Event anArriveEvent = obtainNavigationEvent(arrive);
    List<Event> theArriveEvent = obtainEvents(anArriveEvent);
    Callback mockedCallback = mock(Callback.class);
    enqueueMockResponse();
    telemetryClient.sendEvents(theArriveEvent, mockedCallback);
    GsonBuilder gsonBuilder = configureTypeAdapter(arrive, new GsonBuilder());
    String expectedRequestBody = obtainExpectedRequestBody(gsonBuilder, theArriveEvent.get(0));
    assertRequestBodyEquals(expectedRequestBody);
}
Also used : Callback(okhttp3.Callback) GsonBuilder(com.google.gson.GsonBuilder) Test(org.junit.Test)

Example 27 with Callback

use of zipkin2.Callback in project AndroidStudy by tinggengyan.

the class OkHttpActivity method asyncGet.

/**
 * 异步的请求
 */
private void asyncGet(String url) {
    final Request request = new Request.Builder().url(url).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            Log.d(TAG, "onFailure: " + "at thread:" + Thread.currentThread());
        }

        @Override
        public void onResponse(Call call, final Response response) throws IOException {
            Log.d(TAG, "onResponse: " + "at thread:" + Thread.currentThread());
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        textViewMain.setText(response.body().string());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException)

Example 28 with Callback

use of zipkin2.Callback in project Online_Android_2018_Spring by coding-blocks-archives.

the class MainActivity method makeNetworkCall.

void makeNetworkCall(String url) throws IOException {
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(url).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        // Show a toast
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            // This method does not run on the Main Thread
            String result = response.body().string();
            // ArrayList<GithubUser> users = parseJson(result);
            Gson gson = new Gson();
            ApiResult apiResult = gson.fromJson(result, ApiResult.class);
            final GithubUserAdapter githubUserAdapter = new GithubUserAdapter(apiResult.getItems());
            MainActivity.this.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Code here runs on the Main thread
                    RecyclerView recyclerView = findViewById(R.id.rvUsers);
                    recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
                    recyclerView.setAdapter(githubUserAdapter);
                }
            });
        }
    });
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Gson(com.google.gson.Gson) IOException(java.io.IOException) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Response(okhttp3.Response) Callback(okhttp3.Callback) RecyclerView(android.support.v7.widget.RecyclerView)

Example 29 with Callback

use of zipkin2.Callback in project Dxditor by kimi2009.

the class MainpageModel method getTestData.

@Override
public void getTestData(final ValueCallBack<List<SbxxBean>> callBack) {
    list = new ArrayList<SbxxBean>();
    if (Constants.testData) {
        list.add(new SbxxBean(0, "", "3"));
        list.add(new SbxxBean(1, "", "57"));
        list.add(new SbxxBean(2, "", "31"));
        callBack.onSuccess(list);
    } else {
        Request request = new Request.Builder().url(Constants.getAppDeviceStausCount).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("getAppDeviceStausCount:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        list = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SbxxBean>>() {
                        }.getType());
                        callBack.onSuccess(list);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) 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) SbxxBean(itor.topnetwork.com.dxditor.bean.SbxxBean)

Example 30 with Callback

use of zipkin2.Callback in project Dxditor by kimi2009.

the class MainpageModel method getGjxxData.

@Override
public void getGjxxData(final ValueCallBack<List<GjxxBean>> callBack) {
    gjxxList = new ArrayList<GjxxBean>();
    if (Constants.testData) {
        gjxxList.add(new GjxxBean(1, "已恢复", 11, 0.27f));
        gjxxList.add(new GjxxBean(2, "已处理", 19, 0.46f));
        gjxxList.add(new GjxxBean(0, "告警中", 11, 0.27f));
        callBack.onSuccess(gjxxList);
    } else {
        Request request = new Request.Builder().url(Constants.getAppDeviceAlarmProportion).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("getAppDeviceAlarmProportion:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        gjxxList = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<GjxxBean>>() {
                        }.getType());
                        callBack.onSuccess(gjxxList);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) 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) GjxxBean(itor.topnetwork.com.dxditor.bean.GjxxBean)

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