Java Code Examples for com.facebook.common.util.ByteConstants#MB
The following examples show how to use
com.facebook.common.util.ByteConstants#MB .
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: FrescoHelper.java From base-module with Apache License 2.0 | 6 votes |
private int getMaxCacheSize() { final int maxMemory = Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); if (maxMemory < 32 * ByteConstants.MB) { return 4 * ByteConstants.MB; } else if (maxMemory < 64 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { // We don't want to use more ashmem on Gingerbread for now, since it doesn't respond well to // native memory pressure (doesn't throw exceptions, crashes app, crashes phone) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return 8 * ByteConstants.MB; } else { return maxMemory / 4; } } }
Example 2
Source File: SettingFragment.java From PicKing with Apache License 2.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_screen); colsDetail = (int) SPUtils.get(getActivity(), AppConfig.cols_detail, 0); RadioPreference cols = (RadioPreference) findPreference(AppConfig.cols_detail); cols.setSummary("当前显示列数: " + (colsDetail + 1) + "\n图册页加载图片一般较大,同时显示多列对设备性能要求较高,请酌情选择"); EditTextPreference downloadPath = (EditTextPreference) findPreference(getResources().getString(R.string.download_path)); downloadPath.setSummary((String) SPUtils.get(getActivity(), AppConfig.download_path, AppConfig.DOWNLOAD_PATH)); noMedia = new File((String) SPUtils.get(getActivity(), AppConfig.download_path, AppConfig.DOWNLOAD_PATH) + File.separatorChar + ".nomedia"); SwitchPreference noMediaSwitch = (SwitchPreference) findPreference(AppConfig.hide_pic); if (noMedia.exists()) noMediaSwitch.setChecked(true); else noMediaSwitch.setChecked(false); Fresco.getImagePipelineFactory().getMainFileCache().trimToMinimum(); float size = (float) Fresco.getImagePipelineFactory().getMainFileCache().getSize() / ByteConstants.MB; cacheSize = (EditTextPreference) findPreference(getResources().getString(R.string.cache_size)); cacheSize.setSummary(String.format("已使用 %.2f MB", size)); }
Example 3
Source File: DefaultBitmapMemoryCacheParamsSupplier.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
private int getMaxCacheSize() { final int maxMemory = Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); if (maxMemory < 32 * ByteConstants.MB) { return 4 * ByteConstants.MB; } else if (maxMemory < 64 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { // We don't want to use more ashmem on Gingerbread for now, since it doesn't respond well to // native memory pressure (doesn't throw exceptions, crashes app, crashes phone) if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) { return 8 * ByteConstants.MB; } else { return maxMemory / 4; } } }
Example 4
Source File: AnimatedFrameCacheTest.java From fresco with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); MemoryCacheParams params = new MemoryCacheParams( 4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, TimeUnit.MINUTES.toMillis(5)); when(mMemoryCacheParamsSupplier.get()).thenReturn(params); CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get( mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, null); mCacheKey = new SimpleCacheKey("key"); mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache); mFrame1 = CloseableReference.of(mock(CloseableImage.class)); mFrame2 = CloseableReference.of(mock(CloseableImage.class)); }
Example 5
Source File: DefaultBitmapMemoryCacheParamsSupplier.java From fresco with MIT License | 6 votes |
private int getMaxCacheSize() { final int maxMemory = Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); if (maxMemory < 32 * ByteConstants.MB) { return 4 * ByteConstants.MB; } else if (maxMemory < 64 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { // We don't want to use more ashmem on Gingerbread for now, since it doesn't respond well to // native memory pressure (doesn't throw exceptions, crashes app, crashes phone) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return 8 * ByteConstants.MB; } else { return maxMemory / 4; } } }
Example 6
Source File: MyBitmapMemoryCacheParamsSupplier.java From ImageLoader with Apache License 2.0 | 5 votes |
private int getMaxCacheSize() { final int maxMemory = Math.min(mActivityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); if (maxMemory < 32 * ByteConstants.MB) { return 4 * ByteConstants.MB; } else if (maxMemory < 64 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { return maxMemory / 5; } }
Example 7
Source File: DefaultNativeMemoryChunkPoolParams.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * {@link NativeMemoryChunkPool} manages memory on the native heap, so we don't need as strict * caps as we would if we were on the Dalvik heap. However, since native memory OOMs are * significantly more problematic than Dalvik OOMs, we would like to stay conservative. */ private static int getMaxSizeSoftCap() { final int maxMemory = (int)Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return 3 * ByteConstants.MB; } else if (maxMemory < 32 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { return 12 * ByteConstants.MB; } }
Example 8
Source File: DefaultNativeMemoryChunkPoolParams.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * We need a smaller cap for devices with less then 16 MB so that we don't run the risk of * evicting other processes from the native heap. */ private static int getMaxSizeHardCap() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return maxMemory / 2; } else { return maxMemory / 4 * 3; } }
Example 9
Source File: DefaultBitmapPoolParams.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Our Bitmaps live in ashmem, meaning that they are pinned in androids' shared native memory. * Therefore, we are not constrained by the max heap size of the dalvik heap, but we want to make * sure we don't use too much memory on low end devices, so that we don't force other background * process to be evicted. */ private static int getMaxSizeHardCap() { final int maxMemory = (int)Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory > 16 * ByteConstants.MB) { return maxMemory / 4 * 3; } else { return maxMemory / 2; } }
Example 10
Source File: DefaultEncodedMemoryCacheParamsSupplier.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
private int getMaxCacheSize() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return 1 * ByteConstants.MB; } else if (maxMemory < 32 * ByteConstants.MB) { return 2 * ByteConstants.MB; } else { return 4 * ByteConstants.MB; } }
Example 11
Source File: FrescoManager.java From JianshuApp with GNU General Public License v3.0 | 5 votes |
public static void init(Context context, File baseDirectoryPath) { ImagePipelineConfig.Builder imagePipelineConfigBuilder = ImagePipelineConfig.newBuilder(context) .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(baseDirectoryPath) .setBaseDirectoryName("original") .build()) .setDownsampleEnabled(true); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); Supplier<MemoryCacheParams> memoryCacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(activityManager) { @Override public MemoryCacheParams get() { int maxCacheEntries = 256; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { maxCacheEntries = 64; } return new MemoryCacheParams( getMaxCacheSize(), maxCacheEntries, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); } private int getMaxCacheSize() { final int maxMemory = Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); if (maxMemory < 32 * ByteConstants.MB) { return 4 * ByteConstants.MB; } else if (maxMemory < 64 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { return maxMemory / 4; } } }; imagePipelineConfigBuilder.setBitmapMemoryCacheParamsSupplier(memoryCacheParamsSupplier); Fresco.initialize(context, imagePipelineConfigBuilder.build()); }
Example 12
Source File: DefaultNativeMemoryChunkPoolParams.java From fresco with MIT License | 5 votes |
/** * {@link NativeMemoryChunkPool} manages memory on the native heap, so we don't need as strict * caps as we would if we were on the Dalvik heap. However, since native memory OOMs are * significantly more problematic than Dalvik OOMs, we would like to stay conservative. */ private static int getMaxSizeSoftCap() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return 3 * ByteConstants.MB; } else if (maxMemory < 32 * ByteConstants.MB) { return 6 * ByteConstants.MB; } else { return 12 * ByteConstants.MB; } }
Example 13
Source File: DefaultNativeMemoryChunkPoolParams.java From fresco with MIT License | 5 votes |
/** * We need a smaller cap for devices with less then 16 MB so that we don't run the risk of * evicting other processes from the native heap. */ private static int getMaxSizeHardCap() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return maxMemory / 2; } else { return maxMemory / 4 * 3; } }
Example 14
Source File: DefaultBitmapPoolParams.java From fresco with MIT License | 5 votes |
/** * Our Bitmaps live in ashmem, meaning that they are pinned in androids' shared native memory. * Therefore, we are not constrained by the max heap size of the dalvik heap, but we want to make * sure we don't use too much memory on low end devices, so that we don't force other background * process to be evicted. */ private static int getMaxSizeHardCap() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory > 16 * ByteConstants.MB) { return maxMemory / 4 * 3; } else { return maxMemory / 2; } }
Example 15
Source File: DefaultEncodedMemoryCacheParamsSupplier.java From fresco with MIT License | 5 votes |
private int getMaxCacheSize() { final int maxMemory = (int) Math.min(Runtime.getRuntime().maxMemory(), Integer.MAX_VALUE); if (maxMemory < 16 * ByteConstants.MB) { return 1 * ByteConstants.MB; } else if (maxMemory < 32 * ByteConstants.MB) { return 2 * ByteConstants.MB; } else { return 4 * ByteConstants.MB; } }