1 /* 2 * Copyright (C) 2007-2008 Esmertec AG. 3 * Copyright (C) 2007-2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.im.app; 19 20 import android.app.Activity; 21 import android.content.Context; 22 import android.database.Cursor; 23 import android.graphics.drawable.Drawable; 24 import android.util.AttributeSet; 25 import android.widget.ImageView; 26 import android.widget.LinearLayout; 27 import android.widget.TextView; 28 29 import com.android.im.R; 30 import com.android.im.plugin.BrandingResourceIDs; 31 32 public class BlockedContactView extends LinearLayout { 33 private ImageView mAvatar; 34 private ImageView mBlockedIcon; 35 private TextView mLine1; 36 private TextView mLine2; 37 BlockedContactView(Context context, AttributeSet attrs)38 public BlockedContactView(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 } 41 42 @Override onFinishInflate()43 protected void onFinishInflate() { 44 super.onFinishInflate(); 45 46 mAvatar = (ImageView) findViewById(R.id.avatar); 47 mBlockedIcon = (ImageView)findViewById(R.id.blocked); 48 mLine1 = (TextView) findViewById(R.id.line1); 49 mLine2 = (TextView) findViewById(R.id.line2); 50 } 51 bind(Cursor cursor)52 public void bind(Cursor cursor) { 53 long providerId = cursor.getLong(BlockedContactsActivity.PROVIDER_COLUMN); 54 String username = cursor.getString(BlockedContactsActivity.USERNAME_COLUMN); 55 String nickname = cursor.getString(BlockedContactsActivity.NICKNAME_COLUMN); 56 57 Drawable avatar = DatabaseUtils.getAvatarFromCursor(cursor, 58 BlockedContactsActivity.AVATAR_COLUMN); 59 60 if (avatar != null) { 61 mAvatar.setImageDrawable(avatar); 62 } else { 63 mAvatar.setImageResource(R.drawable.avatar_unknown); 64 } 65 ImApp app = ImApp.getApplication((Activity)mContext); 66 BrandingResources brandingRes = app.getBrandingResource(providerId); 67 mBlockedIcon.setImageDrawable(brandingRes.getDrawable(BrandingResourceIDs.DRAWABLE_BLOCK)); 68 mLine1.setText(nickname); 69 mLine2.setText(ImpsAddressUtils.getDisplayableAddress(username)); 70 } 71 } 72