use of com.yzy.supercleanmaster.model.SDCardInfo in project superCleanMaster by joyoyao.
the class StorageUtil method getSDCardInfo.
public static SDCardInfo getSDCardInfo() {
if (Environment.isExternalStorageRemovable()) {
String sDcString = Environment.getExternalStorageState();
if (sDcString.equals(Environment.MEDIA_MOUNTED)) {
File pathFile = Environment.getExternalStorageDirectory();
try {
StatFs statfs = new StatFs(pathFile.getPath());
// 获取SDCard上BLOCK总数
long nTotalBlocks = statfs.getBlockCount();
// 获取SDCard上每个block的SIZE
long nBlocSize = statfs.getBlockSize();
// 获取可供程序使用的Block的数量
long nAvailaBlock = statfs.getAvailableBlocks();
// 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
long nFreeBlock = statfs.getFreeBlocks();
SDCardInfo info = new SDCardInfo();
// 计算SDCard 总容量大小MB
info.total = nTotalBlocks * nBlocSize;
// 计算 SDCard 剩余大小MB
info.free = nAvailaBlock * nBlocSize;
return info;
} catch (IllegalArgumentException e) {
}
}
}
return null;
}
use of com.yzy.supercleanmaster.model.SDCardInfo in project superCleanMaster by joyoyao.
the class StorageUtil method getSystemSpaceInfo.
public static SDCardInfo getSystemSpaceInfo(Context context) {
File path = Environment.getDataDirectory();
// File path = context.getCacheDir().getAbsoluteFile();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
long totalSize = blockSize * totalBlocks;
long availSize = availableBlocks * blockSize;
SDCardInfo info = new SDCardInfo();
info.total = totalSize;
info.free = availSize;
return info;
}
use of com.yzy.supercleanmaster.model.SDCardInfo in project superCleanMaster by joyoyao.
the class MainFragment method fillData.
private void fillData() {
// TODO Auto-generated method stub
timer = null;
timer2 = null;
timer = new Timer();
timer2 = new Timer();
long l = AppUtil.getAvailMemory(mContext);
long y = AppUtil.getTotalMemory(mContext);
final double x = (((y - l) / (double) y) * 100);
// arcProcess.setProgress((int) x);
arcProcess.setProgress(0);
timer.schedule(new TimerTask() {
@Override
public void run() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (arcProcess.getProgress() >= (int) x) {
timer.cancel();
} else {
arcProcess.setProgress(arcProcess.getProgress() + 1);
}
}
});
}
}, 50, 20);
SDCardInfo mSDCardInfo = StorageUtil.getSDCardInfo();
SDCardInfo mSystemInfo = StorageUtil.getSystemSpaceInfo(mContext);
long nAvailaBlock;
long TotalBlocks;
if (mSDCardInfo != null) {
nAvailaBlock = mSDCardInfo.free + mSystemInfo.free;
TotalBlocks = mSDCardInfo.total + mSystemInfo.total;
} else {
nAvailaBlock = mSystemInfo.free;
TotalBlocks = mSystemInfo.total;
}
final double percentStore = (((TotalBlocks - nAvailaBlock) / (double) TotalBlocks) * 100);
capacity.setText(StorageUtil.convertStorage(TotalBlocks - nAvailaBlock) + "/" + StorageUtil.convertStorage(TotalBlocks));
arcStore.setProgress(0);
timer2.schedule(new TimerTask() {
@Override
public void run() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (arcStore.getProgress() >= (int) percentStore) {
timer2.cancel();
} else {
arcStore.setProgress(arcStore.getProgress() + 1);
}
}
});
}
}, 50, 20);
}
use of com.yzy.supercleanmaster.model.SDCardInfo in project superCleanMaster by joyoyao.
the class StorageUtil method getRootSpaceInfo.
public static SDCardInfo getRootSpaceInfo() {
File path = Environment.getRootDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
long totalSize = blockSize * totalBlocks;
long availSize = availableBlocks * blockSize;
// 获取SDCard上每个block的SIZE
long nBlocSize = stat.getBlockSize();
SDCardInfo info = new SDCardInfo();
// 计算SDCard 总容量大小MB
info.total = totalSize;
// 计算 SDCard 剩余大小MB
info.free = availSize;
return info;
}
Aggregations