| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.graphics.drawable.Drawable; |
| 21 |
import android.text.TextUtils; |
| 22 |
import android.util.AttributeSet; |
| 23 |
import android.view.LayoutInflater; |
| 24 |
import android.view.View; |
| 25 |
import android.widget.ImageView; |
| 26 |
import android.widget.LinearLayout; |
| 27 |
import android.widget.TextView; |
| 28 |
|
| 29 |
import com.android.internal.R; |
| 30 |
import com.android.internal.widget.AccountViewAdapter.AccountElements; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class AccountItemView extends LinearLayout { |
| 37 |
|
| 38 |
private ImageView mAccountIcon; |
| 39 |
private TextView mAccountName; |
| 40 |
private TextView mAccountNumber; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public AccountItemView(Context context) { |
| 46 |
this(context, null); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public AccountItemView(Context context, AttributeSet attrs) { |
| 53 |
super(context, attrs); |
| 54 |
LayoutInflater inflator = (LayoutInflater) |
| 55 |
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 56 |
View view = inflator.inflate(R.layout.simple_account_item, null); |
| 57 |
addView(view); |
| 58 |
initViewItem(view); |
| 59 |
} |
| 60 |
|
| 61 |
private void initViewItem(View view) { |
| 62 |
mAccountIcon = (ImageView)view.findViewById(android.R.id.icon); |
| 63 |
mAccountName = (TextView)view.findViewById(android.R.id.title); |
| 64 |
mAccountNumber = (TextView)view.findViewById(android.R.id.summary); |
| 65 |
} |
| 66 |
|
| 67 |
public void setViewItem(AccountElements element) { |
| 68 |
Drawable drawable = element.getDrawable(); |
| 69 |
if (drawable != null) { |
| 70 |
setAccountIcon(drawable); |
| 71 |
} else { |
| 72 |
setAccountIcon(element.getIcon()); |
| 73 |
} |
| 74 |
setAccountName(element.getName()); |
| 75 |
setAccountNumber(element.getNumber()); |
| 76 |
} |
| 77 |
|
| 78 |
public void setAccountIcon(int resId) { |
| 79 |
mAccountIcon.setImageResource(resId); |
| 80 |
} |
| 81 |
|
| 82 |
public void setAccountIcon(Drawable drawable) { |
| 83 |
mAccountIcon.setBackgroundDrawable(drawable); |
| 84 |
} |
| 85 |
|
| 86 |
public void setAccountName(String name) { |
| 87 |
setText(mAccountName, name); |
| 88 |
} |
| 89 |
|
| 90 |
public void setAccountNumber(String number) { |
| 91 |
setText(mAccountNumber, number); |
| 92 |
} |
| 93 |
|
| 94 |
private void setText(TextView view, String text) { |
| 95 |
if (TextUtils.isEmpty(text)) { |
| 96 |
view.setVisibility(View.GONE); |
| 97 |
} else { |
| 98 |
view.setText(text); |
| 99 |
view.setVisibility(View.VISIBLE); |
| 100 |
} |
| 101 |
} |
| 102 |
} |