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