Java Examples for com.squareup.picasso.OkHttpDownloader

The following java examples will help you to understand the usage of com.squareup.picasso.OkHttpDownloader. These source code samples are taken from different open source projects.

Example 1
Project: tuchong-daily-android-master  File: TuchongApplication.java View source code
public void setPicasso() {
    OkHttpClient client = new OkHttpClient();
    client.networkInterceptors().add(new StethoInterceptor());
    File cache = new File(this.getCacheDir(), PICASSO_CACHE);
    if (!cache.exists()) {
        //noinspection ResultOfMethodCallIgnored
        cache.mkdirs();
    }
    try {
        client.setCache(new Cache(cache, PICASSO_CACHE_SIZE));
    } catch (IOException e) {
        e.printStackTrace();
    }
    Picasso picasso = new Picasso.Builder(this).downloader(new OkHttpDownloader(client)).build();
    Picasso.setSingletonInstance(picasso);
}
Example 2
Project: CeaselessAndroid-master  File: CeaselessApplication.java View source code
@Override
public void onCreate() {
    super.onCreate();
    // crashlytics
    if (!BuildConfig.DEBUG) {
        Fabric.with(this, new Crashlytics());
    }
    // picasso
    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));
    Picasso picasso = builder.build();
    Picasso.setSingletonInstance(picasso);
    Iconify.with(new FontAwesomeModule());
    // realm (added by T. Kopp on 2/2/16)
    RealmConfiguration config = new RealmConfiguration.Builder(this).name(Constants.REALM_FILE_NAME).schemaVersion(Constants.SCHEMA_VERSION).deleteRealmIfMigrationNeeded().build();
    Realm.setDefaultConfiguration(config);
}
Example 3
Project: paradise-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providesPicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            Timber.e(exception, "Failed to load image: %s", uri);
        }
    }).build();
}
Example 4
Project: U2020-mortar-flow-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
            Timber.e(e, "Failed to load image: %s", uri);
        }
    }).build();
}
Example 5
Project: iFixitAndroid-master  File: PicassoUtils.java View source code
public static Picasso with(Context context) {
    // Mimicking Picasso's new OkHttpLoader(context), but with our custom OkHttpClient
    if (singleton == null) {
        OkHttpClient client = Utils.createOkHttpClient();
        try {
            client.setResponseCache(createResponseCache(context));
        } catch (IOException ignored) {
        }
        singleton = new Picasso.Builder(context).downloader(new OkHttpDownloader(client)).build();
    }
    return singleton;
}
Example 6
Project: Pioneer-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
            Timber.e(e, "Failed to load image: %s", uri);
        }
    }).build();
}
Example 7
Project: android-couchpotato-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).memoryCache(new LruCache(Utils.calculateMemoryCacheSize(app))).downloader(new OkHttpDownloader(client)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
            Ln.e(e, "Failed to load image: %s", uri);
        }
    }).build();
}
Example 8
Project: gojira-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    // Create client for picasso with global client specs
    OkHttpClient picassoClient = client.clone();
    // Intercept image loading requests to add auth header
    picassoClient.interceptors().add(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            String url = chain.request().urlString();
            // Get the current server from secure storage
            String server = Hawk.get(Preferences.KEY_SERVER);
            // Add the basic auth header only in Jira server requests
            if (url.contains(server)) {
                Request.Builder builder = chain.request().newBuilder();
                Header header = BasicAuth.getBasicAuthHeader();
                if (header != null) {
                    builder.addHeader(header.getName(), header.getValue());
                }
                return chain.proceed(builder.build());
            } else // Skip image requests that are not for the current Jira server
            {
                return chain.proceed(chain.request());
            }
        }
    });
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(picassoClient)).loggingEnabled(BuildConfig.DEBUG).build();
}
Example 9
Project: Sky31Radio-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(OkHttpClient okHttpClient, Context ctx) {
    Picasso.Builder builder = new Picasso.Builder(ctx);
    builder.downloader(new OkHttpDownloader(okHttpClient)).listener(new Picasso.Listener() {

        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            Timber.e(exception, "Picasso load image failed: " + uri.toString());
        }
    }).indicatorsEnabled(false).loggingEnabled(false);
    return builder.build();
}
Example 10
Project: 3House-master  File: Communicator.java View source code
public Picasso buildPicasso(Context context, final OHServer server) {
    if (requestLoaders.containsKey(server)) {
        return requestLoaders.get(server);
    }
    OkHttpClient httpClient = TrustModifier.createAcceptAllClient();
    httpClient.interceptors().add( chain -> {
        com.squareup.okhttp.Request.Builder newRequest = chain.request().newBuilder();
        if (server.requiresAuth()) {
            newRequest.header(Constants.HEADER_AUTHENTICATION, ConnectorUtil.createAuthValue(server.getUsername(), server.getPassword()));
        }
        return chain.proceed(newRequest.build());
    });
    final Picasso picasso = new Picasso.Builder(context).downloader(new OkHttpDownloader(httpClient)).memoryCache(new LruCache(context)).build();
    requestLoaders.put(server, picasso);
    return picasso;
}
Example 11
Project: Dribble-master  File: AppModule.java View source code
@Provides
@Singleton
public Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).indicatorsEnabled(BuildConfig.DEBUG).downloader(new OkHttpDownloader(client)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
            Timber.e(e, "Failed to load image: %s", uri);
        }
    }).build();
}
Example 12
Project: githot-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(OkHttpClient okHttpClient, Context ctx) {
    Picasso.Builder builder = new Picasso.Builder(ctx);
    builder.downloader(new OkHttpDownloader(okHttpClient)).listener(new Picasso.Listener() {

        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            L.e(exception + "Picasso load image failed: " + uri.toString());
        }
    }).indicatorsEnabled(false).loggingEnabled(false);
    return builder.build();
}
Example 13
Project: mobilevideo-master  File: MobileVideoApplication.java View source code
@Override
public void onCreate() {
    super.onCreate();
    MVDownloadManager.getInstance(getBaseContext());
    BackgroundService.registerDownloadMoniter(getApplicationContext());
    MiPushManager.getInstance(getBaseContext());
    File cacheFile = createDefaultCacheDir(getApplicationContext());
    cache = new LruCache(getApplicationContext());
    Log.d("MobileVideoApplication", " max siz=" + cache.maxSize());
    Picasso picasso = new Picasso.Builder(getApplicationContext()).memoryCache(cache).downloader(new OkHttpDownloader(cacheFile, calculateDiskCacheSize(cacheFile))).build();
    Picasso.setSingletonInstance(picasso);
    Picasso.with(getApplicationContext()).setLoggingEnabled(false);
    Picasso.with(getApplicationContext()).setIndicatorsEnabled(false);
    //check whether have new version
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (iDataORM.getBooleanValue(getApplicationContext(), "development_app", true) == true) {
                checkVerison();
            }
        }
    }, 10000);
}
Example 14
Project: smartpaws-android-master  File: MainActivity.java View source code
// TODO: Strip of NavigationLiveO usage 
@Override
public void onUserInformation() {
    if (INSTANCE == null)
        INSTANCE = this;
    AlarmService.setContext(this);
    ShutdownWakeReceiver.loadReminders();
    this.mUserName.setText("ConFuzzled");
    this.mUserPhoto.setImageResource(R.drawable.logo_confuzzled);
    Picasso.Builder b = new Picasso.Builder(this);
    // Cache is 32MB max
    b.downloader(new OkHttpDownloader(this, 32 * 1024 * 1024));
    b.defaultBitmapConfig(Bitmap.Config.RGB_565);
    PICASSO = b.build();
    String picUri = HttpClient.BASE_URL + "img/" + DataMan.getSelectedConvention(this) + "/nav_header/" + ScreenDensity.getName() + ".jpg";
    Bitmap cachedPic = DataMan.getDatabase().getImage(picUri);
    if (cachedPic == null) {
        MainActivity.PICASSO.load(picUri).into(mUserBackground);
    } else {
        mUserBackground.setImageBitmap(cachedPic);
    }
}
Example 15
Project: UtilsDmo-master  File: ImageLoader.java View source code
/***
     * �始化日志
     *
     * @param context application
     * @param isDebug 开�调试模�,指示器
     * @param isLog   开�日志
     ***/
