private void loadImageViaUnsafeOkHttpPicassoInstance() { // create Picasso.Builder object Picasso.Builder picassoBuilder = new Picasso.Builder(context); // let's change the standard behavior before we create the Picasso instance // for example, let's switch out the standard downloader for the OkHttpClient // this OkHttpClient is special since it allows connection to HTTPS urls with a self-signed certificate picassoBuilder.downloader(new OkHttpDownloader(UnsafeOkHttpClient.getUnsafeOkHttpClient())); // you could further modify Picasso's behavior here, for example setting a custom cache implementation // but that would go too far for this tutorial // Picasso.Builder creates the Picasso object to do the actual requests Picasso picasso = picassoBuilder.build(); picasso .load(UsageExampleListView.eatFoodyImages[3]) .into(imageView4); }
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); }
@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(); }
@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); }
/** * @return */ @Provides @Singleton Picasso providePicasso() { final Context context = activity.getApplicationContext(); return new Picasso.Builder(context) .downloader(new OkHttpDownloader(createOkHttpClient(context))) .listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) { //Timber.e(e, "Failed to load image: %s", uri); } }) .build(); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onCreate() { super.onCreate(); me = this; // Only for development // if (Utils.hasHoneycomb()) { // Utils.enableStrictMode(); // } initAuthData(); picasso = new Picasso.Builder(this) .downloader(new OkHttpDownloader(this, 100 * 1024 * 1024)) .memoryCache(new LruCache(20 * 1024 * 1024)).build(); }
private void initPicasso() { File cacheDirectory = new File(getCacheDir().getAbsolutePath(), "OKHttpCache"); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setCache(new Cache(cacheDirectory, Integer.MAX_VALUE)); /** Dangerous interceptor that rewrites the server's cache-control header. */ okHttpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .header("Cache-Control", "public, max-age=432000") .header("Pragma", "") .build(); } }); OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(okHttpDownloader); Picasso picasso = builder.build(); //picasso.setIndicatorsEnabled(true); //picasso.setLoggingEnabled(true); Picasso.setSingletonInstance(picasso); }
private void initPicasso() { Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); // built.setIndicatorsEnabled(true); // built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); }
@Provides @Singleton Picasso providePicasso(@ApplicationContext Context context){ return new Picasso.Builder(context) .downloader(new OkHttpDownloader(context,Integer.MAX_VALUE)) // .indicatorsEnabled(true) // .loggingEnabled(true) .build(); }
@Override public void onCreate() { super.onCreate(); // config Picasso to use OkHttp for image caching // This will speed up image loading time and allow offline usage of the app Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(false); if(BuildConfig.DEBUG) { built.setLoggingEnabled(true); } Picasso.setSingletonInstance(built); }
public static Picasso getPicasso(Context context) { if (sPicasso == null) { sPicasso = new Picasso.Builder(context) //硬盘缓存池大小 .downloader(new OkHttpDownloader(context, ConfigConstants.MAX_CACHE_DISK_SIZE)) //内存缓存池大小 .memoryCache(new LruCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE)) // .defaultBitmapConfig(Bitmap.Config.ARGB_4444) .build(); } return sPicasso; }
private void setUpPicasso() { Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(ApplicationConstants.DEBUG); built.setLoggingEnabled(ApplicationConstants.DEBUG); Picasso.setSingletonInstance(built); }
public static Picasso getPicasso(){ if(picasso==null){ picasso = new Picasso.Builder(App.getInstance()) .downloader(new OkHttpDownloader(OkHttpProvider.getInstance(sAccount))) .build(); } return picasso; }
@Override protected byte[] doInBackground(Void... params) { try { // Grab an input stream to the image OkHttpDownloader downloader = new OkHttpDownloader(getContext()); Downloader.Response response = downloader.load(Uri.parse(url), 0); // Read the image into a byte array return Okio.buffer(Okio.source(response.getInputStream())).readByteArray(); } catch (Exception e) { Log.d(ImageFragment.class.getSimpleName(), "Error fetching image", e); return null; } }
@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(); }
private void loadImageViaOkHttpPicassoInstance() { // create Picasso.Builder object Picasso.Builder picassoBuilder = new Picasso.Builder(context); // let's change the standard behavior before we create the Picasso instance // for example, let's switch out the standard downloader for the OkHttpClient picassoBuilder.downloader(new OkHttpDownloader(new OkHttpClient())); // Picasso.Builder creates the Picasso object to do the actual requests Picasso picasso = picassoBuilder.build(); picasso .load(UsageExampleListView.eatFoodyImages[2]) .into(imageView3); }
public static Picasso getInstance(Context context, boolean changeCredentials) { if (mPicasso == null || changeCredentials) { OkHttpClient client = RepoManager.provideOkHttpClient( DhisController.getInstance().getUserCredentials(), context); mPicasso = new Picasso.Builder(context) .downloader(new OkHttpDownloader(client)) .build(); mPicasso.setIndicatorsEnabled(false); mPicasso.setLoggingEnabled(false); } return mPicasso; }
@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(); }
@Provides @ApplicationScope 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 exception) { Timber.e(exception, "Failed to load image: %s", uri); } }) .build(); }
@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(); }
public static Picasso getImageLoader(Context context){ if(picasso == null){ OkHttpDownloader downloader = new OkHttpDownloader(context); picasso = new Picasso.Builder(context).downloader(downloader).build(); } return picasso; }
@Provides @Singleton Picasso providePicasso(Application application, OkHttpClient client) { Context context = application.getApplicationContext(); return new Picasso.Builder(context) .downloader(new OkHttpDownloader(client)) .addRequestHandler(new ContentThumbnailRequestHandler(context)) // XXX This is really annoying. //.listener((picasso, uri, exception) -> // Timber.w(exception, "Failed to load image: %s", uri)) .build(); }
public FavouritesListAdapter() { updateList(); 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(); }
@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()); } // Skip image requests that are not for the current Jira server else { return chain.proceed(chain.request()); } } }); return new Picasso.Builder(app) .downloader(new OkHttpDownloader(picassoClient)) .loggingEnabled(BuildConfig.DEBUG) .build(); }
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(); }
@Override public void onCreate() { super.onCreate(); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(false); if(BuildConfig.DEBUG) { built.setLoggingEnabled(true); //LeakCanary.install(this); } Picasso.setSingletonInstance(built); }
private void setUpPicasso() { Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); }
@Provides @Singleton Picasso providePicasso(Context context) { return new Picasso.Builder(context) .downloader(new OkHttpDownloader(context)) .build(); }
public static Downloader createCacheDownloader(Context context) { try { Class.forName("com.squareup.okhttp.OkHttpClient"); File cacheDir = createDefaultCacheDir(context, CACHE_PATH); long cacheSize = calculateDiskCacheSize(cacheDir); return new OkHttpDownloader(cacheDir, cacheSize); } catch (ClassNotFoundException e) { return new UrlConnectionDownloader(context); } }
@Provides @Singleton Picasso providePicasso(OkHttpClient client, MockRestAdapter mockRestAdapter, @IsMockMode boolean isMockMode, Application app) { Picasso.Builder builder = new Picasso.Builder(app); if (isMockMode) { builder.downloader(new MockDownloader(mockRestAdapter, app.getAssets())); } else { builder.downloader(new OkHttpDownloader(client)); } return builder.build(); }
@Provides @Singleton Picasso providePicasso(Application app, OkHttpClient client) { Picasso.Builder builder = new Picasso.Builder(app); builder.downloader(new OkHttpDownloader(client)); return builder.build(); }
@Override public Picasso providePicasso(Application app, OkHttpClient client) { return new Picasso.Builder(app) .indicatorsEnabled(false) .downloader(new OkHttpDownloader(client)) .listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) { Timber.w(e, "Failed to load image: %s", uri); } }) .build(); }
@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(); }
public static void init(Context context, DbxClientV2 dbxClient) { // Configure picasso to know about special thumbnail requests sPicasso = new Picasso.Builder(context) .downloader(new OkHttpDownloader(context)) .addRequestHandler(new FileThumbnailRequestHandler(dbxClient)) .build(); }
@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()); }