android.text.format.Formatter.formatFileSize()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中android.text.format.Formatter.formatFileSize()方法的一些代码示例,展示了Formatter.formatFileSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Formatter.formatFileSize()方法的具体详情如下:
包路径:android.text.format.Formatter
类名称:Formatter
方法名:formatFileSize

Formatter.formatFileSize介绍

暂无

代码示例

代码示例来源:origin: bumptech/glide

private String toMb(int bytes) {
 return Formatter.formatFileSize(context, bytes);
}

代码示例来源:origin: smuyyh/BookReader

/**
 * 获取系统当前可用内存大小
 *
 * @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);// 将获取的内存大小规格化
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initViews(Bundle savedInstanceState) {
  long phoneTotalSize = CommonUtil.getPhoneTotalSize();
  long phoneAvailableSize = CommonUtil.getPhoneAvailableSize();
  //转换为G的显示单位
  String totalSizeStr = Formatter.formatFileSize(this, phoneTotalSize);
  String availabSizeStr = Formatter.formatFileSize(this, phoneAvailableSize);
  //计算占用空间的百分比
  int progress = countProgress(phoneTotalSize, phoneAvailableSize);
  mProgressBar.setProgress(progress);
  mCacheSize.setText("主存储:" + totalSizeStr + "/" + "可用:" + availabSizeStr);
  CustomEmptyView mEmptyLayout = (CustomEmptyView) findViewById(R.id.empty_layout);
  assert mEmptyLayout != null;
  mEmptyLayout.setEmptyImage(R.drawable.img_tips_error_no_downloads);
  mEmptyLayout.setEmptyText("没有找到你的缓存哟");
}

代码示例来源:origin: jeasonlzy/ImagePicker

/**
 * 图片添加成功后,修改当前图片的选中数量
 * 当调用 addSelectedImageItem 或 deleteSelectedImageItem 都会触发当前回调
 */
@Override
public void onImageSelected(int position, ImageItem item, boolean isAdd) {
  if (imagePicker.getSelectImageCount() > 0) {
    mBtnOk.setText(getString(R.string.ip_select_complete, imagePicker.getSelectImageCount(), imagePicker.getSelectLimit()));
  } else {
    mBtnOk.setText(getString(R.string.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.ip_origin_size, fileSize));
  }
}

代码示例来源:origin: jeasonlzy/ImagePicker

@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.ip_origin_size, fileSize));
    } else {
      isOrigin = false;
      mCbOrigin.setText(getString(R.string.ip_origin));
    }
  }
}

代码示例来源:origin: guolindev/giffun

private String toMb(int bytes) {
  return Formatter.formatFileSize(context, bytes);
}

代码示例来源:origin: jaredrummler/AndroidProcesses

html.p().strong("SIZE: ").append(Formatter.formatFileSize(getActivity(), statm.getSize())).close();
 html.p().strong("RSS: ").append(Formatter.formatFileSize(getActivity(), statm.getResidentSetSize())).close();
} catch (IOException e) {
 Log.d(TAG, String.format("Error reading /proc/%d/statm.", process.pid));

代码示例来源:origin: proninyaroslav/libretorrent

private void updatePieceCounter()
  {
    String piecesTemplate = activity.getString(R.string.torrent_pieces_template);
    String pieceLength = Formatter.formatFileSize(activity, pieceSize);
    piecesCounter.setText(String.format(piecesTemplate, downloadedPieces, allPiecesCount, pieceLength));
  }
}

代码示例来源:origin: yangchong211/YCAudioPlayer

private String getDataText(List<DialogListBean> list) {
  StringBuffer stringBuffer = new StringBuffer();
  stringBuffer.append(list.size());
  stringBuffer.append("个/");
  String size = Formatter.formatShortFileSize(this, 10003200);
  stringBuffer.append(size);
  stringBuffer.append("   ");
  stringBuffer.append("可用空间");
  stringBuffer.append(Formatter.formatFileSize(this, SDUtils.getAvailableSize()));
  return stringBuffer.toString();
}

代码示例来源:origin: luhaoaimama1/zone-sdk

