Update QSB visual design and branding

Change-Id: I0b0ee1fff121d3c825ff3d5d9379e4a076d9047d
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 82aa46e..c53e798 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -86,9 +86,6 @@
             <intent-filter>
                 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="com.android.quicksearchbox.UPDATE_SEARCH_WIDGETS" />
-            </intent-filter>
             <meta-data android:name="android.appwidget.provider" android:resource="@xml/search_widget_info" />
         </receiver>
 
diff --git a/res/drawable-hdpi/global_search_source.png b/res/drawable-hdpi/global_search_source.png
index 15c632d..10044a0 100644
--- a/res/drawable-hdpi/global_search_source.png
+++ b/res/drawable-hdpi/global_search_source.png
Binary files differ
diff --git a/res/drawable-hdpi/search_plate_global.9.png b/res/drawable-hdpi/search_plate_global.9.png
index 32c6dc3..e9f4f12 100644
--- a/res/drawable-hdpi/search_plate_global.9.png
+++ b/res/drawable-hdpi/search_plate_global.9.png
Binary files differ
diff --git a/res/drawable-hdpi/search_source_selector_indicator.png b/res/drawable-hdpi/search_source_selector_indicator.png
index b93a0c0..e81d9ac 100644
--- a/res/drawable-hdpi/search_source_selector_indicator.png
+++ b/res/drawable-hdpi/search_source_selector_indicator.png
Binary files differ
diff --git a/res/drawable-mdpi/global_search_source.png b/res/drawable-mdpi/global_search_source.png
index bbe742c..9bcc543 100644
--- a/res/drawable-mdpi/global_search_source.png
+++ b/res/drawable-mdpi/global_search_source.png
Binary files differ
diff --git a/res/drawable-mdpi/search_plate_global.9.png b/res/drawable-mdpi/search_plate_global.9.png
index 1cad902..bb7400e 100644
--- a/res/drawable-mdpi/search_plate_global.9.png
+++ b/res/drawable-mdpi/search_plate_global.9.png
Binary files differ
diff --git a/res/drawable-mdpi/search_source_selector_indicator.png b/res/drawable-mdpi/search_source_selector_indicator.png
index 26bf18a..b3efef2 100644
--- a/res/drawable-mdpi/search_source_selector_indicator.png
+++ b/res/drawable-mdpi/search_source_selector_indicator.png
Binary files differ
diff --git a/res/layout/search_bar.xml b/res/layout/search_bar.xml
index e03ee37..fdbed1f 100644
--- a/res/layout/search_bar.xml
+++ b/res/layout/search_bar.xml
@@ -38,6 +38,9 @@
         android:id="@+id/search_edit_frame"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:paddingLeft="4dip"
+        android:paddingRight="4dip"
+        android:paddingTop="4dip"
         android:layout_marginBottom="-10dip"
         android:orientation="horizontal"
         android:background="@drawable/search_plate_global"
@@ -51,16 +54,15 @@
 
         <EditText
             android:id="@+id/search_src_text"
-            android:background="@drawable/textfield_search"
-            android:layout_height="wrap_content"
             android:layout_width="0dip"
+            android:layout_height="wrap_content"
             android:layout_weight="1.0"
             android:layout_marginLeft="4dip"
-            android:drawablePadding="2dip"
+            android:layout_marginBottom="0dip"
             android:singleLine="true"
             android:ellipsize="end"
             android:inputType="text|textAutoComplete"
-            android:imeOptions="actionSearch"
+            android:imeOptions="actionGo"
         />
 
         <ImageButton 
@@ -69,13 +71,16 @@
             android:src="@drawable/ic_btn_search"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
+            android:layout_marginBottom="4dip"
+            android:visibility="gone"
         />
 
         <ImageButton
             android:id="@+id/search_voice_btn"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:layout_marginLeft="8dip"
+            android:layout_marginLeft="4dip"
+            android:layout_marginBottom="4dip"
             android:background="@drawable/btn_search_dialog_voice"
             android:src="@drawable/ic_btn_speak_now"
         />
diff --git a/res/layout/search_source_selector.xml b/res/layout/search_source_selector.xml
index c69dfc0..9312b08 100644
--- a/res/layout/search_source_selector.xml
+++ b/res/layout/search_source_selector.xml
@@ -16,10 +16,11 @@
 
 <FrameLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="48dip"
