1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package epson.print.Util;
- import android.annotation.TargetApi;
- import android.os.Build;
- import android.os.StatFs;
- public class BmpFileSize {
- public static boolean check24BitBmpCapacity(String str, String str2) {
- int i = get24BitBmpSize(str);
- if (i <= 0) {
- return false;
- }
- try {
- return checkDiskCapacity(str2, i);
- } catch (Exception unused) {
- return false;
- }
- }
- private static int get24BitBmpSize(String str) {
- BmpFileInfo bmpFileInfo = new BmpFileInfo();
- if (!bmpFileInfo.readParams(str)) {
- return -1;
- }
- return (bmpFileInfo.getWidth() * bmpFileInfo.getHeight() * 3) + 138;
- }
- public static boolean checkDiskCapacity(String str, int i) {
- StatFs statFs = new StatFs(str);
- if (Build.VERSION.SDK_INT >= 18) {
- return checkDiskCapacityApi18OrMore(statFs, i);
- }
- return checkDiskCapacityApiLessThan18(statFs, i);
- }
- @TargetApi(18)
- private static boolean checkDiskCapacityApi18OrMore(StatFs statFs, int i) {
- return statFs.getFreeBlocksLong() >= (((long) i) / statFs.getBlockSizeLong()) + 1;
- }
- private static boolean checkDiskCapacityApiLessThan18(StatFs statFs, int i) {
- if (statFs.getFreeBlocks() < (i / statFs.getBlockSize()) + 1) {
- return false;
- }
- return true;
- }
- }
|