Backed out changeset 7c080e5f472b (bug 895423)
authorTim Taubert <ttaubert@mozilla.com>
Sat, 03 Aug 2013 04:14:58 -0700
changeset 148814 be38edff7bd2bc0f0e3cdb27a4a13a4854b5edc3
parent 148813 bed26baa08d9315119989dafa2087afb0e1d2af4
child 148815 a1d3cff2fc9883bf2f1a8389b6b4ea54186a9f42
push idunknown
push userunknown
push dateunknown
bugs895423
milestone25.0a1
backs out7c080e5f472b9eef329f67c4cbcd642ee4eecf6b
Backed out changeset 7c080e5f472b (bug 895423)
mobile/android/base/Makefile.in
mobile/android/base/preferences/SearchEnginePreference.java
mobile/android/base/resources/layout/preference_search_engine.xml
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -469,17 +469,16 @@ RES_LAYOUT = \
   res/layout/launch_app_listitem.xml \
   res/layout/menu_action_bar.xml \
   res/layout/menu_item_action_view.xml \
   res/layout/menu_popup.xml \
   res/layout/notification_icon_text.xml \
   res/layout/notification_progress.xml \
   res/layout/notification_progress_text.xml \
   res/layout/preference_rightalign_icon.xml \
-  res/layout/preference_search_engine.xml \
   res/layout/preference_search_tip.xml \
   res/layout/search_engine_row.xml \
   res/layout/site_setting_item.xml \
   res/layout/site_setting_title.xml \
   res/layout/shared_ui_components.xml \
   res/layout/site_identity.xml \
   res/layout/suggestion_item.xml \
   res/layout/remote_tabs_child.xml \
--- a/mobile/android/base/preferences/SearchEnginePreference.java
+++ b/mobile/android/base/preferences/SearchEnginePreference.java
@@ -9,36 +9,32 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Build;
 import android.preference.Preference;
 import android.text.SpannableString;
 import android.util.Log;
-import android.view.View;
 import android.widget.TextView;
 import android.widget.Toast;
 import org.json.JSONException;
 import org.json.JSONObject;
