1 /* Copyright (C) 2010 The Android Open Source Project. 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.android.exchange.provider; 17 18 import com.android.emailcommon.mail.PackedString; 19 20 import java.util.ArrayList; 21 22 /** 23 * A container for GAL results from EAS 24 * Each element of the galData array becomes an element of the list used by autocomplete 25 */ 26 public class GalResult { 27 // Total number of matches in this result 28 public int total; 29 public ArrayList<GalData> galData = new ArrayList<GalData>(); 30 31 public GalResult() { 32 } 33 34 /** 35 * Legacy method for email address autocomplete 36 */ 37 public void addGalData(long id, String displayName, String emailAddress) { 38 galData.add(new GalData(id, displayName, emailAddress)); 39 } 40 41 public void addGalData(GalData data) { 42 galData.add(data); 43 } 44 45 public int getNumEntries() { return galData.size(); } 46 47 public static class GalData { 48 // PackedString constants for GalData 49 public static final String ID = "_id"; 50 public static final String DISPLAY_NAME = "displayName"; 51 public static final String DISPLAY_NAME_SOURCE = "display_name_source"; 52 public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt"; 53 public static final String EMAIL_ADDRESS = "emailAddress"; 54 public static final String WORK_PHONE = "workPhone"; 55 public static final String HOME_PHONE = "homePhone"; 56 public static final String MOBILE_PHONE = "mobilePhone"; 57 public static final String FIRST_NAME = "firstName"; 58 public static final String LAST_NAME = "lastName"; 59 public static final String COMPANY = "company"; 60 public static final String TITLE = "title"; 61 public static final String OFFICE = "office"; 62 public static final String ALIAS = "alias"; 63 // The Builder we use to construct the PackedString 64 PackedString.Builder builder = new PackedString.Builder(); 65 66 // The following three fields are for legacy email autocomplete 67 public long _id = 0; 68 public String displayName; 69 public String emailAddress; 70 71 /** 72 * Legacy constructor for email address autocomplete 73 */ 74 private GalData(long id, String _displayName, String _emailAddress) { 75 put(ID, Long.toString(id)); 76 _id = id; 77 put(DISPLAY_NAME, _displayName); 78 displayName = _displayName; 79 put(EMAIL_ADDRESS, _emailAddress); 80 emailAddress = _emailAddress; 81 } 82 83 public GalData() { 84 } 85 86 public String get(String field) { 87 return builder.get(field); 88 } 89 90 public void put(String field, String value) { 91 builder.put(field, value); 92 } 93 94 public String toPackedString() { 95 return builder.toString(); 96 } 97 } 98 } 99