Skip to content

Commit

Permalink
I18N the Gallery's Details dialog.
Browse files Browse the repository at this point in the history
  Bug: 7141309

Change-Id: I9e658ea3972713fa39e76894f8ae7d8e3d5cdf2c
  • Loading branch information
shaeberling committed Aug 23, 2013
1 parent 4979893 commit 5996f43
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion res/layout/details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
63 changes: 53 additions & 10 deletions src/com/android/gallery3d/ui/DialogDetailsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -117,6 +119,8 @@ private class DetailsAdapter extends BaseAdapter
implements AddressResolvingListener, ResolutionResolvingListener {
private final ArrayList<String> mItems;
private int mLocationIndex;
private final Locale mDefaultLocale = Locale.getDefault();
private final DecimalFormat mDecimalFormat = new DecimalFormat(".####");
private int mWidthIndex = -1;
private int mHeightIndex = -1;

Expand Down Expand Up @@ -166,20 +170,28 @@ 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;
}
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;
Expand All @@ -188,15 +200,34 @@ 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;
}
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.
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5996f43

Please sign in to comment.