+    android:layout_width="42dip"
     android:layout_height="match_parent"
+    android:layout_marginBottom="2dip"
     android:foreground="@drawable/search_source_selector_indicator"
-    android:foregroundGravity="bottom|right"
+    android:foregroundGravity="bottom|center_horizontal"
     >
 
     <ImageButton
@@ -27,6 +28,7 @@
         android:background="@drawable/search_source_selector_background"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:layout_marginBottom="6dip"
         android:scaleType="centerInside"
         android:focusable="true"
         android:clickable="true"
diff --git a/res/layout/search_widget.xml b/res/layout/search_widget.xml
index 9a6e2c2..38a92d4 100644
--- a/res/layout/search_widget.xml
+++ b/res/layout/search_widget.xml
@@ -14,74 +14,47 @@
      limitations under the License.
 -->
 
-<RelativeLayout
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/widget_search"
+    android:id="@+id/search_plate"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="wrap_content"
+    android:orientation="horizontal"
+    android:paddingLeft="13dip"
+    android:paddingRight="13dip"
+    android:paddingTop="13dip"
+    android:paddingBottom="9dip"
+    android:background="@drawable/search_floater" >
 
-    <!-- Shortcuts come first to give it lower z-index. -->
-    <LinearLayout
-        android:id="@+id/widget_shortcuts"
-        android:layout_width="match_parent"
-        android:layout_height="56dip"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentRight="true"
-        android:layout_alignParentBottom="true"
-        android:layout_marginTop="-10dip"
-        android:layout_marginLeft="10dip"
-        android:layout_marginRight="10dip"
-        android:orientation="horizontal"
-        android:gravity="bottom|left"
-        android:paddingLeft="14dip"
-        android:paddingRight="14dip"
-        android:paddingTop="13dip"
-        android:paddingBottom="12dip"
-        android:background="@drawable/search_floater"
-        android:visibility="invisible"
-        >
-    </LinearLayout>
+    <include android:id="@+id/widget_search_source_selector"
+        layout="@layout/search_source_selector" />
 
-    <LinearLayout
-        android:id="@+id/search_plate"
-        android:layout_width="match_parent"
+    <TextView
+        android:id="@+id/search_widget_text"
+        android:layout_width="0dip"
         android:layout_height="wrap_content"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentRight="true"
-        android:layout_alignParentTop="true"
-        android:orientation="horizontal"
-        android:paddingLeft="14dip"
-        android:paddingRight="14dip"
-        android:paddingTop="13dip"
-        android:paddingBottom="12dip"
-        android:background="@drawable/search_floater" >
+        android:layout_weight="1.0"
+        android:layout_marginLeft="4dip"
+        android:layout_marginBottom="0dip"
+        android:singleLine="true"
+        android:ellipsize="end"
+        android:editable="false"
+        android:focusable="true"
+        android:inputType="none"
+        android:hint="@string/search_widget_hint"
+        android:background="@android:drawable/edit_text"
+        android:textAppearance="?android:attr/textAppearanceMediumInverse"
+        android:textColor="@android:color/primary_text_light"
+    />
 
-        <include android:id="@+id/widget_search_source_selector"
-            layout="@layout/search_source_selector" />
+    <ImageButton
+        android:id="@+id/search_widget_voice_btn"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_marginLeft="4dip"
+        android:layout_marginBottom="4dip"
+        android:background="@drawable/btn_search_dialog_voice"
+        android:src="@drawable/ic_btn_speak_now"
+    />
 
-        <TextView
-            android:id="@+id/search_widget_text"
-            android:layout_width="0dip"
-            android:layout_height="42dip"
-            android:layout_weight="1.0"
-            android:editable="false"
-            android:focusable="true"
-            android:inputType="none"
-            android:hint="@string/search_widget_hint"
-            android:background="@drawable/textfield_searchwidget"
-            android:textAppearance="?android:attr/textAppearanceMediumInverse"
-            android:textColor="@android:color/primary_text_light"
-        />
-
-        <ImageButton
-            android:id="@+id/search_widget_voice_btn"
-            android:layout_width="wrap_content"
-            android:layout_height="42dip"
-            android:layout_marginLeft="4dip"
-            android:background="@drawable/btn_search_dialog_voice"
-            android:src="@drawable/ic_btn_speak_now"
-        />
-
-    </LinearLayout>
-
-</RelativeLayout>
+</LinearLayout>
diff --git a/res/layout/select_search_source.xml b/res/layout/select_search_source.xml
index 2116bb0..6c386b8 100644
--- a/res/layout/select_search_source.xml
+++ b/res/layout/select_search_source.xml
@@ -14,13 +14,30 @@
      limitations under the License.
 -->
 
