Search in sources :

Example 1 with OkHttp3Downloader

use of com.jakewharton.picasso.OkHttp3Downloader in project cw-omnibus by commonsguy.

the class QuestionsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = super.onCreateView(inflater, container, savedInstanceState);
    setRetainInstance(true);
    OkHttpClient.Builder okb = new OkHttpClient.Builder();
    TrustManagerBuilder tmb = new TrustManagerBuilder().withManifestConfig(getActivity());
    try {
        OkHttp3Integrator.applyTo(tmb, okb);
        OkHttpClient ok = okb.build();
        picasso = new Picasso.Builder(getActivity()).downloader(new OkHttp3Downloader(ok)).build();
        Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.stackexchange.com").client(ok).addConverterFactory(GsonConverterFactory.create()).build();
        StackOverflowInterface so = retrofit.create(StackOverflowInterface.class);
        so.questions("android").enqueue(this);
    } catch (Exception e) {
        Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
        Log.e(getClass().getSimpleName(), "Exception from TrustManagerBuilder setup", e);
    }
    return (result);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) TrustManagerBuilder(com.commonsware.cwac.netsecurity.TrustManagerBuilder) Picasso(com.squareup.picasso.Picasso) OkHttp3Downloader(com.jakewharton.picasso.OkHttp3Downloader) TrustManagerBuilder(com.commonsware.cwac.netsecurity.TrustManagerBuilder) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with OkHttp3Downloader

use of com.jakewharton.picasso.OkHttp3Downloader in project u2020 by JakeWharton.

the class DebugDataModule method providePicasso.

@Provides
@Singleton
Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) {
    Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttp3Downloader(client));
    if (isMockMode) {
        builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
    }
    builder.listener((picasso, uri, exception) -> {
        Timber.e(exception, "Error while loading image %s", uri);
    });
    return builder.build();
}
Also used : Picasso(com.squareup.picasso.Picasso) OkHttp3Downloader(com.jakewharton.picasso.OkHttp3Downloader) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 3 with OkHttp3Downloader

use of com.jakewharton.picasso.OkHttp3Downloader in project Tusky by Vavassor.

the class TuskyApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    // Initialize Picasso configuration
    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttp3Downloader(this));
    if (BuildConfig.DEBUG) {
        builder.listener(new Picasso.Listener() {

            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
                exception.printStackTrace();
            }
        });
    }
    try {
        Picasso.setSingletonInstance(builder.build());
    } catch (IllegalStateException e) {
        throw new RuntimeException(e);
    }
    if (BuildConfig.DEBUG) {
        Picasso.with(this).setLoggingEnabled(true);
    }
}
Also used : Picasso(com.squareup.picasso.Picasso) OkHttp3Downloader(com.jakewharton.picasso.OkHttp3Downloader) Uri(android.net.Uri)

Aggregations

OkHttp3Downloader (com.jakewharton.picasso.OkHttp3Downloader)3 Picasso (com.squareup.picasso.Picasso)3 Uri (android.net.Uri)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 TrustManagerBuilder (com.commonsware.cwac.netsecurity.TrustManagerBuilder)1 Provides (dagger.Provides)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Singleton (javax.inject.Singleton)1 OkHttpClient (okhttp3.OkHttpClient)1 Retrofit (retrofit2.Retrofit)1