Add selectors for drawer item state change
For folder items and account items, add a selectors
in drawable and color to allow for an easy state
change (highlighted/focused/unselected).
Change-Id: I618bcb70ca72c9849cf90e9b6662092822e4862e
diff --git a/res/color/account_item_text_color.xml b/res/color/account_item_text_color.xml
new file mode 100644
index 0000000..ee283b2
--- /dev/null
+++ b/res/color/account_item_text_color.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013 Google Inc.
+ Licensed to The Android Open Source Project.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:color="@color/account_item_selected_text_color" />
+ <item android:color="@color/dark_gray_text_color" />
+</selector>
diff --git a/res/color/folder_item_text_color.xml b/res/color/folder_item_text_color.xml
new file mode 100644
index 0000000..ab79a8d
--- /dev/null
+++ b/res/color/folder_item_text_color.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013 Google Inc.
+ Licensed to The Android Open Source Project.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_activated="true" android:color="@android:color/white" />
+ <item android:color="@color/dark_gray_text_color" />
+</selector>
diff --git a/res/drawable/account_radio_button.xml b/res/drawable/account_radio_button.xml
new file mode 100644
index 0000000..d2c4073
--- /dev/null
+++ b/res/drawable/account_radio_button.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013 Google Inc.
+ Licensed to The Android Open Source Project.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:drawable="@drawable/ic_radiobutton_selected" />
+ <item android:drawable="@drawable/ic_radiobutton" />
+</selector>
diff --git a/res/layout/account_item.xml b/res/layout/account_item.xml
index 5a22e8a..1781761 100644
--- a/res/layout/account_item.xml
+++ b/res/layout/account_item.xml
@@ -34,6 +34,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/account_item_left_margin"
+ android:src="@drawable/account_radio_button"
android:layout_centerVertical="true"/>
<LinearLayout
@@ -54,14 +55,15 @@
android:includeFontPadding="false"
android:singleLine="true"
android:ellipsize="end"
- android:textColor="@color/folder_item_text_color"
+ android:textColor="@color/account_item_text_color"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/unread"
style="@style/UnreadCount"
android:layout_alignWithParentIfMissing="true"
- android:layout_alignParentRight="true" />
+ android:layout_alignParentRight="true"
+ android:textColor="@color/account_item_text_color" />
</LinearLayout>
</com.android.mail.ui.AccountItemView>
diff --git a/res/layout/folder_item.xml b/res/layout/folder_item.xml
index 1dcbeb9..3a82e64 100644
--- a/res/layout/folder_item.xml
+++ b/res/layout/folder_item.xml
@@ -75,7 +75,8 @@
style="@style/UnreadCount"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentRight="true"
- android:layout_alignBaseline="@id/name" />
+ android:layout_alignBaseline="@id/name"
+ android:textColor="@color/folder_item_text_color" />
<TextView
android:id="@+id/unseen"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index a80d96f..8cff43d 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -41,13 +41,10 @@
<!-- Folder List/Drawer colors -->
<color name="drawer_background_dim">#66000000</color>
+ <color name="account_item_selected_text_color">#35b4e3</color>
<color name="folder_list_divider_color">@color/gray_text_color</color>
<color name="folder_list_heading_text_color">@color/dark_gray_text_color</color>
- <color name="account_item_text_color">@color/dark_gray_text_color</color>
- <color name="account_item_selected_text_color">#35b4e3</color>
<color name="list_background_color">#eeeeee</color>
- <color name="folder_item_text_color">@color/dark_gray_text_color</color>
- <color name="folder_item_selected_text_color">@android:color/white</color>
<color name="unread_count_color">#aaaaaa</color>
<!-- Compose colors -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index b6ddf8c..9fafa2d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -156,7 +156,6 @@
<item name="android:singleLine">true</item>
<item name="android:includeFontPadding">false</item>
<item name="android:textSize">14sp</item>
- <item name="android:textColor">@color/unread_count_color</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
</style>
diff --git a/src/com/android/mail/adapter/DrawerItem.java b/src/com/android/mail/adapter/DrawerItem.java
index 6b9a2bc..44c03b0 100644
--- a/src/com/android/mail/adapter/DrawerItem.java
+++ b/src/com/android/mail/adapter/DrawerItem.java
@@ -305,10 +305,6 @@
}
}
- public void setSelected(final boolean isSelected) {
- mIsSelected = isSelected;
- }
-
/**
* Return a view for an account object.
* @param position a zero indexed position in to the list.
@@ -364,7 +360,7 @@
folderItemView =
(FolderItemView) mInflater.inflate(R.layout.folder_item, null, false);
}
- folderItemView.bind(mFolder, mActivity, mIsSelected);
+ folderItemView.bind(mFolder, mActivity);
Folder.setFolderBlockColor(mFolder, folderItemView.findViewById(R.id.color_block));
Folder.setIcon(mFolder, (ImageView) folderItemView.findViewById(R.id.folder_icon));
return folderItemView;
diff --git a/src/com/android/mail/ui/AccountItemView.java b/src/com/android/mail/ui/AccountItemView.java
index 801f0bb..7e8edee 100644
--- a/src/com/android/mail/ui/AccountItemView.java
+++ b/src/com/android/mail/ui/AccountItemView.java
@@ -58,30 +58,20 @@
}
/**
- * Sets the account name and draws the unread count. If the account is the current account,
- * the unread count is hidden and the account item is given the focused background to
- * partially highlight it.
+ * Sets the account name and draws the unread count. Depending on the account state (current or
+ * unused), the colors and drawables will change through the call to setSelected for each
+ * necessary element.
*
* @param account account whose name will be displayed
* @param isCurrentAccount true if the account is the one in use, false otherwise
* @param count unread count
*/
public void bind(final Account account, final boolean isCurrentAccount, final int count) {
- final int textColorResId;
- final int buttonResId;
-
- if (isCurrentAccount) {
- textColorResId = R.color.account_item_selected_text_color;
- buttonResId = R.drawable.ic_radiobutton_selected;
- } else {
- textColorResId = R.color.account_item_text_color;
- buttonResId = R.drawable.ic_radiobutton;
- }
mAccountTextView.setText(account.name);
setUnreadCount(count);
- mSelectedButton.setImageResource(buttonResId);
- mAccountTextView.setTextColor(getContext().getResources().getColor(textColorResId));
- mUnreadCountTextView.setTextColor(getContext().getResources().getColor(textColorResId));
+ mUnreadCountTextView.setSelected(isCurrentAccount);
+ mAccountTextView.setSelected(isCurrentAccount);
+ mSelectedButton.setSelected(isCurrentAccount);
}
/**
diff --git a/src/com/android/mail/ui/FolderItemView.java b/src/com/android/mail/ui/FolderItemView.java
index d40ef5c..1d9d857 100644
--- a/src/com/android/mail/ui/FolderItemView.java
+++ b/src/com/android/mail/ui/FolderItemView.java
@@ -63,7 +63,6 @@
private TextView mUnseenCountTextView;
private DropHandler mDropHandler;
private ImageView mFolderParentIcon;
- private boolean mIsSelected;
/**
* A delegate for a handler to handle a drop of an item.
@@ -139,13 +138,8 @@
}
public void bind(final Folder folder, final DropHandler dropHandler) {
- bind(folder, dropHandler, false);
- }
-
- public void bind(final Folder folder, final DropHandler dropHandler, final boolean isSelected) {
mFolder = folder;
mDropHandler = dropHandler;
- mIsSelected = isSelected;
mFolderTextView.setText(folder.name);
mFolderParentIcon.setVisibility(mFolder.hasChildren ? View.VISIBLE : View.GONE);
if (mFolder.isInbox() && mFolder.unseenCount > 0) {
@@ -155,33 +149,15 @@
mUnseenCountTextView.setVisibility(View.GONE);
setUnreadCount(Utils.getFolderUnreadDisplayCount(mFolder));
}
- setFolderSelected();
}
public void bind(final Account account, final DropHandler dropHandler, final int count) {
mFolder = null;
- mIsSelected = false;
mDropHandler = dropHandler;
mFolderTextView.setText(account.name);
mFolderParentIcon.setVisibility(View.GONE);
setUnseenCount(Color.BLACK, 0);
setUnreadCount(count);
- setFolderSelected();
- }
-
- /**
- * Allows for changing view colors/states depending on whether the label is selected
- * in the drawer.
- */
- private void setFolderSelected() {
- final int textColorResId;
- if (mIsSelected) {
- textColorResId = R.color.folder_item_selected_text_color;
- } else {
- textColorResId = R.color.folder_item_text_color;
- }
- mFolderTextView.setTextColor(getContext().getResources().getColor(textColorResId));
- mUnreadCountTextView.setTextColor(getContext().getResources().getColor(textColorResId));
}
/**
diff --git a/src/com/android/mail/ui/FolderListFragment.java b/src/com/android/mail/ui/FolderListFragment.java
index cdba655..623bf00 100644
--- a/src/com/android/mail/ui/FolderListFragment.java
+++ b/src/com/android/mail/ui/FolderListFragment.java
@@ -636,15 +636,13 @@
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final DrawerItem item = (DrawerItem) getItem(position);
- final View view;
+ final View view = item.getView(position, convertView, parent);
final int type = item.mType;
final boolean isSelected =
item.isHighlighted(mCurrentFolderForUnreadCheck, mSelectedFolderType);
if (type == DrawerItem.VIEW_FOLDER) {
mListView.setItemChecked(position, isSelected);
- item.setSelected(isSelected);
}
- view = item.getView(position, convertView, parent);
// If this is the current folder, also check to verify that the unread count
// matches what the action bar shows.
if (type == DrawerItem.VIEW_FOLDER
@@ -960,7 +958,6 @@
folderItemView.bind(folder, mDropHandler);
if (folder.uri.equals(mSelectedFolderUri)) {
getListView().setItemChecked(position, true);
- folderItemView.setSelected(true);
// If this is the current folder, also check to verify that the unread count
// matches what the action bar shows.
final boolean unreadCountDiffers = (mCurrentFolderForUnreadCheck != null)