Example usage for android.text.format Formatter formatShortFileSize

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

Introduction

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

Prototype

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

Source Link

Document

Like #formatFileSize , but trying to generate shorter numbers (showing fewer digits of precision).

Usage

From source file:ee.ria.DigiDoc.adapter.DataFilesAdapter.java

@NonNull
@Override// w  w  w. j  a  v  a  2 s.co  m
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    notificationUtil = new NotificationUtil(activity);
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.fragment_container_datafiles, parent,
                false);
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    final DataFileFacade dataFileFacade = getItem(position);
    if (dataFileFacade != null) {
        viewHolder.fileName.setText(dataFileFacade.getFileName());
        String fileSizeText = getContext().getString(R.string.file_size);
        String fileSizeWithUnit = Formatter.formatShortFileSize(getContext(), dataFileFacade.getFileSize());
        viewHolder.fileSize.setText(String.format(fileSizeText, fileSizeWithUnit));
        viewHolder.removeFile.setOnClickListener(
                new RemoveFileListener(position, dataFileFacade.getFileName(), parent.getContext()));
    }
    return convertView;
}

From source file:org.iota.wallet.ui.fragment.NodeInfoFragment.java

@Subscribe
public void onEvent(NodeInfoResponse nir) {
    swipeRefreshLayout.setRefreshing(false);
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
    nodeInfos = new ArrayList<>();
    nodeInfos.add(new NodeInfo(getString(R.string.info_app_name), nir.getAppName()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_app_version), nir.getAppVersion()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_jre_version), nir.getJreVersion()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_max_processors), nir.getJreAvailableProcessors() + ""));
    nodeInfos.add(new NodeInfo(getString(R.string.info_free_memory),
            Formatter.formatShortFileSize(getActivity(), nir.getJreFreeMemory())));
    nodeInfos.add(new NodeInfo(getString(R.string.info_max_memory),
            Formatter.formatShortFileSize(getActivity(), nir.getJreMaxMemory())));
    nodeInfos.add(new NodeInfo(getString(R.string.info_total_memory),
            Formatter.formatShortFileSize(getActivity(), nir.getJreTotalMemory())));
    nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone), nir.getLatestMilestone()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_index), nir.getLatestMilestoneIndex()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_solid_subtangle),
            nir.getLatestSolidSubtangleMilestone()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_solid_subtangle_index),
            nir.getLatestSolidSubtangleMilestoneIndex()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_neighbors), nir.getNeighbors()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_packets_queue_size), nir.getPacketsQueueSize()));
    nodeInfos.add(new NodeInfo(getString(R.string.info_time), df.format(new Date(nir.getTime()))));
    nodeInfos.add(new NodeInfo(getString(R.string.info_tips), nir.getTips()));
    nodeInfos.add(/*from  w ww . j a  v a  2 s.co  m*/
            new NodeInfo(getString(R.string.info_transactions_to_request), nir.getTransactionsToRequest()));

    setAdapter();

    updateChart(nir.getTips(), nir.getTransactionsToRequest());
}

From source file:com.linroid.pushapp.ui.send.SendActivity.java

private void pushToDevice(List<String> devices) {
    if (devices.size() == 0) {
        Snackbar.make(fab, R.string.error_not_select_any_device, Snackbar.LENGTH_SHORT).show();
        return;//from   w w  w. java2s.c  o  m
    }
    Snackbar.make(fab, getString(R.string.msg_push_install_package, devices.size()), Snackbar.LENGTH_SHORT)
            .show();
    String deviceIds = TextUtils.join(",", devices.toArray());
    if (pack != null) {
        installApi.installPackage(deviceIds, pack.getId(), this);
    } else {
        File apkFile = new File(appInfo.sourceDir);
        CountingTypedFile typedFile = new CountingTypedFile(apkFile);
        dialog.show();
        typedFile.subscribe(new Subscriber<Pair<Long, Long>>() {
            @Override
            public void onCompleted() {
                dialog.setMessage(getString(R.string.msg_upload_complete));
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(Pair<Long, Long> pair) {
                dialog.setMessage(getString(R.string.msg_upload_progress,
                        Formatter.formatShortFileSize(SendActivity.this, pair.second),
                        Formatter.formatShortFileSize(SendActivity.this, pair.first)));
            }
        });
        installApi.installLocal(new TypedString(deviceIds), typedFile, this);
    }
}

From source file:org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences.java

/** OnClickListener for the clear button. We show an alert dialog to confirm the action */
@Override/*from   ww  w .j a v a 2s .c om*/
public void onClick(View v) {
    if (getActivity() == null || v != mClearButton)
        return;

    long totalUsage = 0;
    if (mWebsites != null) {
        for (WebsitePreference preference : mWebsites) {
            totalUsage += preference.site().getTotalUsage();
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(R.string.storage_clear_dialog_clear_storage_option,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    clearStorage();
                }
            });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.storage_clear_site_storage_title);
    Resources res = getResources();
    String dialogFormattedText = res.getString(R.string.storage_clear_dialog_text,
            Formatter.formatShortFileSize(getActivity(), totalUsage));
    builder.setMessage(dialogFormattedText);
    builder.create().show();
}

From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java

private String getFormattedFileInfo() {
    String format = getContext().getString(R.string.file_info);
    String extension = FilenameUtils.getExtension(containerFacade.getName()).toUpperCase();
    String sizeWithUnit = Formatter.formatShortFileSize(getContext(), containerFacade.fileSize());
    return String.format(format, extension, sizeWithUnit);
}

From source file:com.waz.zclient.pages.main.conversation.ConversationFragment.java

@Override
public void onSyncError(final ErrorsList.ErrorDescription errorDescription) {
    switch (errorDescription.getType()) {
    case CANNOT_SEND_ASSET_FILE_NOT_FOUND:
        ViewUtils.showAlertDialog(getActivity(), R.string.asset_upload_error__not_found__title,
                R.string.asset_upload_error__not_found__message, R.string.asset_upload_error__not_found__button,
                null, true);/*from  w ww  . j  ava2 s.  com*/
        errorDescription.dismiss();
        break;
    case CANNOT_SEND_ASSET_TOO_LARGE:
        AlertDialog dialog = ViewUtils.showAlertDialog(getActivity(),
                R.string.asset_upload_error__file_too_large__title,
                R.string.asset_upload_error__file_too_large__message_default,
                R.string.asset_upload_error__file_too_large__button, null, true);
        long maxAllowedSizeInBytes = AssetFactory.getMaxAllowedAssetSizeInBytes();
        if (maxAllowedSizeInBytes > 0) {
            String maxFileSize = Formatter.formatShortFileSize(getContext(), maxAllowedSizeInBytes);
            dialog.setMessage(getString(R.string.asset_upload_error__file_too_large__message, maxFileSize));
        }

        errorDescription.dismiss();
        getControllerFactory().getTrackingController().tagEvent(new SelectedTooLargeFileEvent());
        break;
    case RECORDING_FAILURE:
        ViewUtils.showAlertDialog(getActivity(), R.string.audio_message__recording__failure__title,
                R.string.audio_message__recording__failure__message, R.string.alert_dialog__confirmation, null,
                true);
        errorDescription.dismiss();

        break;
    case CANNOT_SEND_MESSAGE_TO_UNVERIFIED_CONVERSATION:
        onErrorCanNotSentMessageToUnverifiedConversation(errorDescription);
        break;
    }
}