-import org.mozilla.gecko.Favicons;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.util.ThreadUtils;
-import org.mozilla.gecko.widget.FaviconView;
 
 /**
  * Represents an element in the list of search engines on the preferences menu.
  */
 public class SearchEnginePreference extends Preference {
     private static final String LOGTAG = "SearchEnginePreference";
 
     // Dimensions, in dp, of the icon to display for this engine.
     public static int sIconSize;
-    public static int sDialogIconSize;
 
     // Indices in button array of the AlertDialog of the three buttons.
     public static final int INDEX_SET_DEFAULT_BUTTON = 0;
     public static final int INDEX_REMOVE_BUTTON = 1;
 
     // Cache label to avoid repeated use of the resource system.
     public final String LABEL_IS_DEFAULT;
 
@@ -50,41 +46,31 @@ public class SearchEnginePreference exte
     // Dialog element labels.
     private String[] mDialogItems;
 
     // The popup displayed when this element is tapped.
     private AlertDialog mDialog;
 
     private final SearchPreferenceCategory mParentCategory;
 
-    // The icon to display in the prompt when clicked.
-    private BitmapDrawable mPromptIcon;
-    // The bitmap backing the drawable above - needed seperately for the FaviconView.
-    private Bitmap mIconBitmap;
-
     /**
      * Create a preference object to represent a search engine that is attached to category
      * containingCategory.
      * @param context The activity context we operate under.
      * @param parentCategory The PreferenceCategory this object exists within.
      * @see this.setSearchEngine
      */
     public SearchEnginePreference(Context context, SearchPreferenceCategory parentCategory) {
         super(context);
         mParentCategory = parentCategory;
 
         Resources res = getContext().getResources();
 
-        // Set the layout resource for this preference - includes a FaviconView
-        setLayoutResource(R.layout.preference_search_engine);
-
-        // Fetch the dimensions we want to upscale miniscule favicons to.
-        sIconSize = (int) res.getDimension(R.dimen.awesomebar_row_favicon_size_small);
-        sDialogIconSize = (int) res.getDimension(R.dimen.awesomebar_row_favicon_size_large);
-
+        // Fetch the icon dimensions from the resource file.
+        sIconSize = res.getDimensionPixelSize(R.dimen.searchpreferences_icon_size);
         setOnPreferenceClickListener(new OnPreferenceClickListener() {
             @Override
             public boolean onPreferenceClick(Preference preference) {
                 SearchEnginePreference sPref = (SearchEnginePreference) preference;
                 sPref.showDialog();
 
                 return true;
             }
@@ -94,49 +80,39 @@ public class SearchEnginePreference exte
         LABEL_IS_DEFAULT = res.getString(R.string.pref_search_default);
 
         // Set up default dialog items.
         mDialogItems = new String[] { res.getString(R.string.pref_search_set_default),
                                       res.getString(R.string.pref_search_remove) };
     }
 
     /**
-    * Called by android when we're bound to the custom view. Allows us to set the custom properties
-    * of our custom view elements as we desire (We can now use findViewById on them).
-    * @param view The view instance for this Preference object.
-    */
-    @Override
-    protected void onBindView(View view) {
-        super.onBindView(view);
-        // Set the icon in the FaviconView
-        ((FaviconView) view.findViewById(R.id.search_engine_icon)).updateImage(mIconBitmap, getTitle().toString());
-    }
-
-    /**
      * Configure this Preference object from the Gecko search engine JSON object.
      * @param geckoEngineJSON The Gecko-formatted JSON object representing the search engine.
      * @throws JSONException If the JSONObject is invalid.
      */
     public void setSearchEngineFromJSON(JSONObject geckoEngineJSON) throws JSONException {
         final String engineName = geckoEngineJSON.getString("name");
         SpannableString titleSpannable = new SpannableString(engineName);
         mIsImmutableEngine = geckoEngineJSON.getBoolean("immutable");
 
         if (mIsImmutableEngine) {
             // Delete the "Remove" option from the menu.
             mDialogItems = new String[] { getContext().getResources().getString(R.string.pref_search_set_default) };
         }
         setTitle(titleSpannable);
 
-        String iconURI = geckoEngineJSON.getString("iconURI");
-        // Keep a reference to the bitmap - we'll need it later in onBindView.
-        mIconBitmap = BitmapUtils.getBitmapFromDataURI(iconURI);
-        // For the really tiny favicons, upscale them to 16x16 (Otherwise you can hardly see them)
-        if (!Favicons.getInstance().isLargeFavicon(mIconBitmap)) {
-            mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, sIconSize, sIconSize, false);
+        // setIcon is only available on Honeycomb and up.
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+            // Create a drawable from the iconURI and assign it to this Preference for display.
+            String iconURI = geckoEngineJSON.getString("iconURI");
+            Bitmap iconBitmap = BitmapUtils.getBitmapFromDataURI(iconURI);
+            Bitmap scaledIconBitmap = Bitmap.createScaledBitmap(iconBitmap, sIconSize, sIconSize, false);
+            BitmapDrawable drawable = new BitmapDrawable(scaledIconBitmap);
+            setIcon(drawable);
         }
     }
 
     /**
      * Set if this object's UI should show that this is the default engine.
      * @param isDefault Flag indicating if this represents the default engine.
      */
     public void setIsDefaultEngine(boolean isDefault) {
@@ -191,22 +167,20 @@ public class SearchEnginePreference exte
                         break;
                     default:
                         Log.w(LOGTAG, "Selected index out of range.");
                         break;
                 }
             }
         });
 
-        // Copy the icon from this object to the prompt we produce. We lazily create the drawable,
-        // as the user may not ever actually tap this object.
-        if (mPromptIcon == null) {
-            mPromptIcon = new BitmapDrawable(Bitmap.createScaledBitmap(mIconBitmap, sDialogIconSize, sDialogIconSize, false));
+        // Copy the icon, if any, from this object to the prompt we produce.
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+            builder.setIcon(getIcon());
         }
-        builder.setIcon(mPromptIcon);
 
         // We have to construct the dialog itself on the UI thread.
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 mDialog = builder.create();
                 mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
                     // Called when the dialog is shown (so we're finally able to manipulate button enabledness).
deleted file mode 100644
--- a/mobile/android/base/resources/layout/preference_search_engine.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="fill_parent"
-    android:layout_height="wrap_content"
-    android:minHeight="?android:attr/listPreferredItemHeight"
-    android:gravity="center_vertical"
-    android:paddingRight="?android:attr/scrollbarSize">
-
-    <org.mozilla.gecko.widget.FaviconView
-        android:id="@+id/search_engine_icon"
-        android:layout_width="@dimen/favicon_bg"
-        android:layout_height="@dimen/favicon_bg"
-        android:layout_centerVertical="true"
-        android:layout_gravity="center"
-        android:minWidth="@dimen/favicon_bg"
-        android:minHeight="@dimen/favicon_bg" />
-
-    <RelativeLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginLeft="15dip"
-        android:layout_marginRight="6dip"
-        android:layout_marginTop="6dip"
-        android:layout_marginBottom="6dip"
-        android:layout_weight="1">
-
-       <TextView android:id="@+android:id/title"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:singleLine="true"
-            android:textAppearance="@style/TextAppearance"
-            android:ellipsize="marquee"
-            android:fadingEdge="horizontal" />
-
-       <TextView android:id="@+android:id/summary"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@android:id/title"
-            android:layout_alignLeft="@android:id/title"
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:maxLines="2" />
-
-   </RelativeLayout>
-
-</LinearLayout>