Java 类com.squareup.picasso.LruCache 实例源码

项目:rview    文件:PicassoHelper.java   
public static Picasso getDefaultPicassoClient(Context context) {
    if (sDefaultPicasso == null) {
        final File cacheDir = CacheHelper.getImagesCacheDir(context);
        OkHttpClient client = new OkHttpClient.Builder()
                .addNetworkInterceptor(chain -> {
                    Response originalResponse = chain.proceed(chain.request());
                    return CacheHelper.addCacheControl(originalResponse.newBuilder()).build();
                })
                .cache(new Cache(cacheDir, CacheHelper.MAX_DISK_CACHE))
                .build();
        OkHttp3Downloader downloader = new OkHttp3Downloader(client);
        sDefaultPicasso = new Picasso.Builder(context.getApplicationContext())
                .defaultBitmapConfig(Bitmap.Config.ARGB_8888)
                .memoryCache(new LruCache(context))
                .downloader(downloader)
                .build();
    }
    return sDefaultPicasso;
}
项目:Radio2    文件:RadioApplication.java   
@Override
public void onCreate() {
    super.onCreate();
    if (LeakCanary.isInAnalyzerProcess(this)) {

        return;
    }
    LeakCanary.install(this);

    setInstance(this);

    int pool = (Runtime.getRuntime().availableProcessors() * 2) +1 ;

    Log.i("Radio", "Number of core : " + Runtime.getRuntime().availableProcessors() );

    Picasso picasso = new Picasso.Builder(this)
            .memoryCache(new LruCache(16777216))
            .defaultBitmapConfig(Bitmap.Config.RGB_565)
            .executor(new ThreadPoolExecutor(pool, pool, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()))
            .build();

    Picasso.setSingletonInstance(picasso);
}
项目:mm.io    文件:PicassoModule.java   
@Provides
@ApplicationScope
public static Picasso providePicasso(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean largeHeap = (context.getApplicationInfo().flags & ApplicationInfo.FLAG_LARGE_HEAP) != 0;
    int memoryClass = am.getMemoryClass();
    if (largeHeap && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        memoryClass = am.getLargeMemoryClass();
    }
    int memCacheSize = 1024 * 1024 * memoryClass / 3; // Target ~33% of the available heap.

    Picasso picasso = new Picasso.Builder(context)
            .memoryCache(new LruCache(memCacheSize))
            .build();
    Picasso.setSingletonInstance(picasso);
    return picasso;
}
项目:TechDissected    文件:Utils.java   
public static boolean clearCache(Context context)
{
    boolean result = false;

    LruCache pCache = getPicassoCache(context);
    if(pCache != null) {
        pCache.clear();
        result = true;
    }

    File cacheDir = context.getCacheDir();
    if(cacheDir != null && cacheDir.isDirectory())
        result = deleteDir(cacheDir);

    return result;
}
项目:p1-android    文件:P1Application.java   
@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();
}
项目:GitHub    文件:SamplePicassoFactory.java   
public static Picasso getPicasso(Context context) {
  if (sPicasso == null) {
      sPicasso = new Picasso.Builder(context)
          .downloader(new OkHttp3Downloader(context, ConfigConstants.MAX_DISK_CACHE_SIZE))
          .memoryCache(new LruCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE))
          .build();
  }
  return sPicasso;
}
项目:AndroidArchitecture    文件:PicassoUtils.java   
public static void setup(@NonNull Context context) {
    Picasso picasso = new Picasso.Builder(context)
            .downloader(new OkHttp3Downloader(context, DISK_CACHE_SIZE))
            .memoryCache(new LruCache(MEMORY_CACHE_SIZE))
            .build();
    Picasso.setSingletonInstance(picasso);
}
项目:ImageLoadPK    文件:PicassoConfigFactory.java   
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;
    }