-<GridView
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/source_list"
+    android:id="@+id/select_search_source_frame"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/select_search_source_bg"
-    android:numColumns="4"
-    android:horizontalSpacing="8dip"
-    android:verticalSpacing="8dip"
+    android:orientation="vertical"
+    >
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="4dip"
+        android:text="@string/search_source_list_heading"
     />
+
+    <GridView
+        android:id="@+id/source_list"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top|left"
+        android:numColumns="4"
+        android:horizontalSpacing="8dip"
+        android:verticalSpacing="8dip"
+        />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 70d3d64..9c95e48 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -18,10 +18,11 @@
     <string name="app_name">Quick Search Box</string>
 
     <!-- Search widget -->
-    <string name="search_widget">Quick Search Box</string>
-    <string name="search_widget_hint">Quick Search Box</string>
+    <string name="search_widget">Search</string>
+    <string name="search_widget_hint">Search</string>
 
     <!-- Source selector -->
+    <string name="search_source_list_heading">Search in:</string>
     <string name="global_search_label">Everything</string>
 
     <!-- Search settings stuff -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 4cf4109..812f65c 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -19,8 +19,16 @@
         <item name="android:windowAnimationStyle">@null</item>
     </style>
 
-    <style name="Theme.SelectSearchSource" parent="@android:style/Theme.Light.Panel">
+    <style name="Theme.SelectSearchSource" parent="@android:style/Theme.Light.NoTitleBar">
+        <item name="android:colorBackgroundCacheHint">@null</item>
+        <item name="android:windowFrame">@null</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowIsFloating">true</item>
+        <item name="android:backgroundDimEnabled">true</item>
+        <item name="android:windowIsTranslucent">true</item>
+
         <item name="android:windowAnimationStyle">@null</item>
+        <item name="android:windowBackground">@android:color/transparent</item>
     </style>
 
 </resources>
diff --git a/src/com/android/quicksearchbox/SearchActivity.java b/src/com/android/quicksearchbox/SearchActivity.java
index 8aad4e4..4c9dacc 100644
--- a/src/com/android/quicksearchbox/SearchActivity.java
+++ b/src/com/android/quicksearchbox/SearchActivity.java
@@ -176,8 +176,6 @@
 
     private void setLastSelectedSource(Source source) {
         getSources().setLastSelectedSource(source);
-        // Update search widgets to show the new source.
-        SearchWidgetProvider.updateSearchWidgets(this);
     }
 
     private Source getSourceByName(String sourceNameStr) {
@@ -359,8 +357,6 @@
         if (DBG) Log.d(TAG, "Launching suggestion " + suggestion);
         mLauncher.launchSuggestion(suggestion, actionKey, actionMsg);
         getShortcutRepository().reportClick(suggestion);
-        // Update search widgets, since the top shortcuts can have changed.
-        SearchWidgetProvider.updateSearchWidgets(this);
         return true;
     }
 
diff --git a/src/com/android/quicksearchbox/SearchWidgetProvider.java b/src/com/android/quicksearchbox/SearchWidgetProvider.java
index 615781b..5a1e07b 100644
--- a/src/com/android/quicksearchbox/SearchWidgetProvider.java
+++ b/src/com/android/quicksearchbox/SearchWidgetProvider.java
@@ -43,42 +43,11 @@
     private static final boolean DBG = true;
     private static final String TAG = "QSB.SearchWidgetProvider";
 
-    private static final boolean SHOW_SHORTCUT_IN_WIDGET = false;
-
-    private static final String ACTION_UPDATE_SEARCH_WIDGETS =
-            "com.android.quicksearchbox.UPDATE_SEARCH_WIDGETS";
-
     private static final String WIDGET_SEARCH_SOURCE = "launcher-search";
