本文整理匯總了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());
}