1/*
2 * Copyright (C) 2011 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
17package com.android.contacts.group;
18
19import com.android.contacts.R;
20import com.android.contacts.model.AccountType;
21import com.android.contacts.model.AccountTypeManager;
22
23import android.content.Context;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.widget.ImageView;
27import android.widget.TextView;
28
29public class GroupDetailDisplayUtils {
30
31    private GroupDetailDisplayUtils() {
32        // Disallow explicit creation of this class.
33    }
34
35    public static View getNewGroupSourceView(Context context) {
36        LayoutInflater inflater = (LayoutInflater)context.getSystemService(
37                Context.LAYOUT_INFLATER_SERVICE);
38        return inflater.inflate(R.layout.group_source_button, null);
39    }
40
41    public static void bindGroupSourceView(Context context, View view, String accountTypeString,
42            String dataSet) {
43        AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context);
44        AccountType accountType = accountTypeManager.getAccountType(accountTypeString, dataSet);
45
46        TextView label = (TextView) view.findViewById(android.R.id.title);
47        if (label == null) {
48            throw new IllegalStateException("Group source view must contain a TextView with id"
49                    + "android.R.id.label");
50        }
51        label.setText(accountType.getViewGroupLabel(context));
52
53        ImageView accountIcon = (ImageView) view.findViewById(android.R.id.icon);
54        if (accountIcon == null) {
55            throw new IllegalStateException("Group source view must contain an ImageView with id"
56                    + "android.R.id.icon");
57        }
58        accountIcon.setImageDrawable(accountType.getDisplayIcon(context));
59    }
60}