-    private static final String WIDGET_SEARCH_SHORTCUT_SOURCE = "launcher-search-shortcut";
 
     // TODO: Expose SearchManager.SOURCE instead.
     private static final String SOURCE = "source";
 
-    /**
-     * Updates all search widgets.
-     */
-    public static void updateSearchWidgets(Context context) {
-        Intent intent = new Intent(ACTION_UPDATE_SEARCH_WIDGETS);
-        intent.setPackage(context.getPackageName());
-        if (DBG) Log.d(TAG, "Broadcasting " + intent);
-        context.sendBroadcast(intent);
-    }
-
-    @Override
-    public void onReceive(Context context, Intent intent) {
-        String action = intent.getAction();
-        if (ACTION_UPDATE_SEARCH_WIDGETS.equals(action)) {
-            // We requested the update. Find the widgets and update them.
-            AppWidgetManager manager = AppWidgetManager.getInstance(context);
-            ComponentName self = new ComponentName(context, getClass());
-            int[] appWidgetIds = manager.getAppWidgetIds(self);
-            onUpdate(context, manager, appWidgetIds);
-        } else {
-            // Handle actions requested by the widget host.
-            super.onReceive(context, intent);
-        }
-    }
-
     @Override
     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
         updateSearchWidgets(context, appWidgetManager, appWidgetIds);
@@ -121,36 +90,9 @@
             views.setViewVisibility(R.id.search_widget_voice_btn, View.GONE);
         }
 
-        // Shortcuts
-        if (SHOW_SHORTCUT_IN_WIDGET) {
-            bindShortcuts(context, views);
-        }
-
         appWidgetManager.updateAppWidget(appWidgetIds, views);
     }
 
-    private void bindShortcuts(Context context, RemoteViews views) {
-        ShortcutRepository shortcutRepo = getShortcutRepository(context);
-        SuggestionCursor shortcuts = shortcutRepo.getShortcutsForQuery("");
-        try {
-            if (shortcuts != null && shortcuts.getCount() > 0) {
-                shortcuts.moveTo(0);
-                RemoteViews shortcutView = new RemoteViews(context.getPackageName(),
-                        R.layout.widget_suggestion);
-                bindRemoteViewSuggestion(context, shortcutView, shortcuts);
-                views.addView(R.id.widget_shortcuts, shortcutView);
-                views.setViewVisibility(R.id.widget_shortcuts, View.VISIBLE);
-            } else {
-                if (DBG) Log.d(TAG, "No shortcuts, hiding drop-down.");
-                views.setViewVisibility(R.id.widget_shortcuts, View.GONE);
-            }
-        } finally {
-            if (shortcuts != null) {
-                shortcuts.close();
-            }
-        }
-    }
-
     private void bindSourceSelector(Context context, RemoteViews views, Bundle widgetAppData) {
         Source source = getSources(context).getLastSelectedSource();
         Uri sourceIconUri = getSourceIconUri(context, source);
@@ -167,46 +109,6 @@
         return source.getSourceIconUri();
     }
 
-    private void bindRemoteViewSuggestion(Context context, RemoteViews views,
-            SuggestionCursor suggestion) {
-        CharSequence text1 = suggestion.getSuggestionFormattedText1();
-        CharSequence text2 = suggestion.getSuggestionFormattedText2();
-        Uri icon1 = suggestion.getIconUri(suggestion.getSuggestionIcon1());
-        if (icon1 == null) {
-            icon1 = suggestion.getSourceIconUri();
-        }
-        Uri icon2 = suggestion.getIconUri(suggestion.getSuggestionIcon2());
-        PendingIntent pendingIntent = getWidgetSuggestionIntent(context, suggestion);
-        if (DBG) {
-            Log.d(TAG, "Adding shortcut to widget: text1=" + text1 + ",text2=" + text2
-                    + ",icon1=" + icon1 + ",icon2=" + icon2);
-            Log.d(TAG, "    intent=" + pendingIntent);
-        }
-        setText1(views, text1);
-        setIcon1(views, icon1);
-        setPendingIntent(views, pendingIntent);
-    }
-
-    private PendingIntent getWidgetSuggestionIntent(Context context, SuggestionCursor suggestion) {
-        Bundle widgetAppData = new Bundle();
-        widgetAppData.putString(SOURCE, WIDGET_SEARCH_SHORTCUT_SOURCE);
-        Intent intent = suggestion.getSuggestionIntent(context, widgetAppData,
-                KeyEvent.KEYCODE_UNKNOWN, null);
-        return PendingIntent.getActivity(context, 0, intent, 0);
-    }
-
-    private void setText1(RemoteViews views, CharSequence text) {
-        views.setCharSequence(R.id.text1, "setText", text);
-    }
-
-    private void setIcon1(RemoteViews views, Uri icon) {
-        views.setImageViewUri(R.id.icon1, icon);
-    }
-
-    private void setPendingIntent(RemoteViews views, PendingIntent pendingIntent) {
-        views.setOnClickPendingIntent(R.id.widget_suggestion, pendingIntent);
-    }
-
     private QsbApplication getQsbApplication(Context context) {
         return (QsbApplication) context.getApplicationContext();
     }
