android.text.format.Formatter Java Examples
The following examples show how to use
android.text.format.Formatter.
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: VMPickPreviewActivity.java From VMLibrary with Apache License 2.0 | 6 votes |
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int id = buttonView.getId(); if (id == R.id.vm_preview_origin_cb) { if (isChecked) { long size = 0; for (VMPictureBean item : mSelectedPictures) { size += item.size; } String fileSize = Formatter.formatFileSize(this, size); isOrigin = true; mOriginCB.setText(getString(R.string.vm_pick_origin_size, fileSize)); } else { isOrigin = false; mOriginCB.setText(getString(R.string.vm_pick_origin)); } } }
Example #2
Source File: LoadFolderSpaceData.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
@Override protected Pair<String, List<PieEntry>> doInBackground(Void... params) { long[] dataArray = Futils.getSpaces(file, context, new OnProgressUpdate<Long[]>() { @Override public void onUpdate(Long[] data) { publishProgress(data); } }); if (dataArray != null && dataArray[0] != -1 && dataArray[0] != 0) { long totalSpace = dataArray[0]; List<PieEntry> entries = createEntriesFromArray(dataArray, false); return new Pair<String, List<PieEntry>>(Formatter.formatFileSize(context, totalSpace), entries); } return null; }
Example #3
Source File: TrafficStatsActivity.java From MobileGuard with MIT License | 6 votes |
/** * init data */ @Override protected void initData() { long totalRxBytes = TrafficStats.getTotalRxBytes(); long totalTxBytes = TrafficStats.getTotalTxBytes(); long mobileRxBytes = TrafficStats.getMobileRxBytes(); long mobileTxBytes = TrafficStats.getMobileTxBytes(); long totalBytes = totalRxBytes + totalTxBytes; long mobileBytes = mobileRxBytes + mobileTxBytes; tvTotalTrafficStatsSum.setText(getString(R.string.total_traffic_stats_sum, Formatter.formatFileSize(this, totalBytes))); tvMobileTrafficStatsSum.setText(getString(R.string.mobile_traffic_stats_sum, Formatter.formatFileSize(this, mobileBytes))); tvTotalTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, totalTxBytes), Formatter.formatFileSize(this, totalRxBytes))); tvMobileTrafficStats.setText(getString(R.string.traffic_stats_upload_download, Formatter.formatFileSize(this, mobileTxBytes), Formatter.formatFileSize(this, mobileRxBytes))); }
Example #4
Source File: LruMemoryCache.java From sketch with Apache License 2.0 | 6 votes |
@Override public synchronized void trimMemory(int level) { if (closed) { return; } long memoryCacheSize = getSize(); if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_MODERATE) { cache.evictAll(); } else if (level >= android.content.ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) { cache.trimToSize(cache.maxSize() / 2); } long releasedSize = memoryCacheSize - getSize(); SLog.w(NAME, "trimMemory. level=%s, released: %s", SketchUtils.getTrimLevelName(level), Formatter.formatFileSize(context, releasedSize)); }
Example #5
Source File: FileSizeUtil.java From SeeWeather with Apache License 2.0 | 6 votes |
/** * 调用此方法自动计算指定文件或指定文件夹的大小 * * @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 #6
Source File: OfflineLayersAdapter.java From mage-android with Apache License 2.0 | 6 votes |
public void updateDownloadProgress(View view, Layer layer) { int progress = downloadManager.getProgress(layer); long size = layer.getFileSize(); final ProgressBar progressBar = view.findViewById(R.id.layer_progress); final View download = view.findViewById(R.id.layer_download); if (progress <= 0) { String reason = downloadManager.isFailed(layer); if(!StringUtils.isEmpty(reason)) { Toast.makeText(context, reason, Toast.LENGTH_LONG).show(); progressBar.setVisibility(View.GONE); download.setVisibility(View.VISIBLE); } return; } int currentProgress = (int) (progress / (float) size * 100); progressBar.setIndeterminate(false); progressBar.setProgress(currentProgress); TextView layerSize = view.findViewById(R.id.layer_size); layerSize.setText(String.format("Downloading: %s of %s", Formatter.formatFileSize(context, progress), Formatter.formatFileSize(context, size))); }
Example #7
Source File: VMPickPreviewActivity.java From VMLibrary with Apache License 2.0 | 6 votes |
/** * 初始化图片选择回调 * 图片添加成功后,修改当前图片的选中数量 */ private void initSelectedPictureListener() { mSelectedPictureListener = (position, item, isAdd) -> { if (VMPicker.getInstance().getSelectPictureCount() > 0) { int selectCount = VMPicker.getInstance().getSelectPictureCount(); int selectLimit = VMPicker.getInstance().getSelectLimit(); String complete = VMStr.byResArgs(R.string.vm_pick_complete_select, selectCount, selectLimit); getTopBar().setEndBtn(complete); } else { getTopBar().setEndBtn(VMStr.byRes(R.string.vm_pick_complete)); } if (mOriginCB.isChecked()) { long size = 0; for (VMPictureBean VMPictureBean : mSelectedPictures) { size += VMPictureBean.size; } String fileSize = Formatter.formatFileSize(mActivity, size); mOriginCB.setText(getString(R.string.vm_pick_origin_size, fileSize)); } }; VMPicker.getInstance().addOnSelectedPictureListener(mSelectedPictureListener); mSelectedPictureListener.onPictureSelected(0, null, false); }
Example #8
Source File: CPUUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 获取 CPU 最大频率 ( 单位 KHZ) * @return CPU 最大频率 ( 单位 KHZ) */ public static String getMaxCpuFreq() { String result = ""; ProcessBuilder cmd; InputStream is = null; try { String[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"}; cmd = new ProcessBuilder(args); Process process = cmd.start(); is = process.getInputStream(); byte[] re = new byte[24]; while (is.read(re) != -1) { result = result + new String(re); } result = Formatter.formatFileSize(DevUtils.getContext(), Long.parseLong(result.trim()) * 1024) + " Hz"; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getMaxCpuFreq"); result = "unknown"; } finally { CloseUtils.closeIOQuietly(is); } return result; }
Example #9
Source File: LruMemoryCache.java From sketch with Apache License 2.0 | 6 votes |
@Override public synchronized SketchRefBitmap remove(@NonNull String key) { if (closed) { return null; } if (disabled) { if (SLog.isLoggable(SLog.LEVEL_DEBUG | SLog.TYPE_CACHE)) { SLog.d(NAME, "Disabled. Unable remove, key=%s", key); } return null; } SketchRefBitmap refBitmap = cache.remove(key); if (SLog.isLoggable(SLog.LEVEL_DEBUG | SLog.TYPE_CACHE)) { SLog.d(NAME, "remove. memoryCacheSize: %s", Formatter.formatFileSize(context, cache.size())); } return refBitmap; }
Example #10
Source File: ZipFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
@Override protected void onPostExecute(List<ZipEntry> result) { dataSourceL1.addAll(result); selectedInList1.clear(); srcAdapter.notifyDataSetChanged(); selectionStatusTV.setText(selectedInList1.size() + "/" + dataSourceL1.size()); rightStatus.setText( Formatter.formatFileSize(activity, zip.file.length()) + "/" + Formatter.formatFileSize(activity, zip.unZipSize)); if (dataSourceL1.size() == 0) { nofilelayout.setVisibility(View.VISIBLE); } else { nofilelayout.setVisibility(View.GONE); } mSwipeRefreshLayout.setRefreshing(false); }
Example #11
Source File: Downloads.java From Beedio with GNU General Public License v2.0 | 6 votes |
@Override public void run() { long downloadSpeedValue = DownloadManager.getDownloadSpeed(); String downloadSpeedText = "Speed:" + Formatter.formatShortFileSize(getActivity(), downloadSpeedValue) + "/s"; downloadSpeed.setText(downloadSpeedText); if (downloadSpeedValue > 0) { long remainingMills = DownloadManager.getRemaining(); String remainingText = "Remaining:" + Utils.getHrsMinsSecs(remainingMills); remaining.setText(remainingText); } else { remaining.setText(R.string.remaining_undefine); } if (getFragmentManager() != null && getFragmentManager().findFragmentByTag ("downloadsInProgress") != null) { downloadsInProgress.updateDownloadItem(); } mainHandler.postDelayed(this, 1000); }
Example #12
Source File: DownloadManagerUi.java From delion with Apache License 2.0 | 6 votes |
private void update(long usedBytes) { Context context = mSpaceUsedTextView.getContext(); if (mFileSystemBytes == Long.MAX_VALUE) { try { mFileSystemBytes = mFileSystemBytesTask.get(); } catch (Exception e) { Log.e(TAG, "Failed to get file system size."); } // Display how big the storage is. String fileSystemReadable = Formatter.formatFileSize(context, mFileSystemBytes); mSpaceTotalTextView.setText(context.getString( R.string.download_manager_ui_space_used, fileSystemReadable)); } // Indicate how much space has been used by downloads. int percentage = mFileSystemBytes == 0 ? 0 : (int) (100.0 * usedBytes / mFileSystemBytes); mSpaceBar.setProgress(percentage); mSpaceUsedTextView.setText(Formatter.formatFileSize(context, usedBytes)); }
Example #13
Source File: ImagePreviewActivity.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@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("原图"); } } }
Example #14
Source File: NetworkUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * Return the server address by wifi. * * @return the server address by wifi */ @RequiresPermission(ACCESS_WIFI_STATE) public static String getServerAddressByWifi() { @SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) Utils.getApp().getSystemService(Context.WIFI_SERVICE); if (wm == null) return ""; return Formatter.formatIpAddress(wm.getDhcpInfo().serverAddress); }
Example #15
Source File: LocalNetwork.java From AndroidDemo with MIT License | 5 votes |
/** * 创建客户端 * * @param context 上下文 * @param callback 用于处理服务端的回复 * @return LocalNetwork */ public static LocalNetwork createClient(Context context, Callback callback) { ClientNetwork network = new ClientNetwork(callback); WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); String address = Formatter.formatIpAddress(wifi.getConnectionInfo().getIpAddress()); network.setSelfIp(address); return new LocalNetwork(network); }
Example #16
Source File: MemoryUtil.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 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);// 将获取的内存大小规格化 }
Example #17
Source File: DirectoryFragment.java From FireFiles with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(Long result) { if (isCancelled()) { result = null; } if (mSizeView.getTag() == this && result != null) { mSizeView.setTag(null); String size = Formatter.formatFileSize(mSizeView.getContext(), result); mSizeView.setText(size); mSizes.put(mPosition, result); } }
Example #18
Source File: AppFragment.java From apkextractor with GNU General Public License v3.0 | 5 votes |
@Override public void onMultiSelectItemChanged(List<AppItem> selected_items, long length) { if(getActivity()==null)return; tv_multi_select_head.setText(selected_items.size()+getResources().getString(R.string.unit_item)+"/"+ Formatter.formatFileSize(getActivity(),length)); btn_export.setEnabled(selected_items.size()>0); btn_share.setEnabled(selected_items.size()>0); }
Example #19
Source File: FileSendActivity.java From apkextractor with GNU General Public License v3.0 | 5 votes |
private String getFilesInfoMessage(){ StringBuilder stringBuilder=new StringBuilder(); for(FileItem fileItem:sendingFiles){ if(fileItem.canGetRealPath()){ stringBuilder.append(fileItem.getPath()); }else{ stringBuilder.append(fileItem.getName()); } stringBuilder.append("("); stringBuilder.append(Formatter.formatFileSize(this,fileItem.length())); stringBuilder.append(")"); stringBuilder.append("\n\n"); } return stringBuilder.toString(); }
Example #20
Source File: WorldCupDownloadManager.java From letv with Apache License 2.0 | 5 votes |
public void completeDownloadInfo(String id) { DownloadInfo info = (DownloadInfo) this.downloadMaps.get(id); Constants.debug("finishDownload:" + info.id + SearchCriteria.LT + info.isHd + ">:" + Formatter.formatFileSize(this.mContext, info.total)); synchronized (this.downloadMaps) { this.downloadMaps.remove(id); } NotifyManage.notifyFinish(this.mContext, info); startPendingDownload(); }
Example #21
Source File: AppGridAdapter.java From FlyWoo with Apache License 2.0 | 5 votes |
/** * 网格的单个item的视图填充数据 * @param position */ @Override protected void onBindItemVu(int position) { AppEntity item = list.get(position); vu.setAppIcon(((BitmapDrawable) item.getIcon()).getBitmap()); vu.setAppName(item.getAppName()); vu.setAppSize(Formatter.formatFileSize(context, item.length())); vu.setChecked(BaseApplication.sendFileStates.containsKey(item.getAbsolutePath())); }
Example #22
Source File: FileRecord.java From edslite with GNU General Public License v2.0 | 5 votes |
protected void appendSizeInfo(Context context, StringBuilder sb) { sb.append(String.format("%s: %s", context.getText(R.string.size), Formatter.formatFileSize(context, getSize()) )); }
Example #23
Source File: MemoryInfo.java From MobileInfo with Apache License 2.0 | 5 votes |
/** * rom * * @param context * @return */ private static String getRomSpace(Context context) { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return Formatter.formatFileSize(context, availableBlocks * blockSize); }
Example #24
Source File: DeviceUtils.java From fangzhuishushenqi with Apache License 2.0 | 5 votes |
/** * 获取系统当前可用内存大小 * * @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);// 将获取的内存大小规格化 }
Example #25
Source File: ImageActivity.java From android-slideshow with MIT License | 5 votes |
@Override public void updateImageDetails(FileItem item, int width, int height){ File file = new File(item.getPath()); // Location String location = file.getParent().replace(getRootLocation(), ""); if (location.length() > LOCATION_DETAIL_MAX_LENGTH){ location = "..." + location.substring(location.length() - (LOCATION_DETAIL_MAX_LENGTH - 3)); } ((TextView)findViewById(R.id.image_detail_location1)).setText(location); ((TextView)findViewById(R.id.image_detail_location2)).setText(location); Log.d(TAG, String.format("Current image location: %s", location)); // Dimensions String dimensions = getResources().getString(R.string.image_detail_dimensions, width, height); ((TextView)findViewById(R.id.image_detail_dimensions1)).setText(dimensions); ((TextView)findViewById(R.id.image_detail_dimensions2)).setText(dimensions); Log.d(TAG, String.format("Current image dimensions: %s", dimensions)); // Size String size = getResources().getString(R.string.image_detail_size, Formatter.formatShortFileSize(this, file.length())); ((TextView)findViewById(R.id.image_detail_size1)).setText(size); ((TextView)findViewById(R.id.image_detail_size2)).setText(size); Log.d(TAG, String.format("Current image size: %s", size)); // Modified String modified = getResources().getString(R.string.image_detail_modified, DateFormat.getMediumDateFormat(this).format(file.lastModified())); ((TextView)findViewById(R.id.image_detail_modified1)).setText(modified); ((TextView)findViewById(R.id.image_detail_modified2)).setText(modified); Log.d(TAG, String.format("Current image modified: %s", modified)); // Save this spot saveCurrentImagePath(); }
Example #26
Source File: DownloadAdapter.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
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("停止"); download.setText("下载"); break; case Progress.PAUSE: netSpeed.setText("暂停中"); download.setText("继续"); break; case Progress.ERROR: netSpeed.setText("下载出错"); download.setText("出错"); break; case Progress.WAITING: netSpeed.setText("等待中"); download.setText("等待"); break; case Progress.FINISH: netSpeed.setText("下载完成"); download.setText("完成"); break; case Progress.LOADING: String speed = Formatter.formatFileSize(context, progress.speed); netSpeed.setText(String.format("%s/s", speed)); download.setText("暂停"); break; } tvProgress.setText(numberFormat.format(progress.fraction)); pbProgress.setMax(10000); pbProgress.setProgress((int) (progress.fraction * 10000)); }
Example #27
Source File: FileUtils.java From styT with Apache License 2.0 | 5 votes |
/** * 获得sd卡剩余容量,即可用大小 * * @return */ public static String getSDAvailableSize(Context ontext) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return Formatter.formatFileSize(ontext, blockSize * availableBlocks); }
Example #28
Source File: WebsitePreference.java From delion with Apache License 2.0 | 5 votes |
@Override protected void onBindView(View view) { super.onBindView(view); TextView usageText = (TextView) view.findViewById(R.id.usage_text); usageText.setVisibility(View.GONE); if (mCategory.showStorageSites()) { long totalUsage = mSite.getTotalUsage(); if (totalUsage > 0) { usageText.setText(Formatter.formatShortFileSize(getContext(), totalUsage)); usageText.setTextSize(TEXT_SIZE_SP); usageText.setVisibility(View.VISIBLE); } } if (!mFaviconFetched) { // Start the favicon fetching. Will respond in onFaviconAvailable. mFaviconHelper = new FaviconHelper(); if (!mFaviconHelper.getLocalFaviconImageForURL( Profile.getLastUsedProfile(), faviconUrl(), mFaviconSizePx, this)) { onFaviconAvailable(null, null); } mFaviconFetched = true; } float density = getContext().getResources().getDisplayMetrics().density; int iconPadding = Math.round(FAVICON_PADDING_DP * density); View iconView = view.findViewById(android.R.id.icon); iconView.setPadding(iconPadding, iconPadding, iconPadding, iconPadding); }
Example #29
Source File: SimpleActivity.java From stynico with MIT License | 5 votes |
/** * 获得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); }
Example #30
Source File: SystemUtils.java From mobile-manager-tool with MIT License | 5 votes |
private String[] getTotalMemory() { String[] result = {"",""}; //1-total 2-avail final ActivityManager activityManager = (ActivityManager) AppMain.getInstance().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(mi); long mTotalMem = 0; long mAvailMem = mi.availMem; String str1 = "/proc/meminfo"; String str2; String[] arrayOfString; try { FileReader localFileReader = new FileReader(str1); BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192); str2 = localBufferedReader.readLine(); arrayOfString = str2.split("\\s+"); mTotalMem = Integer.valueOf(arrayOfString[1]).intValue() * 1024; localBufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } result[0] = Formatter.formatFileSize(AppMain.getInstance(), mTotalMem); result[1] = Formatter.formatFileSize(AppMain.getInstance(), mAvailMem); Log.i(">>>SystemUtils", "meminfo total:" + result[0] + " used:" + result[1]); return result; }