当前位置: 首页>>代码示例>>Java>>正文


Java Formatter.formatFileSize方法代码示例

本文整理汇总了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));
        }
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:ImagePreviewActivity.java

示例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);// 将获取的内存大小规格化
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:DeviceUtils.java

示例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";
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:CacheManager.java

示例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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:UploadAdapter.java

示例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;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:DesActivity.java

示例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);// 将获取的内存大小规格化
}
 
开发者ID:jqjm,项目名称:Liteframework,代码行数:12,代码来源:MemoryUtil.java

示例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);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:14,代码来源:SimpleActivity.java

示例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);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:14,代码来源:SimpleActivity.java

示例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);
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:14,代码来源:SimpleActivity.java

示例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";
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:DownloadService.java

示例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);
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:14,代码来源:MemoryUtil.java

示例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;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:41,代码来源:DetailFragment.java

示例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);
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:13,代码来源:MemoryCache.java

示例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";
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:7,代码来源:FileDownloader.java

示例15: sdSize

import android.text.format.Formatter; //导入方法依赖的package包/类
public static String sdSize(Context context) {
    return Formatter.formatFileSize(context, getTotalExternalMemorySize()) + " " +
            Formatter.formatFileSize(context, getAvailableExternalMemorySize());
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:5,代码来源:Device.java


注:本文中的android.text.format.Formatter.formatFileSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。