项目:PGMacTips    文件:ImageUtilities.java   
@Override
protected Void doInBackground(Void... params) {

    Picasso p;

    if (cacheSizeMaxPercent > 0 && cacheSizeMaxPercent < 1) {
        p = new Picasso.Builder(context)
                .memoryCache(new LruCache((int) (
                        cacheSizeMaxPercent * ImageUtilities.getMaxCacheSize())))
                .build();
    } else {
        p = new Picasso.Builder(context)
                .build();
    }

    for (String str : imageURLs) {
        try {
            if (isCancelled()) {
                return null;
            }
            p.with(context).load(str).fetch();
            Thread.sleep(500);
        } catch (OutOfMemoryError e1) {
            //If we run out of memory, make sure to catch it!
            p.with(context).invalidate(str);
            return null;
        } catch (Exception e) {
        }
    }

    return null;
}
项目:greedo-layout-for-android    文件:App.java   
@Override
public void onCreate() {
    super.onCreate();

    Picasso picasso = new Picasso.Builder(this)
            .memoryCache(new LruCache(calculateMemoryCacheSize()))
            .build();
    Picasso.setSingletonInstance(picasso);
}
项目:DiskPicasso    文件:SinglePicasso.java   
/**
 * Initialize picasso.
 *
 * @param context              Android application context preferably.
 * @param memoryCacheSizeBytes Memory cache byte size.
 * @param indicatorEnabled     Enable indicator or not.
 * @param loggingEnabled       Enable logging or not.
 */
public synchronized static void init(Context context, int memoryCacheSizeBytes, boolean indicatorEnabled, boolean loggingEnabled) {
    if (sPicassoInstance == null) {
        Picasso.Builder builder = new Picasso.Builder(context);
        builder.memoryCache(new LruCache(memoryCacheSizeBytes));

        CacheExecutor executor = new CacheExecutor.Builder().setCore(1).setMax(2).build();
        builder.executor(executor);

        sPicassoInstance = builder.build();
        sPicassoInstance.setIndicatorsEnabled(indicatorEnabled);
        sPicassoInstance.setLoggingEnabled(loggingEnabled);
    }
}
项目:mc_backup    文件:ImageLoader.java   
public static synchronized Picasso with(Context context) {
    if (instance == null) {
        lrucache = new LruCache(context);
        Picasso.Builder builder = new Picasso.Builder(context).memoryCache(lrucache);

        final Distribution distribution = Distribution.getInstance(context);
        builder.downloader(new ImageDownloader(context, distribution));
        instance = builder.build();
    }

    return instance;
}
项目:fresco    文件:SamplePicassoFactory.java   
public static Picasso getPicasso(Context context) {
  if (sPicasso == null) {
      sPicasso = new Picasso.Builder(context)
          .downloader(new OkHttp3Downloader(context, ConfigConstants.MAX_DISK_CACHE_SIZE))
          .memoryCache(new LruCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE))
          .build();
  }
  return sPicasso;
}
项目:TechDissected    文件:Utils.java   
/**
 * For some reason, Picasso doesn't allow us to access its
 * cache. I guess we'll just have to force our way in through
 * Java reflection. Returns null if unsuccessful.
 * <br>
 * This may stop working in future versions of the Picasso library.
 *
 * @param context
 * @return
 */
