Skip to content

Instantly share code, notes, and snippets.

Flowable<String> f = Flowable.just("Hello");
Disposable d1 = f.subscribeWith(new DisposableSubscriber<String>() { … });
Observable<String> o = Observable.just("Hello");
Disposable d2 = o.subscribeWith(new DisposableObserver<String>() { … });
Maybe<String> m = Maybe.just("Hello");
Disposable d3 = m.subscribeWith(new DisposableMaybeObserver<String>() { … });
Single<String> s = Single.just("Hello");
PicassoTrustAll.getInstance(getApplicationContext())
.load("base_url"+"Your Image Path")
.into(ImageView);
public static class PicassoTrustAll {
private static Picasso mInstance = null;
private PicassoTrustAll(Context context) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
try {
clientBuilder.sslSocketFactory(getSSLConfig(context).getSocketFactory());
}
catch (Exception e) {
e.printStackTrace();
}
clientBuilder.hostnameVerifier(new HostnameVerifier() {
private static SSLContext getSSLConfig(Context context) throws CertificateException, IOException,
KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
// Loading CAs from an InputStream
CertificateFactory cf = null;
cf = CertificateFactory.getInstance("X.509");
Certificate ca;
// I'm using Java7. If you used Java6 close it manually with finally.
try (InputStream cert = context.getResources().openRawResource(R.raw.nginxselfsigned)) {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
//Basic Auth
if (!TextUtils.isEmpty(username)
&& !TextUtils.isEmpty(password)) {
authToken = Credentials.basic(username, password);
}
//Create a new Interceptor.
Interceptor headerAuthorizationInterceptor = new Interceptor() {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
//Create a new Interceptor.
Interceptor headerAuthorizationInterceptor = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Request request = chain.request();
Headers headers = request.headers().newBuilder().add("Authorization", authToken).build();
request = request.newBuilder().headers(headers).build();
return chain.proceed(request);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
// set your desired log level
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// add logging as last interceptor
clientBuilder.addInterceptor(loggingInterceptor);