Bug 808663 - Use new favicon style for search providers. r=bnicholson
authorWes Johnston <wjohnston@mozilla.com>
Thu, 15 Nov 2012 19:16:35 -0800
changeset 113467 acd75423cc39d30ba214d354241bd75d355db5dc
parent 113466 f3b9e6da96f25a3da2b88e3effe356ea09a5ab23
child 113468 9f48d082d7d079e51b444c3b863a2fc95c60cc64
push id18166
push userwjohnston@mozilla.com
push dateFri, 16 Nov 2012 03:16:55 +0000
treeherdermozilla-inbound@2d3acb8280f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs808663
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808663 - Use new favicon style for search providers. r=bnicholson
mobile/android/base/awesomebar/AllPagesTab.java
mobile/android/base/resources/layout/awesomebar_suggestion_row.xml.in
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -22,16 +22,17 @@ import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.Drawable;
 import android.os.AsyncTask;
 import android.os.Handler;
 import android.os.Message;
 import android.os.SystemClock;
 import android.text.TextUtils;
+import android.util.Base64;
 import android.util.Log;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
 import android.view.animation.TranslateAnimation;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
@@ -455,17 +456,17 @@ public class AllPagesTab extends Awesome
                         return true;
                     }
                     return false;
                 }
             };
 
             // set the search engine icon (e.g., Google) for the row
             FlowLayout suggestionView = viewHolder.suggestionView;
-            viewHolder.iconView.setImageDrawable(engine.icon);
+            updateFavicon(viewHolder.iconView, engine.icon);
 
             // user-entered search term is first suggestion
             viewHolder.userEnteredTextView.setText(mSearchTerm);
             viewHolder.userEnteredView.setOnClickListener(clickListener);
             
             // add additional suggestions given by this engine
             int recycledSuggestionCount = suggestionView.getChildCount();
             int suggestionCount = engine.suggestions.size();
@@ -505,24 +506,24 @@ public class AllPagesTab extends Awesome
 
             if (showedSuggestions)
                 mAnimateSuggestions = false;
         }
     };
 
     private class SearchEngine {
         public String name;
-        public Drawable icon;
+        public Bitmap icon;
         public ArrayList<String> suggestions;
 
         public SearchEngine(String name) {
             this(name, null);
         }
 
-        public SearchEngine(String name, Drawable icon) {
+        public SearchEngine(String name, Bitmap icon) {
             this.name = name;
             this.icon = icon;
             this.suggestions = new ArrayList<String>();
         }
     };
 
     /**
      * Sets suggestions associated with the current suggest engine.
@@ -547,17 +548,17 @@ public class AllPagesTab extends Awesome
             boolean suggestionsPrompted = suggest.getBoolean("prompted");
             JSONArray engines = data.getJSONArray("searchEngines");
 
             mSearchEngines = new ArrayList<SearchEngine>();
             for (int i = 0; i < engines.length(); i++) {
                 JSONObject engineJSON = engines.getJSONObject(i);
                 String name = engineJSON.getString("name");
                 String iconURI = engineJSON.getString("iconURI");
-                Drawable icon = getDrawableFromDataURI(iconURI);
+                Bitmap icon = getBitmapFromDataURI(iconURI);
                 if (name.equals(suggestEngine) && suggestTemplate != null) {
                     // suggest engine should be at the front of the list
                     mSearchEngines.add(0, new SearchEngine(name, icon));
                     mSuggestClient = new SuggestClient(GeckoApp.mAppContext, suggestTemplate, SUGGESTION_TIMEOUT, SUGGESTION_MAX);
                 } else {
                     mSearchEngines.add(new SearchEngine(name, icon));
                 }
             }
@@ -569,28 +570,19 @@ public class AllPagesTab extends Awesome
         } catch (JSONException e) {
             Log.e(LOGTAG, "Error getting search engine JSON", e);
         }
 
         mCursorAdapter.notifyDataSetChanged();
         filterSuggestions(mSearchTerm);
     }
 
-    private Drawable getDrawableFromDataURI(String dataURI) {
-        String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
-        Drawable drawable = null;
-        try {
-            byte[] bytes = GeckoAppShell.decodeBase64(base64, GeckoAppShell.BASE64_DEFAULT);
-            ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
-            drawable = Drawable.createFromStream(stream, "src");
-            stream.close();
-        } catch (IllegalArgumentException e) {
-            Log.i(LOGTAG, "exception while decoding drawable: " + base64, e);
-        } catch (IOException e) { }
-        return drawable;
+    private Bitmap getBitmapFromDataURI(String dataURI) {
+        byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
+        return BitmapFactory.decodeByteArray(raw, 0, raw.length);
     }
 
     private void showSuggestionsOptIn() {
         mSuggestionsOptInPrompt = LayoutInflater.from(mContext).inflate(R.layout.awesomebar_suggestion_prompt, (LinearLayout)getView(), false);
         ((TextView) mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_title))
                 .setText(getResources().getString(R.string.suggestions_prompt, mSearchEngines.get(0).name));
         mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_yes).setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
--- a/mobile/android/base/resources/layout/awesomebar_suggestion_row.xml.in
+++ b/mobile/android/base/resources/layout/awesomebar_suggestion_row.xml.in
@@ -7,23 +7,24 @@
 <org.mozilla.gecko.AnimatedHeightLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:gecko="http://schemas.android.com/apk/res/@ANDROID_PACKAGE_NAME@"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:minHeight="@dimen/awesomebar_row_height"
                 android:padding="7dip">
 
     <ImageView android:id="@+id/suggestion_icon"
-               android:layout_width="32dip"
-               android:layout_height="32dip"
+               android:layout_width="@dimen/awesomebar_row_favicon_bg"
+               android:layout_height="@dimen/awesomebar_row_favicon_bg"
                android:layout_marginLeft="6dip"
                android:layout_marginRight="6dip"
-               android:minWidth="32dip"
-               android:minHeight="32dip"
-               android:scaleType="fitCenter"/>
+               android:minWidth="@dimen/awesomebar_row_favicon_bg"
+               android:minHeight="@dimen/awesomebar_row_favicon_bg"
+               android:scaleType="center"
+               android:background="@drawable/awesomebar_row_favicon_bg"/>
 
     <org.mozilla.gecko.FlowLayout android:id="@+id/suggestion_layout"
                                   android:layout_toRightOf="@id/suggestion_icon"
                                   android:layout_width="wrap_content"
                                   android:layout_height="wrap_content">
 
         <include layout="@layout/awesomebar_suggestion_item"
                  android:id="@+id/suggestion_user_entered"/>