com.facebook.common.util.ByteConstants Java Examples

The following examples show how to use com.facebook.common.util.ByteConstants. 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: SettingFragment.java    From PicKing with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: DefaultBitmapMemoryCacheParamsSupplier.java    From fresco with MIT License 6 votes vote down vote up
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 #3
Source File: App.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
private void loadLibrary() {
  // bugly
  Context context = getApplicationContext();
  // 获取当前包名
  String packageName = context.getPackageName();
  // 获取当前进程名
  String processName = Util.getProcessName(android.os.Process.myPid());
  // 设置是否为上报进程
  UserStrategy strategy = new UserStrategy(context);
  strategy.setUploadProcess(processName == null || processName.equals(packageName));
  CrashReport.initCrashReport(this, BuildConfig.BUGLY_APPID, BuildConfig.DEBUG, strategy);
  CrashReport.setIsDevelopmentDevice(this, BuildConfig.DEBUG);

  // fresco
  final int cacheSize = (int) (Runtime.getRuntime().maxMemory() / 8);
  ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
      .setBitmapMemoryCacheParamsSupplier(
          () -> new MemoryCacheParams(cacheSize, Integer.MAX_VALUE, cacheSize, Integer.MAX_VALUE,
              2 * ByteConstants.MB))
      .setBitmapsConfig(Bitmap.Config.RGB_565)
      .setDownsampleEnabled(true)
      .build();
  Fresco.initialize(this, config);

}
 
Example #4
Source File: DefaultNativeMemoryChunkPoolParams.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public static PoolParams get() {
  SparseIntArray DEFAULT_BUCKETS = new SparseIntArray();
  DEFAULT_BUCKETS.put(1 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(2 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(4 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(8 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(16 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(32 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(64 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(128 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(256 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(512 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(1024 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  return new PoolParams(
      getMaxSizeSoftCap(),
      getMaxSizeHardCap(),
      DEFAULT_BUCKETS);
}
 
Example #5
Source File: DefaultBitmapMemoryCacheParamsSupplier.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
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 #6
Source File: FrescoHelper.java    From base-module with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: AnimatedFrameCacheTest.java    From fresco with MIT License 6 votes vote down vote up
@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 #8
Source File: DefaultEncodedMemoryCacheParamsSupplier.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
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 #9
Source File: DefaultEncodedMemoryCacheParamsSupplier.java    From fresco with MIT License 5 votes vote down vote up
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 #10
Source File: DefaultBitmapPoolParams.java    From fresco with MIT License 5 votes vote down vote up
/**
 * 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 #11
Source File: DefaultNativeMemoryChunkPoolParams.java    From fresco with MIT License 5 votes vote down vote up
/**
 * 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 #12
Source File: DefaultNativeMemoryChunkPoolParams.java    From fresco with MIT License 5 votes vote down vote up
/**
 * {@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 vote down vote up
public static PoolParams get() {
  SparseIntArray DEFAULT_BUCKETS = new SparseIntArray();
  DEFAULT_BUCKETS.put(1 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(2 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(4 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(8 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(16 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(32 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(64 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(128 * ByteConstants.KB, SMALL_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(256 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(512 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  DEFAULT_BUCKETS.put(1024 * ByteConstants.KB, LARGE_BUCKET_LENGTH);
  return new PoolParams(getMaxSizeSoftCap(), getMaxSizeHardCap(), DEFAULT_BUCKETS);
}
 
Example #14
Source File: FrescoManager.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
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 #15
Source File: ImagePipelineConfig.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private static DiskCacheConfig getDefaultMainDiskCacheConfig(Context context) {
  return DiskCacheConfig.newBuilder()
      .setBaseDirectoryPath(context.getApplicationContext().getCacheDir())
      .setBaseDirectoryName("image_cache")
      .setMaxCacheSize(40 * ByteConstants.MB)
      .setMaxCacheSizeOnLowDiskSpace(10 * ByteConstants.MB)
      .setMaxCacheSizeOnVeryLowDiskSpace(2 * ByteConstants.MB)
      .build();
}
 
Example #16
Source File: DefaultBitmapPoolParams.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #17
Source File: DefaultNativeMemoryChunkPoolParams.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #18
Source File: DefaultNativeMemoryChunkPoolParams.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@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 #19
Source File: DiskCache.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void init(Context context, String name) {
  try {
    File lrcCacheDir = getDiskCacheDir(context, name);
    if (!lrcCacheDir.exists()) {
      lrcCacheDir.mkdir();
    }
    mLrcCache = DiskLruCache.open(lrcCacheDir, getAppVersion(context), 1, 10 * ByteConstants.MB);
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example #20
Source File: MyBitmapMemoryCacheParamsSupplier.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
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;
    }
}