Home | History | Annotate | Download | only in account
      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 
     17 package com.android.contacts.common.model.account;
     18 
     19 import android.content.Context;
     20 import android.util.Log;
     21 import com.android.contacts.common.R;
     22 import com.android.contacts.common.model.dataitem.DataKind;
     23 
     24 public class FallbackAccountType extends BaseAccountType {
     25 
     26   private static final String TAG = "FallbackAccountType";
     27 
     28   private FallbackAccountType(Context context, String resPackageName) {
     29     this.accountType = null;
     30     this.dataSet = null;
     31     this.titleRes = R.string.account_phone;
     32     this.iconRes = R.mipmap.ic_contacts_launcher;
     33 
     34     // Note those are only set for unit tests.
     35     this.resourcePackageName = resPackageName;
     36     this.syncAdapterPackageName = resPackageName;
     37 
     38     try {
     39       addDataKindStructuredName(context);
     40       addDataKindDisplayName(context);
     41       addDataKindPhoneticName(context);
     42       addDataKindNickname(context);
     43       addDataKindPhone(context);
     44       addDataKindEmail(context);
     45       addDataKindStructuredPostal(context);
     46       addDataKindIm(context);
     47       addDataKindOrganization(context);
     48       addDataKindPhoto(context);
     49       addDataKindNote(context);
     50       addDataKindWebsite(context);
     51       addDataKindSipAddress(context);
     52       addDataKindGroupMembership(context);
     53 
     54       mIsInitialized = true;
     55     } catch (DefinitionException e) {
     56       Log.e(TAG, "Problem building account type", e);
     57     }
     58   }
     59 
     60   public FallbackAccountType(Context context) {
     61     this(context, null);
     62   }
     63 
     64   /**
     65    * Used to compare with an {@link ExternalAccountType} built from a test contacts.xml. In order to
     66    * build {@link DataKind}s with the same resource package name, {@code resPackageName} is
     67    * injectable.
     68    */
     69   static AccountType createWithPackageNameForTest(Context context, String resPackageName) {
     70     return new FallbackAccountType(context, resPackageName);
     71   }
     72 
     73   @Override
     74   public boolean areContactsWritable() {
     75     return true;
     76   }
     77 }
     78