Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 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 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.model.dataitem; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.ContentValues; |
| 20 | import android.content.Context; |
| 21 | import android.provider.ContactsContract.Data; |
| 22 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 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; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 26 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 27 | import com.google.common.collect.Iterators; |
| 28 | |
| 29 | import java.text.SimpleDateFormat; |
| 30 | import java.util.List; |
| 31 | |
| 32 | /** |
| 33 | * Description of a specific data type, usually marked by a unique |
| 34 | * {@link Data#MIMETYPE}. Includes details about how to view and edit |
| 35 | * {@link Data} rows of this kind, including the possible {@link EditType} |
| 36 | * labels and editable {@link EditField}. |
| 37 | */ |
| 38 | public final class DataKind { |
| 39 | |
Gary Mai | 7a6daea | 2016-10-10 15:41:48 -0700 | [diff] [blame] | 40 | public static final String PSEUDO_MIME_TYPE_NAME = "#name"; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 41 | public static final String PSEUDO_MIME_TYPE_PHONETIC_NAME = "#phoneticName"; |
| 42 | public static final String PSEUDO_COLUMN_PHONETIC_NAME = "#phoneticName"; |
| 43 | |
| 44 | public String resourcePackageName; |
| 45 | public String mimeType; |
| 46 | public int titleRes; |
| 47 | public int iconAltRes; |
| 48 | public int iconAltDescriptionRes; |
| 49 | public int weight; |
| 50 | public boolean editable; |
| 51 | |
| 52 | public StringInflater actionHeader; |
| 53 | public StringInflater actionAltHeader; |
| 54 | public StringInflater actionBody; |
| 55 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 56 | public String typeColumn; |
| 57 | |
| 58 | /** |
| 59 | * Maximum number of values allowed in the list. -1 represents infinity. |
| 60 | */ |
| 61 | public int typeOverallMax; |
| 62 | |
| 63 | public List<EditType> typeList; |
| 64 | public List<EditField> fieldList; |
| 65 | |
| 66 | public ContentValues defaultValues; |
| 67 | |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 68 | /** |
| 69 | * If this is a date field, this specifies the format of the date when saving. The |
| 70 | * date includes year, month and day. If this is not a date field or the date field is not |
| 71 | * editable, this value should be ignored. |
| 72 | */ |
| 73 | public SimpleDateFormat dateFormatWithoutYear; |
| 74 | |
| 75 | /** |
| 76 | * If this is a date field, this specifies the format of the date when saving. The |
| 77 | * date includes month and day. If this is not a date field, the field is not editable or |
| 78 | * dates without year are not supported, this value should be ignored. |
| 79 | */ |
| 80 | public SimpleDateFormat dateFormatWithYear; |
| 81 | |
| 82 | /** |
| 83 | * The number of lines available for displaying this kind of data. |
| 84 | * Defaults to 1. |
| 85 | */ |
| 86 | public int maxLinesForDisplay; |
| 87 | |
| 88 | public DataKind() { |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 89 | maxLinesForDisplay = 1; |
| 90 | } |
| 91 | |
Chiao Cheng | 4eff3d8 | 2012-12-06 12:15:08 -0800 | [diff] [blame] | 92 | public DataKind(String mimeType, int titleRes, int weight, boolean editable) { |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 93 | this.mimeType = mimeType; |
| 94 | this.titleRes = titleRes; |
| 95 | this.weight = weight; |
| 96 | this.editable = editable; |
| 97 | this.typeOverallMax = -1; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 98 | maxLinesForDisplay = 1; |
| 99 | } |
| 100 | |
| 101 | public String getKindString(Context context) { |
| 102 | return (titleRes == -1 || titleRes == 0) ? "" : context.getString(titleRes); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public String toString() { |
| 107 | final StringBuilder sb = new StringBuilder(); |
| 108 | sb.append("DataKind:"); |
| 109 | sb.append(" resPackageName=").append(resourcePackageName); |
| 110 | sb.append(" mimeType=").append(mimeType); |
| 111 | sb.append(" titleRes=").append(titleRes); |
| 112 | sb.append(" iconAltRes=").append(iconAltRes); |
| 113 | sb.append(" iconAltDescriptionRes=").append(iconAltDescriptionRes); |
| 114 | sb.append(" weight=").append(weight); |
| 115 | sb.append(" editable=").append(editable); |
| 116 | sb.append(" actionHeader=").append(actionHeader); |
| 117 | sb.append(" actionAltHeader=").append(actionAltHeader); |
| 118 | sb.append(" actionBody=").append(actionBody); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 119 | sb.append(" typeColumn=").append(typeColumn); |
| 120 | sb.append(" typeOverallMax=").append(typeOverallMax); |
| 121 | sb.append(" typeList=").append(toString(typeList)); |
| 122 | sb.append(" fieldList=").append(toString(fieldList)); |
| 123 | sb.append(" defaultValues=").append(defaultValues); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 124 | sb.append(" dateFormatWithoutYear=").append(toString(dateFormatWithoutYear)); |
| 125 | sb.append(" dateFormatWithYear=").append(toString(dateFormatWithYear)); |
| 126 | |
| 127 | return sb.toString(); |
| 128 | } |
| 129 | |
| 130 | public static String toString(SimpleDateFormat format) { |
| 131 | return format == null ? "(null)" : format.toPattern(); |
| 132 | } |
| 133 | |
| 134 | public static String toString(Iterable<?> list) { |
| 135 | if (list == null) { |
| 136 | return "(null)"; |
| 137 | } else { |
| 138 | return Iterators.toString(list.iterator()); |
| 139 | } |
| 140 | } |
| 141 | } |