public static void init(Context context, boolean isDebug, boolean isLog) {
    //�置缓存
    // 设置缓存大�
    cache = new LruCache(5 * 1024 * 1024);
    //�置线程池
    ExecutorService executorService = Executors.newFixedThreadPool(8);
    Picasso.Builder builder = new Picasso.Builder(context);
    //�置下载器
    builder.downloader(new OkHttpDownloader(context));
    builder.defaultBitmapConfig(Bitmap.Config.ARGB_4444);
    builder.memoryCache(cache);
    builder.executor(executorService);
    //�置调试指示器
    builder.indicatorsEnabled(isDebug);
    //构造一个Picasso
    Picasso picasso = builder.build();
    //�置日志
    picasso.setLoggingEnabled(isLog);
    //设置全局�列instance
    Picasso.setSingletonInstance(picasso);
}
Example 16
Project: popcorn-android-master  File: PopcornApplication.java View source code
@Override
public void onCreate() {
    super.onCreate();
    sThis = this;
    if (!BuildConfig.GIT_BRANCH.equals("local"))
        Fabric.with(this, new Crashlytics());
    sDefSystemLanguage = LocaleUtils.getCurrentAsString();
    LeakCanary.install(this);
    Foreground.init(this);
    Constants.DEBUG_ENABLED = false;
    int versionCode = 0;
    try {
        String packageName = getPackageName();
        PackageInfo packageInfo = getPackageManager().getPackageInfo(packageName, 0);
        int flags = packageInfo.applicationInfo.flags;
        versionCode = packageInfo.versionCode;
        Constants.DEBUG_ENABLED = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    //initialise logging
    if (Constants.DEBUG_ENABLED) {
        Timber.plant(new Timber.DebugTree());
    }
    PopcornUpdater.getInstance(this, this).checkUpdates(false);
    if (VersionUtils.isUsingCorrectBuild()) {
        TorrentService.start(this);
    }
    File path = new File(PrefUtils.get(this, Prefs.STORAGE_LOCATION, StorageUtils.getIdealCacheDirectory(this).toString()));
    File directory = new File(path, "/torrents/");
    if (PrefUtils.get(this, Prefs.REMOVE_CACHE, true)) {
        FileUtils.recursiveDelete(directory);
        FileUtils.recursiveDelete(new File(path + "/subs"));
    } else {
        File statusFile = new File(directory, "status.json");
        statusFile.delete();
    }
    Timber.d("StorageLocations: " + StorageUtils.getAllStorageLocations());
    Timber.i("Chosen cache location: " + directory);
    if (PrefUtils.get(this, Prefs.INSTALLED_VERSION, 0) < versionCode) {
        PrefUtils.save(this, Prefs.INSTALLED_VERSION, versionCode);
        FileUtils.recursiveDelete(new File(StorageUtils.getIdealCacheDirectory(this) + "/backend"));
    }
    Picasso.Builder builder = new Picasso.Builder(getAppContext());
    OkHttpDownloader downloader = new OkHttpDownloader(getHttpClient());
    builder.downloader(downloader);
    Picasso.setSingletonInstance(builder.build());
}
Example 17
Project: PushApp-Android-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(OkHttpClient okHttp, Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    return new Picasso.Builder(context).downloader(new OkHttpDownloader(okHttp)).listener(new Picasso.Listener() {

        @Override
        public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            Timber.e("Image load failed: %s\n%s", uri, exception.getMessage());
        }
    }).memoryCache(//30M
    new LruCache(am.getMemoryClass() * 1024 * 1024 / 8)).build();
}
Example 18
Project: sbt-android-master  File: DebugDataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) {
    Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttpDownloader(client));
    if (isMockMode) {
        builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
    }
    builder.listener(( picasso,  uri,  exception) -> {
        Timber.e(exception, "Error while loading image " + uri);
    });
    return builder.build();
}
Example 19
Project: Blip-master  File: RandomFragment.java View source code
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_random, container, false);
    if (SharedPrefs.getInstance().isNightModeEnabled()) {
        rootView.setBackgroundColor(getActivity().getResources().getColor(R.color.primary_light_night));
    }
    setHasOptionsMenu(true);
    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefresh);
    title = (TextView) rootView.findViewById(R.id.title);
    date = (TextView) rootView.findViewById(R.id.date);
    alt = (TextView) rootView.findViewById(R.id.alt);
    img = (ImageView) rootView.findViewById(R.id.img);
    favourite = (ImageView) rootView.findViewById(R.id.favourite);
    browser = (ImageView) rootView.findViewById(R.id.open_in_browser);
    transcript = (ImageView) rootView.findViewById(R.id.transcript);
    imgContainer = rootView.findViewById(R.id.img_container);
    share = (ImageView) rootView.findViewById(R.id.share);
    explain = (ImageView) rootView.findViewById(R.id.help);
    backgroundCard = (CardView) rootView.findViewById(R.id.comic);
    browser.setOnClickListener(this);
    transcript.setOnClickListener(this);
    imgContainer.setOnClickListener(this);
    favourite.setOnClickListener(this);
    share.setOnClickListener(this);
    explain.setOnClickListener(this);
    alt.setOnClickListener(this);
    if (SharedPrefs.getInstance().isNightModeEnabled()) {
        backgroundCard.setCardBackgroundColor(getActivity().getResources().getColor(R.color.primary_night));
        title.setTextColor(getActivity().getResources().getColor(android.R.color.white));
        date.setTextColor(getActivity().getResources().getColor(android.R.color.white));
        alt.setTextColor(getActivity().getResources().getColor(android.R.color.white));
        transcript.setColorFilter(getActivity().getResources().getColor(android.R.color.white));
        share.setColorFilter(getActivity().getResources().getColor(android.R.color.white));
        explain.setColorFilter(getActivity().getResources().getColor(android.R.color.white));
        browser.setColorFilter(getActivity().getResources().getColor(android.R.color.white));
    }
    databaseManager = new DatabaseManager(getActivity());
    simpleDateFormat = new SimpleDateFormat("MMMM dd, yyyy (EEEE)", Locale.getDefault());
    OkHttpClient picassoClient = BlipApplication.getInstance().client.clone();
    picassoClient.interceptors().add(BlipUtils.REWRITE_CACHE_CONTROL_INTERCEPTOR);
    new Picasso.Builder(getActivity()).downloader(new OkHttpDownloader(picassoClient)).build();
    int num = 0;
    if (savedInstanceState != null)
        num = savedInstanceState.getInt("NUM");
    loadComic(num);
    swipeRefreshLayout.setColorSchemeResources(R.color.accent);
    swipeRefreshLayout.setOnRefreshListener(this);
    return rootView;
}
Example 20
Project: Kore-master  File: HostManager.java View source code
/**
     * Returns the current host {@link Picasso} image downloader
     * @return {@link Picasso} instance suitable to download images from the current xbmc
     */
