Example usage for android.text.format Formatter formatFileSize

List of usage examples for android.text.format Formatter formatFileSize

Introduction

In this page you can find the example usage for android.text.format Formatter formatFileSize.

Prototype

public static String formatFileSize(@Nullable Context context, long sizeBytes) 

Source Link

Document

Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.

Usage

From source file:Main.java

public static String toFileSizeFormat(Context context, long number) {
    return Formatter.formatFileSize(context, number);
}

From source file:Main.java

public static String formatByteSize(long size) {
    return Formatter.formatFileSize(getAppContext(), size);
}

From source file:Main.java

public static String formatSize(Context context, long sizeInBytes) {
    return Formatter.formatFileSize(context, sizeInBytes);
}

From source file:Main.java

public static String formatSize(Context context, String size) {
    return Formatter.formatFileSize(context, Long.valueOf(TextUtils.isEmpty(size) ? "0" : size));
}

From source file:Main.java

public static String getSizeText(Context context, long currentBytes, long totalBytes) {
    StringBuffer sizeText = new StringBuffer();
    if (totalBytes > 0) {
        sizeText.append(Formatter.formatFileSize(context, currentBytes));
        sizeText.append("/");
        sizeText.append(Formatter.formatFileSize(context, totalBytes));
    }//from   w  w w  .j av  a2 s  . c om
    return sizeText.toString();
}

From source file:Main.java

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

From source file:Main.java

public static String byte2Common(Context context, String fsize) {
    if (TextUtils.isEmpty(fsize)) {
        return "";
    }//w ww  .  java2 s . c  o  m
    Long sizeLong = Long.parseLong(fsize);
    return Formatter.formatFileSize(context, sizeLong);
}

From source file:Main.java

public static String getAvailMemory(Context c) {

    ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    MemoryInfo mi = new MemoryInfo();
    am.getMemoryInfo(mi);//  ww w  .java  2s  . c  o  m

    return Formatter.formatFileSize(c, mi.availMem);
}

From source file:Main.java

public static String getAvailMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    MemoryInfo mi = new MemoryInfo();
    am.getMemoryInfo(mi);/*w  ww  .j a va  2 s .  c om*/
    return Formatter.formatFileSize(context, mi.availMem);
}

From source file:Main.java

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);
}