List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:app.philm.in.network.PhilmTmdb.java
License:Apache License
@Override protected RestAdapter.Builder newRestAdapterBuilder() { RestAdapter.Builder b = super.newRestAdapterBuilder(); if (mCacheLocation != null) { OkHttpClient client = new OkHttpClient(); try {/*from ww w . j a v a2 s . c om*/ File cacheDir = new File(mCacheLocation, UUID.randomUUID().toString()); Cache cache = new Cache(cacheDir, 1024); client.setCache(cache); } catch (IOException e) { Log.e(TAG, "Could not use OkHttp Cache", e); } client.setConnectTimeout(Constants.CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(Constants.READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); b.setClient(new OkClient(client)); } return b; }
From source file:appewtc.masterung.testdrivinglicense.ConfirmScoreActivity.java
public void clickOKConfirm(View view) { String urlPHP = "http://swiftcodingthai.com/toey/add_score.php"; OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("id_login", loginStrings[0]) .add("Date", dateString).add("Score", scoreString).build(); Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override// w ww . ja v a 2 s .co m public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { Intent intent = new Intent(ConfirmScoreActivity.this, ScoreListView.class); intent.putExtra("login", loginStrings); startActivity(intent); finish(); } }); }
From source file:appewtc.masterung.testdrivinglicense.ScoreListView.java
private void createListView() { String urlPHP = "http://swiftcodingthai.com/toey/get_score_where.php"; OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("id_login", loginStrings[0]) .build();/* w w w. j a v a 2s.com*/ Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { String strResponse = response.body().string(); Log.d("10AugV2", "strResponse ==> " + strResponse); try { JSONArray jsonArray = new JSONArray(strResponse); String[] dateStrings = new String[jsonArray.length()]; String[] scoreStrings = new String[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); dateStrings[i] = jsonObject.getString("Date"); scoreStrings[i] = "? = " + jsonObject.getString("Score") + " ?"; } // for CoaurseAdapter coaurseAdapter = new CoaurseAdapter(ScoreListView.this, 1, dateStrings, scoreStrings); listView.setAdapter(coaurseAdapter); } catch (Exception e) { e.printStackTrace(); } } // onResponse }); }
From source file:appewtc.masterung.testdrivinglicense.SignUpActivity.java
private void upLoadNewUser() { OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = new FormEncodingBuilder().add("isAdd", "true").add("Name", nameString) .add("Surname", surnameString).add("Age", ageString).add("User", userString) .add("Password", passwordString).build(); Request.Builder builder = new Request.Builder(); Request request = builder.url(urlPHP).post(requestBody).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override/*from w ww.ja va 2 s . c o m*/ public void onFailure(Request request, IOException e) { } @Override public void onResponse(Response response) throws IOException { finish(); } }); }
From source file:at.aau.itec.android.mediaplayer.dash.DashMediaExtractor.java
License:Open Source License
public DashMediaExtractor() { mHttpClient = new OkHttpClient(); }
From source file:at.aau.itec.android.mediaplayer.dash.DashParser.java
License:Open Source License
/** * Parses an MPD XML file. This needs to be executed off the main thread, else a * NetworkOnMainThreadException gets thrown. * @param source the URl of an MPD XML file * @return a MPD object//from www.ja v a 2s. c o m * @throws android.os.NetworkOnMainThreadException if executed on the main thread */ public MPD parse(UriSource source) { MPD mpd = null; OkHttpClient httpClient = new OkHttpClient(); Headers.Builder headers = new Headers.Builder(); if (source.getHeaders() != null && !source.getHeaders().isEmpty()) { for (String name : source.getHeaders().keySet()) { headers.add(name, source.getHeaders().get(name)); } } Request.Builder request = new Request.Builder().url(source.getUri().toString()).headers(headers.build()); try { Response response = httpClient.newCall(request.build()).execute(); if (!response.isSuccessful()) { throw new IOException("error requesting the MPD"); } mpd = parse(response.body().byteStream()); } catch (IOException e) { Log.e(TAG, "error downloading the MPD", e); throw new RuntimeException("error downloading the MPD", e); } catch (XmlPullParserException e) { Log.e(TAG, "error parsing the MPD", e); throw new RuntimeException("error parsing the MPD", e); } return mpd; }
From source file:au.com.wallaceit.reddinator.RedditData.java
License:Open Source License
private boolean createHttpClient() { httpClient = new OkHttpClient(); httpClient.setConnectTimeout(10, TimeUnit.SECONDS); httpClient.setReadTimeout(10, TimeUnit.SECONDS); httpClient.networkInterceptors().add(new Interceptor() { @Override/*w w w. jav a 2 s .c om*/ public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); Request requestWithUserAgent = originalRequest.newBuilder().removeHeader("User-Agent") .addHeader("User-Agent", userAgent).build(); return chain.proceed(requestWithUserAgent); } }); return true; }
From source file:augsburg.se.alltagsguide.ServicesModule.java
License:Open Source License
@Singleton @Provides/*from w ww . ja v a 2s .com*/ OkHttpClient okHttpClient(Context context, @Named("cacheDir") File cachedir) { Ln.d("okHttpClient is intialized."); int cacheSize = 50 * 1024 * 1024; // 50 MiB Cache cache = new Cache(cachedir, cacheSize); OkHttpClient client = new OkHttpClient(); client.setCache(cache); client.setConnectTimeout(10, TimeUnit.SECONDS); client.setWriteTimeout(10, TimeUnit.SECONDS); client.setReadTimeout(30, TimeUnit.SECONDS); return client; }
From source file:bitrefill.retrofit.Generator.java
static OkHttpClient getClient(Config config) { OkHttpClient client = new OkHttpClient(); configAuth(client, config); configLogger(client, config); return client; }
From source file:br.com.mobiplus.flickr.rest.RetrofitFacade.java
public RetrofitFacade(Context context) { this.context = context.getApplicationContext(); this.requestInterceptor = new RetrofitRequestInterceptor(context); final OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(60, TimeUnit.SECONDS); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); this.gsonRestAdapter = new RestAdapter.Builder().setLogLevel(RestAdapter.LogLevel.FULL) .setLog(new AndroidLog("##FLICKR_CLIENT")).setEndpoint(SERVER_ENDPOINT) .setRequestInterceptor(requestInterceptor).setClient(new OkClient(okHttpClient)).build(); this.service = gsonRestAdapter.create(RetrofitUrlMapping.class); }