MCPcopy Create free account
hub / github.com/Skykai521/ECTranslation / run

Method run

src/RequestRunnable.java:49–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47 }
48
49 public void run() {
50 try {
51 URI uri = createTranslationURI(mQuery);
52 RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000)
53 .setConnectionRequestTimeout(5000).build();
54 HttpGet httpGet = new HttpGet(uri);
55 httpGet.setConfig(requestConfig);
56 HttpClient client = HttpClients.createDefault();
57 HttpResponse response = client.execute(httpGet);
58 int status = response.getStatusLine().getStatusCode();
59 if (status >= 200 && status < 300) {
60 HttpEntity resEntity = response.getEntity();
61 String json = EntityUtils.toString(resEntity, "UTF-8");
62 Gson gson = new Gson();
63 Translation translation = gson.fromJson(json, Translation.class);
64 //show result
65 showPopupBalloon(translation.toString());
66 } else {
67 showPopupBalloon(response.getStatusLine().getReasonPhrase());
68 }
69 } catch (IOException e) {
70 showPopupBalloon(e.getMessage());
71 } catch (URISyntaxException e) {
72 e.printStackTrace();
73 }
74 }
75
76 private void showPopupBalloon(final String result) {
77 ApplicationManager.getApplication().invokeLater(new Runnable() {

Callers

nothing calls this directly

Calls 3

createTranslationURIMethod · 0.95
toStringMethod · 0.95
showPopupBalloonMethod · 0.95

Tested by

no test coverage detected