Fix bug 4142917 - Add support for specifying a custom home icon in action bar

Add ActionBar methods for setting icon and logo.

Change-Id: I6151689138c734b7212c3469b8ba8f28f0fd5ec4
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index fc5fac6..a9e84d7 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -160,6 +160,66 @@
     public abstract void setCustomView(int resId);
 
     /**
+     * Set the icon to display in the 'home' section of the action bar.
+     * The action bar will use an icon specified by its style or the
+     * activity icon by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param resId Resource ID of a drawable to show as an icon.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setIcon(int resId);
+
+    /**
+     * Set the icon to display in the 'home' section of the action bar.
+     * The action bar will use an icon specified by its style or the
+     * activity icon by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param icon Drawable to show as an icon.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setIcon(Drawable icon);
+
+    /**
+     * Set the logo to display in the 'home' section of the action bar.
+     * The action bar will use a logo specified by its style or the
+     * activity logo by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param resId Resource ID of a drawable to show as a logo.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setLogo(int resId);
+
+    /**
+     * Set the logo to display in the 'home' section of the action bar.
+     * The action bar will use a logo specified by its style or the
+     * activity logo by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param logo Drawable to show as a logo.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setLogo(Drawable logo);
+
+    /**
      * Set the adapter and navigation callback for list navigation mode.
      *
      * The supplied adapter will provide views for the expanded list as well as
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 8f1354b..b712fdb 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -889,23 +889,24 @@
         return mTabs.get(index);
     }
 
-    /**
-     * This fragment is added when we're keeping a back stack in a tab switch
-     * transaction. We use it to change the selected tab in the action bar view
-     * when we back out.
-     */
-    private class SwitchSelectedTabViewFragment extends Fragment {
-        private int mSelectedTabIndex;
 
-        public SwitchSelectedTabViewFragment(int oldSelectedTab) {
-            mSelectedTabIndex = oldSelectedTab;
-        }
+    @Override
+    public void setIcon(int resId) {
+        mActionView.setIcon(mContext.getResources().getDrawable(resId));
+    }
 
-        @Override
-        public void onDetach() {
-            if (mSelectedTabIndex >= 0 && mSelectedTabIndex < getTabCount()) {
-                mActionView.setTabSelected(mSelectedTabIndex);
-            }
-        }
+    @Override
+    public void setIcon(Drawable icon) {
+        mActionView.setIcon(icon);
+    }
+
+    @Override
+    public void setLogo(int resId) {
+        mActionView.setLogo(mContext.getResources().getDrawable(resId));
+    }
+
+    @Override
+    public void setLogo(Drawable logo) {
+        mActionView.setLogo(logo);
     }
 }
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 81d02ee..2d9a9f2 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -416,6 +416,21 @@
         }
     }
 
+    public void setIcon(Drawable icon) {
+        mIcon = icon;
+        if (icon != null &&
+                ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) {
+            mIconView.setImageDrawable(icon);
+        }
+    }
+
+    public void setLogo(Drawable logo) {
+        mLogo = logo;
+        if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
+            mIconView.setImageDrawable(logo);
+        }
+    }
+
     public void setNavigationMode(int mode) {
         final int oldMode = mNavigationMode;
         if (mode != oldMode) {