Commit a3d81701 authored by newt's avatar newt Committed by Commit bot

Clean up some strings.

- Moves some strings from android_ui_strings.grd to
  android_chrome_strings.grd since they're only used in src/chrome
- Simplifies string loading and formatting in Data Saver promo
- Uses Android's Formatter class to format byte/KB/MB values instead of
  rolling our own solution in WebsitePreference.java.
- Neatens up android_ui_strings.grd

Review URL: https://codereview.chromium.org/926033003

Cr-Commit-Position: refs/heads/master@{#316282}
parent 546fd757
......@@ -102,7 +102,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/data_reduction_compressed_size"
......@@ -110,7 +111,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
......
......@@ -12,7 +12,6 @@ import static org.chromium.third_party.android.datausagechart.ChartDataUsageView
import android.content.Context;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.text.Html;
import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
......@@ -101,9 +100,9 @@ public class BandwidthStatisticsPreferenceCategory extends PreferenceCategory {
super.onBindView(view);
if (mOriginalTotalPhrase == null) updateDetailData();
mOriginalSizeTextView = (TextView) view.findViewById(R.id.data_reduction_original_size);
mOriginalSizeTextView.setText(Html.fromHtml(mOriginalTotalPhrase));
mOriginalSizeTextView.setText(mOriginalTotalPhrase);
mReceivedSizeTextView = (TextView) view.findViewById(R.id.data_reduction_compressed_size);
mReceivedSizeTextView.setText(Html.fromHtml(mReceivedTotalPhrase));
mReceivedSizeTextView.setText(mReceivedTotalPhrase);
mPercentReductionTextView = (TextView) view.findViewById(R.id.data_reduction_percent);
mPercentReductionTextView.setText(mPercentReductionPhrase);
mStartDateTextView = (TextView) view.findViewById(R.id.data_reduction_start_date);
......@@ -145,21 +144,13 @@ public class BandwidthStatisticsPreferenceCategory extends PreferenceCategory {
mOriginalNetworkStatsHistory.getValues(start, end, now, null);
// Only received bytes are tracked.
final long originalTotalBytes = originalEntry.rxBytes;
String originalTotalPhrase = getContext().getString(
R.string.data_reduction_statistics_original_size_suffix,
String.format("<b>%s</b>",
Formatter.formatFileSize(context, originalTotalBytes)));
mOriginalTotalPhrase = originalTotalPhrase;
mOriginalTotalPhrase = Formatter.formatFileSize(context, originalTotalBytes);
NetworkStatsHistory.Entry compressedEntry =
mReceivedNetworkStatsHistory.getValues(start, end, now, null);
// Only received bytes are tracked.
final long compressedTotalBytes = compressedEntry.rxBytes;
String compressedTotalPhrase = getContext().getString(
R.string.data_reduction_statistics_compressed_size_suffix,
String.format("<b>%s</b>",
Formatter.formatFileSize(context, compressedTotalBytes)));
mReceivedTotalPhrase = compressedTotalPhrase;
mReceivedTotalPhrase = Formatter.formatFileSize(context, compressedTotalBytes);
float percentage = 0.0f;
if (originalTotalBytes > 0L && originalTotalBytes > compressedTotalBytes) {
......
......@@ -14,6 +14,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.text.format.Formatter;
import android.widget.ListAdapter;
import org.chromium.chrome.R;
......@@ -72,7 +73,7 @@ public class SingleWebsitePreferences extends PreferenceFragment
Context context = preference.getContext();
preference.setTitle(String.format(
context.getString(R.string.origin_settings_storage_usage_brief),
WebsitePreference.sizeValueToString(context, usage)));
Formatter.formatShortFileSize(context, usage)));
((ClearWebsiteStorage) preference).setConfirmationListener(this);
} else {
getPreferenceScreen().removePreference(preference);
......
......@@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.preference.Preference;
import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
......@@ -23,9 +24,6 @@ import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.widget.RoundedIconGenerator;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* A preference that displays a website's URL and, optionally, some extra permission-related data
* (e.g. the amount of local storage used by the site, or an icon describing what type of media
......@@ -149,7 +147,7 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
long totalUsage = mSite.getTotalUsage();
if (mFilter.showStorageSites(mCategoryFilter)) {
if (totalUsage > 0) {
usageText.setText(sizeValueToString(getContext(), totalUsage));
usageText.setText(Formatter.formatShortFileSize(getContext(), totalUsage));
usageText.setTextSize(TEXT_SIZE_SP);
usageText.setVisibility(View.VISIBLE);
}
......@@ -217,29 +215,4 @@ class WebsitePreference extends Preference implements FaviconImageCallback {
return 0;
}
}
static String sizeValueToString(Context context, long bytes) {
final String label[] = {
context.getString(R.string.origin_settings_storage_bytes),
context.getString(R.string.origin_settings_storage_kbytes),
context.getString(R.string.origin_settings_storage_mbytes),
context.getString(R.string.origin_settings_storage_gbytes),
context.getString(R.string.origin_settings_storage_tbytes),
};
if (bytes <= 0) {
return NumberFormat.getIntegerInstance().format(0) + " " + label[0];
}
int i = 0;
float size = bytes;
for (i = 0; i < label.length; ++i) {
if (size < 1024 || i == label.length - 1)
break;
size /= 1024.0F;
}
DecimalFormat formatter = new DecimalFormat("#.## ");
return formatter.format(size) + label[i];
}
}
......@@ -94,6 +94,27 @@
<release allow_pseudo="false" seq="1">
<messages fallback_to_english="true">
<!-- Generic strings -->
<message name="IDS_OK" desc="Label for a confirm button. Used in multiple contexts. [CHAR-LIMIT=20]">
OK
</message>
<message name="IDS_CANCEL" desc="Label for a cancel button. Used in multiple contexts. [CHAR-LIMIT=20]">
Cancel
</message>
<message name="IDS_SAVE" desc="Label for a button to save a change. Used in multiple contexts. [CHAR-LIMIT=20]">
Save
</message>
<message name="IDS_DELETE" desc="Label for a delete button. Used in multiple contexts. [CHAR-LIMIT=20]">
Delete
</message>
<message name="IDS_TEXT_ON" desc="Text indicating that an option is turned on. [CHAR-LIMIT=20]">
On
</message>
<message name="IDS_TEXT_OFF" desc="Text indicating that an option is turned off. [CHAR-LIMIT=20]">
Off
</message>
<message name="IDS_LEARN_MORE" desc="Generic label for menu item to learn more about a feature. [CHAR-LIMIT=32]">
Learn more
</message>
<message name="IDS_CLOSE" desc="Content description for a button to close a dialog or popup" >
Close
</message>
......@@ -420,21 +441,6 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_ORIGIN_SETTINGS_STORAGE_USAGE_BRIEF" desc="Explanation of how much local storage a website is using">
<ph name="STORAGE_AMOUNT">%1$s<ex>2 MB</ex></ph> stored data
</message>
<message name="IDS_ORIGIN_SETTINGS_STORAGE_BYTES" desc="Unit appended to the storage usage value representing bytes">
bytes
</message>
<message name="IDS_ORIGIN_SETTINGS_STORAGE_KBYTES" desc="Unit appended to the storage usage value representing kilobytes">
KB
</message>
<message name="IDS_ORIGIN_SETTINGS_STORAGE_MBYTES" desc="Unit appended to the storage usage value representing megabytes">
MB
</message>
<message name="IDS_ORIGIN_SETTINGS_STORAGE_GBYTES" desc="Unit appended to the storage usage value representing gigabytes">
GB
</message>
<message name="IDS_ORIGIN_SETTINGS_STORAGE_TBYTES" desc="Unit appended to the storage usage value representing terabytes">
TB
</message>
<!-- Data Saver -->
<message name="IDS_REDUCE_DATA_USAGE_TITLE" desc="Menu item for reducing data usage.">
......@@ -449,15 +455,9 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_DATA_REDUCTION_STATISTICS_TITLE" desc="Data reduction statistics title.">
Data savings
</message>
<message name="IDS_DATA_REDUCTION_STATISTICS_ORIGINAL_SIZE_SUFFIX" desc="Data Reduction statistics original size suffix" translateable="false">
<ph name="SIZE">%1$s<ex>972.1KB</ex></ph>
</message>
<message name="IDS_DATA_REDUCTION_ORIGINAL_SIZE_LABEL" desc="Data Reduction statistics original size label">
Original size
</message>
<message name="IDS_DATA_REDUCTION_STATISTICS_COMPRESSED_SIZE_SUFFIX" desc="Data Reduction statistics compressed size suffix" translateable="false">
<ph name="SIZE">%1$s<ex>492.4KB</ex></ph>
</message>
<message name="IDS_DATA_REDUCTION_COMPRESSED_SIZE_LABEL" desc="Data Reduction statistics compressed size label">
After compression
</message>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment