Java Code Examples for com.squareup.picasso.Picasso#setSingletonInstance()
The following examples show how to use
com.squareup.picasso.Picasso#setSingletonInstance() .
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: 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 2
Source File: GalaxyZooApplication.java From android-galaxyzoo with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); //Catch leaks, in debug builds (release builds use a no-op). LeakCanary.install(this); //Let us log errors from Picasso to give us some clues when things go wrong. //Unfortunately, we can't get these errors in the regular onError() callback: //https://github.com/square/picasso/issues/379 final Picasso picasso = (new Picasso.Builder(this)).listener(GalaxyZooApplication.picassoListener).build(); //This affects what, for instance, Picasso.with() will return: try { Picasso.setSingletonInstance(picasso); } catch (final IllegalStateException ex) { //Nevermind if this happens. It's not worth crashing the app because of this. //It would just mean that we don't log the errors. Log.error("GalaxyZooApplication.onCreate(): It is too late to call Picasso.setSingletonInstance().", ex); } }
Example 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: HookManager.java From xposed-aweme with Apache License 2.0 | 5 votes |
public HookManager initialization(Context context, XC_LoadPackage.LoadPackageParam param) { if (mContext != null) { // 不需要再初始化了 return this; } // 调试开关 Alog.setDebug(BuildConfig.DEBUG); mContext = context; mHandler = new AppHandler(); mLoadPackageParam = param; mCachePreferences = new CachePreferences(context, Constant.Name.AWE_ME); mUserConfigManager = new UserConfigManager(this); mObjectManager = new ObjectManager(); mVersionManager = new VersionManager(this); mReceiverHelper = new ReceiverHelper(context, this, com.sky.xposed.common.Constant.Action.REFRESH_PREFERENCE); ToastUtil.getInstance().init(context); Picasso.setSingletonInstance(new Picasso.Builder(context).build()); // 添加统计 CrashReport.initCrashReport(mContext, "5a1f1ac8fe", BuildConfig.DEBUG); CrashReport.setAppChannel(mContext, BuildConfig.FLAVOR); // 注册事件 mReceiverHelper.registerReceiver(); return this; }
Example 10
Source File: MoviesApp.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; Picasso picasso = new Picasso.Builder(this) .downloader(new OkHttp3Downloader(this)) .build(); Picasso.setSingletonInstance(picasso); }
Example 11
Source File: MoviesApp.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; Picasso picasso = new Picasso.Builder(this) .downloader(new OkHttp3Downloader(this)) .build(); Picasso.setSingletonInstance(picasso); RealmConfiguration configuration = new RealmConfiguration.Builder(this) .rxFactory(new RealmObservableFactory()) .build(); Realm.setDefaultConfiguration(configuration); }
Example 12
Source File: DayPictureApp.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; RepositoryProvider.init(); Picasso picasso = new Picasso.Builder(this) .downloader(new OkHttp3Downloader(this)) .build(); Picasso.setSingletonInstance(picasso); }
Example 13
Source File: MoviesApp.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); sInstance = this; Picasso picasso = new Picasso.Builder(this) .downloader(new OkHttp3Downloader(this)) .build(); Picasso.setSingletonInstance(picasso); RealmConfiguration configuration = new RealmConfiguration.Builder(this) .rxFactory(new RealmObservableFactory()) .build(); Realm.setDefaultConfiguration(configuration); }
Example 14
Source File: App.java From greedo-layout-for-android with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); Picasso picasso = new Picasso.Builder(this) .memoryCache(new LruCache(calculateMemoryCacheSize())) .build(); Picasso.setSingletonInstance(picasso); }
Example 15
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 16
Source File: App.java From AndroidProcesses with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); AndroidProcesses.setLoggingEnabled(true); Picasso.setSingletonInstance(new Picasso.Builder(this) .addRequestHandler(new AppIconRequestHandler(this)) .build()); }
Example 17
Source File: PluginManager.java From xposed-rimet with Apache License 2.0 | 5 votes |
private PluginManager(Build build) { mContext = build.mContext; mLoadPackageParam = build.mLoadPackageParam; // 调试开关 Alog.setDebug(BuildConfig.DEBUG); // 创建缓存管理 mCacheManager = new CacheManager(mContext); // 创建配置管理对象 mConfigManager = new ConfigManager .Build(this) .setConfigName(Constant.Name.RIMET) .build(); // 获取版本管理对象 mVersionManager = new VersionManager .Build(mContext) .setConfigManager(mConfigManager) .setCacheManager(mCacheManager) .build(); mHandler = new PluginHandler(); ToastUtil.getInstance().init(mContext); Picasso.setSingletonInstance(new Picasso.Builder(mContext).build()); // 添加统计 CrashReport.initCrashReport(mContext, "3f1c04b5b5", BuildConfig.DEBUG); CrashReport.setAppChannel(mContext, BuildConfig.FLAVOR); // 个别需要静态引用 sXPluginManager = this; }
Example 18
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 19
Source File: TangramApplication.java From Tangram-Android with MIT License | 4 votes |
@Override public void onCreate() { super.onCreate(); Picasso.setSingletonInstance(new Picasso.Builder(this).loggingEnabled(true).build()); }