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 EMAIL_ADDRESS = "emailAddress"; 52 public static final String WORK_PHONE = "workPhone"; 53 public static final String HOME_PHONE = "homePhone"; 54 public static final String MOBILE_PHONE = "mobilePhone"; 55 public static final String FIRST_NAME = "firstName"; 56 public static final String LAST_NAME = "lastName"; 57 public static final String COMPANY = "company"; 58 public static final String TITLE = "title"; 59 public static final String OFFICE = "office"; 60 public static final String ALIAS = "alias"; 61 // The Builder we use to construct the PackedString 62 PackedString.Builder builder = new PackedString.Builder(); 63 64 // The following three fields are for legacy email autocomplete 65 public long _id = 0; 66 public String displayName; 67 public String emailAddress; 68 69 /** 70 * Legacy constructor for email address autocomplete 71 */ 72 private GalData(long id, String _displayName, String _emailAddress) { 73 put(ID, Long.toString(id)); 74 _id = id; 75 put(DISPLAY_NAME, _displayName); 76 displayName = _displayName; 77 put(EMAIL_ADDRESS, _emailAddress); 78 emailAddress = _emailAddress; 79 } 80 81 public GalData() { 82 } 83 84 public String get(String field) { 85 return builder.get(field); 86 } 87 88 public void put(String field, String value) { 89 builder.put(field, value); 90 } 91 92 public String toPackedString() { 93 return builder.toString(); 94 } 95 } 96 } 97