summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui
diff options
context:
space:
mode:
authorSascha Haeberling <haeberling@google.com>2013-08-26 14:41:46 -0700
committerSascha Haeberling <haeberling@google.com>2013-08-26 14:41:46 -0700
commitfa2b9222725e96fdb584aca1b1213b0bda8af110 (patch)
treea3a1f9ca75e1b45cc76928231656168e9855042c /src/com/android/gallery3d/ui
parentdc514bb1f6ad5927d76c5f5a52742428cb0846fa (diff)
downloadandroid_packages_apps_Gallery2-fa2b9222725e96fdb584aca1b1213b0bda8af110.tar.gz
android_packages_apps_Gallery2-fa2b9222725e96fdb584aca1b1213b0bda8af110.tar.bz2
android_packages_apps_Gallery2-fa2b9222725e96fdb584aca1b1213b0bda8af110.zip
Make parsing integers for details dialog more robust.
Bug: 7141309 Also make sure "orientation" is localized. Change-Id: Ib950eca6becd2eed21bebfbd48e11a182b76e45a
Diffstat (limited to 'src/com/android/gallery3d/ui')
-rw-r--r--src/com/android/gallery3d/ui/DialogDetailsView.java44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/com/android/gallery3d/ui/DialogDetailsView.java b/src/com/android/gallery3d/ui/DialogDetailsView.java
index b8496ec1f..30fd1e18f 100644
--- a/src/com/android/gallery3d/ui/DialogDetailsView.java
+++ b/src/com/android/gallery3d/ui/DialogDetailsView.java
@@ -185,30 +185,20 @@ public class DialogDetailsView implements DetailsViewContainer {
}
case MediaDetails.INDEX_WIDTH:
mWidthIndex = mItems.size();
- value = detail.getValue().toString();
- try {
- value = toLocalNumber(Integer.parseInt(value));
- } catch (NumberFormatException ex) {
- // Just keep the current "value" if we cannot parse
- // it as a fallback.
- }
- if (value.equalsIgnoreCase("0")) {
+ if (detail.getValue().toString().equalsIgnoreCase("0")) {
value = context.getString(R.string.unknown);
resolutionIsValid = false;
+ } else {
+ value = toLocalInteger(detail.getValue());
}
break;
case MediaDetails.INDEX_HEIGHT: {
mHeightIndex = mItems.size();
- value = detail.getValue().toString();
- try {
- value = toLocalNumber(Integer.parseInt(value));
- } catch (NumberFormatException ex) {
- // Just keep the current "value" if we cannot parse
- // it as a fallback.
- }
- if (value.equalsIgnoreCase("0")) {
+ if (detail.getValue().toString().equalsIgnoreCase("0")) {
value = context.getString(R.string.unknown);
resolutionIsValid = false;
+ } else {
+ value = toLocalInteger(detail.getValue());
}
break;
}
@@ -228,6 +218,9 @@ public class DialogDetailsView implements DetailsViewContainer {
double focalLength = Double.parseDouble(detail.getValue().toString());
value = toLocalNumber(focalLength);
break;
+ case MediaDetails.INDEX_ORIENTATION:
+ value = toLocalInteger(detail.getValue());
+ break;
default: {
Object valueObj = detail.getValue();
// This shouldn't happen, log its key to help us diagnose the problem.
@@ -313,6 +306,25 @@ public class DialogDetailsView implements DetailsViewContainer {
notifyDataSetChanged();
}
+ /**
+ * Converts the given integer (given as String or Integer object) to a
+ * localized String version.
+ */
+ private String toLocalInteger(Object valueObj) {
+ if (valueObj instanceof Integer) {
+ return toLocalNumber((Integer) valueObj);
+ } else {
+ String value = valueObj.toString();
+ try {
+ value = toLocalNumber(Integer.parseInt(value));
+ } catch (NumberFormatException ex) {
+ // Just keep the current "value" if we cannot
+ // parse it as a fallback.
+ }
+ return value;
+ }
+ }
+
/** Converts the given integer to a localized String version. */
private String toLocalNumber(int n) {
return String.format(mDefaultLocale, "%d", n);