blob: 636ee88c012a1c177a263009bc0ea87113e7f29c [file] [log] [blame]
Marcus Hagerottfac695a2016-08-24 17:02:40 -07001/*
2 * Copyright (C) 2016 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 */
Gary Mai69c182a2016-12-05 13:07:03 -080016package com.android.contacts.model.account;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070017
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070018import android.accounts.AuthenticatorDescription;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070019import android.content.Context;
Gary Mai698cee72016-09-19 16:09:54 -070020import android.provider.ContactsContract.CommonDataKinds.Nickname;
21import android.provider.ContactsContract.CommonDataKinds.StructuredName;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070022
Arthur Wang3f6a2442016-12-05 14:51:59 -080023import com.android.contacts.R;
Gary Mai69c182a2016-12-05 13:07:03 -080024import com.android.contacts.model.dataitem.DataKind;
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070025
Gary Mai698cee72016-09-19 16:09:54 -070026import com.google.common.collect.Lists;
27
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070028import java.util.Collections;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070029
30/**
31 * Account type for SIM card contacts
Marcus Hagerottfac695a2016-08-24 17:02:40 -070032 */
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070033public class SimAccountType extends BaseAccountType {
Marcus Hagerottfac695a2016-08-24 17:02:40 -070034
35 public SimAccountType(Context context) {
Marcus Hagerottfac695a2016-08-24 17:02:40 -070036 this.titleRes = R.string.account_sim;
John Shaobd9ef3c2016-12-15 12:42:03 -080037 this.iconRes = R.drawable.quantum_ic_sim_card_vd_theme_24;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070038
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070039 try {
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070040 addDataKindStructuredName(context);
Gary Mai7a6daea2016-10-10 15:41:48 -070041 addDataKindName(context);
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070042 final DataKind phoneKind = addDataKindPhone(context);
43 phoneKind.typeOverallMax = 1;
44 // SIM card contacts don't necessarily support separate types (based on data exposed
45 // in Samsung and LG Contacts Apps.
46 phoneKind.typeList = Collections.emptyList();
47
48 mIsInitialized = true;
49 } catch (DefinitionException e) {
50 // Just fail fast. Because we're explicitly adding the fields in this class this
51 // exception should only happen in case of a bug.
52 throw new IllegalStateException(e);
53 }
54 }
55
56 @Override
57 public boolean areContactsWritable() {
58 return true;
Marcus Hagerottfac695a2016-08-24 17:02:40 -070059 }
60
61 @Override
62 public boolean isGroupMembershipEditable() {
63 return false;
64 }
Marcus Hagerottcf7f2952016-09-06 13:49:17 -070065
66 @Override
67 public void initializeFieldsFromAuthenticator(AuthenticatorDescription authenticator) {
68 // Do nothing. We want to use our local icon and title
69 }
Gary Mai698cee72016-09-19 16:09:54 -070070
71 @Override
72 protected DataKind addDataKindStructuredName(Context context) throws DefinitionException {
73 final DataKind kind = addKind(new DataKind(StructuredName.CONTENT_ITEM_TYPE,
74 R.string.nameLabelsGroup, Weight.NONE, true));
75 kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
76 kind.actionBody = new SimpleInflater(Nickname.NAME);
77 kind.typeOverallMax = 1;
78
Gary Mai7a6daea2016-10-10 15:41:48 -070079
80 kind.fieldList = Lists.newArrayList();
81 kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
82 FLAGS_PERSON_NAME));
83 kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
84 FLAGS_PERSON_NAME));
85
86 return kind;
87 }
88
89 @Override
90 protected DataKind addDataKindName(Context context) throws DefinitionException {
91 final DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_NAME,
92 R.string.nameLabelsGroup, Weight.NONE, true));
93 kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
94 kind.actionBody = new SimpleInflater(Nickname.NAME);
95 kind.typeOverallMax = 1;
96
Gary Mai698cee72016-09-19 16:09:54 -070097 final boolean displayOrderPrimary =
98 context.getResources().getBoolean(R.bool.config_editor_field_order_primary);
99
100 kind.fieldList = Lists.newArrayList();
101 if (!displayOrderPrimary) {
102 kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
103 FLAGS_PERSON_NAME));
104 kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
105 FLAGS_PERSON_NAME));
106 } else {
107 kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
108 FLAGS_PERSON_NAME));
109 kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
110 FLAGS_PERSON_NAME));
111 }
112
113 return kind;
114 }
Marcus Hagerottfac695a2016-08-24 17:02:40 -0700115}