Java 类com.squareup.picasso.OkHttpDownloader 实例源码

项目:android-tutorials-picasso    文件:UsageExamplePicassoBuilderBasics.java   
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);
}
项目:tuchong-daily-android    文件:TuchongApplication.java   
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);
}
项目:paradise    文件:DataModule.java   
@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();
}
项目:CeaselessAndroid    文件:CeaselessApplication.java   
@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);

}
项目:android-shared    文件:ActivityModule.java   
/**
 * @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();
}
项目:p1-android    文件:P1Application.java   
@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();
}
项目:PhotoDiscovery    文件:App.java   
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);
}
项目:PlayTogether    文件:MyApplication.java   
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);
    }
项目:AppsFeed    文件:ApplicationModule.java   
@Provides
@Singleton
Picasso providePicasso(@ApplicationContext Context context){
    return new Picasso.Builder(context)
            .downloader(new OkHttpDownloader(context,Integer.MAX_VALUE))
           // .indicatorsEnabled(true)
           // .loggingEnabled(true)
            .build();
}
项目:XYZReader    文件:XYZReaderApplication.java   
@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);
}
项目:ImageLoadPK    文件:PicassoConfigFactory.java   
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;
    }
项目:Fad-Flicks    文件:Global.java   
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);
}
项目:gitlab-android    文件:GitlabClient.java   
public static Picasso getPicasso(){
    if(picasso==null){
        picasso = new Picasso.Builder(App.getInstance())
                .downloader(new OkHttpDownloader(OkHttpProvider.getInstance(sAccount)))
                .build();
    }
    return picasso;
}
项目:SteamGifts    文件:ImageFragment.java   
@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;
    }
}
项目:Pioneer    文件:DataModule.java   
@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();
}
项目:android-tutorials-picasso    文件:UsageExamplePicassoBuilderBasics.java   
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);
}
项目:dhis2-android-dashboard    文件:PicassoProvider.java   
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;
}
项目:githot    文件:DataModule.java   
@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();
}
项目:AndroidPickings    文件:DataModule.java   
@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();
}
项目:Sky31Radio    文件:DataModule.java   
@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();
}
项目:RecifeBomDeBola    文件:Util.java   
public static Picasso getImageLoader(Context context){
    if(picasso == null){
        OkHttpDownloader downloader = new OkHttpDownloader(context);
        picasso = new Picasso.Builder(context).downloader(downloader).build();
    }
    return picasso;
}
项目:edm    文件:DataModule.java   
@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();
}
项目:Blip    文件:FavouritesFragment.java   
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();
}
项目:gojira    文件:DataModule.java   
@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();
}
项目:TheMovie    文件:DataModule.java   
@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();
}
项目:NasaPic    文件:DefaultPicasso.java   
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();
}
项目:Super-Duo    文件:AlexandriaApplication.java   
@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);
}
项目:SteamGifts    文件:ImageFragment.java   
@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;
    }
}
项目:Pioneer    文件:DataModule.java   
@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();
}
项目:mapbox-android-demo    文件:MapboxApplication.java   
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);
}
项目:routemaster-android    文件:MainApplication.java   
@Provides
@Singleton
Picasso providePicasso(Context context) {
    return new Picasso.Builder(context)
        .downloader(new OkHttpDownloader(context))
        .build();
}
项目:photo-paper    文件:Cache.java   
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);
    }
}
项目:ShopAfter    文件:DataModule.java   
@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();
}
项目:ponyville-live-android    文件:DebugNetModule.java   
@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();
}
项目:ponyville-live-android    文件:NetModule.java   
@Provides
@Singleton
Picasso providePicasso(Application app, OkHttpClient client) {
    Picasso.Builder builder = new Picasso.Builder(app);
    builder.downloader(new OkHttpDownloader(client));
    return builder.build();
}
项目:Nefete    文件:DataModule.java   
@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();
}
项目:Qiitanium    文件:DebugDataSourceModule.java   
@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();
}
项目:android-couchpotato    文件:DataModule.java   
@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();
}
项目:dropbox-sdk-java    文件:PicassoClient.java   
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();
    }
项目:popcorn-android    文件:PopcornApplication.java   
@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());
}