diff options
author | Brian Attwell <brianattwell@google.com> | 2014-10-17 14:32:35 -0700 |
---|---|---|
committer | Brian Attwell <brianattwell@google.com> | 2014-10-17 21:38:32 +0000 |
commit | ed95f6c490fb9549a88918ddf421cfb70694c52d (patch) | |
tree | 0265a853b72551d9389174c0abf29123672f1bb1 | |
parent | aef550d6b509fa31e5f19a8a700abc31c5d4689f (diff) | |
download | android_packages_apps_ContactsCommon-ed95f6c490fb9549a88918ddf421cfb70694c52d.tar.gz android_packages_apps_ContactsCommon-ed95f6c490fb9549a88918ddf421cfb70694c52d.tar.bz2 android_packages_apps_ContactsCommon-ed95f6c490fb9549a88918ddf421cfb70694c52d.zip |
Improve appearance of export file path
I fixed two issues
1. We were using two kinds of numerals in the file path, arabic
and english. Lets just stick with english numerals
2. English numerals are "weakly LTR" characters. Therefore,
having the following formatting 0001.vcf is equivalent to
<weak ltr chars><neutral chars><strong rtl chars>. This results
in weird rendering, since the default locale is RTL. Fix: put
the url in a LTR embedding.
Bug: 9195099
Change-Id: I1260a3430d7d3a0c029c1a1ac5ffcc421b08a98a
-rw-r--r-- | src/com/android/contacts/common/vcard/ExportVCardActivity.java | 16 | ||||
-rw-r--r-- | src/com/android/contacts/common/vcard/VCardService.java | 9 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/com/android/contacts/common/vcard/ExportVCardActivity.java b/src/com/android/contacts/common/vcard/ExportVCardActivity.java index 3d6f6022..008beb68 100644 --- a/src/com/android/contacts/common/vcard/ExportVCardActivity.java +++ b/src/com/android/contacts/common/vcard/ExportVCardActivity.java @@ -30,6 +30,8 @@ import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Messenger; +import android.text.BidiFormatter; +import android.text.TextDirectionHeuristics; import android.text.TextUtils; import android.util.Log; @@ -111,6 +113,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection, private VCardService mService; private final Messenger mIncomingMessenger = new Messenger(new IncomingHandler()); + private static final BidiFormatter mBidiFormatter = BidiFormatter.getInstance(); // Used temporarily when asking users to confirm the file name private String mTargetFileName; @@ -208,13 +211,22 @@ public class ExportVCardActivity extends Activity implements ServiceConnection, } } + /** + * Returns the name of the target path with additional formatting characters to improve its + * appearance in bidirectional text. + */ + private String getTargetFileForDisplay() { + return mBidiFormatter.unicodeWrap(mTargetFileName, TextDirectionHeuristics.LTR); + } + @Override protected Dialog onCreateDialog(int id, Bundle bundle) { switch (id) { case R.id.dialog_export_confirmation: { return new AlertDialog.Builder(this) .setTitle(R.string.confirm_export_title) - .setMessage(getString(R.string.confirm_export_message, mTargetFileName)) + .setMessage(getString(R.string.confirm_export_message, + getTargetFileForDisplay())) .setPositiveButton(android.R.string.ok, new ExportConfirmationListener(mTargetFileName)) .setNegativeButton(android.R.string.cancel, this) @@ -258,7 +270,7 @@ public class ExportVCardActivity extends Activity implements ServiceConnection, ((AlertDialog)dialog).setMessage(mErrorReason); } else if (id == R.id.dialog_export_confirmation) { ((AlertDialog)dialog).setMessage( - getString(R.string.confirm_export_message, mTargetFileName)); + getString(R.string.confirm_export_message, getTargetFileForDisplay())); } else { super.onPrepareDialog(id, dialog, args); } diff --git a/src/com/android/contacts/common/vcard/VCardService.java b/src/com/android/contacts/common/vcard/VCardService.java index e2adbbde..0a50becc 100644 --- a/src/com/android/contacts/common/vcard/VCardService.java +++ b/src/com/android/contacts/common/vcard/VCardService.java @@ -37,6 +37,7 @@ import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -472,7 +473,8 @@ public class VCardService extends Service { * This method increments "index" part from 1 to maximum, and checks whether any file name * following naming rule is available. If there's no file named /mnt/sdcard/00001.vcf, the * name will be returned to a caller. If there are 00001.vcf 00002.vcf, 00003.vcf is - * returned. + * returned. We format these numbers in the US locale to ensure we they appear as + * english numerals. * * There may not be any appropriate file name. If there are 99999 vCard files in the * storage, for example, there's no appropriate name, so this method returns @@ -495,7 +497,7 @@ public class VCardService extends Service { if (!ALLOW_LONG_FILE_NAME) { final String possibleBody = - String.format(bodyFormat, mFileNamePrefix, 1, mFileNameSuffix); + String.format(Locale.US, bodyFormat, mFileNamePrefix, 1, mFileNameSuffix); if (possibleBody.length() > 8 || mFileNameExtension.length() > 3) { Log.e(LOG_TAG, "This code does not allow any long file name."); mErrorReason = getString(R.string.fail_reason_too_long_filename, @@ -507,7 +509,8 @@ public class VCardService extends Service { for (int i = mFileIndexMinimum; i <= mFileIndexMaximum; i++) { boolean numberIsAvailable = true; - final String body = String.format(bodyFormat, mFileNamePrefix, i, mFileNameSuffix); + final String body + = String.format(Locale.US, bodyFormat, mFileNamePrefix, i, mFileNameSuffix); // Make sure that none of the extensions of mExtensionsToConsider matches. If this // number is free, we'll go ahead with mFileNameExtension (which is included in // mExtensionsToConsider) |