本文整理汇总了Java中android.text.format.Formatter.formatShortFileSize方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.formatShortFileSize方法的具体用法?Java Formatter.formatShortFileSize怎么用?Java Formatter.formatShortFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.Formatter
的用法示例。
在下文中一共展示了Formatter.formatShortFileSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStatusbarNotification
import android.text.format.Formatter; //导入方法依赖的package包/类
private void updateStatusbarNotification(long currentSize, long totalSize, int currentFiles, int totalFiles) {
if (mNotificationBuilder != null) {
String formattedCurrentSize = Formatter.formatShortFileSize(this, currentSize);
String formattedTotalSize = Formatter.formatShortFileSize(this, totalSize);
int textId;
String formattedString;
if (totalFiles <= 0) {
textId = R.string.pasting_copy_one;
// Display the progress in bytes only
formattedString = getResources().getString(textId, formattedCurrentSize, formattedTotalSize);
}
else {
textId = R.string.pasting_copy_many;
// Display the progress in number of files and bytes
formattedString = getResources().getString(textId, currentFiles, totalFiles,
formattedCurrentSize, formattedTotalSize);
}
mNotificationBuilder.setProgress((int)totalSize, (int)currentSize, false);
updateStatusbarNotification(formattedString);
}
}
示例2: onPrompt
import android.text.format.Formatter; //导入方法依赖的package包/类
@Override
public void onPrompt(UpdateAgent agent) {
final UpdateInfo info = agent.getInfo();
String size = Formatter.formatShortFileSize(mContext, info.size);
String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);
final AlertDialog dialog = new AlertDialog.Builder(mContext).create();
dialog.setTitle("应用更新");
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
float density = mContext.getResources().getDisplayMetrics().density;
TextView tv = new TextView(mContext);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setVerticalScrollBarEnabled(true);
tv.setTextSize(14);
tv.setMaxHeight((int) (250 * density));
dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);
DialogInterface.OnClickListener listener = new OnPromptClick(agent, true);
if (info.isForce) {
tv.setText("您需要更新应用才能继续使用\n\n" + content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
} else {
tv.setText(content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
if (info.isIgnorable) {
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
}
}
dialog.show();
}
示例3: prompt
import android.text.format.Formatter; //导入方法依赖的package包/类
@Override
public void prompt(IUpdateAgent agent) {
if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
return;
}
final UpdateInfo info = agent.getInfo();
String size = Formatter.formatShortFileSize(mContext, info.size);
String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);
final AlertDialog dialog = new AlertDialog.Builder(mContext).create();
dialog.setTitle("应用更新");
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
float density = mContext.getResources().getDisplayMetrics().density;
TextView tv = new TextView(mContext);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setVerticalScrollBarEnabled(true);
tv.setTextSize(14);
tv.setMaxHeight((int) (250 * density));
dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);
DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);
if (info.isForce) {
tv.setText("您需要更新应用才能继续使用\n\n" + content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
} else {
tv.setText(content);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
if (info.isIgnorable) {
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
}
}
dialog.show();
}
示例4: getSubTitlePrefix
import android.text.format.Formatter; //导入方法依赖的package包/类
private String getSubTitlePrefix() {
return Formatter.formatShortFileSize(getContext(), getExtraLongValue("size")) + " · ";
}