本文整理汇总了Java中android.text.format.Formatter.formatFileSize方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.formatFileSize方法的具体用法?Java Formatter.formatFileSize怎么用?Java Formatter.formatFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.Formatter
的用法示例。
在下文中一共展示了Formatter.formatFileSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCheckedChanged
import android.text.format.Formatter; //导入方法依赖的package包/类
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int id = buttonView.getId();
if (id == R.id.cb_origin) {
if (isChecked) {
long size = 0;
for (ImageItem item : selectedImages)
size += item.size;
String fileSize = Formatter.formatFileSize(this, size);
isOrigin = true;
mCbOrigin.setText(getString(R.string.origin_size, fileSize));
} else {
isOrigin = false;
mCbOrigin.setText(getString(R.string.origin));
}
}
}
示例2: getAvailMemory
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* 获取系统当前可用内存大小
*
* @param context
* @return
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
示例3: getAllCacheFolderSize
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* 获取整个Cache文件夹大小
*/
public String getAllCacheFolderSize(Context context) {
try {
long size = 0;
for (String path : cachePaths) {
size += getFolderSize(new File(path));
}
return Formatter.formatFileSize(context, size);
} catch (Exception e) {
e.printStackTrace();
}
return "0";
}
示例4: refresh
import android.text.format.Formatter; //导入方法依赖的package包/类
public void refresh(Progress progress) {
String currentSize = Formatter.formatFileSize(context, progress.currentSize);
String totalSize = Formatter.formatFileSize(context, progress.totalSize);
downloadSize.setText(currentSize + "/" + totalSize);
priority.setText(String.format("优先级:%s", progress.priority));
switch (progress.status) {
case Progress.NONE:
netSpeed.setText("停止");
upload.setText("上传");
break;
case Progress.PAUSE:
netSpeed.setText("暂停中");
upload.setText("继续");
break;
case Progress.ERROR:
netSpeed.setText("上传出错");
upload.setText("出错");
break;
case Progress.WAITING:
netSpeed.setText("等待中");
upload.setText("等待");
break;
case Progress.FINISH:
upload.setText("完成");
netSpeed.setText("上传成功");
break;
case Progress.LOADING:
String speed = Formatter.formatFileSize(context, progress.speed);
netSpeed.setText(String.format("%s/s", speed));
upload.setText("停止");
break;
}
tvProgress.setText(numberFormat.format(progress.fraction));
pbProgress.setMax(10000);
pbProgress.setProgress((int) (progress.fraction * 10000));
}
示例5: refreshUi
import android.text.format.Formatter; //导入方法依赖的package包/类
private void refreshUi(Progress progress) {
String currentSize = Formatter.formatFileSize(this, progress.currentSize);
String totalSize = Formatter.formatFileSize(this, progress.totalSize);
downloadSize.setText(currentSize + "/" + totalSize);
String speed = Formatter.formatFileSize(this, progress.speed);
netSpeed.setText(String.format("%s/s", speed));
tvProgress.setText(numberFormat.format(progress.fraction));
pbProgress.setMax(10000);
pbProgress.setProgress((int) (progress.fraction * 10000));
switch (progress.status) {
case Progress.NONE:
download.setText("下载");
break;
case Progress.LOADING:
download.setText("暂停");
break;
case Progress.PAUSE:
download.setText("继续");
break;
case Progress.WAITING:
download.setText("等待");
break;
case Progress.ERROR:
download.setText("出错");
break;
case Progress.FINISH:
if (ApkUtils.isAvailable(this, new File(progress.filePath))) {
download.setText("卸载");
} else {
download.setText("安装");
}
break;
}
}
示例6: getAvailMemory
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* Get available memory info.
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static String getAvailMemory(Context context) {// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// mi.availMem; 当前系统的可用内存
return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
}
示例7: getSDAvailableSize
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* 获得sd卡剩余容量,即可用大小
*
* @return
*/
private String getSDAvailableSize()
{
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(SimpleActivity.this, blockSize * availableBlocks);
}
示例8: getRomTotalSize
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* 获得机身内存总大小
*
* @return
*/
private String getRomTotalSize()
{
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
}
示例9: getRomAvailableSize
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* 获得机身可用内存
*
* @return
*/
private String getRomAvailableSize()
{
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(SimpleActivity.this, blockSize * availableBlocks);
}
示例10: calculateDownloadSpeed
import android.text.format.Formatter; //导入方法依赖的package包/类
public void calculateDownloadSpeed(long lastStarted, long curtime, long downloadedSize) {
long time = (curtime - lastStarted) / 1000;
if (time > 0) {
this.mSpeed = Formatter.formatFileSize(mContext, downloadedSize / time) + "/s";
return;
}
this.mSpeed = "0.00 B/s";
}
示例11: getAllMemory
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* Get all memory
*
* @param context
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static String getAllMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.totalMem);
}
示例12: doInBackground
import android.text.format.Formatter; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
filePath = doc.path;
if (!Utils.isDir(doc.mimeType)) {
final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, doc.mimeType);
int thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
Point mThumbSize = new Point(thumbSize, thumbSize);
final Uri uri = DocumentsContract.buildDocumentUri(doc.authority, doc.documentId);
final Context context = getActivity();
final ContentResolver resolver = context.getContentResolver();
ContentProviderClient client = null;
try {
if (doc.mimeType.equals(Document.MIME_TYPE_APK) && !TextUtils.isEmpty(filePath)) {
result = ((BitmapDrawable) IconUtils.loadPackagePathIcon(context, filePath, Document.MIME_TYPE_APK)).getBitmap();
} else {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority());
result = DocumentsContract.getDocumentThumbnail(resolver, uri, mThumbSize, null);
}
} catch (Exception e) {
if (!(e instanceof OperationCanceledException)) {
Log.w(TAG_DETAIL, "Failed to load thumbnail for " + uri + ": " + e);
}
CrashReportingManager.logException(e);
} finally {
ContentProviderClientCompat.releaseQuietly(client);
}
sizeString = Formatter.formatFileSize(context, doc.size);
}
else{
if(!TextUtils.isEmpty(filePath)){
File dir = new File(filePath);
sizeString = Formatter.formatFileSize(getActivity(), Utils.getDirectorySize(dir));
}
}
return null;
}
示例13: getAvailableMemory
import android.text.format.Formatter; //导入方法依赖的package包/类
/**
* Get available memory
*
* @param context
* @return
*/
public static String getAvailableMemory(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return Formatter.formatFileSize(context, mi.availMem);
}
示例14: getFormattedSpeed
import android.text.format.Formatter; //导入方法依赖的package包/类
public String getFormattedSpeed() {
if (this.mDownloadVideo.timestamp >= System.currentTimeMillis()) {
return "";
}
return "@ " + Formatter.formatFileSize(this.mContext, (long) (((double) this.mDownloadVideo.downloaded) / (((double) getTotalTime()) / 1000.0d))) + "/s";
}
示例15: sdSize
import android.text.format.Formatter; //导入方法依赖的package包/类
public static String sdSize(Context context) {
return Formatter.formatFileSize(context, getTotalExternalMemorySize()) + " " +
Formatter.formatFileSize(context, getAvailableExternalMemorySize());
}