/**
 * 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);// 将获取的内存大小规格化
}

代码示例来源:origin: Leeii/LeeFream

/**
 * 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);// 将获取的内存大小规格化
}

代码示例来源:origin: lytsing/weibo

protected void onPostExecute(Long result) {
  Preference clearCache = getPreferenceScreen().findPreference("clear-cache");
  String cacheSize = Formatter.formatFileSize(sSettingsActivity, result);
  clearCache.setSummary("Cache size: " + cacheSize);
}

代码示例来源:origin: BrightcoveOS/android-player-samples

@Override
public void onDownloadProgress(@NonNull final Video video, @NonNull final DownloadStatus status) {
  Log.i(TAG, String.format(
      "Downloaded %s out of %s of '%s' video. Progress %3.2f",
      Formatter.formatFileSize(MainActivity.this, status.getBytesDownloaded()),
      Formatter.formatFileSize(MainActivity.this, status.getMaxSize()),
      video.getName(), status.getProgress()));
  videoListAdapter.notifyVideoChanged(video, status);
}

代码示例来源:origin: proninyaroslav/libretorrent

public void setDownloadPath(String path)
{
  if (path == null) {
    return;
  }
  downloadDir = path;
  pathToUploadView.setText(path);
  freeSpaceView.setText(String.format(getString(R.string.free_space),
             Formatter.formatFileSize(activity.getApplicationContext(),
                          FileIOUtils.getFreeSpace(path))));
}

代码示例来源:origin: proninyaroslav/libretorrent

private void updateFileSize()
{
  if (fileTree == null)
    return;
  filesSize.setText(String.format(getString(R.string.files_size),
      Formatter.formatFileSize(activity.getApplicationContext(),
          fileTree.selectedFileSize()),
      Formatter.formatFileSize(activity.getApplicationContext(),
          fileTree.size())));
}

代码示例来源:origin: proninyaroslav/libretorrent

private void updateFileSize()
{
  if (fileTree == null)
    return;
  filesSize.setText(String.format(getString(R.string.files_size),
           Formatter.formatFileSize(activity.getApplicationContext(),
                        fileTree.selectedFileSize()),
           Formatter.formatFileSize(activity.getApplicationContext(),
                        fileTree.size())));
}

代码示例来源:origin: WhiteDG/BihuDaily

/**
 * 获取总缓存大小
 *
 * @return cacheDir目录下文件总大小
 */
public static String getTotalCacheSize() {
  long cacheSize = getFolderSize(BihuDailyApplication.getAppContext().getCacheDir());
  if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
    cacheSize += getFolderSize(BihuDailyApplication.getAppContext().getExternalCacheDir());
  }
  return Formatter.formatFileSize(BihuDailyApplication.getAppContext(), cacheSize);
}

代码示例来源:origin: JackWHLiu/jackknife

public static String getRomAvailableSize(Context context) {
  File path = Environment.getDataDirectory();
  StatFs stat = new StatFs(path.getPath());
  long blockSize = stat.getBlockSize();
  long availableBlocks = stat.getAvailableBlocks();
  return Formatter.formatFileSize(context, blockSize * availableBlocks);
}

代码示例来源:origin: JackWHLiu/jackknife

public static String getRomTotalSize(Context context) {
  File path = Environment.getDataDirectory();
  StatFs stat = new StatFs(path.getPath());
  long blockSize = stat.getBlockSize();
  long totalBlocks = stat.getBlockCount();
  return Formatter.formatFileSize(context, blockSize * totalBlocks);
}

代码示例来源:origin: wasdennnoch/AndroidN-ify

public static void hookStorageTile(Object tile, Context context) {
  File path = Environment.getDataDirectory();
  StatFs stat = new StatFs(path.getPath());
  long blockSize = stat.getBlockSizeLong();
  long availableBlocks = stat.getAvailableBlocksLong();
  long totalBlocks = stat.getBlockCountLong();
  long available = availableBlocks * blockSize;
  long total = totalBlocks * blockSize;
  long used = total - available;
  String summary = ResourceUtils.getInstance().getString(R.string.storage_summary, Formatter.formatFileSize(context, used), Formatter.formatFileSize(context, total));
  XposedHelpers.setObjectField(tile, "summary", summary);
}

相关文章