Improved layout of contact filter view
Also, no longer showing the down-arrow when there
is no filter or only one filter.
Change-Id: Ie9bbb7aa279ff2013e4c24ca8f302d864679c35c
diff --git a/res/drawable-hdpi/cab_divider_holo_light.png b/res/drawable-hdpi/cab_divider_holo_light.png
new file mode 100644
index 0000000..ecaa019
--- /dev/null
+++ b/res/drawable-hdpi/cab_divider_holo_light.png
Binary files differ
diff --git a/res/drawable-mdpi/cab_divider_holo_light.png b/res/drawable-mdpi/cab_divider_holo_light.png
new file mode 100644
index 0000000..4a77a85
--- /dev/null
+++ b/res/drawable-mdpi/cab_divider_holo_light.png
Binary files differ
diff --git a/res/layout/navigation_bar.xml b/res/layout/navigation_bar.xml
index 08070a7..b2c8fa8 100644
--- a/res/layout/navigation_bar.xml
+++ b/res/layout/navigation_bar.xml
@@ -21,45 +21,57 @@
android:layout_height="match_parent"
android:orientation="horizontal">
- <FrameLayout
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/filter_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:paddingRight="10dip"
- android:minWidth="240dip"
- android:background="@drawable/filter_selector_background">
- <TextView
- android:id="@+id/search_label"
+ android:orientation="horizontal"
+ android:layout_marginLeft="8dip">
+ <FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:text="@string/search_label"
- android:gravity="center_vertical" />
-
- <view
- class="com.android.contacts.list.ContactListFilterView"
- android:id="@+id/filter_view"
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:gravity="center_vertical">
-
+ android:minWidth="220dip"
+ android:background="@drawable/filter_selector_background">
<TextView
- android:id="@+id/label"
+ android:id="@+id/search_label"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="8dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
+ android:layout_height="match_parent"
android:gravity="center_vertical"
- android:ellipsize="end" />
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/search_label" />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="8dip"
- android:layout_gravity="bottom"
- android:src="@drawable/filter_selector_corner" />
- </view>
+ <view
+ class="com.android.contacts.list.ContactListFilterView"
+ android:id="@+id/filter_view"
+ android:layout_height="match_parent"
+ android:layout_width="wrap_content">
+ <TextView
+ android:id="@+id/label"
+ android:layout_height="match_parent"
+ android:layout_width="wrap_content"
+ android:gravity="center_vertical"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:ellipsize="end" />
+ </view>
+ </FrameLayout>
- </FrameLayout>
+ <ImageView
+ android:id="@+id/filter_indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="8dip"
+ android:layout_marginBottom="13dip"
+ android:layout_gravity="bottom"
+ android:src="@drawable/filter_selector_corner" />
+ </LinearLayout>
+ <View
+ android:layout_width="3dip"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="7dip"
+ android:layout_marginRight="7dip"
+ android:background="@drawable/cab_divider_holo_light" />
<view
class="android.widget.SearchView"
android:id="@+id/search_view"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 960df1e..681b8db 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1321,7 +1321,7 @@
<string name="contact_directory_account_description">from <xliff:g id="type" example="Corporate Directory">%1$s</xliff:g> (<xliff:g id="name" example="me@acme.com">%2$s</xliff:g>)</string>
<!-- The label displayed in the Contacts action bar when in search mode [CHAR LIMIT=64] -->
- <string name="search_label">Searching all contact</string>
+ <string name="search_label">Searching all contacts</string>
<!-- The label in section header in the contact list for a contact directory [CHAR LIMIT=128] -->
<string name="directory_search_label">Directory</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e0ac68e..7c2fa78 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -188,7 +188,7 @@
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
</style>
-
+
<style name="CustomContactListFilterView" parent="CustomContactListFilterTheme">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index ec36356..a5d1114 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -18,6 +18,7 @@
import com.android.contacts.R;
import com.android.contacts.list.ContactListFilterController;
+import com.android.contacts.list.ContactListFilterController.ContactListFilterListener;
import com.android.contacts.list.ContactListFilterView;
import com.android.contacts.list.ContactsRequest;
@@ -35,7 +36,8 @@
/**
* Adapter for the action bar at the top of the Contacts activity.
*/
-public class ActionBarAdapter implements OnQueryChangeListener, OnCloseListener {
+public class ActionBarAdapter
+ implements OnQueryChangeListener, OnCloseListener, ContactListFilterListener {
public interface Listener {
void onAction();
@@ -60,6 +62,9 @@
private Listener mListener;
private ContactListFilterView mFilterView;
+ private View mFilterIndicator;
+ private ContactListFilterController mFilterController;
+ private View mFilterContainer;
public ActionBarAdapter(Context context) {
mContext = context;
@@ -80,16 +85,19 @@
mNavigationBar = LayoutInflater.from(mContext).inflate(R.layout.navigation_bar, null);
actionBar.setCustomNavigationMode(mNavigationBar);
+ mFilterContainer = mNavigationBar.findViewById(R.id.filter_container);
mFilterView = (ContactListFilterView) mNavigationBar.findViewById(R.id.filter_view);
mSearchLabel = (TextView) mNavigationBar.findViewById(R.id.search_label);
+ mFilterIndicator = mNavigationBar.findViewById(R.id.filter_indicator);
mSearchView = (SearchView) mNavigationBar.findViewById(R.id.search_view);
+
mSearchView.setIconifiedByDefault(false);
mSearchView.setEnabled(false);
mSearchView.setOnQueryChangeListener(this);
mSearchView.setOnCloseListener(this);
mSearchView.setQuery(mQueryString, false);
- updateVisibility();
+ update();
}
public void setListener(Listener listener) {
@@ -97,7 +105,9 @@
}
public void setContactListFilterController(ContactListFilterController controller) {
- controller.setFilterSpinner(mFilterView);
+ mFilterController = controller;
+ mFilterController.setAnchor(mFilterContainer);
+ mFilterController.addListener(this);
}
public boolean isSearchMode() {
@@ -107,7 +117,7 @@
public void setSearchMode(boolean flag) {
if (mSearchMode != flag) {
mSearchMode = flag;
- updateVisibility();
+ update();
if (mListener != null) {
mListener.onAction();
}
@@ -123,13 +133,21 @@
mSearchView.setQuery(query, false);
}
- public void updateVisibility() {
+ public void update() {
if (mSearchMode) {
mSearchLabel.setVisibility(View.VISIBLE);
mFilterView.setVisibility(View.GONE);
+ mFilterIndicator.setVisibility(View.INVISIBLE);
} else {
mSearchLabel.setVisibility(View.GONE);
mFilterView.setVisibility(View.VISIBLE);
+ boolean showIndicator = false;
+ if (mFilterController != null && mFilterController.isLoaded()) {
+ mFilterView.setContactListFilter(mFilterController.getFilter());
+ mFilterView.bindView(false);
+ showIndicator = mFilterController.getFilterList().size() > 1;
+ }
+ mFilterIndicator.setVisibility(showIndicator ? View.VISIBLE : View.INVISIBLE);
}
}
@@ -137,7 +155,7 @@
public boolean onQueryTextChanged(String queryString) {
mQueryString = queryString;
mSearchMode = !TextUtils.isEmpty(queryString);
- updateVisibility();
+ update();
if (mListener != null) {
mListener.onAction();
}
@@ -181,4 +199,18 @@
outState.putParcelable(KEY_MODE_SEARCH, mSavedStateForSearchMode);
}
}
+
+ @Override
+ public void onContactListFiltersLoaded() {
+ update();
+ }
+
+ @Override
+ public void onContactListFilterChanged() {
+ update();
+ }
+
+ @Override
+ public void onContactListFilterCustomizationRequest() {
+ }
}
diff --git a/src/com/android/contacts/list/ContactListFilterController.java b/src/com/android/contacts/list/ContactListFilterController.java
index 2b406a3..6553315 100644
--- a/src/com/android/contacts/list/ContactListFilterController.java
+++ b/src/com/android/contacts/list/ContactListFilterController.java
@@ -64,13 +64,13 @@
private Context mContext;
private LoaderManager mLoaderManager;
- private ContactListFilterListener mListener;
+ private List<ContactListFilterListener> mListeners = new ArrayList<ContactListFilterListener>();
private ListPopupWindow mPopup;
private int mPopupWidth = -1;
private SparseArray<ContactListFilter> mFilters;
private ArrayList<ContactListFilter> mFilterList;
private int mNextFilterId = 1;
- private ContactListFilterView mFilterView;
+ private View mAnchor;
private FilterListAdapter mFilterListAdapter;
private ContactListFilter mFilter;
private boolean mFiltersLoaded;
@@ -89,13 +89,17 @@
mLoaderManager = activity.getLoaderManager();
}
- public void setListener(ContactListFilterListener listener) {
- mListener = listener;
+ public void addListener(ContactListFilterListener listener) {
+ mListeners.add(listener);
}
- public void setFilterSpinner(ContactListFilterView filterSpinner) {
- mFilterView = filterSpinner;
- mFilterView.setOnClickListener(this);
+ public void removeListener(ContactListFilterListener listener) {
+ mListeners.remove(listener);
+ }
+
+ public void setAnchor(View anchor) {
+ mAnchor = anchor;
+ mAnchor.setOnClickListener(this);
}
public ContactListFilter getFilter() {
@@ -202,13 +206,11 @@
if (filterChanged) {
mFiltersLoaded = true;
- mListener.onContactListFilterChanged();
+ notifyContactListFilterChanged();
} else if (!mFiltersLoaded) {
mFiltersLoaded = true;
- mListener.onContactListFiltersLoaded();
+ notifyContacListFiltersLoaded();
}
-
- updateFilterView();
}
public void postDelayedRefresh() {
@@ -240,9 +242,8 @@
if (!filter.equals(mFilter)) {
mFilter = filter;
ContactListFilter.storeToPreferences(getSharedPreferences(), mFilter);
- updateFilterView();
- if (mListener != null) {
- mListener.onContactListFilterChanged();
+ if (mListeners != null) {
+ notifyContactListFilterChanged();
}
}
}
@@ -260,14 +261,14 @@
a.recycle();
if (mPopupWidth == -1) {
- mPopupWidth = mFilterView.getWidth();
+ mPopupWidth = mAnchor.getWidth();
}
}
mPopup = new ListPopupWindow(mContext, null);
mPopup.setWidth(mPopupWidth);
mPopup.setAdapter(mFilterListAdapter);
- mPopup.setAnchorView(mFilterView);
+ mPopup.setAnchorView(mAnchor);
mPopup.setOnItemClickListener(this);
mPopup.setModal(true);
mPopup.show();
@@ -277,7 +278,7 @@
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mPopup.dismiss();
if (mFilters.get((int) id).filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
- mListener.onContactListFilterCustomizationRequest();
+ notifyContactListFilterCustomizationRequest();
} else {
setContactListFilter((int) id);
}
@@ -285,18 +286,28 @@
public void selectCustomFilter() {
mFilter = new ContactListFilter(ContactListFilter.FILTER_TYPE_CUSTOM);
- updateFilterView();
- mListener.onContactListFilterChanged();
+ notifyContactListFilterChanged();
}
private ContactListFilter getDefaultFilter() {
return mFilters.size() > 0 ? mFilters.valueAt(0) : null;
}
- protected void updateFilterView() {
- if (mFiltersLoaded) {
- mFilterView.setContactListFilter(mFilter);
- mFilterView.bindView(false);
+ private void notifyContacListFiltersLoaded() {
+ for (ContactListFilterListener listener : mListeners) {
+ listener.onContactListFiltersLoaded();
+ }
+ }
+
+ private void notifyContactListFilterChanged() {
+ for (ContactListFilterListener listener : mListeners) {
+ listener.onContactListFilterChanged();
+ }
+ }
+
+ private void notifyContactListFilterCustomizationRequest() {
+ for (ContactListFilterListener listener : mListeners) {
+ listener.onContactListFilterCustomizationRequest();
}
}
diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
index 4d66dd2..bd43afc 100644
--- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java
@@ -57,7 +57,15 @@
public void setContactListFilterController(ContactListFilterController filterController) {
mFilterController = filterController;
- mFilterController.setListener(this);
+ mFilterController.addListener(this);
+ }
+
+ @Override
+ public void onDetach() {
+ if (mFilterController != null) {
+ mFilterController.removeListener(this);
+ }
+ super.onDetach();
}
@Override