1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.contacts.editor; 18 19 import static android.provider.ContactsContract.CommonDataKinds.Event; 20 import static android.provider.ContactsContract.CommonDataKinds.GroupMembership; 21 import static android.provider.ContactsContract.CommonDataKinds.Photo; 22 import static android.provider.ContactsContract.CommonDataKinds.StructuredName; 23 24 import com.android.contacts.R; 25 import com.android.contacts.common.model.dataitem.DataKind; 26 import com.google.common.collect.Maps; 27 28 import java.util.HashMap; 29 30 /** 31 * Utility methods for creating contact editor. 32 */ 33 public class EditorUiUtils { 34 35 // Maps DataKind.mimeType to editor view layouts. 36 private static final HashMap<String, Integer> mimetypeLayoutMap = Maps.newHashMap(); 37 static { 38 // Generally there should be a layout mapped to each existing DataKind mimetype but lots of 39 // them use the default text_fields_editor_view which we return as default so they don't 40 // need to be mapped. 41 // 42 // Other possible mime mappings are: 43 // DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME 44 // Nickname.CONTENT_ITEM_TYPE 45 // Email.CONTENT_ITEM_TYPE 46 // StructuredPostal.CONTENT_ITEM_TYPE 47 // Im.CONTENT_ITEM_TYPE 48 // Note.CONTENT_ITEM_TYPE 49 // Organization.CONTENT_ITEM_TYPE 50 // Phone.CONTENT_ITEM_TYPE 51 // SipAddress.CONTENT_ITEM_TYPE 52 // Website.CONTENT_ITEM_TYPE 53 // Relation.CONTENT_ITEM_TYPE 54 // 55 // Un-supported mime types need to mapped with -1. 56 57 mimetypeLayoutMap.put(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME, 58 R.layout.phonetic_name_editor_view); 59 mimetypeLayoutMap.put(StructuredName.CONTENT_ITEM_TYPE, 60 R.layout.structured_name_editor_view); 61 mimetypeLayoutMap.put(GroupMembership.CONTENT_ITEM_TYPE, -1); 62 mimetypeLayoutMap.put(Photo.CONTENT_ITEM_TYPE, -1); 63 mimetypeLayoutMap.put(Event.CONTENT_ITEM_TYPE, R.layout.event_field_editor_view); 64 } 65 66 /** 67 * Fetches a layout for a given mimetype. 68 * 69 * @param mimetype The mime type (e.g. StructuredName.CONTENT_ITEM_TYPE) 70 * @return The layout resource id. 71 */ 72 public static int getLayoutResourceId(String mimetype) { 73 final Integer id = mimetypeLayoutMap.get(mimetype); 74 if (id == null) { 75 return R.layout.text_fields_editor_view; 76 } 77 return id; 78 } 79 } 80