Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2013, Google Inc. |
| 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 | package com.android.mail.ui; |
| 17 | |
| 18 | import com.android.mail.R; |
| 19 | |
Rohan Shah | b905f0e | 2013-04-26 09:17:37 -0700 | [diff] [blame] | 20 | import android.widget.ImageView; |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 21 | import android.widget.TextView; |
| 22 | |
| 23 | import com.android.mail.providers.Account; |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 24 | import com.android.mail.utils.Utils; |
| 25 | |
| 26 | import android.content.Context; |
Rohan Shah | 074a5a1 | 2013-04-04 17:43:15 -0700 | [diff] [blame] | 27 | |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.widget.RelativeLayout; |
| 31 | |
| 32 | /** |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 33 | * The view for each account in the folder list/drawer. |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 34 | */ |
| 35 | public class AccountItemView extends RelativeLayout { |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 36 | private TextView mAccountTextView; |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 37 | private TextView mUnreadCountTextView; |
Rohan Shah | b905f0e | 2013-04-26 09:17:37 -0700 | [diff] [blame] | 38 | private ImageView mSelectedButton; |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 39 | |
| 40 | public AccountItemView(Context context) { |
| 41 | super(context); |
| 42 | } |
| 43 | |
| 44 | public AccountItemView(Context context, AttributeSet attrs) { |
| 45 | super(context, attrs); |
| 46 | } |
| 47 | |
| 48 | public AccountItemView(Context context, AttributeSet attrs, int defStyle) { |
| 49 | super(context, attrs, defStyle); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected void onFinishInflate() { |
| 54 | super.onFinishInflate(); |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 55 | mAccountTextView = (TextView)findViewById(R.id.name); |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 56 | mUnreadCountTextView = (TextView)findViewById(R.id.unread); |
Rohan Shah | b905f0e | 2013-04-26 09:17:37 -0700 | [diff] [blame] | 57 | mSelectedButton = (ImageView)findViewById(R.id.account_radio_button); |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 60 | /** |
Rohan Shah | c1e4506 | 2013-04-28 10:50:49 -0700 | [diff] [blame^] | 61 | * Sets the account name and draws the unread count. Depending on the account state (current or |
| 62 | * unused), the colors and drawables will change through the call to setSelected for each |
| 63 | * necessary element. |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 64 | * |
| 65 | * @param account account whose name will be displayed |
Rohan Shah | 074a5a1 | 2013-04-04 17:43:15 -0700 | [diff] [blame] | 66 | * @param isCurrentAccount true if the account is the one in use, false otherwise |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 67 | * @param count unread count |
| 68 | */ |
Rohan Shah | 074a5a1 | 2013-04-04 17:43:15 -0700 | [diff] [blame] | 69 | public void bind(final Account account, final boolean isCurrentAccount, final int count) { |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 70 | mAccountTextView.setText(account.name); |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 71 | setUnreadCount(count); |
Rohan Shah | c1e4506 | 2013-04-28 10:50:49 -0700 | [diff] [blame^] | 72 | mUnreadCountTextView.setSelected(isCurrentAccount); |
| 73 | mAccountTextView.setSelected(isCurrentAccount); |
| 74 | mSelectedButton.setSelected(isCurrentAccount); |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
Rohan Shah | 671133b | 2013-03-26 14:48:10 -0700 | [diff] [blame] | 78 | * Sets the unread count, taking care to hide/show the textview if the count |
| 79 | * is zero/non-zero. |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 80 | */ |
Rohan Shah | 074a5a1 | 2013-04-04 17:43:15 -0700 | [diff] [blame] | 81 | private void setUnreadCount(final int count) { |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 82 | mUnreadCountTextView.setVisibility(count > 0 ? View.VISIBLE : View.GONE); |
| 83 | if (count > 0) { |
| 84 | mUnreadCountTextView.setText(Utils.getUnreadCountString(getContext(), count)); |
| 85 | } |
| 86 | } |
Rohan Shah | b958701 | 2013-03-20 14:34:38 -0700 | [diff] [blame] | 87 | } |