()
| 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() { |
nothing calls this directly
no test coverage detected