blob: 993e6cca60eabf61370852c9d70954c4e2acdb77 [file] [log] [blame]
Chiao Chenge88fcd32012-11-13 18:38:05 -08001/*
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 Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.model.dataitem;
Chiao Chenge88fcd32012-11-13 18:38:05 -080018
19import android.content.ContentValues;
20import android.content.Context;
21import android.provider.ContactsContract.Data;
22
Gary Mai69c182a2016-12-05 13:07:03 -080023import com.android.contacts.model.account.AccountType.EditField;
24import com.android.contacts.model.account.AccountType.EditType;
25import com.android.contacts.model.account.AccountType.StringInflater;
Gary Mai0a49afa2016-12-05 15:53:58 -080026
Chiao Chenge88fcd32012-11-13 18:38:05 -080027import com.google.common.collect.Iterators;
28
29import java.text.SimpleDateFormat;
30import 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 */
38public final class DataKind {
39
Gary Mai7a6daea2016-10-10 15:41:48 -070040 public static final String PSEUDO_MIME_TYPE_NAME = "#name";
Chiao Chenge88fcd32012-11-13 18:38:05 -080041 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 Chenge88fcd32012-11-13 18:38:05 -080056 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 Chenge88fcd32012-11-13 18:38:05 -080068 /**
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 Chenge88fcd32012-11-13 18:38:05 -080089 maxLinesForDisplay = 1;
90 }
91
Chiao Cheng4eff3d82012-12-06 12:15:08 -080092 public DataKind(String mimeType, int titleRes, int weight, boolean editable) {
Chiao Chenge88fcd32012-11-13 18:38:05 -080093 this.mimeType = mimeType;
94 this.titleRes = titleRes;
95 this.weight = weight;
96 this.editable = editable;
97 this.typeOverallMax = -1;
Chiao Chenge88fcd32012-11-13 18:38:05 -080098 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 Chenge88fcd32012-11-13 18:38:05 -0800119 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 Chenge88fcd32012-11-13 18:38:05 -0800124 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}