本文整理匯總了Java中com.squareup.picasso.OkHttpDownloader類的典型用法代碼示例。如果您正苦於以下問題:Java OkHttpDownloader類的具體用法?Java OkHttpDownloader怎麽用?Java OkHttpDownloader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OkHttpDownloader類屬於com.squareup.picasso包,在下文中一共展示了OkHttpDownloader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadImageViaUnsafeOkHttpPicassoInstance
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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);
}
開發者ID:fs-opensource,項目名稱:android-tutorials-picasso,代碼行數:20,代碼來源:UsageExamplePicassoBuilderBasics.java
示例2: setPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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);
}
示例3: providesPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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();
}
示例4: onCreate
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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);
}
示例5: providePicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
/**
* @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();
}
示例6: onCreate
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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();
}
示例7: initPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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);
}
示例8: initPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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);
}
示例9: providePicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@Provides
@Singleton
Picasso providePicasso(@ApplicationContext Context context){
return new Picasso.Builder(context)
.downloader(new OkHttpDownloader(context,Integer.MAX_VALUE))
// .indicatorsEnabled(true)
// .loggingEnabled(true)
.build();
}
示例10: onCreate
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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);
}
示例11: getPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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;
}
示例12: setUpPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
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);
}
示例13: getPicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
public static Picasso getPicasso(){
if(picasso==null){
picasso = new Picasso.Builder(App.getInstance())
.downloader(new OkHttpDownloader(OkHttpProvider.getInstance(sAccount)))
.build();
}
return picasso;
}
示例14: doInBackground
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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;
}
}
示例15: providePicasso
import com.squareup.picasso.OkHttpDownloader; //導入依賴的package包/類
@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();
}