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 
17 package com.android.contacts.group;
18 
19 import android.content.Context;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.widget.ImageView;
23 import android.widget.TextView;
24 
25 import com.android.contacts.R;
26 import com.android.contacts.common.model.AccountTypeManager;
27 import com.android.contacts.common.model.account.AccountType;
28 
29 public class GroupDetailDisplayUtils {
30 
GroupDetailDisplayUtils()31     private GroupDetailDisplayUtils() {
32         // Disallow explicit creation of this class.
33     }
34 
getNewGroupSourceView(Context context)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 
bindGroupSourceView(Context context, View view, String accountTypeString, String dataSet)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 }
61