Loading res/drawable-v21/drawer_item_background.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2016 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 --> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/nav_item_selected_background"> <item> <selector> <item android:drawable="@color/nav_item_selected_background" android:state_checked="true"/> <item android:drawable="@android:color/transparent"/> </selector> </item> </ripple> No newline at end of file res/drawable/drawer_item_background.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2016 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_checked="true" android:drawable="@color/nav_item_selected_background"/> <item android:drawable="@android:color/transparent" /> </selector> No newline at end of file res/layout/contacts_drawer_activity.xml +1 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:itemBackground="@drawable/drawer_item_background" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer"/> Loading res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ <color name="action_bar_background">#0288d1</color> <color name="nav_item_selected_background">#0f000000</color> <color name="background_social_updates">#ffeeeeee</color> <color name="action_bar_button_text_color">#FFFFFF</color> Loading src/com/android/contacts/ContactsDrawerActivity.java +98 −1 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import com.android.contacts.common.util.ImplicitIntentsUtil; import com.android.contacts.common.util.ViewUtil; import com.android.contacts.editor.ContactEditorFragment; import com.android.contacts.group.GroupListItem; import com.android.contacts.group.GroupMetadata; import com.android.contacts.group.GroupUtil; import com.android.contacts.group.GroupsFragment; import com.android.contacts.group.GroupsFragment.GroupsListener; Loading @@ -59,7 +60,11 @@ import com.android.contacts.util.PhoneCapabilityTester; import com.android.contactsbind.Assistants; import com.android.contactsbind.HelpUtils; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; /** * A common superclass for Contacts activities with a navigation drawer. Loading @@ -81,6 +86,13 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i protected GroupsFragment mGroupsFragment; protected AccountFiltersFragment mAccountFiltersFragment; // Checkable menu item lookup maps. Every map declared here should be added to // clearCheckedMenus() so that they can be cleared. // TODO find a better way to handle selected menu item state, when swicthing to fragments. protected Map<Long, MenuItem> mGroupMenuMap = new HashMap<>(); protected Map<ContactListFilter, MenuItem> mFilterMenuMap = new HashMap<>(); protected Map<Integer, MenuItem> mIdMenuMap = new HashMap<>(); @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); Loading Loading @@ -109,6 +121,10 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i mNavigationView.setNavigationItemSelectedListener(this); final Menu menu = mNavigationView.getMenu(); final MenuItem allContacts = menu.findItem(R.id.nav_all_contacts); mIdMenuMap.put(R.id.nav_all_contacts, allContacts); final boolean showBlockedNumbers = PhoneCapabilityTester.isPhone(this) && ContactsUtils.FLAG_N_FEATURE && BlockedNumberContractCompat.canCurrentUserBlockNumbers(this); Loading @@ -119,6 +135,9 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i if (Assistants.getDuplicatesActivityIntent(this) == null) { menu.removeItem(R.id.nav_find_duplicates); } else { final MenuItem findDup = menu.findItem(R.id.nav_find_duplicates); mIdMenuMap.put(R.id.nav_find_duplicates, findDup); } if (!HelpUtils.isHelpAndFeedbackAvailable()) { Loading @@ -126,6 +145,19 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i } loadGroupsAndFilters(); if (isDuplicatesActivity()) { clearCheckedMenus(); mIdMenuMap.get(R.id.nav_find_duplicates).setCheckable(true); mIdMenuMap.get(R.id.nav_find_duplicates).setChecked(true); } } /** * Returns true if child class is DuplicatesActivity */ protected boolean isDuplicatesActivity() { return false; } // Set up fragment manager to load groups and filters. Loading Loading @@ -174,6 +206,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final MenuItem groupsMenuItem = menu.findItem(R.id.nav_groups); final SubMenu subMenu = groupsMenuItem.getSubMenu(); subMenu.removeGroup(R.id.nav_groups_items); mGroupMenuMap = new HashMap<>(); if (groupListItems != null) { // Add each group Loading @@ -184,6 +217,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final String title = groupListItem.getTitle(); final MenuItem menuItem = subMenu.add(R.id.nav_groups_items, Menu.NONE, Menu.NONE, title); mGroupMenuMap.put(groupListItem.getGroupId(), menuItem); menuItem.setIcon(R.drawable.ic_menu_label); menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override Loading Loading @@ -211,6 +245,27 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i return true; } }); if (getGroupMetadata() != null) { updateGroupMenu(getGroupMetadata()); } } protected void updateGroupMenu(GroupMetadata groupMetadata) { clearCheckedMenus(); if (groupMetadata != null && mGroupMenuMap != null && mGroupMenuMap.get(groupMetadata.groupId) != null) { mGroupMenuMap.get(groupMetadata.groupId).setCheckable(true); mGroupMenuMap.get(groupMetadata.groupId).setChecked(true); } } /** * Returns group metadata if the child class is {@link GroupMembersActivity}, and null * otherwise. */ protected GroupMetadata getGroupMetadata() { return null; } protected void onGroupMenuItemClicked(long groupId) { Loading @@ -229,6 +284,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final MenuItem filtersMenuItem = menu.findItem(R.id.nav_filters); final SubMenu subMenu = filtersMenuItem.getSubMenu(); subMenu.removeGroup(R.id.nav_filters_items); mFilterMenuMap = new HashMap<>(); if (accountFilterItems == null || accountFilterItems.size() < 2) { return; Loading @@ -239,6 +295,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final String accountName = filter.accountName; final MenuItem menuItem = subMenu.add(R.id.nav_filters_items, Menu.NONE, Menu.NONE, accountName); mFilterMenuMap.put(filter, menuItem); final Intent intent = new Intent(); intent.putExtra(AccountFilterUtil.EXTRA_CONTACT_LIST_FILTER, filter); menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { Loading @@ -257,10 +314,36 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i // Get rid of the default memu item overlay and show original account icons. menuItem.getIcon().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP); } if (getContactListFilter() != null) { updateFilterMenu(getContactListFilter()); } } protected void updateFilterMenu(ContactListFilter filter) { clearCheckedMenus(); if (filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS) { if (mIdMenuMap != null && mIdMenuMap.get(R.id.nav_all_contacts) != null) { mIdMenuMap.get(R.id.nav_all_contacts).setCheckable(true); mIdMenuMap.get(R.id.nav_all_contacts).setChecked(true); } } else { if (mFilterMenuMap != null && mFilterMenuMap.get(filter) != null) { mFilterMenuMap.get(filter).setCheckable(true); mFilterMenuMap.get(filter).setChecked(true); } } } /** * @return true if the child activity should finish after launching another activity. * Returns the current filter if the child class is {@link PeopleActivity}, and null otherwise. */ protected ContactListFilter getContactListFilter() { return null; } /** * Returns true if the child activity should finish after launching another activity. */ protected abstract boolean shouldFinish(); Loading Loading @@ -318,4 +401,18 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i return ContactListFilter.createFilterWithType(ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS); } private void clearCheckedMenus() { clearCheckedMenu(mFilterMenuMap); clearCheckedMenu(mGroupMenuMap); clearCheckedMenu(mIdMenuMap); } private void clearCheckedMenu(Map<?, MenuItem> map) { final Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry pair = (Entry)it.next(); map.get(pair.getKey()).setCheckable(false); map.get(pair.getKey()).setChecked(false); } } } Loading
res/drawable-v21/drawer_item_background.xml 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2016 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 --> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/nav_item_selected_background"> <item> <selector> <item android:drawable="@color/nav_item_selected_background" android:state_checked="true"/> <item android:drawable="@android:color/transparent"/> </selector> </item> </ripple> No newline at end of file
res/drawable/drawer_item_background.xml 0 → 100644 +22 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2016 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_checked="true" android:drawable="@color/nav_item_selected_background"/> <item android:drawable="@android:color/transparent" /> </selector> No newline at end of file
res/layout/contacts_drawer_activity.xml +1 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,7 @@ android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:itemBackground="@drawable/drawer_item_background" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer"/> Loading
res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ <color name="action_bar_background">#0288d1</color> <color name="nav_item_selected_background">#0f000000</color> <color name="background_social_updates">#ffeeeeee</color> <color name="action_bar_button_text_color">#FFFFFF</color> Loading
src/com/android/contacts/ContactsDrawerActivity.java +98 −1 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import com.android.contacts.common.util.ImplicitIntentsUtil; import com.android.contacts.common.util.ViewUtil; import com.android.contacts.editor.ContactEditorFragment; import com.android.contacts.group.GroupListItem; import com.android.contacts.group.GroupMetadata; import com.android.contacts.group.GroupUtil; import com.android.contacts.group.GroupsFragment; import com.android.contacts.group.GroupsFragment.GroupsListener; Loading @@ -59,7 +60,11 @@ import com.android.contacts.util.PhoneCapabilityTester; import com.android.contactsbind.Assistants; import com.android.contactsbind.HelpUtils; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; /** * A common superclass for Contacts activities with a navigation drawer. Loading @@ -81,6 +86,13 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i protected GroupsFragment mGroupsFragment; protected AccountFiltersFragment mAccountFiltersFragment; // Checkable menu item lookup maps. Every map declared here should be added to // clearCheckedMenus() so that they can be cleared. // TODO find a better way to handle selected menu item state, when swicthing to fragments. protected Map<Long, MenuItem> mGroupMenuMap = new HashMap<>(); protected Map<ContactListFilter, MenuItem> mFilterMenuMap = new HashMap<>(); protected Map<Integer, MenuItem> mIdMenuMap = new HashMap<>(); @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); Loading Loading @@ -109,6 +121,10 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i mNavigationView.setNavigationItemSelectedListener(this); final Menu menu = mNavigationView.getMenu(); final MenuItem allContacts = menu.findItem(R.id.nav_all_contacts); mIdMenuMap.put(R.id.nav_all_contacts, allContacts); final boolean showBlockedNumbers = PhoneCapabilityTester.isPhone(this) && ContactsUtils.FLAG_N_FEATURE && BlockedNumberContractCompat.canCurrentUserBlockNumbers(this); Loading @@ -119,6 +135,9 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i if (Assistants.getDuplicatesActivityIntent(this) == null) { menu.removeItem(R.id.nav_find_duplicates); } else { final MenuItem findDup = menu.findItem(R.id.nav_find_duplicates); mIdMenuMap.put(R.id.nav_find_duplicates, findDup); } if (!HelpUtils.isHelpAndFeedbackAvailable()) { Loading @@ -126,6 +145,19 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i } loadGroupsAndFilters(); if (isDuplicatesActivity()) { clearCheckedMenus(); mIdMenuMap.get(R.id.nav_find_duplicates).setCheckable(true); mIdMenuMap.get(R.id.nav_find_duplicates).setChecked(true); } } /** * Returns true if child class is DuplicatesActivity */ protected boolean isDuplicatesActivity() { return false; } // Set up fragment manager to load groups and filters. Loading Loading @@ -174,6 +206,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final MenuItem groupsMenuItem = menu.findItem(R.id.nav_groups); final SubMenu subMenu = groupsMenuItem.getSubMenu(); subMenu.removeGroup(R.id.nav_groups_items); mGroupMenuMap = new HashMap<>(); if (groupListItems != null) { // Add each group Loading @@ -184,6 +217,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final String title = groupListItem.getTitle(); final MenuItem menuItem = subMenu.add(R.id.nav_groups_items, Menu.NONE, Menu.NONE, title); mGroupMenuMap.put(groupListItem.getGroupId(), menuItem); menuItem.setIcon(R.drawable.ic_menu_label); menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override Loading Loading @@ -211,6 +245,27 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i return true; } }); if (getGroupMetadata() != null) { updateGroupMenu(getGroupMetadata()); } } protected void updateGroupMenu(GroupMetadata groupMetadata) { clearCheckedMenus(); if (groupMetadata != null && mGroupMenuMap != null && mGroupMenuMap.get(groupMetadata.groupId) != null) { mGroupMenuMap.get(groupMetadata.groupId).setCheckable(true); mGroupMenuMap.get(groupMetadata.groupId).setChecked(true); } } /** * Returns group metadata if the child class is {@link GroupMembersActivity}, and null * otherwise. */ protected GroupMetadata getGroupMetadata() { return null; } protected void onGroupMenuItemClicked(long groupId) { Loading @@ -229,6 +284,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final MenuItem filtersMenuItem = menu.findItem(R.id.nav_filters); final SubMenu subMenu = filtersMenuItem.getSubMenu(); subMenu.removeGroup(R.id.nav_filters_items); mFilterMenuMap = new HashMap<>(); if (accountFilterItems == null || accountFilterItems.size() < 2) { return; Loading @@ -239,6 +295,7 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i final String accountName = filter.accountName; final MenuItem menuItem = subMenu.add(R.id.nav_filters_items, Menu.NONE, Menu.NONE, accountName); mFilterMenuMap.put(filter, menuItem); final Intent intent = new Intent(); intent.putExtra(AccountFilterUtil.EXTRA_CONTACT_LIST_FILTER, filter); menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { Loading @@ -257,10 +314,36 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i // Get rid of the default memu item overlay and show original account icons. menuItem.getIcon().setColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP); } if (getContactListFilter() != null) { updateFilterMenu(getContactListFilter()); } } protected void updateFilterMenu(ContactListFilter filter) { clearCheckedMenus(); if (filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS) { if (mIdMenuMap != null && mIdMenuMap.get(R.id.nav_all_contacts) != null) { mIdMenuMap.get(R.id.nav_all_contacts).setCheckable(true); mIdMenuMap.get(R.id.nav_all_contacts).setChecked(true); } } else { if (mFilterMenuMap != null && mFilterMenuMap.get(filter) != null) { mFilterMenuMap.get(filter).setCheckable(true); mFilterMenuMap.get(filter).setChecked(true); } } } /** * @return true if the child activity should finish after launching another activity. * Returns the current filter if the child class is {@link PeopleActivity}, and null otherwise. */ protected ContactListFilter getContactListFilter() { return null; } /** * Returns true if the child activity should finish after launching another activity. */ protected abstract boolean shouldFinish(); Loading Loading @@ -318,4 +401,18 @@ public abstract class ContactsDrawerActivity extends AppCompatContactsActivity i return ContactListFilter.createFilterWithType(ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS); } private void clearCheckedMenus() { clearCheckedMenu(mFilterMenuMap); clearCheckedMenu(mGroupMenuMap); clearCheckedMenu(mIdMenuMap); } private void clearCheckedMenu(Map<?, MenuItem> map) { final Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry pair = (Entry)it.next(); map.get(pair.getKey()).setCheckable(false); map.get(pair.getKey()).setChecked(false); } } }