From 18fdcb6de7e1268ed6e5c7664b2c838fe9d494ae Mon Sep 17 00:00:00 2001 From: Mike LeBeau Date: Mon, 20 Jul 2009 17:40:46 -0700 Subject: [PATCH] Display a Google logo in the search widget if Google is the chosen web search provider. Listen for broadcasts of that setting changing to correctly update the widget as appropriate. --- res/drawable/placeholder_google.png | Bin 0 -> 3729 bytes src/com/android/launcher/Search.java | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 res/drawable/placeholder_google.png diff --git a/res/drawable/placeholder_google.png b/res/drawable/placeholder_google.png new file mode 100644 index 0000000000000000000000000000000000000000..bc72d347d8c47e3aac700a43038282df707ca024 GIT binary patch literal 3729 zcmV;C4sP*@P)4Tx0C)kNmUmPX*B8g%%xo{TU6vwc>AklFq%OTkl_mFQv@x1^BM1TV}0C2duqR=S6Xn?LjUp6xrb&~O43j*Nv zEr418u3H3zGns$s|L;SQD-ufpfWpxLJ03rmi*g~#S@{x?OrJ!Vo{}kJ7$ajbnjp%m zGEV!%=70KpVow?KvV}a4moSaFCQKV= zXBIPnpP$8-NG!rR+)R#`$7JVZi#Wn10DSspSrkx`)s~4C+0n+?(b2-z5-tDd^^cpM zz5W?wz5V3zGUCskL5!X++LzcbT23thtSPiMTfS&1I{|204}j|3FPi>70OSh+Xzlyz zdl<5LNtZ}OE>>3g`T3RtKG#xK(9i3CI(+v0d-&=+OWAp!Ysd8Ar*foO5~i%E+?=c& zshF87;&Ay)i~kOm zCIB-Z!^JGdti+UJsxgN!t(Y#%b<8kk67vyD#cE*9urAm@Y#cTXn~yERR$}Y1E!Yd# zo7hq8Ya9;8z!~A3Z~?e@Tn26#t`xT$*Ni)h>&K1Yrto;Y8r}@=h7ZGY@Dh9xekcA2 z{tSKqKZ<`tAQQ9+wgf*y0zpVvOQ<9qCY&Y=5XJ~ILHOG0j2XwBQ%7jM`P2tv~{#P+6CGu9Y;5!2hua>CG_v;z4S?CC1rc%807-x z8s$^ULkxsr$OvR)G0GUn7`GVjR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!blr2xdFvyqp5EecFz>oX%kMaF{mg5C0g0WoZ1?! zm(W1>K{vQ-(9OyHU=M1Cwb{81A=*hyRpBJ}pu6mDFpH4^u+H*H;vKJw7r8=V zJ6w!KGgNfK))kwA51>br$Dt);FiOFyswGP03c|yO`ZHYj*RrRrI~|WyHR{&`izZ&0Gf@@M{Lt58?>1k?|m_T8?w z0^|RI0c(PlZu-ZnrgP}WBKKFyL^og3rjFvqp+eJDH4tWr8D~aKBZ8(HqNb}o_5ZC$ zn8FoJ1v{(RGYMVkIR5BXL#K+i_C%|r%{1MBaS~`(37snXQ=wv%*18N>+hb7SvoTn; v?bMo9hez4~^h5}FntXtMBq_XWFE#xKIXMV?i^JWf00000NkvXXu0mjfL983R literal 0 HcmV?d00001 diff --git a/src/com/android/launcher/Search.java b/src/com/android/launcher/Search.java index 96c0022..a0402a9 100644 --- a/src/com/android/launcher/Search.java +++ b/src/com/android/launcher/Search.java @@ -16,13 +16,20 @@ package com.android.launcher; +import android.app.SearchManager; import android.content.ActivityNotFoundException; +import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Configuration; +import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.server.search.SearchableInfo; +import android.server.search.Searchables; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; @@ -68,6 +75,10 @@ public class Search extends LinearLayout // For voice searching private Intent mVoiceSearchIntent; + + private Drawable mGooglePlaceholder; + + private SearchManager mSearchManager; /** * Used to inflate the Workspace from XML. @@ -129,6 +140,8 @@ public class Search extends LinearLayout mVoiceSearchIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH); mVoiceSearchIntent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); + + mSearchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE); } /** @@ -293,6 +306,10 @@ public class Search extends LinearLayout mSearchText = (TextView) findViewById(R.id.search_src_text); mVoiceButton = (ImageButton) findViewById(R.id.search_voice_btn); + + mGooglePlaceholder = getContext().getResources().getDrawable(R.drawable.placeholder_google); + mContext.registerReceiver(mBroadcastReceiver, + new IntentFilter(SearchManager.INTENT_ACTION_SEARCH_SETTINGS_CHANGED)); mSearchText.setOnKeyListener(this); @@ -304,6 +321,13 @@ public class Search extends LinearLayout mVoiceButton.setOnLongClickListener(this); configureVoiceSearchButton(); + setUpTextField(); + } + + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (mBroadcastReceiver != null) getContext().unregisterReceiver(mBroadcastReceiver); } /** @@ -323,6 +347,28 @@ public class Search extends LinearLayout // finally, set visible state of voice search button, as appropriate mVoiceButton.setVisibility(voiceSearchVisible ? View.VISIBLE : View.GONE); } + + /** + * Sets up the look of the text field. If Google is the chosen search provider, includes + * a Google logo as placeholder. + */ + private void setUpTextField() { + boolean showGooglePlaceholder = false; + SearchableInfo webSearchSearchable = mSearchManager.getDefaultSearchableForWebSearch(); + if (webSearchSearchable != null) { + ComponentName webSearchComponent = webSearchSearchable.getSearchActivity(); + if (webSearchComponent != null) { + String componentString = webSearchComponent.flattenToShortString(); + if (Searchables.ENHANCED_GOOGLE_SEARCH_COMPONENT_NAME.equals(componentString) || + Searchables.GOOGLE_SEARCH_COMPONENT_NAME.equals(componentString)) { + showGooglePlaceholder = true; + } + } + } + + mSearchText.setCompoundDrawablesWithIntrinsicBounds( + showGooglePlaceholder ? mGooglePlaceholder : null, null, null, null); + } /** * Sets the {@link Launcher} that this gadget will call on to display the search dialog. @@ -330,6 +376,17 @@ public class Search extends LinearLayout public void setLauncher(Launcher launcher) { mLauncher = launcher; } + + // Broadcast receiver for web search provider change notifications + private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (SearchManager.INTENT_ACTION_SEARCH_SETTINGS_CHANGED.equals(action)) { + setUpTextField(); + } + } + }; /** * Moves the view to the top left corner of its parent. -- 2.11.0