From 32d580c360da0a0f15e7a080f4ebd0b7b514fe4c Mon Sep 17 00:00:00 2001 From: Bjorn Bringert Date: Wed, 6 Jan 2010 09:29:11 +0000 Subject: [PATCH] Copy SearchSourceSelector from QuickSearchBox The widget shows the icon for a search source, and when clicked fires an intent that shows a search source selection activity. That intent is handled by the QuickSearchBox app. This change also adds the source selector to the in-app search dialog. An upcoming change to QuickSearchBox will add the search source selector to the home screen search widget and to the Quick Search Box activity. TODO: Add assets for selected and pressed states to the search selector. TODO: The SearchDialog hides when the soruce selection activity appears. This will be fixed when SearchDialog is changed from a system window to a normal app window. Change-Id: I91eadd60682577614e274ecf5b995b927c70a48a --- api/current.xml | 11 + core/java/android/app/SearchDialog.java | 19 +- core/java/android/app/SearchManager.java | 10 + .../android/app/SearchSourceSelector.java | 197 ++++++++++++++++++ .../search_source_selector_indicator.png | Bin 0 -> 252 bytes .../search_source_selector_indicator.png | Bin 0 -> 195 bytes .../search_source_selector_background.xml | 21 ++ core/res/res/layout/search_bar.xml | 11 +- .../res/res/layout/search_source_selector.xml | 35 ++++ 9 files changed, 290 insertions(+), 14 deletions(-) create mode 100644 core/java/android/app/SearchSourceSelector.java create mode 100644 core/res/res/drawable-hdpi/search_source_selector_indicator.png create mode 100644 core/res/res/drawable-mdpi/search_source_selector_indicator.png create mode 100644 core/res/res/drawable/search_source_selector_background.xml create mode 100644 core/res/res/layout/search_source_selector.xml diff --git a/api/current.xml b/api/current.xml index cbe47ff7af6ae..64a7d7a29632d 100644 --- a/api/current.xml +++ b/api/current.xml @@ -23917,6 +23917,17 @@ visibility="public" > + + path = uri.getPathSegments(); + if (path == null || path.size() != 3) return null; + String pkg = path.get(1); + String cls = path.get(2); + if (TextUtils.isEmpty(pkg) || TextUtils.isEmpty(cls)) return null; + return new ComponentName(pkg, cls); + } + + public void onClick(View v) { + trigger(); + } + + private void trigger() { + try { + Intent intent = createIntent(mSource, mQuery, mAppSearchData); + intent.setSourceBounds(getOnScreenRect(mIconView)); + mIconView.getContext().startActivity(intent); + } catch (ActivityNotFoundException ex) { + Log.e(TAG, "No source selector activity found", ex); + } + } + + // TODO: This code is replicated in lots of places: + // - android.provider.ContactsContract.QuickContact.showQuickContact() + // - android.widget.RemoteViews.setOnClickPendingIntent() + // - com.android.launcher2.Launcher.onClick() + // - com.android.launcher.Launcher.onClick() + // - com.android.server.status.StatusBarService.Launcher.onClick() + private static Rect getOnScreenRect(View v) { + final float appScale = v.getResources().getCompatibilityInfo().applicationScale; + final int[] pos = new int[2]; + v.getLocationOnScreen(pos); + final Rect rect = new Rect(); + rect.left = (int) (pos[0] * appScale + 0.5f); + rect.top = (int) (pos[1] * appScale + 0.5f); + rect.right = (int) ((pos[0] + v.getWidth()) * appScale + 0.5f); + rect.bottom = (int) ((pos[1] + v.getHeight()) * appScale + 0.5f); + return rect; + } + +} diff --git a/core/res/res/drawable-hdpi/search_source_selector_indicator.png b/core/res/res/drawable-hdpi/search_source_selector_indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..b93a0c0bbfb33c70bfd4ec8ef5e1d8eab835568b GIT binary patch literal 252 zcmVXcblRu%&>ptrZz%--IDSr z1<%~X^wgl##FWaylc_d9MX8=Hjv*DdlK%YvZ_g~yz{#XAk8wrC`$ewZ|BQ`||F>ry zIxutQ%>V!Y{QNAxM55*Y<4YGVUHT-?^(djs(4^tT&(F^fi>zv#+r30$U1NLu^Z(!8 t-cICt_~}L0L8*KDYP%N-v@kO9FnsQu)X7!xGy`ZMgQu&X%Q~loCIA^}P~!jq literal 0 HcmV?d00001 diff --git a/core/res/res/drawable/search_source_selector_background.xml b/core/res/res/drawable/search_source_selector_background.xml new file mode 100644 index 0000000000000..fcacd892f3b70 --- /dev/null +++ b/core/res/res/drawable/search_source_selector_background.xml @@ -0,0 +1,21 @@ + + + + + + + + diff --git a/core/res/res/layout/search_bar.xml b/core/res/res/layout/search_bar.xml index cf246ba3906a4..12285fde6cee6 100644 --- a/core/res/res/layout/search_bar.xml +++ b/core/res/res/layout/search_bar.xml @@ -55,14 +55,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> - - + android:layout_gravity="center_vertical" /> + + + + + + +