blob: f36f370345349ce961847e6e5dcdf4b1d43afde8 [file] [log] [blame]
Chiao Chenge88fcd32012-11-13 18:38:05 -08001/*
2 * Copyright (C) 2009 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.account;
Chiao Chenge88fcd32012-11-13 18:38:05 -080018
Marcus Hagerottfac695a2016-08-24 17:02:40 -070019import android.accounts.AuthenticatorDescription;
Chiao Chenge88fcd32012-11-13 18:38:05 -080020import android.content.Context;
John Shaobd9ef3c2016-12-15 12:42:03 -080021import android.graphics.PorterDuff;
22import android.graphics.drawable.Drawable;
23import android.support.v4.content.ContextCompat;
Chiao Chenge88fcd32012-11-13 18:38:05 -080024
Arthur Wang3f6a2442016-12-05 14:51:59 -080025import com.android.contacts.R;
Gary Mai69c182a2016-12-05 13:07:03 -080026import com.android.contacts.model.dataitem.DataKind;
Walter Jang3a0b4832016-10-12 11:02:54 -070027import com.android.contactsbind.FeedbackHelper;
Chiao Chenge88fcd32012-11-13 18:38:05 -080028
29public class FallbackAccountType extends BaseAccountType {
30 private static final String TAG = "FallbackAccountType";
31
32 private FallbackAccountType(Context context, String resPackageName) {
33 this.accountType = null;
34 this.dataSet = null;
35 this.titleRes = R.string.account_phone;
John Shaobd9ef3c2016-12-15 12:42:03 -080036 this.iconRes = R.drawable.quantum_ic_smartphone_vd_theme_24;
Chiao Chenge88fcd32012-11-13 18:38:05 -080037
38 // Note those are only set for unit tests.
39 this.resourcePackageName = resPackageName;
40 this.syncAdapterPackageName = resPackageName;
41
42 try {
43 addDataKindStructuredName(context);
Gary Mai7a6daea2016-10-10 15:41:48 -070044 addDataKindName(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080045 addDataKindPhoneticName(context);
46 addDataKindNickname(context);
47 addDataKindPhone(context);
48 addDataKindEmail(context);
49 addDataKindStructuredPostal(context);
50 addDataKindIm(context);
51 addDataKindOrganization(context);
52 addDataKindPhoto(context);
53 addDataKindNote(context);
54 addDataKindWebsite(context);
55 addDataKindSipAddress(context);
Walter Jang33ec69b2016-03-14 14:49:37 -070056 addDataKindGroupMembership(context);
Chiao Chenge88fcd32012-11-13 18:38:05 -080057
58 mIsInitialized = true;
59 } catch (DefinitionException e) {
Walter Jang3a0b4832016-10-12 11:02:54 -070060 FeedbackHelper.sendFeedback(context, TAG, "Failed to build fallback account type", e);
Chiao Chenge88fcd32012-11-13 18:38:05 -080061 }
62 }
63
John Shaobd9ef3c2016-12-15 12:42:03 -080064 @Override
65 public Drawable getDisplayIcon(Context context) {
66 final Drawable icon = context.getResources().getDrawable(iconRes);
67 icon.mutate().setColorFilter(ContextCompat.getColor(context,
68 R.color.actionbar_icon_color_grey), PorterDuff.Mode.SRC_ATOP);
69 return icon;
70 }
71
Chiao Chenge88fcd32012-11-13 18:38:05 -080072 public FallbackAccountType(Context context) {
73 this(context, null);
74 }
75
76 /**
77 * Used to compare with an {@link ExternalAccountType} built from a test contacts.xml.
78 * In order to build {@link DataKind}s with the same resource package name,
79 * {@code resPackageName} is injectable.
80 */
Chiao Chenge88fcd32012-11-13 18:38:05 -080081 static AccountType createWithPackageNameForTest(Context context, String resPackageName) {
82 return new FallbackAccountType(context, resPackageName);
83 }
84
85 @Override
Marcus Hagerottfac695a2016-08-24 17:02:40 -070086 public void initializeFieldsFromAuthenticator(AuthenticatorDescription authenticator) {
87 // Do nothing. For "Device" accounts we want to just display them using our own strings
88 // and icons.
89 }
90
91 @Override
Chiao Chenge88fcd32012-11-13 18:38:05 -080092 public boolean areContactsWritable() {
93 return true;
94 }
95}