Java Code Examples for android.text.format.Formatter#formatFileSize()

The following examples show how to use android.text.format.Formatter#formatFileSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImagePreviewActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@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.atom_ui_ip_origin_size, fileSize));
        } else {
            isOrigin = false;
            mCbOrigin.setText(getString(R.string.atom_ui_ip_origin));
        }
    }
}
 
Example 2
Source File: ImagePreviewActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 图片添加成功后,修改当前图片的选中数量
 * 当调用 addSelectedImageItem 或 deleteSelectedImageItem 都会触发当前回调
 */
@Override
public void onImageSelected(int position, ImageItem item, boolean isAdd) {
    if(isDelete){
        if (imagePicker.getSelectImageCount() > 0) {
            mBtnOk.setText(getString(R.string.atom_ui_ip_select_delete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
        } else {
            mBtnOk.setText(getString(R.string.atom_ui_common_delete));
        }
    }else{
        if (imagePicker.getSelectImageCount() > 0) {
            mBtnOk.setText(getString(R.string.atom_ui_ip_select_complete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
        } else {
            mBtnOk.setText(getString(R.string.atom_ui_ip_complete));
        }
    }


    if (mCbOrigin.isChecked()) {
        long size = 0;
        for (ImageItem imageItem : selectedImages)
            size += imageItem.size;
        String fileSize = Formatter.formatFileSize(this, size);
        mCbOrigin.setText(getString(R.string.atom_ui_ip_origin_size, fileSize));
    }
}
 
Example 3
Source File: FileSizeUtil.java    From SeeWeather with Apache License 2.0 6 votes vote down vote up
/**
 * 调用此方法自动计算指定文件或指定文件夹的大小
 *
 * @param filePath 文件路径
 * @return 计算好的带B、KB、MB、GB的字符串
 */
public static String getAutoFileOrFilesSize(String filePath) {
    File file = new File(filePath);
    long blockSize = 0;
    try {
        if (file.isDirectory()) {
            blockSize = getFileSizes(file);
        }
        else {
            blockSize = getFileSize(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
        PLog.e("获取文件大小失败!");
    }
    return Formatter.formatFileSize(BaseApplication.getAppContext(),blockSize);
}
 
Example 4
Source File: AppInfosHolder.java    From miappstore with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshView(AppDetail appDetail, String hostUrl, int position) {
    tv_name.setText(appDetail.getDisPlayName());
    bitmapUtils.display(iv_icon, hostUrl + appDetail.getIcon());
    rb_score.setRating((float) appDetail.getRatingScore());
    String apkSize = Formatter.formatFileSize(UiUtils.getContext(), appDetail.getApkSize());
    tv_size_publisher.setText(apkSize+" | "+appDetail.getPublisherName());
}
 
Example 5
Source File: DataReductionStatsPreference.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Update data reduction statistics whenever the chart's inspection
 * range changes. In particular, this creates strings describing the total
 * original size of all data received over the date range, the total size
 * of all data received (after compression), the percent data reduction
 * and the range of dates over which these statistics apply.
 */
private void updateDetailData() {
    final long start = mLeftPosition;
    // Include up to the last second of the currently selected day.
    final long end = mRightPosition;
    final long now = mCurrentTime;
    final Context context = getContext();

    NetworkStatsHistory.Entry originalEntry =
            mOriginalNetworkStatsHistory.getValues(start, end, now, null);
    // Only received bytes are tracked.
    final long originalTotalBytes = originalEntry.rxBytes;
    mOriginalTotalPhrase = Formatter.formatFileSize(context, originalTotalBytes);

    NetworkStatsHistory.Entry compressedEntry =
            mReceivedNetworkStatsHistory.getValues(start, end, now, null);
    // Only received bytes are tracked.
    final long compressedTotalBytes = compressedEntry.rxBytes;
    mReceivedTotalPhrase = Formatter.formatFileSize(context, compressedTotalBytes);

    float percentage = 0.0f;
    if (originalTotalBytes > 0L && originalTotalBytes > compressedTotalBytes) {
        percentage = (originalTotalBytes - compressedTotalBytes) / (float) originalTotalBytes;
    }
    mPercentReductionPhrase = String.format("%.0f%%", 100.0 * percentage);

    mStartDatePhrase = formatDate(context, start);
    mEndDatePhrase = formatDate(context, end);
}
 
Example 6
Source File: SDCardUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取内置 SDCard 已使用空间大小
 * @return 内置 SDCard 已使用空间大小
 */
public static String getUsedBlocksFormat() {
    try {
        long size = getUsedBlocks(Environment.getExternalStorageDirectory().getPath());
        return Formatter.formatFileSize(DevUtils.getContext(), size);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getUsedBlocksFormat");
        return null;
    }
}
 
Example 7
Source File: SDCardUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取内置 SDCard 空闲空间大小
 * @return 内置 SDCard 空闲空间大小
 */
public static String getAvailableBlocksFormat() {
    try {
        long size = getAvailableBlocks(Environment.getExternalStorageDirectory().getPath());
        return Formatter.formatFileSize(DevUtils.getContext(), size);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getAvailableBlocksFormat");
        return null;
    }
}
 
Example 8
Source File: FileSizeUtil.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 调用此方法自动计算指定文件或指定文件夹的大小
 *
 * @param filePath 文件路径
 * @return 计算好的带B、KB、MB、GB的字符串
 */
public static String getAutoFileOrFilesSize(String filePath) {
    File file = new File(filePath);
    long blockSize = 0;
    try {
        if (file.isDirectory()) {
            blockSize = getFileSizes(file);
        } else {
            blockSize = getFileSize(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Formatter.formatFileSize(App.getContext(), blockSize);
}
 
Example 9
Source File: DeviceUtils.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 获得SD卡总大小
 *
 * @return
 */
private static String getSDTotalSize(Context context) {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
 
Example 10
Source File: FxService.java    From stynico with MIT License 5 votes vote down vote up
private String getSDAvailableSize()
{
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(this, blockSize * availableBlocks);
}
 
Example 11
Source File: DownloadUtil.java    From letv with Apache License 2.0 5 votes vote down vote up
public static String calculateDownloadSpeed(long timestamp, long curtime, long downloadedSize) {
    long time = (curtime - timestamp) / 1000;
    if (time <= 0 || downloadedSize <= 0) {
        return "";
    }
    return Formatter.formatFileSize(BaseApplication.getInstance(), downloadedSize / time) + "/s";
}
 
Example 12
Source File: UploadActivity.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
@Override
public void upProgress(long currentSize, long totalSize) {
    String downloadLength = Formatter.formatFileSize(getApplicationContext(), currentSize);
    String totalLength = Formatter.formatFileSize(getApplicationContext(), totalSize);
    tvDownloadSize.setText(downloadLength + "/" + totalLength);
    tvProgress.setText(( currentSize *1.0F  / totalSize )*100.0F + "%");
    LogUtils.d(( currentSize *1.0F / totalSize )*100.0F+"");
    pbProgress.setMax(100);
    pbProgress.setProgress((int) (( currentSize  / totalSize )*100.0F));
}
 
Example 13
Source File: FileUtil.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public static String getFileSize(Context context, File file) {
    if (!file.exists() || !file.isFile()) {
        return null;
    }
    return Formatter.formatFileSize(context, file.length());
}
 
Example 14
Source File: DataCleanUtil.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public static String getApplicationDataSizeStr(Context context) {
    return Formatter.formatFileSize(context, getApplicationDataSize(context));
}
 
Example 15
Source File: UpdateDownloadService.java    From v9porn with MIT License 4 votes vote down vote up
private void updateNotification(BaseDownloadTask task, int soFarBytes, int totalBytes, int action) {
    int progress = (int) (((float) soFarBytes / totalBytes) * 100);
    String fileSize = Formatter.formatFileSize(UpdateDownloadService.this, soFarBytes).replace("MB", "") + "/ " + Formatter.formatFileSize(UpdateDownloadService.this, totalBytes);
    startNotification(action, progress, fileSize, task.getSpeed());
}
 
Example 16
Source File: ArchPackagesStringConverters.java    From ArchPackages with GNU General Public License v3.0 4 votes vote down vote up
public static String convertBytesToMb(Context context, String bytes) {
    return Formatter.formatFileSize(context, Long.parseLong(bytes));
}
 
Example 17
Source File: NetworkUsageStatsFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
private String formatSize(long sizeBytes) {
    return Formatter.formatFileSize(getActivity(), sizeBytes);
}
 
Example 18
Source File: AppCacheUtils.java    From v9porn with MIT License 2 votes vote down vote up
/**
 * 获取videoCache缓存大小
 *
 * @param context context
 * @return 缓存大小
 */
public static String getVideoCacheFileSizeStr(Context context) {
    long fileSize = getVideoCacheFileSizeNum(context);
    return Formatter.formatFileSize(context, fileSize);
}
 
Example 19
Source File: SdCardUtils.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Formats a content size to be in the form of bytes, kilobytes, megabytes,
 * etc
 * 
 * @return
 */
public static String formatFileSize(Context context, long fileSize) {
	return Formatter.formatFileSize(context, fileSize);
}
 
Example 20
Source File: AppCacheUtils.java    From v9porn with MIT License 2 votes vote down vote up
/**
 * 获取RxCache缓存大小
 *
 * @param context context
 * @return 缓存大小
 */
public static String getRxcacheFileSizeStr(Context context) {
    long fileSize = getRxcacheFileSizeNum(context);
    return Formatter.formatFileSize(context, fileSize);
}