public static LruCache getPicassoCache(final Context context)
{
    try {
        Field cacheField = Picasso.class.getDeclaredField("cache");
        cacheField.setAccessible(true);
        LruCache cache = (LruCache) cacheField.get(Picasso.with(context));
        return cache;
    }
    catch(Exception e) {
        return null;
    }
}
项目:android-couchpotato    文件:DataModule.java   
@Provides @Singleton Picasso providePicasso(Application app, OkHttpClient client) {
  return new Picasso.Builder(app).memoryCache(new LruCache(Utils.calculateMemoryCacheSize(app)))
      .downloader(new OkHttpDownloader(client))
      .listener(new Picasso.Listener() {
        @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
          Ln.e(e, "Failed to load image: %s", uri);
        }
      })
      .build();
}
项目:AndroidMusicBot    文件:AlbumArtLoader.java   
private AlbumArtLoader() {
  images = new LruCache((int) (Runtime.getRuntime().maxMemory() * (8 / 100f)));
}
项目:Uoccin    文件:Session.java   
private void buildPicasso() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BASIC);

    File cache = new File(appcx.getCacheDir(), "picasso_cache");
    if (!cache.exists())
        cache.mkdirs();

    OkHttpClient httpClient = new OkHttpClient.Builder()
            .addInterceptor(logging)
            /*.addNetworkInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    okhttp3.Response originalResponse = chain.proceed(chain.request());*/
                    /*String cacheControl = originalResponse.header("Cache-Control");
                    if (cacheControl == null || cacheControl.contains("no-store") ||
                            cacheControl.contains("no-cache") ||
                            cacheControl.contains("must-revalidate") ||
                            cacheControl.contains("max-age=0")) {
                        return originalResponse.newBuilder()
                                .header("Cache-Control", "public, max-age=" + 5000)
                                .build();
                    } else
                        return originalResponse;*/

                    /*return originalResponse.newBuilder()
                            .header("Cache-Control", "public, max-age=" + 5000)
                            .build();
                }
            })*/
            .addInterceptor(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    Request originalRequest = chain.request();
                    return chain.proceed(originalRequest.newBuilder()
                            .header("User-Agent", Commons.USER_AGENT)
                            //.header("Cache-Control", "public, max-age=" + 5000)
                            .build());
                }
            })
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(120, TimeUnit.SECONDS)
            .cache(new Cache(cache, 100000000))
            .build();

    picasso = new Picasso.Builder(appcx)
            .downloader(new OkHttp3Downloader(httpClient))
            .memoryCache(new LruCache(appcx)) // do we need this?
            .build();
    //picasso.setIndicatorsEnabled(true);

    Picasso.setSingletonInstance(picasso);
}
项目:android-sidekick    文件:PicassoHandle.java   
private CacheManager(Context context) {
    this.cache = new LruCache(calculateMemoryCacheSize(context));
}
项目:gdgapp    文件:App.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Const.DEVELOPER_MODE) {
        StrictMode.ThreadPolicy.Builder b = new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
                b.penaltyFlashScreen();
        }
        //StrictMode.setThreadPolicy(b.build());

    }

    if (BuildConfig.DEBUG) {
        Timber.plant(new Timber.DebugTree());
    } else {
        // TODO Crashlytics.start(this);
        // TODO Timber.plant(new CrashlyticsTree());
    }

    // Initialize ACRA Bugreporting (reports get send to GDG[x] Hub)
    ACRA.init(this);

    mInstance = this;

    mPreferences = getSharedPreferences("gdg", MODE_PRIVATE);

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);

        if(mPreferences.getInt(Const.SETTINGS_VERSION_CODE, 0) < pInfo.versionCode)
            migrate(mPreferences.getInt(Const.SETTINGS_VERSION_CODE, 0), pInfo.versionCode);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }

    // Initialize ModelCache and Volley
    getModelCache();
    getBitmapCache();
    GdgVolley.init(this);

    mPreferences.edit().putInt(Const.SETTINGS_APP_STARTS, mPreferences.getInt(Const.SETTINGS_APP_STARTS,0)+1).apply();

    // Initialize Picasso
    mPicasso = new Picasso.Builder(this)
            .downloader(new OkHttpDownloader(this))
            .memoryCache(new LruCache(this))
            .build();
    mPicasso.setDebugging(Const.DEVELOPER_MODE);

    // Initialize GA
    mGaInstance = GoogleAnalytics.getInstance(getApplicationContext());
    mTracker = mGaInstance.getTracker(getString(R.string.ga_trackingId));
    GAServiceManager.getInstance().setDispatchPeriod(0);
    mTracker.setAppName(getString(R.string.app_name));
    mTracker.setAnonymizeIp(true);
    mGaInstance.setDefaultTracker(mTracker);

    mOrganizerChecker = new OrganizerChecker(this, mPreferences);
    mOrganizerChecker.setLastOrganizerCheckTime(mPreferences.getLong("organizer_check_time", 0));
    mOrganizerChecker.setLastOrganizerCheckId(mPreferences.getString("organizer_check_id", null));

    GoogleAnalytics.getInstance(this).setAppOptOut(mPreferences.getBoolean("analytics",false));

    // Init LastLocationFinder
    mLocationFinder = new GingerbreadLastLocationFinder(this);
    mLocationFinder.setChangedLocationListener(this);
    updateLastLocation();
}