Home | History | Annotate | Download | only in tests
      1 /*
      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  */
     16 package com.android.contacts.tests;
     17 
     18 import android.content.Context;
     19 import android.graphics.Canvas;
     20 import android.graphics.ColorFilter;
     21 import android.graphics.PixelFormat;
     22 import android.graphics.drawable.Drawable;
     23 
     24 import com.android.contacts.model.account.AccountType;
     25 import com.android.contacts.model.account.AccountWithDataSet;
     26 
     27 public class FakeAccountType extends AccountType {
     28     public boolean areContactsWritable = false;
     29     public boolean isGroupMembershipEditable = false;
     30     public String displayLabel = "The Default Label";
     31     public Drawable displayIcon = new Drawable() {
     32         @Override
     33         public void draw(Canvas canvas) {
     34         }
     35 
     36         @Override
     37         public void setAlpha(int alpha) {
     38         }
     39 
     40         @Override
     41         public void setColorFilter(ColorFilter colorFilter) {
     42         }
     43 
     44         @Override
     45         public int getOpacity() {
     46             return PixelFormat.OPAQUE;
     47         }
     48     };
     49 
     50     public FakeAccountType() {
     51     }
     52 
     53     public FakeAccountType(String type) {
     54         accountType = type;
     55     }
     56 
     57     @Override
     58     public Drawable getDisplayIcon(Context context) {
     59         return displayIcon;
     60     }
     61 
     62     @Override
     63     public String getDisplayLabel(Context context) {
     64         return displayLabel;
     65     }
     66 
     67     @Override
     68     public boolean areContactsWritable() {
     69         return areContactsWritable;
     70     }
     71 
     72     @Override
     73     public boolean isGroupMembershipEditable() {
     74         return isGroupMembershipEditable;
     75     }
     76 
     77     public static FakeAccountType create(String accountType, String label) {
     78         final FakeAccountType result = new FakeAccountType();
     79         result.accountType = accountType;
     80         result.displayLabel = label;
     81         return result;
     82     }
     83 
     84     public static FakeAccountType create(String accountType, String label, Drawable icon) {
     85         final FakeAccountType result = new FakeAccountType();
     86         result.accountType = accountType;
     87         result.displayIcon = icon;
     88         result.displayLabel = label;
     89         return result;
     90     }
     91 
     92     public static AccountType create(AccountWithDataSet account, String label, Drawable icon) {
     93         final FakeAccountType result = create(account.type, label, icon);
     94         result.accountType = account.type;
     95         result.dataSet = account.dataSet;
     96         return result;
     97     }
     98 }
     99