Home | History | Annotate | Download | only in model
      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.model;
     18 
     19 import com.android.contacts.R;
     20 import com.android.contacts.test.NeededForTesting;
     21 
     22 import android.content.Context;
     23 import android.util.Log;
     24 
     25 public class FallbackAccountType extends BaseAccountType {
     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_launcher_contacts;
     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 
     53             mIsInitialized = true;
     54         } catch (DefinitionException e) {
     55             Log.e(TAG, "Problem building account type", e);
     56         }
     57     }
     58 
     59     public FallbackAccountType(Context context) {
     60         this(context, null);
     61     }
     62 
     63     /**
     64      * Used to compare with an {@link ExternalAccountType} built from a test contacts.xml.
     65      * In order to build {@link DataKind}s with the same resource package name,
     66      * {@code resPackageName} is injectable.
     67      */
     68     @NeededForTesting
     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