List of usage examples for android.text.format Formatter formatFileSize
public static String formatFileSize(@Nullable Context context, long sizeBytes)
From source file:net.vexelon.myglob.fragments.HomeFragment.java
/** * Update all data with respect to selected account *//* www.j a v a 2 s. c om*/ private void updateProfileView(String phoneNumber) { if (Defs.LOG_ENABLED) Log.v(Defs.LOG_TAG, "Updating selection for: " + phoneNumber); View v = getView(); // XXX When calling this method from another fragment view is sometimes <null> :( if (v == null) { if (Defs.LOG_ENABLED) Log.w(Defs.LOG_TAG, "View is <null>!"); return; } LinearLayout profileLayout = (LinearLayout) v.findViewById(R.id.ly_profile); User user = UsersManager.getInstance().getUserByPhoneNumber(phoneNumber); if (user != null) { Date today = new Date(); setText(v, R.id.tv_profile_number, user.getPhoneNumber()); setText(v, R.id.tv_profile_name, user.getAccountName()); setText(v, R.id.tv_checks_today, String.valueOf(user.getChecksToday(today))); setText(v, R.id.tv_checks_overal, String.valueOf(user.getChecksTotal())); setText(v, R.id.tv_traffic_today, Formatter.formatFileSize(this.getActivity(), user.getTrafficToday(today))); setText(v, R.id.tv_traffic_overal, Formatter.formatFileSize(this.getActivity(), user.getTrafficTotal())); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(user.getLastCheckDateTime()); StringBuilder dateText = new StringBuilder(100); dateText.append(getString(R.string.text_from)).append(" ") .append(Defs.globalDateFormat.format(calendar.getTime())); setText(v, R.id.tv_profile_lastchecked_at, dateText.toString()); TextView textContent = (TextView) v.findViewById(R.id.tv_status_content); if (user.getLastCheckData().length() > 0) { textContent.setText(Html.fromHtml(user.getLastCheckData())); } else { textContent.setText(R.string.text_no_data); } // make profile layout pane visible profileLayout.setVisibility(View.VISIBLE); } else if (UsersManager.getInstance().getUsersCount() == 0) { // hide profile layout pane, since no user data is available profileLayout.setVisibility(View.GONE); TextView textContent = (TextView) getView().findViewById(R.id.tv_status_content); textContent.setText(R.string.text_no_accounts); } else { Toast.makeText(this.getActivity().getApplicationContext(), R.string.text_account_not_found, Toast.LENGTH_SHORT).show(); } }
From source file:com.doomy.padlock.InfoFragment.java
/** * Gets random access memory size./*from ww w . j a v a2s . c o m*/ * * @return The RAM size. */ public String getRAMSize() { ActivityManager mActivityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mMemoryInfo = new ActivityManager.MemoryInfo(); mActivityManager.getMemoryInfo(mMemoryInfo); long mTotalMemory = mMemoryInfo.totalMem; return Formatter.formatFileSize(getActivity(), mTotalMemory); }
From source file:me.xiaopan.sketchsample.activity.MainActivity.java
private List<Object> makeMenuList() { List<Object> menuList = new ArrayList<Object>(); final View.OnClickListener menuClickListener = new View.OnClickListener() { @Override// w ww . ja v a 2s.c o m public void onClick(View v) { drawerLayout.closeDrawer(Gravity.LEFT); } }; menuList.add("Integrated Page"); for (Page page : Page.getNormalPage()) { if (!page.isDisable()) { menuList.add(page); } } menuList.add("Test Page"); for (Page page : Page.getTestPage()) { if (!page.isDisable()) { menuList.add(page); } } menuList.add("Cache"); menuList.add(new InfoMenu("Memory Cache (Click Clean)") { @Override public String getInfo() { MemoryCache memoryCache = Sketch.with(getBaseContext()).getConfiguration().getMemoryCache(); String usedSizeFormat = Formatter.formatFileSize(getBaseContext(), memoryCache.getSize()); String maxSizeFormat = Formatter.formatFileSize(getBaseContext(), memoryCache.getMaxSize()); return usedSizeFormat + "/" + maxSizeFormat; } @Override public void onClick(AssemblyRecyclerAdapter adapter) { Sketch.with(getBaseContext()).getConfiguration().getMemoryCache().clear(); menuClickListener.onClick(null); adapter.notifyDataSetChanged(); EventBus.getDefault().post(new CacheCleanEvent()); } }); menuList.add(new InfoMenu("Bitmap Pool (Click Clean)") { @Override public String getInfo() { BitmapPool bitmapPool = Sketch.with(getBaseContext()).getConfiguration().getBitmapPool(); String usedSizeFormat = Formatter.formatFileSize(getBaseContext(), bitmapPool.getSize()); String maxSizeFormat = Formatter.formatFileSize(getBaseContext(), bitmapPool.getMaxSize()); return usedSizeFormat + "/" + maxSizeFormat; } @Override public void onClick(AssemblyRecyclerAdapter adapter) { Sketch.with(getBaseContext()).getConfiguration().getBitmapPool().clear(); menuClickListener.onClick(null); adapter.notifyDataSetChanged(); EventBus.getDefault().post(new CacheCleanEvent()); } }); menuList.add(new InfoMenu("Disk Cache (Click Clean)") { @Override public String getInfo() { DiskCache diskCache = Sketch.with(getBaseContext()).getConfiguration().getDiskCache(); String usedSizeFormat = Formatter.formatFileSize(getBaseContext(), diskCache.getSize()); String maxSizeFormat = Formatter.formatFileSize(getBaseContext(), diskCache.getMaxSize()); return usedSizeFormat + "/" + maxSizeFormat; } @Override public void onClick(final AssemblyRecyclerAdapter adapter) { new AsyncTask<Integer, Integer, Integer>() { @Override protected Integer doInBackground(Integer... params) { Sketch.with(getBaseContext()).getConfiguration().getDiskCache().clear(); return null; } @Override protected void onPostExecute(Integer integer) { super.onPostExecute(integer); menuClickListener.onClick(null); adapter.notifyDataSetChanged(); EventBus.getDefault().post(new CacheCleanEvent()); } }.execute(0); } }); menuList.add(new CheckMenu(this, "Disable Memory Cache", AppConfig.Key.GLOBAL_DISABLE_CACHE_IN_MEMORY, null, menuClickListener)); menuList.add(new CheckMenu(this, "Disable Bitmap Pool", AppConfig.Key.GLOBAL_DISABLE_BITMAP_POOL, null, menuClickListener)); menuList.add(new CheckMenu(this, "Disable Disk Cache", AppConfig.Key.GLOBAL_DISABLE_CACHE_IN_DISK, null, menuClickListener)); menuList.add("Gesture Zoom"); menuList.add(new CheckMenu(this, "Enabled Gesture Zoom In Detail Page", AppConfig.Key.SUPPORT_ZOOM, new CheckMenu.OnCheckedChangedListener() { @Override public void onCheckedChangedBefore(boolean checked) { if (!checked && AppConfig.getBoolean(getBaseContext(), AppConfig.Key.SUPPORT_LARGE_IMAGE)) { AppConfig.putBoolean(getBaseContext(), AppConfig.Key.SUPPORT_LARGE_IMAGE, false); } } @Override public void onCheckedChanged(boolean checked) { } }, menuClickListener)); menuList.add(new CheckMenu(this, "Enabled Read Mode In Detail Page", AppConfig.Key.READ_MODE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Enabled Location Animation In Detail Page", AppConfig.Key.LOCATION_ANIMATE, null, menuClickListener)); menuList.add("Block Display Large Image"); menuList.add(new CheckMenu(this, "Enabled Block Display Large Image In Detail Page", AppConfig.Key.SUPPORT_LARGE_IMAGE, new CheckMenu.OnCheckedChangedListener() { @Override public void onCheckedChangedBefore(boolean checked) { if (checked && !AppConfig.getBoolean(getBaseContext(), AppConfig.Key.SUPPORT_ZOOM)) { AppConfig.putBoolean(getBaseContext(), AppConfig.Key.SUPPORT_ZOOM, true); } } @Override public void onCheckedChanged(boolean checked) { } }, menuClickListener)); menuList.add(new CheckMenu(this, "Visible To User Decode Large Image In Detail Page", AppConfig.Key.PAGE_VISIBLE_TO_USER_DECODE_LARGE_IMAGE, null, menuClickListener)); menuList.add("GIF"); menuList.add(new CheckMenu(this, "Auto Play GIF In List", AppConfig.Key.PLAY_GIF_ON_LIST, null, menuClickListener)); menuList.add(new CheckMenu(this, "Click Play GIF In List", AppConfig.Key.CLICK_PLAY_GIF, null, menuClickListener)); menuList.add( new CheckMenu(this, "Show GIF Flag In List", AppConfig.Key.SHOW_GIF_FLAG, null, menuClickListener)); menuList.add("Decode"); menuList.add(new CheckMenu(this, "In Prefer Quality Over Speed", AppConfig.Key.GLOBAL_IN_PREFER_QUALITY_OVER_SPEED, null, menuClickListener)); menuList.add(new CheckMenu(this, "Low Quality Bitmap", AppConfig.Key.GLOBAL_LOW_QUALITY_IMAGE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Enabled Thumbnail Mode In List", AppConfig.Key.THUMBNAIL_MODE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Cache Processed Image In Disk", AppConfig.Key.CACHE_PROCESSED_IMAGE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Disabled Correct Image Orientation", AppConfig.Key.DISABLE_CORRECT_IMAGE_ORIENTATION, null, menuClickListener)); menuList.add("Other"); menuList.add(new CheckMenu(this, "Show Unsplash Large Image In Detail Page", AppConfig.Key.SHOW_UNSPLASH_LARGE_IMAGE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Show Mapping Thumbnail In Detail Page", AppConfig.Key.SHOW_TOOLS_IN_IMAGE_DETAIL, null, menuClickListener)); menuList.add(new CheckMenu(this, "Show Press Status In List", AppConfig.Key.CLICK_SHOW_PRESSED_STATUS, null, menuClickListener)); menuList.add(new CheckMenu(this, "Show Image From Corner Mark", AppConfig.Key.SHOW_IMAGE_FROM_FLAG, null, menuClickListener)); menuList.add(new CheckMenu(this, "Show Download Progress In List", AppConfig.Key.SHOW_IMAGE_DOWNLOAD_PROGRESS, null, menuClickListener)); menuList.add(new CheckMenu(this, "Click Show Image On Pause Download In List", AppConfig.Key.CLICK_RETRY_ON_PAUSE_DOWNLOAD, null, menuClickListener)); menuList.add(new CheckMenu(this, "Click Retry On Error In List", AppConfig.Key.CLICK_RETRY_ON_FAILED, null, menuClickListener)); menuList.add(new CheckMenu(this, "Scrolling Pause Load Image In List", AppConfig.Key.SCROLLING_PAUSE_LOAD, null, menuClickListener)); menuList.add(new CheckMenu(this, "Mobile Network Pause Download Image", AppConfig.Key.MOBILE_NETWORK_PAUSE_DOWNLOAD, null, menuClickListener)); menuList.add("Log"); menuList.add(new CheckMenu(this, "Output Request Course Log", AppConfig.Key.LOG_REQUEST, null, menuClickListener)); menuList.add(new CheckMenu(this, "Output Cache Log", AppConfig.Key.LOG_CACHE, null, menuClickListener)); menuList.add( new CheckMenu(this, "Output Gesture Zoom Log", AppConfig.Key.LOG_ZOOM, null, menuClickListener)); menuList.add(new CheckMenu(this, "Output Block Display Large Image Log", AppConfig.Key.LOG_LARGE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Output Used Time Log", AppConfig.Key.LOG_TIME, null, menuClickListener)); menuList.add(new CheckMenu(this, "Output Other Log", AppConfig.Key.LOG_BASE, null, menuClickListener)); menuList.add(new CheckMenu(this, "Sync Output Log To Disk (cache/sketch_log)", AppConfig.Key.OUT_LOG_2_SDCARD, null, menuClickListener)); return menuList; }
From source file:com.amaze.carbonfilemanager.services.ZipTask.java
private void publishResults(int id, String fileName, int sourceFiles, int sourceProgress, long total, long done, int speed, boolean isCompleted) { if (!progressHandler.getCancelled()) { float progressPercent = ((float) done / total) * 100; mBuilder.setProgress(100, Math.round(progressPercent), false); mBuilder.setOngoing(true);/*from www. j ava 2 s. c o m*/ int title = R.string.compressing; mBuilder.setContentTitle(c.getResources().getString(title)); mBuilder.setContentText(new File(fileName).getName() + " " + Formatter.formatFileSize(c, done) + "/" + Formatter.formatFileSize(c, total)); int id1 = Integer.parseInt("789" + id); mNotifyManager.notify(id1, mBuilder.build()); if (done == total || total == 0) { mBuilder.setContentTitle(getString(R.string.compression_complete)); mBuilder.setContentText(""); mBuilder.setProgress(100, 100, false); mBuilder.setOngoing(false); mNotifyManager.notify(id1, mBuilder.build()); publishCompletedResult(id1); isCompleted = true; } DataPackage intent = new DataPackage(); intent.setName(fileName); intent.setSourceFiles(sourceFiles); intent.setSourceProgress(sourceProgress); intent.setTotal(total); intent.setByteProgress(done); intent.setSpeedRaw(speed); intent.setMove(false); intent.setCompleted(isCompleted); putDataPackage(intent); if (progressListener != null) { progressListener.onUpdate(intent); if (isCompleted) progressListener.refresh(); } } else { publishCompletedResult(Integer.parseInt("789" + id)); } }
From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentInfoFragment.java
public void setDownloadPath(String path) { if (path == null) { return;/* w w w. java 2s . c o m*/ } pathToUploadView.setText(path); freeSpace.setText(String.format(getString(R.string.free_space), Formatter.formatFileSize(activity.getApplicationContext(), FileIOUtils.getFreeSpace(path)))); }
From source file:com.waz.zclient.pages.main.conversation.views.row.message.views.VideoMessageViewController.java
private void updateViews(String action, Drawable background, ProgressIndicator progressIndicator) { placeHolderDots.setVisibility(GONE); actionButton.setVisibility(VISIBLE); actionButton.setText(action);//from w w w .j a v a 2 s. c o m actionButton.setBackground(background); if (progressIndicator == null) { actionButton.clearProgress(); progressIndicatorObserver.clear(); } else { progressIndicatorObserver.addAndUpdate(progressIndicator); } StringBuilder info = new StringBuilder(StringUtils.formatTimeSeconds(asset.getDuration().getSeconds())); long size = asset.getSizeInBytes(); if (size > 0 && asset.getStatus() != AssetStatus.DOWNLOAD_DONE) { info.append(INFO_DIVIDER).append(Formatter.formatFileSize(context, asset.getSizeInBytes())); } videoInfoText.setText(info.toString()); }
From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFilesFragment.java
@Override public void onItemCheckedChanged(TorrentContentFileTree node, boolean selected) { if (node.getSelectState() == TorrentContentFileTree.SelectState.DISABLED) { return;/*from w w w. j a v a 2 s .c o m*/ } node.select((selected ? TorrentContentFileTree.SelectState.SELECTED : TorrentContentFileTree.SelectState.UNSELECTED)); adapter.updateItem(node); if (callback != null) { callback.onTorrentFilesChanged(); } filesSize.setText(String.format(getString(R.string.files_size), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.selectedFileSize()), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.size()))); }
From source file:com.waz.zclient.pages.main.conversation.views.row.message.views.FileMessageViewController.java
private String getFileInfoString(Asset asset) { boolean fileSizeNotAvailable = asset.getSizeInBytes() < 0; String fileExtension = getFileExtension(asset); int infoStringId; switch (message.getMessageStatus()) { case PENDING: if (asset.getStatus() == AssetStatus.UPLOAD_CANCELLED) { infoStringId = getCancelledStatusStringResource(fileSizeNotAvailable, fileExtension); } else {/*ww w .j a v a 2 s . c om*/ infoStringId = getUploadingStatusStringResource(fileSizeNotAvailable, fileExtension); } break; case FAILED: infoStringId = getUploadFailedStatusStringResource(fileSizeNotAvailable, fileExtension); break; case SENT: // File already uploaded switch (asset.getStatus()) { case UPLOAD_IN_PROGRESS: infoStringId = getUploadingStatusStringResource(fileSizeNotAvailable, fileExtension); break; case UPLOAD_FAILED: infoStringId = getUploadFailedStatusStringResource(fileSizeNotAvailable, fileExtension); break; case DOWNLOAD_IN_PROGRESS: infoStringId = getDownloadingStatusStringResource(fileSizeNotAvailable, fileExtension); break; default: infoStringId = getDefaulStatusStringResource(fileSizeNotAvailable, fileExtension); break; } break; default: infoStringId = getDefaulStatusStringResource(fileSizeNotAvailable, fileExtension); break; } if (infoStringId == 0) { return ""; } if (fileSizeNotAvailable) { return TextUtils.isEmpty(fileExtension) ? context.getString(infoStringId) : context.getString(infoStringId, fileExtension.toUpperCase(Locale.getDefault())); } else { String fileSize = Formatter.formatFileSize(context, asset.getSizeInBytes()); return TextUtils.isEmpty(fileExtension) ? context.getString(infoStringId, fileSize) : context.getString(infoStringId, fileSize, fileExtension.toUpperCase(Locale.getDefault())); } }
From source file:com.amaze.carbonfilemanager.fragments.ProcessViewer.java
public void processResults(final DataPackage dataPackage, ServiceType serviceType) { if (dataPackage != null) { String name = dataPackage.getName(); long total = dataPackage.getTotal(); long doneBytes = dataPackage.getByteProgress(); boolean move = dataPackage.isMove(); if (!isInitialized) { // initializing views for the first time chartInit(total);//from w ww .ja v a2 s . c om // setting progress image setupDrawables(serviceType, move); isInitialized = true; } addEntry(Futils.readableFileSizeFloat(doneBytes), Futils.readableFileSizeFloat(dataPackage.getSpeedRaw())); mProgressFileNameText.setText(name); Spanned bytesText = Html.fromHtml(getResources().getString(R.string.written) + " <font color='" + accentColor + "'><i>" + Formatter.formatFileSize(getContext(), doneBytes) + " </font></i>" + getResources().getString(R.string.out_of) + " <i>" + Formatter.formatFileSize(getContext(), total) + "</i>"); mProgressBytesText.setText(bytesText); Spanned fileProcessedSpan = Html.fromHtml(getResources().getString(R.string.processing_file) + " <font color='" + accentColor + "'><i>" + (dataPackage.getSourceProgress()) + " </font></i>" + getResources().getString(R.string.of) + " <i>" + dataPackage.getSourceFiles() + "</i>"); mProgressFileText.setText(fileProcessedSpan); Spanned speedSpan = Html.fromHtml( getResources().getString(R.string.current_speed) + ": <font color='" + accentColor + "'><i>" + Formatter.formatFileSize(getContext(), dataPackage.getSpeedRaw()) + "/s</font></i>"); mProgressSpeedText.setText(speedSpan); Spanned timerSpan = Html.fromHtml(getResources().getString(R.string.service_timer) + ": <font color='" + accentColor + "'><i>" + formatTimer(++time) + "</font></i>"); mProgressTimer.setText(timerSpan); } }
From source file:com.fastaccess.ui.modules.repos.RepoPagerActivity.java
@Override public void onInitRepo() { hideProgress();/*from w w w .java 2 s.c o m*/ if (getPresenter().getRepo() == null) { return; } setTaskName(getPresenter().getRepo().getFullName()); bottomNavigation.setOnMenuItemClickListener(getPresenter()); Repo repoModel = getPresenter().getRepo(); if (repoModel.getTopics() != null && !repoModel.getTopics().isEmpty()) { tagsIcon.setVisibility(View.VISIBLE); topicsList.setAdapter(new TopicsAdapter(repoModel.getTopics())); } else { topicsList.setVisibility(View.GONE); } onRepoPinned(AbstractPinnedRepos.isPinned(repoModel.getFullName())); wikiLayout.setVisibility(repoModel.isHasWiki() ? View.VISIBLE : View.GONE); pinText.setText(R.string.pin); detailsIcon.setVisibility(InputHelper.isEmpty(repoModel.getDescription()) ? View.GONE : View.VISIBLE); language.setVisibility(InputHelper.isEmpty(repoModel.getLanguage()) ? View.GONE : View.VISIBLE); if (!InputHelper.isEmpty(repoModel.getLanguage())) { language.setText(repoModel.getLanguage()); language.setTextColor(ColorsProvider.getColorAsColor(repoModel.getLanguage(), language.getContext())); } forkRepo.setText(numberFormat.format(repoModel.getForksCount())); starRepo.setText(numberFormat.format(repoModel.getStargazersCount())); watchRepo.setText(numberFormat.format(repoModel.getSubsCount())); if (repoModel.getOwner() != null) { avatarLayout.setUrl(repoModel.getOwner().getAvatarUrl(), repoModel.getOwner().getLogin(), repoModel.getOwner().isOrganizationType(), LinkParserHelper.isEnterprise(repoModel.getHtmlUrl())); } else if (repoModel.getOrganization() != null) { avatarLayout.setUrl(repoModel.getOrganization().getAvatarUrl(), repoModel.getOrganization().getLogin(), true, LinkParserHelper.isEnterprise(repoModel.getHtmlUrl())); } long repoSize = repoModel.getSize() > 0 ? (repoModel.getSize() * 1000) : repoModel.getSize(); date.setText(SpannableBuilder.builder().append(ParseDateFormat.getTimeAgo(repoModel.getPushedAt())) .append(" ,").append(" ").append(Formatter.formatFileSize(this, repoSize))); size.setVisibility(View.GONE); title.setText(repoModel.getFullName()); TextViewCompat.setTextAppearance(title, R.style.TextAppearance_AppCompat_Medium); title.setTextColor(ViewHelper.getPrimaryTextColor(this)); if (repoModel.getLicense() != null) { licenseLayout.setVisibility(View.VISIBLE); LicenseModel licenseModel = repoModel.getLicense(); license.setText(!InputHelper.isEmpty(licenseModel.getSpdxId()) ? licenseModel.getSpdxId() : licenseModel.getName()); } supportInvalidateOptionsMenu(); if (!PrefGetter.isRepoGuideShowed()) { } onRepoWatched(getPresenter().isWatched()); onRepoStarred(getPresenter().isStarred()); onRepoForked(getPresenter().isForked()); }