Home | History | Annotate | Download | only in calendar
      1 /*
      2  * Copyright (C) 2010 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.calendar;
     18 
     19 import com.android.common.contacts.BaseEmailAddressAdapter;
     20 import com.android.ex.chips.AccountSpecifier;
     21 
     22 import android.content.Context;
     23 import android.text.TextUtils;
     24 import android.view.LayoutInflater;
     25 import android.view.View;
     26 import android.view.ViewGroup;
     27 import android.widget.TextView;
     28 
     29 /**
     30 * An adaptation of {@link BaseEmailAddressAdapter} for the Email app. The main
     31 * purpose of the class is to bind the generic implementation to the resources
     32 * defined locally: strings and layouts.
     33 */
     34 public class EmailAddressAdapter extends BaseEmailAddressAdapter implements AccountSpecifier {
     35 
     36    private LayoutInflater mInflater;
     37 
     38    public EmailAddressAdapter(Context context) {
     39        super(context);
     40        mInflater = LayoutInflater.from(context);
     41    }
     42 
     43    @Override
     44    protected View inflateItemView(ViewGroup parent) {
     45        return mInflater.inflate(R.layout.email_autocomplete_item, parent, false);
     46    }
     47 
     48    @Override
     49    protected View inflateItemViewLoading(ViewGroup parent) {
     50        return mInflater.inflate(R.layout.email_autocomplete_item_loading, parent, false);
     51    }
     52 
     53    @Override
     54    protected void bindView(View view, String directoryType, String directoryName,
     55            String displayName, String emailAddress) {
     56      TextView text1 = (TextView)view.findViewById(R.id.text1);
     57      TextView text2 = (TextView)view.findViewById(R.id.text2);
     58      text1.setText(displayName);
     59      text2.setText(emailAddress);
     60    }
     61 
     62    @Override
     63    protected void bindViewLoading(View view, String directoryType, String directoryName) {
     64        TextView text1 = (TextView)view.findViewById(R.id.text1);
     65        String text = getContext().getString(R.string.directory_searching_fmt,
     66                TextUtils.isEmpty(directoryName) ? directoryType : directoryName);
     67        text1.setText(text);
     68    }
     69 }
     70