diff options
| author | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-04-21 16:03:46 +0900 |
|---|---|---|
| committer | Daisuke Miyakawa <dmiyakawa@google.com> | 2010-04-21 16:06:09 +0900 |
| commit | 56374c43f77ffb412864f53779b4a660ed6de7aa (patch) | |
| tree | 8c3deabbe35d22fabe6a790993e74f81f13d0552 /core/java/android/pim | |
| parent | b633123f9b5a969af59cef52b56ba94ef1a38f1c (diff) | |
| download | frameworks_base-56374c43f77ffb412864f53779b4a660ed6de7aa.zip frameworks_base-56374c43f77ffb412864f53779b4a660ed6de7aa.tar.gz frameworks_base-56374c43f77ffb412864f53779b4a660ed6de7aa.tar.bz2 | |
vCard refactoring.
Change-Id: Ie6c5e0edae4a13279d5118f0380d863e4ff05727
Diffstat (limited to 'core/java/android/pim')
| -rw-r--r-- | core/java/android/pim/vcard/JapaneseUtils.java | 1 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardComposer.java | 33 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardConfig.java | 21 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardEntry.java | 40 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardEntryConstructor.java | 54 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardEntryHandler.java | 9 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardInterpreter.java | 2 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardInterpreterCollection.java | 2 | ||||
| -rw-r--r-- | core/java/android/pim/vcard/VCardUtils.java | 29 |
9 files changed, 109 insertions, 82 deletions
diff --git a/core/java/android/pim/vcard/JapaneseUtils.java b/core/java/android/pim/vcard/JapaneseUtils.java index b37b07d..dcfe980 100644 --- a/core/java/android/pim/vcard/JapaneseUtils.java +++ b/core/java/android/pim/vcard/JapaneseUtils.java @@ -27,7 +27,6 @@ import java.util.Map; new HashMap<Character, String>(); static { - // There's no logical mapping rule in Unicode. Sigh. sHalfWidthMap.put('\u3001', "\uFF64"); sHalfWidthMap.put('\u3002', "\uFF61"); sHalfWidthMap.put('\u300C', "\uFF62"); diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java index 8c007fe..170d6fa 100644 --- a/core/java/android/pim/vcard/VCardComposer.java +++ b/core/java/android/pim/vcard/VCardComposer.java @@ -90,14 +90,14 @@ import java.util.Map; * if (composer != null) { * composer.terminate(); * } - * } </pre> - * <P> + * }</pre> + * <p> * Users have to manually take care of memory efficiency. Even one vCard may contain * image of non-trivial size for mobile devices. - * </P> - * <P> - * In default, Default {@link VCardBuilder} class is used to build each vCard. - * </P> + * </p> + * <p> + * {@link VCardBuilder} is used to build each vCard. + * </p> */ public class VCardComposer { private static final String LOG_TAG = "VCardComposer"; @@ -161,14 +161,14 @@ public class VCardComposer { * Must not close the stream outside this class. * </p> */ - public class HandlerForOutputStream implements OneEntryHandler { + public final class HandlerForOutputStream implements OneEntryHandler { @SuppressWarnings("hiding") - private static final String LOG_TAG = "vcard.VCardComposer.HandlerForOutputStream"; + private static final String LOG_TAG = "VCardComposer.HandlerForOutputStream"; private boolean mOnTerminateIsCalled = false; - final private OutputStream mOutputStream; // mWriter will close this. - protected Writer mWriter; + private final OutputStream mOutputStream; // mWriter will close this. + private Writer mWriter; /** * Input stream will be closed on the detruction of this object. @@ -177,7 +177,7 @@ public class VCardComposer { mOutputStream = outputStream; } - public final boolean onInit(final Context context) { + public boolean onInit(final Context context) { try { mWriter = new BufferedWriter(new OutputStreamWriter( mOutputStream, mCharset)); @@ -207,7 +207,7 @@ public class VCardComposer { return true; } - public final boolean onEntryCreated(String vcard) { + public boolean onEntryCreated(String vcard) { try { mWriter.write(vcard); } catch (IOException e) { @@ -220,7 +220,7 @@ public class VCardComposer { return true; } - public final void onTerminate() { + public void onTerminate() { mOnTerminateIsCalled = true; if (mWriter != null) { try { @@ -242,8 +242,6 @@ public class VCardComposer { } } - // Users can override this if they want to (e.g. if they don't want to close the stream). - // TODO: Should expose bare OutputStream instead? public void closeOutputStream() { try { mWriter.close(); @@ -312,8 +310,7 @@ public class VCardComposer { * a Handler object given via {{@link #addHandler(OneEntryHandler)} returns false. * If false, this ignores those errors. */ - public VCardComposer(final Context context, final int vcardType, - String charset, + public VCardComposer(final Context context, final int vcardType, String charset, final boolean careHandlerErrors) { mContext = context; mVCardType = vcardType; @@ -380,6 +377,7 @@ public class VCardComposer { mCharset = charset; } } + Log.d(LOG_TAG, "Use the charset \"" + mCharset + "\""); } @@ -602,7 +600,6 @@ public class VCardComposer { return ""; } else { final VCardBuilder builder = new VCardBuilder(mVCardType, mCharset); - // TODO: Android-specific X attributes? builder.appendNameProperties(contentValuesListMap.get(StructuredName.CONTENT_ITEM_TYPE)) .appendNickNames(contentValuesListMap.get(Nickname.CONTENT_ITEM_TYPE)) .appendPhones(contentValuesListMap.get(Phone.CONTENT_ITEM_TYPE)) diff --git a/core/java/android/pim/vcard/VCardConfig.java b/core/java/android/pim/vcard/VCardConfig.java index 657672c..6c25216 100644 --- a/core/java/android/pim/vcard/VCardConfig.java +++ b/core/java/android/pim/vcard/VCardConfig.java @@ -153,6 +153,7 @@ public class VCardConfig { * In vCard 3.0, Quoted-Printable is explicitly "prohibitted", so we don't need to care this * kind of problem (hopefully). * </p> + * @hide */ public static final int FLAG_REFRAIN_QP_TO_NAME_PROPERTIES = 0x10000000; @@ -171,7 +172,7 @@ public class VCardConfig { * able to parse them as we expect. * </p> */ - public static final int FLAG_CONVERT_PHONETIC_NAME_STRINGS = 0x0800000; + public static final int FLAG_CONVERT_PHONETIC_NAME_STRINGS = 0x08000000; /** * <p> @@ -184,21 +185,20 @@ public class VCardConfig { * How more than one TYPE fields are expressed is different between vCard 2.1 and vCard 3.0. * </p> * <p> - * e.g.<BR /> - * 1) Probably valid in both vCard 2.1 and vCard 3.0: "ADR;TYPE=DOM;TYPE=HOME:..."<BR /> - * 2) Valid in vCard 2.1 but not in vCard 3.0: "ADR;DOM;HOME:..."<BR /> - * 3) Valid in vCard 3.0 but not in vCard 2.1: "ADR;TYPE=DOM,HOME:..."<BR /> - * </p> - * <p> - * 2) had been the default of VCard exporter/importer in Android, but it is found that - * some external exporter is not able to parse the type format like 2) but only 3). + * e.g. * </p> + * <ol> + * <li>Probably valid in both vCard 2.1 and vCard 3.0: "ADR;TYPE=DOM;TYPE=HOME:..."</li> + * <li>Valid in vCard 2.1 but not in vCard 3.0: "ADR;DOM;HOME:..."</li> + * <li>Valid in vCard 3.0 but not in vCard 2.1: "ADR;TYPE=DOM,HOME:..."</li> + * </ol> * <p> * If you are targeting to the importer which cannot accept TYPE params without "TYPE=" * strings (which should be rare though), please use this flag. * </p> * <p> - * Example usage: int vcardType = (VCARD_TYPE_V21_GENERIC | FLAG_APPEND_TYPE_PARAM); + * Example usage: + * <pre class="prettyprint">int type = (VCARD_TYPE_V21_GENERIC | FLAG_APPEND_TYPE_PARAM);</pre> * </p> */ public static final int FLAG_APPEND_TYPE_PARAM = 0x04000000; @@ -261,7 +261,6 @@ public class VCardConfig { */ public static final int VCARD_TYPE_UNKNOWN = 0; - /** * <p> * Generic vCard format with the vCard 2.1. When composing a vCard entry, diff --git a/core/java/android/pim/vcard/VCardEntry.java b/core/java/android/pim/vcard/VCardEntry.java index 5b8422f..ec03cf4 100644 --- a/core/java/android/pim/vcard/VCardEntry.java +++ b/core/java/android/pim/vcard/VCardEntry.java @@ -78,12 +78,12 @@ public class VCardEntry { Im.PROTOCOL_GOOGLE_TALK); } - static public class PhoneData { + public static class PhoneData { public final int type; public final String data; public final String label; - // isPrimary is changable only when there's no appropriate one existing in - // the original VCard. + // isPrimary is (not final but) changable, only when there's no appropriate one existing + // in the original VCard. public boolean isPrimary; public PhoneData(int type, String data, String label, boolean isPrimary) { this.type = type; @@ -109,13 +109,11 @@ public class VCardEntry { } } - static public class EmailData { + public static class EmailData { public final int type; public final String data; // Used only when TYPE is TYPE_CUSTOM. public final String label; - // isPrimary is changable only when there's no appropriate one existing in - // the original VCard. public boolean isPrimary; public EmailData(int type, String data, String label, boolean isPrimary) { this.type = type; @@ -141,9 +139,9 @@ public class VCardEntry { } } - static public class PostalData { - // Determined by vCard spec. - // PO Box, Extended Addr, Street, Locality, Region, Postal Code, Country Name + public static class PostalData { + // Determined by vCard specification. + // - PO Box, Extended Addr, Street, Locality, Region, Postal Code, Country Name public static final int ADDR_MAX_DATA_SIZE = 7; private final String[] dataArray; public final String pobox; @@ -248,10 +246,11 @@ public class VCardEntry { } } - static public class OrganizationData { + public static class OrganizationData { public final int type; // non-final is Intentional: we may change the values since this info is separated into - // two parts in vCard: "ORG" + "TITLE". + // two parts in vCard: "ORG" + "TITLE", and we have to cope with each field in + // different timing. public String companyName; public String departmentName; public String titleName; @@ -313,7 +312,7 @@ public class VCardEntry { } } - static public class ImData { + public static class ImData { public final int protocol; public final String customProtocol; public final int type; @@ -441,7 +440,7 @@ public class VCardEntry { private String mSuffix; // Used only when no family nor given name is found. - private String mFullName; + private String mFormattedName; private String mPhoneticFamilyName; private String mPhoneticGivenName; @@ -499,7 +498,6 @@ public class VCardEntry { } } - // Use NANP in default when there's no information about locale. final int formattingType = VCardUtils.getPhoneNumberFormat(mVCardType); formattedNumber = PhoneNumberUtils.formatNumber(builder.toString(), formattingType); } @@ -754,11 +752,11 @@ public class VCardEntry { if (propName.equals(VCardConstants.PROPERTY_VERSION)) { // vCard version. Ignore this. } else if (propName.equals(VCardConstants.PROPERTY_FN)) { - mFullName = propValue; - } else if (propName.equals(VCardConstants.PROPERTY_NAME) && mFullName == null) { + mFormattedName = propValue; + } else if (propName.equals(VCardConstants.PROPERTY_NAME) && mFormattedName == null) { // Only in vCard 3.0. Use this if FN, which must exist in vCard 3.0 but may not // actually exist in the real vCard data, does not exist. - mFullName = propValue; + mFormattedName = propValue; } else if (propName.equals(VCardConstants.PROPERTY_N)) { handleNProperty(propValueList); } else if (propName.equals(VCardConstants.PROPERTY_SORT_STRING)) { @@ -1016,8 +1014,8 @@ public class VCardEntry { */ private void constructDisplayName() { // FullName (created via "FN" or "NAME" field) is prefered. - if (!TextUtils.isEmpty(mFullName)) { - mDisplayName = mFullName; + if (!TextUtils.isEmpty(mFormattedName)) { + mDisplayName = mFormattedName; } else if (!(TextUtils.isEmpty(mFamilyName) && TextUtils.isEmpty(mGivenName))) { mDisplayName = VCardUtils.constructNameFromElements(mVCardType, mFamilyName, mMiddleName, mGivenName, mPrefix, mSuffix); @@ -1320,7 +1318,7 @@ public class VCardEntry { && TextUtils.isEmpty(mGivenName) && TextUtils.isEmpty(mPrefix) && TextUtils.isEmpty(mSuffix) - && TextUtils.isEmpty(mFullName) + && TextUtils.isEmpty(mFormattedName) && TextUtils.isEmpty(mPhoneticFamilyName) && TextUtils.isEmpty(mPhoneticMiddleName) && TextUtils.isEmpty(mPhoneticGivenName) @@ -1379,7 +1377,7 @@ public class VCardEntry { } public String getFullName() { - return mFullName; + return mFormattedName; } public String getPhoneticFamilyName() { diff --git a/core/java/android/pim/vcard/VCardEntryConstructor.java b/core/java/android/pim/vcard/VCardEntryConstructor.java index e3c691a..a0abae8 100644 --- a/core/java/android/pim/vcard/VCardEntryConstructor.java +++ b/core/java/android/pim/vcard/VCardEntryConstructor.java @@ -20,9 +20,7 @@ import android.text.TextUtils; import android.util.CharsetUtils; import android.util.Log; -import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.net.QuotedPrintableCodec; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; @@ -31,6 +29,23 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +/** + * <p> + * The {@link VCardInterpreter} implementation which enables {@link VCardEntryHandler} objects + * to easily handle each vCard entry. + * </p> + * <p> + * This class understand details inside vCard and translates it to {@link VCardEntry}. + * Then the class throw it to {@link VCardEntryHandler} registered via + * {@link #addEntryHandler(VCardEntryHandler)}, so that all those registered objects + * are able to handle the {@link VCardEntry} object. + * </p> + * <p> + * If you want to know the detail inside vCard, it would be better to implement + * {@link VCardInterpreter} directly, instead of relying on this class and + * {@link VCardEntry} created by the object. + * </p> + */ public class VCardEntryConstructor implements VCardInterpreter { private static String LOG_TAG = "VCardEntryConstructor"; @@ -48,27 +63,33 @@ public class VCardEntryConstructor implements VCardInterpreter { private final int mVCardType; private final Account mAccount; - /** For measuring performance. */ + // For measuring performance. private long mTimePushIntoContentResolver; - final private List<VCardEntryHandler> mEntryHandlers = new ArrayList<VCardEntryHandler>(); + private final List<VCardEntryHandler> mEntryHandlers = new ArrayList<VCardEntryHandler>(); public VCardEntryConstructor() { - this(null, false, VCardConfig.VCARD_TYPE_V21_GENERIC, null); + this(VCardConfig.VCARD_TYPE_V21_GENERIC, null, null, false); } public VCardEntryConstructor(final int vcardType) { - this(null, false, vcardType, null); + this(vcardType, null, null, false); + } + + public VCardEntryConstructor(final int vcardType, final Account account) { + this(vcardType, account, null, false); } - public VCardEntryConstructor(final String inputCharset, - final int vcardType, final Account account) { - this(inputCharset, false, vcardType, account); + public VCardEntryConstructor(final int vcardType, final Account account, + final String inputCharset) { + this(vcardType, account, inputCharset, false); } - public VCardEntryConstructor(final String inputCharset, - final boolean strictLineBreakParsing, final int vcardType, - final Account account) { + /** + * @hide + */ + public VCardEntryConstructor(final int vcardType, final Account account, + final String inputCharset, final boolean strictLineBreakParsing) { if (inputCharset != null) { mSourceCharset = inputCharset; } else { @@ -95,17 +116,11 @@ public class VCardEntryConstructor implements VCardInterpreter { } } - /** - * Called when the parse failed between {@link #startEntry()} and {@link #endEntry()}. - */ public void clear() { mCurrentVCardEntry = null; mCurrentProperty = new VCardEntry.Property(); } - /** - * Assume that VCard is not nested. In other words, this code does not accept - */ public void startEntry() { if (mCurrentVCardEntry != null) { Log.e(LOG_TAG, "Nested VCard code is not supported now."); @@ -211,6 +226,9 @@ public class VCardEntryConstructor implements VCardInterpreter { } } + /** + * @hide + */ public void showPerformanceInfo() { Log.d(LOG_TAG, "time for insert ContactStruct to database: " + mTimePushIntoContentResolver + " ms"); diff --git a/core/java/android/pim/vcard/VCardEntryHandler.java b/core/java/android/pim/vcard/VCardEntryHandler.java index 83a67fe..56bf69d 100644 --- a/core/java/android/pim/vcard/VCardEntryHandler.java +++ b/core/java/android/pim/vcard/VCardEntryHandler.java @@ -16,8 +16,13 @@ package android.pim.vcard; /** - * The interface called by {@link VCardEntryConstructor}. Useful when you don't want to - * handle detailed information as what {@link VCardParser} provides via {@link VCardInterpreter}. + * <p> + * The interface called by {@link VCardEntryConstructor}. + * </p> + * <p> + * This class is useful when you don't want to know vCard data in detail. If you want to know + * it, it would be better to consider using {@link VCardInterpreter}. + * </p> */ public interface VCardEntryHandler { /** diff --git a/core/java/android/pim/vcard/VCardInterpreter.java b/core/java/android/pim/vcard/VCardInterpreter.java index b5237c0..03704a2 100644 --- a/core/java/android/pim/vcard/VCardInterpreter.java +++ b/core/java/android/pim/vcard/VCardInterpreter.java @@ -20,7 +20,7 @@ import java.util.List; /** * <P> * The interface which should be implemented by the classes which have to analyze each - * vCard entry more minutely than {@link VCardEntry} class analysis. + * vCard entry minutely. * </P> * <P> * Here, there are several terms specific to vCard (and this library). diff --git a/core/java/android/pim/vcard/VCardInterpreterCollection.java b/core/java/android/pim/vcard/VCardInterpreterCollection.java index 99f81f7..4952dc7 100644 --- a/core/java/android/pim/vcard/VCardInterpreterCollection.java +++ b/core/java/android/pim/vcard/VCardInterpreterCollection.java @@ -23,7 +23,7 @@ import java.util.List; * {@link VCardInterpreter} objects and make a user object treat them as one * {@link VCardInterpreter} object. */ -public class VCardInterpreterCollection implements VCardInterpreter { +public final class VCardInterpreterCollection implements VCardInterpreter { private final Collection<VCardInterpreter> mInterpreterCollection; public VCardInterpreterCollection(Collection<VCardInterpreter> interpreterCollection) { diff --git a/core/java/android/pim/vcard/VCardUtils.java b/core/java/android/pim/vcard/VCardUtils.java index 426d3b4..680ef6f 100644 --- a/core/java/android/pim/vcard/VCardUtils.java +++ b/core/java/android/pim/vcard/VCardUtils.java @@ -39,6 +39,7 @@ import java.util.Set; /** * Utilities for VCard handling codes. + * @hide */ public class VCardUtils { private static final String LOG_TAG = "VCardUtils"; @@ -247,10 +248,13 @@ public class VCardUtils { } /** + * <p> * Inserts postal data into the builder object. - * + * </p> + * <p> * Note that the data structure of ContactsContract is different from that defined in vCard. * So some conversion may be performed in this method. + * </p> */ public static void insertStructuredPostalDataUsingContactsStruct(int vcardType, final ContentProviderOperation.Builder builder, @@ -378,9 +382,13 @@ public class VCardUtils { } /** + * <p> * This is useful when checking the string should be encoded into quoted-printable * or not, which is required by vCard 2.1. + * </p> + * <p> * See the definition of "7bit" in vCard 2.1 spec for more information. + * </p> */ public static boolean containsOnlyNonCrLfPrintableAscii(final String...values) { if (values == null) { @@ -414,13 +422,16 @@ public class VCardUtils { new HashSet<Character>(Arrays.asList('[', ']', '=', ':', '.', ',', ' ')); /** + * <p> * This is useful since vCard 3.0 often requires the ("X-") properties and groups * should contain only alphabets, digits, and hyphen. - * + * </p> + * <p> * Note: It is already known some devices (wrongly) outputs properties with characters * which should not be in the field. One example is "X-GOOGLE TALK". We accept * such kind of input but must never output it unless the target is very specific - * to the device which is able to parse the malformed input. + * to the device which is able to parse the malformed input. + * </p> */ public static boolean containsOnlyAlphaDigitHyphen(final String...values) { if (values == null) { @@ -459,13 +470,13 @@ public class VCardUtils { } /** - * <P> + * <p> * Returns true when the given String is categorized as "word" specified in vCard spec 2.1. - * </P> - * <P> - * vCard 2.1 specifies:<BR /> + * </p> + * <p> + * vCard 2.1 specifies:<br /> * word = <any printable 7bit us-ascii except []=:., > - * </P> + * </p> */ public static boolean isV21Word(final String value) { if (TextUtils.isEmpty(value)) { @@ -550,7 +561,7 @@ public class VCardUtils { //// The methods bellow may be used by unit test. /** - * @hide + * @hide */ public static String parseQuotedPrintable(String value, boolean strictLineBreaking, String sourceCharset, String targetCharset) { |
