1 /* 2 * Copyright (C) 2011 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.model.dataitem; 18 19 import android.content.ContentValues; 20 import android.provider.ContactsContract.Data; 21 22 import com.android.contacts.R; 23 import com.android.contacts.model.account.AccountType.EditField; 24 import com.android.contacts.model.account.AccountType.EditType; 25 import com.android.contacts.model.account.AccountType.StringInflater; 26 import com.google.common.collect.Iterators; 27 28 import java.text.SimpleDateFormat; 29 import java.util.List; 30 31 /** 32 * Description of a specific data type, usually marked by a unique 33 * {@link Data#MIMETYPE}. Includes details about how to view and edit 34 * {@link Data} rows of this kind, including the possible {@link EditType} 35 * labels and editable {@link EditField}. 36 */ 37 public final class DataKind { 38 39 public static final String PSEUDO_MIME_TYPE_DISPLAY_NAME = "#displayName"; 40 public static final String PSEUDO_MIME_TYPE_PHONETIC_NAME = "#phoneticName"; 41 public static final String PSEUDO_COLUMN_PHONETIC_NAME = "#phoneticName"; 42 43 public String resourcePackageName; 44 public String mimeType; 45 public int titleRes; 46 public int iconAltRes; 47 public int iconAltDescriptionRes; 48 public int weight; 49 public boolean editable; 50 51 public StringInflater actionHeader; 52 public StringInflater actionAltHeader; 53 public StringInflater actionBody; 54 55 public boolean actionBodySocial = false; 56 57 public String typeColumn; 58 59 /** 60 * Maximum number of values allowed in the list. -1 represents infinity. 61 */ 62 public int typeOverallMax; 63 64 public List<EditType> typeList; 65 public List<EditField> fieldList; 66 67 public ContentValues defaultValues; 68 69 /** Layout resource id for an editor view to edit this {@link DataKind}. */ 70 public final int editorLayoutResourceId; 71 72 /** 73 * If this is a date field, this specifies the format of the date when saving. The 74 * date includes year, month and day. If this is not a date field or the date field is not 75 * editable, this value should be ignored. 76 */ 77 public SimpleDateFormat dateFormatWithoutYear; 78 79 /** 80 * If this is a date field, this specifies the format of the date when saving. The 81 * date includes month and day. If this is not a date field, the field is not editable or 82 * dates without year are not supported, this value should be ignored. 83 */ 84 public SimpleDateFormat dateFormatWithYear; 85 86 /** 87 * The number of lines available for displaying this kind of data in a 88 * {@link ContactDetailFragment} (and possibly elsewhere) 89 * Defaults to 1. 90 */ 91 public int maxLinesForDisplay; 92 93 public DataKind() { 94 editorLayoutResourceId = R.layout.text_fields_editor_view; 95 maxLinesForDisplay = 1; 96 } 97 98 public DataKind(String mimeType, int titleRes, int weight, boolean editable, 99 int editorLayoutResourceId) { 100 this.mimeType = mimeType; 101 this.titleRes = titleRes; 102 this.weight = weight; 103 this.editable = editable; 104 this.typeOverallMax = -1; 105 this.editorLayoutResourceId = editorLayoutResourceId; 106 maxLinesForDisplay = 1; 107 } 108 109 @Override 110 public String toString() { 111 final StringBuilder sb = new StringBuilder(); 112 sb.append("DataKind:"); 113 sb.append(" resPackageName=").append(resourcePackageName); 114 sb.append(" mimeType=").append(mimeType); 115 sb.append(" titleRes=").append(titleRes); 116 sb.append(" iconAltRes=").append(iconAltRes); 117 sb.append(" iconAltDescriptionRes=").append(iconAltDescriptionRes); 118 sb.append(" weight=").append(weight); 119 sb.append(" editable=").append(editable); 120 sb.append(" actionHeader=").append(actionHeader); 121 sb.append(" actionAltHeader=").append(actionAltHeader); 122 sb.append(" actionBody=").append(actionBody); 123 sb.append(" actionBodySocial=").append(actionBodySocial); 124 sb.append(" typeColumn=").append(typeColumn); 125 sb.append(" typeOverallMax=").append(typeOverallMax); 126 sb.append(" typeList=").append(toString(typeList)); 127 sb.append(" fieldList=").append(toString(fieldList)); 128 sb.append(" defaultValues=").append(defaultValues); 129 sb.append(" editorLayoutResourceId=").append(editorLayoutResourceId); 130 sb.append(" dateFormatWithoutYear=").append(toString(dateFormatWithoutYear)); 131 sb.append(" dateFormatWithYear=").append(toString(dateFormatWithYear)); 132 133 return sb.toString(); 134 } 135 136 public static String toString(SimpleDateFormat format) { 137 return format == null ? "(null)" : format.toPattern(); 138 } 139 140 public static String toString(Iterable<?> list) { 141 if (list == null) { 142 return "(null)"; 143 } else { 144 return Iterators.toString(list.iterator()); 145 } 146 } 147 } 148