⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcardcreator.java

📁 goolge phone 目前没有开放的android 平台的源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   VCardCreator.java

package android.syncml.pim.vcreator;

import java.util.Iterator;
import java.util.List;
import org.apache.commons.codec.binary.Base64;

// Referenced classes of package android.syncml.pim.vcreator:
//            ContactStruct

public class VCardCreator
{

    public VCardCreator()
    {
    }

    public static String createVCard(ContactStruct struct, int vcardversion)
        throws Exception
    {
        returnStr = new StringBuffer("");
        if(struct.name == null || struct.name.trim().equals(""))
            throw new Exception("=== struct.name MUST have value.");
        version = vcardversion;
        if(version == 1)
            ENTER = "\r\n";
        else
        if(version == 2)
            ENTER = "\n";
        else
            throw new Exception("=== version not match VERSION_VCARD21 or VERSION_VCARD30.");
        returnStr.append("BEGIN:VCARD").append(ENTER);
        if(version == 1)
            returnStr.append("VERSION:2.1").append(ENTER);
        else
            returnStr.append("VERSION:3.0").append(ENTER);
        if(!isNull(struct.name))
            appendNameStr(struct.name);
        if(!isNull(struct.company))
            returnStr.append("ORG:").append(struct.company).append(ENTER);
        if(!isNull(struct.notes))
            returnStr.append("NOTE:").append(foldingString(struct.notes)).append(ENTER);
        if(!isNull(struct.title))
            returnStr.append("TITLE:").append(foldingString(struct.title)).append(ENTER);
        if(struct.photoBytes != null)
            appendPhotoStr(struct.photoBytes, struct.photoType);
        if(struct.phoneList != null)
            appendPhoneStr(struct.phoneList);
        if(struct.contactmethodList != null)
            appendContactmethodStr(struct.contactmethodList);
        returnStr.append("END:VCARD").append(ENTER);
        return returnStr.toString();
    }

    private static boolean isNull(String str)
    {
        return str == null || str.trim().equals("");
    }

    private static String foldingString(String str)
    {
        if(str.endsWith("\r\n"))
            str = str.substring(0, str.length() - 2);
        if(str.endsWith("\n"))
            str = str.substring(0, str.length() - 1);
        if(version == 1)
            return str.replaceAll("\r\n", "\n").replaceAll("\n", "\r\n ");
        if(version == 2)
            return str.replaceAll("\r\n", "\n").replaceAll("\n", "\n ");
        else
            return null;
    }

    private static void appendNameStr(String name)
    {
        returnStr.append("FN:").append(name).append(ENTER);
        returnStr.append("N:").append(name).append(ENTER);
    }

    private static void appendPhotoStr(byte bytes[], String type)
        throws Exception
    {
        String value;
        try
        {
            value = foldingString(new String(Base64.encodeBase64(bytes, true)));
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new Exception("=== Analyse photo bytes failed.");
        }
        if(isNull(type))
            type = "image/jpeg";
        String apptype;
        if(type.indexOf("jpeg") > 0)
            apptype = "JPEG";
        else
        if(type.indexOf("gif") > 0)
            apptype = "GIF";
        else
        if(type.indexOf("bmp") > 0)
            apptype = "BMP";
        else
            apptype = type.substring(type.indexOf("/")).toUpperCase();
        if(version == 1)
            returnStr.append("LOGO;").append(apptype).append(";ENCODING=BASE64:").append(value).append(ENTER).append(ENTER);
        if(version == 2)
            returnStr.append("LOGO;TYPE=").append(apptype).append(";ENCODING=b:").append(value).append(ENTER).append(ENTER);
    }

    private static void appendPhoneStr(List phoneList)
    {
        ContactStruct.PhonesStruct phone;
        String type;
        for(Iterator iter = phoneList.iterator(); iter.hasNext(); returnStr.append("TEL;TYPE=").append(type).append(":").append(phone.data).append(ENTER))
        {
            phone = (ContactStruct.PhonesStruct)iter.next();
            type = "HOME";
            if(phone.type.equals("1"))
                type = "VOICE";
            if(phone.type.equals("0"))
                type = "WORK";
            if(phone.type.equals("3"))
                type = "FAX";
            if(phone.type.equals("5"))
                type = "PAGER";
            if(phone.type.equals("8"))
                type = "HOME";
        }

    }

    private static void appendContactmethodStr(List contactMList)
    {
        Iterator iter = contactMList.iterator();
        do
        {
            if(!iter.hasNext())
                break;
            ContactStruct.PhonesStruct contactm = (ContactStruct.PhonesStruct)iter.next();
            if(contactm.type.equals("1") && !isNull(contactm.data))
                returnStr.append("EMAIL;TYPE=INTERNET:").append(foldingString(contactm.data)).append(ENTER);
            if((contactm.type.equals("2") || contactm.type.equals("3")) && !isNull(contactm.data))
                returnStr.append("ADR;TYPE=POSTAL:").append(foldingString(contactm.data)).append(ENTER);
        } while(true);
    }

    public static final int VERSION_VCARD21 = 1;
    public static final int VERSION_VCARD30 = 2;
    private static int version;
    private static String ENTER;
    private static StringBuffer returnStr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -