// Path: library/src/main/java/com/onegravity/contactpicker/Helper.java
// public class Helper {
// 
//     public static boolean isNullOrEmpty(CharSequence string){
//         return string == null || string.length() == 0;
//     }
// 
//     public static DisplayMetrics getDisplayMetrics(Context context) {
//         Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         display.getMetrics( metrics );
//         return metrics;
//     }
// 
//     public static void closeQuietly(Cursor cursor) {
//         try {
//             cursor.close();
//         }
//         catch (Exception ignore) {}
//     }
// 
//     public static void closeQuietly(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (IOException ignore) {}
//     }
// 
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/contact/Contact.java
// public interface Contact extends ContactElement {
// 
//     String getFirstName();
// 
//     String getLastName();
// 
//     /**
//      * ContactsContract.CommonDataKinds.Email.TYPE values:
//      *
//      * - TYPE_CUSTOM
//      * - TYPE_HOME
//      * - TYPE_WORK
//      * - TYPE_OTHER
//      * - TYPE_MOBILE
//      *
//      * @param type the type
//      * @return a String with the Email.
//      */
//     String getEmail(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getEmail(int)
//      * @return the map type to email.
//      */
//     Map<Integer, String> getMapEmail();
// 
//     /**
//      * ContactsContract.CommonDataKinds.Email.ContactsContract.CommonDataKinds.Phone.TYPE values:
//      *
//      * - TYPE_CUSTOM, TYPE_HOME, TYPE_MOBILE, TYPE_WORK, TYPE_FAX_WORK, TYPE_FAX_HOME, TYPE_PAGER
//      * - TYPE_OTHER, TYPE_CALLBACK, TYPE_CAR, TYPE_COMPANY_MAIN, TYPE_ISDN, TYPE_MAIN
//      * - TYPE_OTHER_FAX, TYPE_RADIO, TYPE_TELEX, TYPE_TTY_TDD, TYPE_WORK_MOBILE, TYPE_WORK_PAGER
//      * - TYPE_ASSISTANT, TYPE_MMS
//      *
//      * @param type the type
//      * @return a String with the phone.
//      */
//     String getPhone(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getPhone(int)
//      * @return the map type to phone.
//      */
//     Map<Integer, String> getMapPhone();
// 
//     /**
//      * * ContactsContract.CommonDataKinds.StructuredPostal.TYPE values:
//      *
//      * - TYPE_CUSTOM
//      * - TYPE_HOME
//      * - TYPE_WORK
//      * - TYPE_OTHER
//      *
//      * @param type the type
//      * @return A String with the address
//      */
//     String getAddress(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getAddress(int)
//      * @return the map type to address.
//      */
//     Map<Integer, String> getMapAddress();
// 
//     /**
//      * The contact letter is used in the ContactBadge (if no contact picture can be found).
//      */
//     char getContactLetter();
// 
//     /**
//      * The contact letter according to the sort order is used in the SectionIndexer for the fast
//      * scroll indicator.
//      */
//     char getContactLetter(ContactSortOrder sortOrder);
// 
//     /**
//      * The contact color is used in the ContactBadge (if no contact picture can be found) as
//      * background color.
//      */
//     int getContactColor();
// 
//     /**
//      * Unique key across all contacts that won't change even if the column id changes.
//      */
//     String getLookupKey();
// 
//     Uri getPhotoUri();
// 
//     Set<Long> getGroupIds();
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/contact/ContactSortOrder.java
// public enum ContactSortOrder {
//     FIRST_NAME,     // sort by first name
//     LAST_NAME,      // sort by last name
//     AUTOMATIC;      // sort by display name (device specific)
// 
//     public static ContactSortOrder lookup(String name) {
//         try {
//             return ContactSortOrder.valueOf(name);
//         }
//         catch (IllegalArgumentException ignore) {
//             Log.e(ContactSortOrder.class.getSimpleName(), ignore.getMessage());
//             return AUTOMATIC;
//         }
//     }
// 
// }


import java.util.regex.Pattern;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import com.onegravity.contactpicker.Helper;
import com.onegravity.contactpicker.contact.Contact;
import com.onegravity.contactpicker.contact.ContactSortOrder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
    public Map<Integer, String> getMapPhone() {
        return mPhone;
    }

    @Override
    public String getAddress(int type) {
        String address = mAddress.get(type);
        if (address == null && !mAddress.isEmpty()) {
            address = "";
        }
        return address;
    }

    @Override
    public Map<Integer, String> getMapAddress() {
        return mAddress;
    }

    @Override
    public char getContactLetter() {
        if (mContactLetterBadge == 0) {
            Matcher m = CONTACT_LETTER.matcher(getDisplayName());
            String letter = m.matches() ? m.group(1).toUpperCase(Locale.US) : "?";
            mContactLetterBadge = Helper.isNullOrEmpty(letter) ? '?' : letter.charAt(0);
        }

        return mContactLetterBadge;
    }

    @Override
// Path: library/src/main/java/com/onegravity/contactpicker/Helper.java
// public class Helper {
// 
//     public static boolean isNullOrEmpty(CharSequence string){
//         return string == null || string.length() == 0;
//     }
// 
//     public static DisplayMetrics getDisplayMetrics(Context context) {
//         Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         display.getMetrics( metrics );
//         return metrics;
//     }
// 
//     public static void closeQuietly(Cursor cursor) {
//         try {
//             cursor.close();
//         }
//         catch (Exception ignore) {}
//     }
// 
//     public static void closeQuietly(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (IOException ignore) {}
//     }
// 
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/contact/Contact.java
// public interface Contact extends ContactElement {
// 
//     String getFirstName();
// 
//     String getLastName();
// 
//     /**
//      * ContactsContract.CommonDataKinds.Email.TYPE values:
//      *
//      * - TYPE_CUSTOM
//      * - TYPE_HOME
//      * - TYPE_WORK
//      * - TYPE_OTHER
//      * - TYPE_MOBILE
//      *
//      * @param type the type
//      * @return a String with the Email.
//      */
//     String getEmail(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getEmail(int)
//      * @return the map type to email.
//      */
//     Map<Integer, String> getMapEmail();
// 
//     /**
//      * ContactsContract.CommonDataKinds.Email.ContactsContract.CommonDataKinds.Phone.TYPE values:
//      *
//      * - TYPE_CUSTOM, TYPE_HOME, TYPE_MOBILE, TYPE_WORK, TYPE_FAX_WORK, TYPE_FAX_HOME, TYPE_PAGER
//      * - TYPE_OTHER, TYPE_CALLBACK, TYPE_CAR, TYPE_COMPANY_MAIN, TYPE_ISDN, TYPE_MAIN
//      * - TYPE_OTHER_FAX, TYPE_RADIO, TYPE_TELEX, TYPE_TTY_TDD, TYPE_WORK_MOBILE, TYPE_WORK_PAGER
//      * - TYPE_ASSISTANT, TYPE_MMS
//      *
//      * @param type the type
//      * @return a String with the phone.
//      */
//     String getPhone(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getPhone(int)
//      * @return the map type to phone.
//      */
//     Map<Integer, String> getMapPhone();
// 
//     /**
//      * * ContactsContract.CommonDataKinds.StructuredPostal.TYPE values:
//      *
//      * - TYPE_CUSTOM
//      * - TYPE_HOME
//      * - TYPE_WORK
//      * - TYPE_OTHER
//      *
//      * @param type the type
//      * @return A String with the address
//      */
//     String getAddress(int type);
// 
//     /**
//      * @see com.onegravity.contactpicker.contact.Contact#getAddress(int)
//      * @return the map type to address.
//      */
//     Map<Integer, String> getMapAddress();
// 
//     /**
//      * The contact letter is used in the ContactBadge (if no contact picture can be found).
//      */
//     char getContactLetter();
// 
//     /**
//      * The contact letter according to the sort order is used in the SectionIndexer for the fast
//      * scroll indicator.
//      */
//     char getContactLetter(ContactSortOrder sortOrder);
// 
//     /**
//      * The contact color is used in the ContactBadge (if no contact picture can be found) as
//      * background color.
//      */
//     int getContactColor();
// 
//     /**
//      * Unique key across all contacts that won't change even if the column id changes.
//      */
//     String getLookupKey();
// 
//     Uri getPhotoUri();
// 
//     Set<Long> getGroupIds();
// }
// 
// Path: library/src/main/java/com/onegravity/contactpicker/contact/ContactSortOrder.java
// public enum ContactSortOrder {
//     FIRST_NAME,     // sort by first name
//     LAST_NAME,      // sort by last name
//     AUTOMATIC;      // sort by display name (device specific)
// 
//     public static ContactSortOrder lookup(String name) {
//         try {
//             return ContactSortOrder.valueOf(name);
//         }
//         catch (IllegalArgumentException ignore) {
//             Log.e(ContactSortOrder.class.getSimpleName(), ignore.getMessage());
//             return AUTOMATIC;
//         }
//     }
// 
// }


// Path: library/src/main/java/com/onegravity/contactpicker/core/ContactImpl.java
import java.util.regex.Pattern;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import com.onegravity.contactpicker.Helper;
import com.onegravity.contactpicker.contact.Contact;
import com.onegravity.contactpicker.contact.ContactSortOrder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;

    public Map<Integer, String> getMapPhone() {
        return mPhone;
    }

    @Override
    public String getAddress(int type) {
        String address = mAddress.get(type);
        if (address == null && !mAddress.isEmpty()) {
            address = "";
        }
        return address;
    }

    @Override
    public Map<Integer, String> getMapAddress() {
        return mAddress;
    }

    @Override
    public char getContactLetter() {
        if (mContactLetterBadge == 0) {
            Matcher m = CONTACT_LETTER.matcher(getDisplayName());
            String letter = m.matches() ? m.group(1).toUpperCase(Locale.US) : "?";
            mContactLetterBadge = Helper.isNullOrEmpty(letter) ? '?' : letter.charAt(0);
        }

        return mContactLetterBadge;
    }

    @Override
    public char getContactLetter(ContactSortOrder sortOrder) {