Java Code Examples for com.squareup.picasso.Picasso#setSingletonInstance()

The following examples show how to use com.squareup.picasso.Picasso#setSingletonInstance() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: arcusandroid   File: ImageManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 Project: FaceT   File: MyApp.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@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 3
@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 4
Source Project: xposed-rimet   File: PluginManager.java    License: Apache License 2.0 5 votes vote down vote up
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 5
Source Project: xposed-aweme   File: HookManager.java    License: Apache License 2.0 5 votes vote down vote up
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 6
Source Project: ChatApp   File: Capabilities.java    License: Apache License 2.0 5 votes vote down vote up
@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 7
Source Project: Simple-Blog-App   File: SimpleBlog.java    License: MIT License 5 votes vote down vote up
@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 8
Source Project: Simple-Blog-App   File: Global.java    License: MIT License 5 votes vote down vote up
@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 9
Source Project: PhotoDiscovery   File: App.java    License: Apache License 2.0 5 votes vote down vote up
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 10
Source Project: PlayTogether   File: MyApplication.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: AndroidSchool   File: MoviesApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    sInstance = this;

    Picasso picasso = new Picasso.Builder(this)
            .downloader(new OkHttp3Downloader(this))
            .build();
    Picasso.setSingletonInstance(picasso);
}
 
Example 12
Source Project: AndroidSchool   File: MoviesApp.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: AndroidSchool   File: DayPictureApp.java    License: Apache License 2.0 5 votes vote down vote up
@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 14
Source Project: AndroidSchool   File: MoviesApp.java    License: Apache License 2.0 5 votes vote down vote up
@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 15
Source Project: greedo-layout-for-android   File: App.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Picasso picasso = new Picasso.Builder(this)
            .memoryCache(new LruCache(calculateMemoryCacheSize()))
            .build();
    Picasso.setSingletonInstance(picasso);
}
 
Example 16
Source Project: Woodmin   File: Woodmin.java    License: Apache License 2.0 5 votes vote down vote up
@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 17
Source Project: AndroidProcesses   File: App.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void onCreate() {
  super.onCreate();
  AndroidProcesses.setLoggingEnabled(true);
  Picasso.setSingletonInstance(new Picasso.Builder(this)
      .addRequestHandler(new AppIconRequestHandler(this))
      .build());
}
 
Example 18
Source Project: Woodmin   File: Woodmin.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: Tangram-Android   File: TangramApplication.java    License: MIT License 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    Picasso.setSingletonInstance(new Picasso.Builder(this).loggingEnabled(true).build());
}