Back to project page android-rest-client.
The source code is released under:
Apache License
If you think the Android project android-rest-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dg.libs.rest; // w w w .j a v a2s .c o m import android.content.Context; import com.araneaapps.android.libs.asyncrunners.models.AsyncRunners; import com.dg.libs.rest.authentication.AuthenticationProvider; public class RestClientConfiguration { private static Context applicationContext; private AuthenticationProvider authenticationProvider; int connectionTimeout; int socketTimeout; private RestClientConfiguration(AuthenticationProvider authenticationProvider, int connectionTimeout, int socketTimeout) { this.authenticationProvider = authenticationProvider; this.connectionTimeout = connectionTimeout; this.socketTimeout = socketTimeout; } private static RestClientConfiguration generateDefaultConfig() { return new ConfigurationBuilder().create(); } private static RestClientConfiguration instance; public static void init(Context context) { applicationContext = context.getApplicationContext(); AsyncRunners.init(applicationContext); instance = generateDefaultConfig(); } public static void init(Context context, RestClientConfiguration restClientConfiguration) { applicationContext = context.getApplicationContext(); AsyncRunners.init(applicationContext); instance = restClientConfiguration; } public static RestClientConfiguration get() { if (instance == null) { throw new IllegalStateException("You need to call Init on " + RestClientConfiguration.class + " First. Do it in your class extending application"); } return instance; } public AuthenticationProvider getAuthenticationProvider() { return authenticationProvider; } public int getConnectionTimeout() { return connectionTimeout; } public int getSocketTimeout() { return socketTimeout; } public Context getContext() { return applicationContext; } public static class ConfigurationBuilder { private AuthenticationProvider authenticationProvider; private int connectionTimeout = 10000; private int socketTimeout = 20000; public ConfigurationBuilder setAuthenticationProvider(AuthenticationProvider authenticationProvider) { this.authenticationProvider = authenticationProvider; return this; } public ConfigurationBuilder setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; return this; } public ConfigurationBuilder setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; return this; } public RestClientConfiguration create() { return new RestClientConfiguration(authenticationProvider, connectionTimeout, socketTimeout); } } }