diff options
| author | Sascha Haeberling <haeberling@google.com> | 2013-08-26 14:56:41 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2013-08-26 14:56:41 -0700 |
| commit | 87863a9f3104a870916adcf3e096fc98d0adcfd2 (patch) | |
| tree | a3e3f62cd482f4806dd2dcc11c26248fad0445c9 | |
| parent | d818d9f6cfa0811f40f70912aae845918a264e5c (diff) | |
| parent | fa2b9222725e96fdb584aca1b1213b0bda8af110 (diff) | |
| download | android_packages_apps_Gallery2-87863a9f3104a870916adcf3e096fc98d0adcfd2.tar.gz android_packages_apps_Gallery2-87863a9f3104a870916adcf3e096fc98d0adcfd2.tar.bz2 android_packages_apps_Gallery2-87863a9f3104a870916adcf3e096fc98d0adcfd2.zip | |
am fa2b9222: Make parsing integers for details dialog more robust.
* commit 'fa2b9222725e96fdb584aca1b1213b0bda8af110':
Make parsing integers for details dialog more robust.
| -rw-r--r-- | src/com/android/gallery3d/ui/DialogDetailsView.java | 44 |
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); |
