Java Code Examples for com.squareup.picasso.Picasso#Builder
The following examples show how to use
com.squareup.picasso.Picasso#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PicassoModule.java From firebase-android-sdk with Apache License 2.0 | 8 votes |
@Provides @FirebaseAppScope Picasso providesFiamController( Application application, PicassoErrorListener picassoErrorListener) { okhttp3.OkHttpClient client = new OkHttpClient.Builder() .addInterceptor( new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { return chain.proceed( chain.request().newBuilder().addHeader("Accept", "image/*").build()); } }) .build(); Picasso.Builder builder = new Picasso.Builder(application); builder.listener(picassoErrorListener).downloader(new OkHttp3Downloader(client)); return builder.build(); }
Example 2
Source File: ImageManager.java From arcusandroid with Apache License 2.0 | 6 votes |
/** * Enables or disables the disk cache for the life of the application. This method cannot be * called more than once per lifetime of the app and should therefore be called only during * application startup; subsequent calls have no effect on the disk cache state. * * Note that when enabling Piccaso cache indicators, you may still find that some images appear * as though they've been loaded from disk. This will be true for any app-packaged drawable or * bitmap resource that's placed by Picasso. (These are always "from disk" with or without the * presence of a disk cache.) Similarly, it's possible to get green-tagged images when using * Picasso to "load" manually pre-loaded BitmapDrawables. * * @param diskCacheEnabled */ public static void setConfiguration(Context context, boolean diskCacheEnabled, Integer cacheHeapPercent) { try { Picasso.Builder builder = new Picasso.Builder((ArcusApplication.getContext())); if (diskCacheEnabled) { builder.downloader(new OkHttp3Downloader(new OkHttpClient())); } if (cacheHeapPercent != null) { ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); int memoryClass = am.getMemoryClass(); int heapSize = (int) ((float)(1024 * 1024 * memoryClass) * ((float) cacheHeapPercent / 100.0)); builder.memoryCache(new LruCache(heapSize)); logger.debug("Setting Picasso in-memory LRU cache max size to {} bytes; {}% of heap sized {}", heapSize, cacheHeapPercent, 1024 * 1024 * memoryClass); } Picasso.setSingletonInstance(builder.build()); } catch (IllegalStateException e) { logger.warn("Picasso setConfiguration() has already been called; ignoring request."); } }
Example 3
Source File: ImageModule.java From cathode with Apache License 2.0 | 6 votes |
@Provides @Singleton Picasso providePicasso(Context context, Downloader downloader, ImageRequestHandler imageRequestHandler, ShowRequestHandler showRequestHandler, SeasonRequestHandler seasonRequestHandler, EpisodeRequestHandler episodeRequestHandler, MovieRequestHandler movieRequestHandler, PersonRequestHandler personRequestHandler) { Picasso.Builder builder = new Picasso.Builder(context).requestTransformer(new ImageRequestTransformer(context)) .addRequestHandler(imageRequestHandler) .addRequestHandler(showRequestHandler) .addRequestHandler(seasonRequestHandler) .addRequestHandler(episodeRequestHandler) .addRequestHandler(movieRequestHandler) .addRequestHandler(personRequestHandler) .downloader(downloader); if (BuildConfig.DEBUG) { builder.listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { Timber.d(exception); } }); } return builder.build(); }
Example 4
Source File: MyApp.java From FaceT with Mozilla Public License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); Log.d("Myapp " , " start"); // _instance = this; FirebaseApp.getApps(this); //enable the offline capability for firebase if (!FirebaseApp.getApps(this).isEmpty()) { FirebaseDatabase.getInstance().setPersistenceEnabled(true); } EmojiManager.install(new EmojiOneProvider()); Picasso.Builder builder = new Picasso.Builder(this); // builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); // built.setIndicatorsEnabled(false); // built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); // Initialize the SDK before executing any other operations, FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); }
Example 5
Source File: DebugDataModule.java From u2020-mvp with Apache License 2.0 | 5 votes |
@Provides @ApplicationScope Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) { Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttp3Downloader(client)); if (isMockMode) { builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets())); } builder.listener((picasso, uri, exception) -> Timber.e(exception, "Error while loading image %s", uri)); return builder.build(); }
Example 6
Source File: DebugDataModule.java From u2020 with Apache License 2.0 | 5 votes |
@Provides @Singleton Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) { Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttp3Downloader(client)); if (isMockMode) { builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets())); } builder.listener((picasso, uri, exception) -> { Timber.e(exception, "Error while loading image %s", uri); }); return builder.build(); }
Example 7
Source File: DataModule.java From Sky31Radio with Apache License 2.0 | 5 votes |
@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 8
Source File: Woodmin.java From Woodmin with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); Picasso.Builder picassoBuilder = new Picasso.Builder(getApplicationContext()); Picasso picasso = picassoBuilder.build(); //picasso.setIndicatorsEnabled(true); try { Picasso.setSingletonInstance(picasso); } catch (IllegalStateException ignored) { Log.e(LOG_TAG, "Picasso instance already used"); } }
Example 9
Source File: DataModule.java From githot with Apache License 2.0 | 5 votes |
@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 10
Source File: MyApplication.java From PlayTogether with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: App.java From PhotoDiscovery with Apache License 2.0 | 5 votes |
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); }
Example 12
Source File: Global.java From Simple-Blog-App with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttp3Downloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(true); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); }
Example 13
Source File: SimpleBlog.java From Simple-Blog-App with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); if (!FirebaseApp.getApps(this).isEmpty()) { FirebaseDatabase.getInstance().setPersistenceEnabled(true);//offlinecapability } Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(false); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); }
Example 14
Source File: AppWhitelistAdapter.java From SABS with MIT License | 5 votes |
public AppWhitelistAdapter(@NonNull Context context, @NonNull List<AppInfo> appInfos) { super(context, 0, appInfos); mPackageManager = getContext().getPackageManager(); this.appInfos = appInfos; mAppInfoOriginal = appInfos; // in constructor Picasso.Builder builder = new Picasso.Builder(context); builder.addRequestHandler(new AppIconRequestHandler(context)); mPicasso = builder.build(); }
Example 15
Source File: PackageDisablerFragment.java From SABS with MIT License | 5 votes |
DisablerAppAdapter(List<AppInfo> appInfoList) { applicationInfoList = appInfoList; // in constructor Picasso.Builder builder = new Picasso.Builder(context); builder.addRequestHandler(new AppIconRequestHandler(context)); mPicasso = builder.build(); }
Example 16
Source File: Capabilities.java From ChatApp with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); // For offline use FirebaseDatabase.getInstance().setPersistenceEnabled(true); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); Picasso build = builder.build(); build.setLoggingEnabled(true); Picasso.setSingletonInstance(build); // If user disconnect if(FirebaseAuth.getInstance().getCurrentUser() != null) { final DatabaseReference userDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()); userDatabase.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot != null) { userDatabase.child("online").onDisconnect().setValue(ServerValue.TIMESTAMP); } } @Override public void onCancelled(DatabaseError databaseError) { Log.d(TAG, "usersDatabase failed: " + databaseError.getMessage()); } }); } }
Example 17
Source File: AppWhitelistAdapter.java From notSABS with MIT License | 5 votes |
public AppWhitelistAdapter(@NonNull Context context, @NonNull List<AppInfo> appInfos) { super(context, 0, appInfos); mPackageManager = getContext().getPackageManager(); this.appInfos = appInfos; mAppInfoOriginal = appInfos; // in constructor Picasso.Builder builder = new Picasso.Builder(context); builder.addRequestHandler(new AppIconRequestHandler(context)); mPicasso = builder.build(); }
Example 18
Source File: PackageDisablerFragment.java From notSABS with MIT License | 5 votes |
DisablerAppAdapter(List<AppInfo> appInfoList) { applicationInfoList = appInfoList; // in constructor Picasso.Builder builder = new Picasso.Builder(context); builder.addRequestHandler(new AppIconRequestHandler(context)); mPicasso = builder.build(); }
Example 19
Source File: ImageCoordinator.java From graphhopper-navigation-android with MIT License | 4 votes |
private void initializePicasso(Context context) { Picasso.Builder builder = new Picasso.Builder(context); picassoImageLoader = builder.build(); }
Example 20
Source File: ImageAdapter.java From incubator-weex-playground with Apache License 2.0 | 4 votes |
@Override public void setImage(final String url, final ImageView view, WXImageQuality quality, final WXImageStrategy strategy) { Runnable runnable = new Runnable() { @Override public void run() { if(view==null||view.getLayoutParams()==null){ return; } if (TextUtils.isEmpty(url)) { view.setImageBitmap(null); return; } if (null != strategy){ recordImgLoadAction(strategy.instanceId); } String temp = url; if (url.startsWith("//")) { temp = "http:" + url; } if(!TextUtils.isEmpty(strategy.placeHolder)){ Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication()); Picasso picasso=builder.build(); picasso.load(Uri.parse(strategy.placeHolder)).into(view); view.setTag(strategy.placeHolder.hashCode(),picasso); } Picasso.with(WXEnvironment.getApplication()) .load(temp) .transform(new BlurTransformation(strategy.blurRadius)) .into(view, new Callback() { @Override public void onSuccess() { if(strategy.getImageListener()!=null){ strategy.getImageListener().onImageFinish(url,view,true,null); } recordImgLoadResult(strategy.instanceId,true,null); if(!TextUtils.isEmpty(strategy.placeHolder)){ ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view); } } @Override public void onError() { if(strategy.getImageListener()!=null){ strategy.getImageListener().onImageFinish(url,view,false,null); } recordImgLoadResult(strategy.instanceId,false,null); } }); } }; if(Thread.currentThread() == Looper.getMainLooper().getThread()){ runnable.run(); }else { WXSDKManager.getInstance().postOnUiThread(runnable, 0); } }