當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。