use of com.squareup.okhttp.OkHttpClient in project nmid-headline by miao1007.
the class WebViewFragment method trySetupWebview.
private void trySetupWebview() {
//http://202.202.43.205:8086/api/android/newscontent?category=1&id=194
url = HeadlineService.END_POINT + "/api/android/newscontent?id=" + feed.getIdmember() + "&category=" + feed.getCategory();
WebSettings settings = mWebView.getSettings();
mWebView.setWebContentsDebuggingEnabled(true);
settings.setTextZoom(WebViewPref.getWebViewTextZoom(getActivity()));
switch(WebViewPref.isAutoLoadImages(getActivity())) {
case 0:
settings.setLoadsImagesAutomatically(false);
break;
case 1:
break;
case 2:
if (!NetworkUtils.isWifiAviliable(getActivity())) {
settings.setLoadsImagesAutomatically(false);
}
break;
}
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
String htmlData;
if (ThemePref.isNightMode(getActivity())) {
// Webview will use asserts/style_night.css
htmlData = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style_night.css\" /> <body class= \"gloable\"> " + response.body().string() + "</body>";
} else {
// Webview will use asserts/style.css
htmlData = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /> <body class= \"gloable\"> " + response.body().string() + "</body>";
}
Log.d(TAG, Thread.currentThread().getName());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mWebView.loadDataWithBaseURL("file:///android_asset/", htmlData, MIME_TYPE, ENCODING, null);
}
});
}
});
}
use of com.squareup.okhttp.OkHttpClient in project nmid-headline by miao1007.
the class WebContentGetTask method doInBackground.
@Override
protected String doInBackground(String... params) {
OkHttpClient client = new OkHttpClient();
Cache cache;
File tmpFile = new File(GlobalContext.getInstance().getCacheDir().getPath(), ".webview_cache");
try {
cache = new Cache(tmpFile, 10 * 60 * 60);
client.setCache(cache);
} catch (Exception e) {
}
if (params[0] == null) {
throw new IllegalStateException("set url before execute!");
}
Request request = new Request.Builder().url(params[0]).build();
try {
return client.newCall(request).execute().body().string();
} catch (IOException e) {
return null;
}
}
use of com.squareup.okhttp.OkHttpClient in project Android-CleanArchitecture by android10.
the class ApiConnection method connectToApi.
private void connectToApi() {
OkHttpClient okHttpClient = this.createClient();
final Request request = new Request.Builder().url(this.url).addHeader(CONTENT_TYPE_LABEL, CONTENT_TYPE_VALUE_JSON).get().build();
try {
this.response = okHttpClient.newCall(request).execute().body().string();
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.squareup.okhttp.OkHttpClient in project PocketHub by pockethub.
the class ImageBinPoster method post.
/**
* Post the image to ImageBin
*
* @param bytes Bytes of the image to post
* @param callback Request callback
*/
public static void post(byte[] bytes, Callback callback) {
RequestBody requestBody = new MultipartBuilder().type(MultipartBuilder.FORM).addFormDataPart("file", "test", RequestBody.create(MediaType.parse("image/*"), bytes)).build();
Request request = new Request.Builder().url("https://imagebin.ca/upload.php").post(requestBody).build();
OkHttpClient client = new OkHttpClient();
Call call = client.newCall(request);
call.enqueue(callback);
}
use of com.squareup.okhttp.OkHttpClient in project FloatingSearchView by renaudcerrato.
the class RetrofitModule method provideHttpClient.
@Provides
@Singleton
OkHttpClient provideHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient();
httpClient.interceptors().add(logging);
return httpClient;
}
Aggregations