@@ -215,10 +117,6 @@
         return getQsbApplication(context).getSources();
     }
 
-    private ShortcutRepository getShortcutRepository(Context context) {
-        return getQsbApplication(context).getShortcutRepository();
-    }
-
     private SuggestionViewFactory getSuggestionViewFactory(Context context) {
         return getQsbApplication(context).getSuggestionViewFactory();
     }
diff --git a/src/com/android/quicksearchbox/SelectSearchSourceActivity.java b/src/com/android/quicksearchbox/SelectSearchSourceActivity.java
index c48f03c..82dded1 100644
--- a/src/com/android/quicksearchbox/SelectSearchSourceActivity.java
+++ b/src/com/android/quicksearchbox/SelectSearchSourceActivity.java
@@ -70,34 +70,29 @@
 
     private void handleIntent(Intent intent) {
         if (DBG) Log.d(TAG, "handleIntent(" + getIntent().toUri(0) + ")");
-        setupWindow(intent.getSourceBounds());
         updateSources();
+        positionWindow(intent.getSourceBounds());
     }
 
-    private void setupWindow(Rect target) {
-        if (target == null) {
-            Log.w(TAG, "No source bounds in intent.");
-            target = new Rect(0,0,0,0);
-        }
-        if (DBG) Log.d(TAG, "Source bounds: " + target);
-
+    private void positionWindow(Rect target) {
+        if (DBG) Log.d(TAG, "target: " + target);
         Window window = getWindow();
-        WindowManager windowManager = window.getWindowManager();
-        int screenWidth = windowManager.getDefaultDisplay().getWidth();
-        int screenHeight = windowManager.getDefaultDisplay().getHeight();
-        if (DBG) Log.d(TAG, "Screen size: " + screenWidth + "x" + screenHeight);
 
         WindowManager.LayoutParams lp = window.getAttributes();
         // TODO: Get these offsets from the position of the bubble arrow
-        int offsetX = 30;
-        int offsetY = 0;
-        lp.x = target.centerX() - offsetX;
-        lp.y = target.centerY() - offsetY;
-        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
-        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+        // TODO: These need to be scaled to the device density
+        int offsetX = 0;
+        int offsetY = 10;
+        lp.x = 0;
+        lp.y = target.bottom - offsetY;
         lp.gravity = Gravity.TOP | Gravity.LEFT;
-        lp.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
-                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
+        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
+        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+        // Use screen coordinates
+        lp.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
+        lp.flags |=  WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
+        // Put window on top of input method
+        lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
         window.setAttributes(lp);
         if (DBG) Log.d(TAG, "Window params: " + lp);
     }
diff --git a/src/com/android/quicksearchbox/ShortcutRepositoryImplLog.java b/src/com/android/quicksearchbox/ShortcutRepositoryImplLog.java
index 26986a8..2d6f237 100644
--- a/src/com/android/quicksearchbox/ShortcutRepositoryImplLog.java
+++ b/src/com/android/quicksearchbox/ShortcutRepositoryImplLog.java
@@ -183,11 +183,6 @@
     public void clearHistory() {
         SQLiteDatabase db = getOpenHelper().getWritableDatabase();
         getOpenHelper().clearDatabase(db);
-        // TODO: We should probably have a content provider for
-        // the shortcuts instead. Then the SearchWidgetProvider
-        // could register an observer to update the widget
-        // shortcuts whenever they change.
-        SearchWidgetProvider.updateSearchWidgets(mContext);
     }
 
     public void deleteRepository() {