New SearchView expansion using ActionBar feature.
Change-Id: Ib0a4bdc45af65fdeeb354ee02de02b251fec471d
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index 1fcf7ee..d1c848a 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -2003,6 +2003,16 @@
android:value=".app.SearchQueryResults" />
</activity>
+ <activity android:name=".view.SearchViewAlwaysVisible" android:label="Views/Search View/Always Expanded"
+ android:theme="@android:style/Theme.Holo">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.SAMPLE_CODE" />
+ </intent-filter>
+ <meta-data android:name="android.app.default_searchable"
+ android:value=".app.SearchQueryResults" />
+ </activity>
+
<activity android:name=".view.SearchViewFilterMode" android:label="Views/Search View/Filter"
android:theme="@android:style/Theme.Holo">
<intent-filter>
diff --git a/samples/ApiDemos/res/xml/searchable.xml b/samples/ApiDemos/res/xml/searchable.xml
index df4ef7a..a2d048a 100644
--- a/samples/ApiDemos/res/xml/searchable.xml
+++ b/samples/ApiDemos/res/xml/searchable.xml
@@ -19,8 +19,7 @@
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
- android:hint="@string/search_hint"
- android:searchMode="showSearchLabelAsBadge"
+ android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_form"
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/SearchViewActionBar.java b/samples/ApiDemos/src/com/example/android/apis/view/SearchViewActionBar.java
index 7488fcc..8ffa3b9 100644
--- a/samples/ApiDemos/src/com/example/android/apis/view/SearchViewActionBar.java
+++ b/samples/ApiDemos/src/com/example/android/apis/view/SearchViewActionBar.java
@@ -25,8 +25,10 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.Window;
+import android.view.MenuItem.OnActionExpandListener;
import android.widget.Button;
import android.widget.SearchView;
import android.widget.TextView;
@@ -65,15 +67,21 @@
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.searchview_in_menu, menu);
- mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
- setupSearchView();
+ MenuItem searchItem = menu.findItem(R.id.action_search);
+ mSearchView = (SearchView) searchItem.getActionView();
+ setupSearchView(searchItem);
return true;
}
- private void setupSearchView() {
+ private void setupSearchView(MenuItem searchItem) {
- mSearchView.setIconifiedByDefault(true);
+ if (isAlwaysExpanded()) {
+ mSearchView.setIconifiedByDefault(false);
+ } else {
+ searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM
+ | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
+ }
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
@@ -116,4 +124,8 @@
mSearchView.setIconified(false);
}
}
+
+ protected boolean isAlwaysExpanded() {
+ return false;
+ }
}
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/SearchViewAlwaysVisible.java b/samples/ApiDemos/src/com/example/android/apis/view/SearchViewAlwaysVisible.java
new file mode 100644
index 0000000..8c67563
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/view/SearchViewAlwaysVisible.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+package com.example.android.apis.view;
+
+import com.example.android.apis.R;
+
+import android.app.Activity;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.SearchView;
+import android.widget.TextView;
+
+import java.util.List;
+
+/**
+ * This demonstrates the usage of SearchView in an ActionBar as a menu item.
+ * It sets a SearchableInfo on the SearchView for suggestions and submitting queries to.
+ */
+public class SearchViewAlwaysVisible extends SearchViewActionBar {
+
+ @Override
+ protected boolean isAlwaysExpanded() {
+ return true;
+ }
+}