Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.model.account; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 18 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 19 | import android.accounts.AuthenticatorDescription; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 20 | import android.content.Context; |
John Shao | bd9ef3c | 2016-12-15 12:42:03 -0800 | [diff] [blame] | 21 | import android.graphics.PorterDuff; |
| 22 | import android.graphics.drawable.Drawable; |
| 23 | import android.support.v4.content.ContextCompat; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 24 | |
Arthur Wang | 3f6a244 | 2016-12-05 14:51:59 -0800 | [diff] [blame] | 25 | import com.android.contacts.R; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 26 | import com.android.contacts.model.dataitem.DataKind; |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 27 | import com.android.contactsbind.FeedbackHelper; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 28 | |
| 29 | public 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 Shao | bd9ef3c | 2016-12-15 12:42:03 -0800 | [diff] [blame] | 36 | this.iconRes = R.drawable.quantum_ic_smartphone_vd_theme_24; |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 37 | |
| 38 | // Note those are only set for unit tests. |
| 39 | this.resourcePackageName = resPackageName; |
| 40 | this.syncAdapterPackageName = resPackageName; |
| 41 | |
| 42 | try { |
| 43 | addDataKindStructuredName(context); |
Gary Mai | 7a6daea | 2016-10-10 15:41:48 -0700 | [diff] [blame] | 44 | addDataKindName(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 45 | 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 Jang | 33ec69b | 2016-03-14 14:49:37 -0700 | [diff] [blame] | 56 | addDataKindGroupMembership(context); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 57 | |
| 58 | mIsInitialized = true; |
| 59 | } catch (DefinitionException e) { |
Walter Jang | 3a0b483 | 2016-10-12 11:02:54 -0700 | [diff] [blame] | 60 | FeedbackHelper.sendFeedback(context, TAG, "Failed to build fallback account type", e); |
Chiao Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
John Shao | bd9ef3c | 2016-12-15 12:42:03 -0800 | [diff] [blame] | 64 | @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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 72 | 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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 81 | static AccountType createWithPackageNameForTest(Context context, String resPackageName) { |
| 82 | return new FallbackAccountType(context, resPackageName); |
| 83 | } |
| 84 | |
| 85 | @Override |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 86 | 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 Cheng | e88fcd3 | 2012-11-13 18:38:05 -0800 | [diff] [blame] | 92 | public boolean areContactsWritable() { |
| 93 | return true; |
| 94 | } |
| 95 | } |