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);
}
java类com.squareup.picasso.OkHttpDownloader的实例源码
UsageExamplePicassoBuilderBasics.java 文件源码
项目:android-tutorials-picasso
阅读 22
收藏 0
点赞 0
评论 0
TuchongApplication.java 文件源码
项目:tuchong-daily-android
阅读 32
收藏 0
点赞 0
评论 0
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);
}
DataModule.java 文件源码
项目:paradise
阅读 20
收藏 0
点赞 0
评论 0
@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();
}
CeaselessApplication.java 文件源码
项目:CeaselessAndroid
阅读 19
收藏 0
点赞 0
评论 0
@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);
}
ActivityModule.java 文件源码
项目:android-shared
阅读 21
收藏 0
点赞 0
评论 0
/**
* @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();
}
P1Application.java 文件源码
项目:p1-android
阅读 23
收藏 0
点赞 0
评论 0
@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();
}
App.java 文件源码
项目:PhotoDiscovery
阅读 33
收藏 0
点赞 0
评论 0
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);
}
MyApplication.java 文件源码
项目:PlayTogether
阅读 27
收藏 0
点赞 0
评论 0
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);
}
ApplicationModule.java 文件源码
项目:AppsFeed
阅读 24
收藏 0
点赞 0
评论 0
@Provides
@Singleton
Picasso providePicasso(@ApplicationContext Context context){
return new Picasso.Builder(context)
.downloader(new OkHttpDownloader(context,Integer.MAX_VALUE))
// .indicatorsEnabled(true)
// .loggingEnabled(true)
.build();
}
XYZReaderApplication.java 文件源码
项目:XYZReader
阅读 21
收藏 0
点赞 0
评论 0
@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);
}
PicassoConfigFactory.java 文件源码
项目:ImageLoadPK
阅读 16
收藏 0
点赞 0
评论 0
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;
}
Global.java 文件源码
项目:Fad-Flicks
阅读 24
收藏 0
点赞 0
评论 0
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);
}
GitlabClient.java 文件源码
项目:gitlab-android
阅读 18
收藏 0
点赞 0
评论 0
public static Picasso getPicasso(){
if(picasso==null){
picasso = new Picasso.Builder(App.getInstance())
.downloader(new OkHttpDownloader(OkHttpProvider.getInstance(sAccount)))
.build();
}
return picasso;
}
ImageFragment.java 文件源码
项目:SteamGifts
阅读 24
收藏 0
点赞 0
评论 0
@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;
}
}
DataModule.java 文件源码
项目:Pioneer
阅读 21
收藏 0
点赞 0
评论 0
@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();
}
UsageExamplePicassoBuilderBasics.java 文件源码
项目:android-tutorials-picasso
阅读 23
收藏 0
点赞 0
评论 0
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);
}
PicassoProvider.java 文件源码
项目:dhis2-android-dashboard
阅读 25
收藏 0
点赞 0
评论 0
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;
}
DataModule.java 文件源码
项目:githot
阅读 32
收藏 0
点赞 0
评论 0
@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();
}
DataModule.java 文件源码
项目:AndroidPickings
阅读 26
收藏 0
点赞 0
评论 0
@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();
}
DataModule.java 文件源码
项目:Sky31Radio
阅读 24
收藏 0
点赞 0
评论 0
@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();
}
Util.java 文件源码
项目:RecifeBomDeBola
阅读 22
收藏 0
点赞 0
评论 0
public static Picasso getImageLoader(Context context){
if(picasso == null){
OkHttpDownloader downloader = new OkHttpDownloader(context);
picasso = new Picasso.Builder(context).downloader(downloader).build();
}
return picasso;
}
DataModule.java 文件源码
项目:edm
阅读 22
收藏 0
点赞 0
评论 0
@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();
}
FavouritesFragment.java 文件源码
项目:Blip
阅读 20
收藏 0
点赞 0
评论 0
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();
}
DataModule.java 文件源码
项目:gojira
阅读 27
收藏 0
点赞 0
评论 0
@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();
}
DataModule.java 文件源码
项目:TheMovie
阅读 23
收藏 0
点赞 0
评论 0
@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();
}
DefaultPicasso.java 文件源码
项目:NasaPic
阅读 21
收藏 0
点赞 0
评论 0
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();
}
AlexandriaApplication.java 文件源码
项目:Super-Duo
阅读 21
收藏 0
点赞 0
评论 0
@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);
}
ImageFragment.java 文件源码
项目:SteamGifts
阅读 26
收藏 0
点赞 0
评论 0
@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;
}
}
DataModule.java 文件源码
项目:Pioneer
阅读 25
收藏 0
点赞 0
评论 0
@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();
}
MapboxApplication.java 文件源码
项目:mapbox-android-demo
阅读 18
收藏 0
点赞 0
评论 0
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);
}