public Picasso getPicasso() {
    if (currentPicasso == null) {
        currentHostInfo = getHostInfo();
        if (currentHostInfo != null) {
            //                currentPicasso = new Picasso.Builder(context)
            //                        .downloader(new BasicAuthUrlConnectionDownloader(context,
            //                                currentHostInfo.getUsername(), currentHostInfo.getPassword()))
            //                        .indicatorsEnabled(BuildConfig.DEBUG)
            //                        .build();
            // Http client should already handle authentication
            OkHttpClient picassoClient = getConnection().getOkHttpClient().clone();
            //                OkHttpClient picassoClient = new OkHttpClient();
            //                // Set authentication on the client
            //                if (!TextUtils.isEmpty(currentHostInfo.getUsername())) {
            //                    picassoClient.interceptors().add(new Interceptor() {
            //                        @Override
            //                        public Response intercept(Chain chain) throws IOException {
            //
            //                            String creds = currentHostInfo.getUsername() + ":" + currentHostInfo.getPassword();
            //                            Request newRequest = chain.request().newBuilder()
            //                                    .addHeader("Authorization",
            //                                            "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP))
            //                                    .build();
            //                            return chain.proceed(newRequest);
            //                        }
            //                    });
            //                }
            // Set cache
            File cacheDir = NetUtils.createDefaultCacheDir(context);
            long cacheSize = NetUtils.calculateDiskCacheSize(cacheDir);
            picassoClient.setCache(new com.squareup.okhttp.Cache(cacheDir, cacheSize));
            currentPicasso = new Picasso.Builder(context).downloader(new OkHttpDownloader(picassoClient)).build();
        }
    }
    return currentPicasso;
}
Example 21
Project: NasaPic-master  File: DefaultPicasso.java View source code
public static Picasso get(Context context, Picasso.Listener errorListener) {
    Picasso.Builder builder = new Picasso.Builder(context).downloader(new OkHttpDownloader(context, PICASSO_CACHE_IN_BYTES));
    if (errorListener != null) {
        builder = builder.listener(errorListener);
    }
    return builder.build();
}
Example 22
Project: Trackables-master  File: DataModule.java View source code
@Singleton
@Provides
public Picasso providePicasso(App app, OkHttpDownloader okHttpDownloader) {
    return new Picasso.Builder(app).downloader(okHttpDownloader).indicatorsEnabled(true).build();
}
Example 23
Project: criticalmaps-android-master  File: AppModule.java View source code
@Provides
@Singleton
public Picasso providePicasso(App app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).build();
}
Example 24
Project: filepicker-android-master  File: ImageLoader.java View source code
// Return Picasso object with the session set, so Picasso can fetch thumbnails from Filepicker Api
private static Picasso buildImageLoader(final Context context) {
    Picasso.Builder builder = new Picasso.Builder(context);
    OkHttpClient fpHttpClient = new OkHttpClient();
    fpHttpClient.networkInterceptors().add(new FpSessionedInterceptor(context));
    builder.downloader(new OkHttpDownloader(fpHttpClient));
    return builder.build();
}
Example 25
Project: GeekBand-Android-1501-Homework-master  File: SamplePicassoFactory.java View source code
public static Picasso getPicasso(Context context) {
    if (sPicasso == null) {
        sPicasso = new Picasso.Builder(context).downloader(new OkHttpDownloader(context, ConfigConstants.MAX_DISK_CACHE_SIZE)).memoryCache(new LruCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE)).build();
    }
    return sPicasso;
}
Example 26
Project: android-gluten-master  File: TracedPicassoDownloader.java View source code
static Downloader create(Context context) {
    return new OkHttpDownloader(context);
}
Example 27
Project: kc-android-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).build();
}
Example 28
Project: KingsCrossApp-master  File: DataModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    return new Picasso.Builder(app).downloader(new OkHttpDownloader(client)).build();
}
Example 29
Project: ponyville-live-android-master  File: NetModule.java View source code
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    Picasso.Builder builder = new Picasso.Builder(app);
    builder.downloader(new OkHttpDownloader(client));
    return builder.build();
}
Example 30
Project: android-rssreader-master  File: HttpLoaderImpl.java View source code
@Override
public Picasso getPicasso() {
    if (picasso == null) {
        picasso = new Picasso.Builder(context).downloader(new OkHttpDownloader(client)).build();
        picasso.setLoggingEnabled(BuildConfig.DEBUG);
        picasso.setIndicatorsEnabled(BuildConfig.DEBUG);
    }
    return picasso;
}