diff --git a/res/layout/details.xml b/res/layout/details.xml index dfda0ee22..1fea0a0fb 100644 --- a/res/layout/details.xml +++ b/res/layout/details.xml @@ -19,5 +19,5 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" - android:gravity="left" + android:gravity="start" /> diff --git a/src/com/android/gallery3d/ui/DialogDetailsView.java b/src/com/android/gallery3d/ui/DialogDetailsView.java index 058c03654..b8496ec1f 100644 --- a/src/com/android/gallery3d/ui/DialogDetailsView.java +++ b/src/com/android/gallery3d/ui/DialogDetailsView.java @@ -39,7 +39,9 @@ import com.android.gallery3d.ui.DetailsHelper.DetailsViewContainer; import com.android.gallery3d.ui.DetailsHelper.ResolutionResolvingListener; +import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Locale; import java.util.Map.Entry; public class DialogDetailsView implements DetailsViewContainer { @@ -117,6 +119,8 @@ private class DetailsAdapter extends BaseAdapter implements AddressResolvingListener, ResolutionResolvingListener { private final ArrayList mItems; private int mLocationIndex; + private final Locale mDefaultLocale = Locale.getDefault(); + private final DecimalFormat mDecimalFormat = new DecimalFormat(".####"); private int mWidthIndex = -1; private int mHeightIndex = -1; @@ -166,13 +170,15 @@ private void setDetails(Context context, MediaDetails details) { value = (String) detail.getValue(); double time = Double.valueOf(value); if (time < 1.0f) { - value = String.format("1/%d", (int) (0.5f + 1 / time)); + value = String.format(mDefaultLocale, "%d/%d", 1, + (int) (0.5f + 1 / time)); } else { int integer = (int) time; time -= integer; value = String.valueOf(integer) + "''"; if (time > 0.0001) { - value += String.format(" 1/%d", (int) (0.5f + 1 / time)); + value += String.format(mDefaultLocale, " %d/%d", 1, + (int) (0.5f + 1 / time)); } } break; @@ -180,6 +186,12 @@ private void setDetails(Context context, MediaDetails details) { 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")) { value = context.getString(R.string.unknown); resolutionIsValid = false; @@ -188,6 +200,12 @@ private void setDetails(Context context, MediaDetails details) { 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")) { value = context.getString(R.string.unknown); resolutionIsValid = false; @@ -195,8 +213,21 @@ private void setDetails(Context context, MediaDetails details) { break; } case MediaDetails.INDEX_PATH: - // Get the path and then fall through to the default case + // Prepend the new-line as a) paths are usually long, so + // the formatting is better and b) an RTL UI will see it + // as a separate section and interpret it for what it + // is, rather than trying to make it RTL (which messes + // up the path). + value = "\n" + detail.getValue().toString(); path = detail.getValue().toString(); + break; + case MediaDetails.INDEX_ISO: + value = toLocalNumber(Integer.parseInt((String) detail.getValue())); + break; + case MediaDetails.INDEX_FOCAL_LENGTH: + double focalLength = Double.parseDouble(detail.getValue().toString()); + value = toLocalNumber(focalLength); + break; default: { Object valueObj = detail.getValue(); // This shouldn't happen, log its key to help us diagnose the problem. @@ -216,9 +247,9 @@ private void setDetails(Context context, MediaDetails details) { context, key), value); } mItems.add(value); - if (!resolutionIsValid) { - DetailsHelper.resolveResolution(path, this); - } + } + if (!resolutionIsValid) { + DetailsHelper.resolveResolution(path, this); } } @@ -271,14 +302,26 @@ public void onResolutionAvailable(int width, int height) { if (width == 0 || height == 0) return; // Update the resolution with the new width and height Context context = mActivity.getAndroidContext(); - String widthString = String.format("%s: %d", DetailsHelper.getDetailsName( - context, MediaDetails.INDEX_WIDTH), width); - String heightString = String.format("%s: %d", DetailsHelper.getDetailsName( - context, MediaDetails.INDEX_HEIGHT), height); + String widthString = String.format(mDefaultLocale, "%s: %d", + DetailsHelper.getDetailsName( + context, MediaDetails.INDEX_WIDTH), width); + String heightString = String.format(mDefaultLocale, "%s: %d", + DetailsHelper.getDetailsName( + context, MediaDetails.INDEX_HEIGHT), height); mItems.set(mWidthIndex, String.valueOf(widthString)); mItems.set(mHeightIndex, String.valueOf(heightString)); notifyDataSetChanged(); } + + /** Converts the given integer to a localized String version. */ + private String toLocalNumber(int n) { + return String.format(mDefaultLocale, "%d", n); + } + + /** Converts the given double to a localized String version. */ + private String toLocalNumber(double n) { + return mDecimalFormat.format(n); + } } @Override