summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2011-03-22 14:13:34 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-03-22 14:13:34 -0700
commite9f66af90a886cc55fc20c14375d8572bdf6dbd3 (patch)
tree3a395b1da798649cf0565415b32c3f238631c835
parentaceaa225608930011f10950fe2dc319e95e9e200 (diff)
parent1969b8799085322f9ef6e75b78c2c9a5d5944801 (diff)
downloadframeworks_base-e9f66af90a886cc55fc20c14375d8572bdf6dbd3.zip
frameworks_base-e9f66af90a886cc55fc20c14375d8572bdf6dbd3.tar.gz
frameworks_base-e9f66af90a886cc55fc20c14375d8572bdf6dbd3.tar.bz2
Merge "Fix bug 4142917 - Add support for specifying a custom home icon in action bar"
-rw-r--r--api/current.xml52
-rw-r--r--core/java/android/app/ActionBar.java60
-rw-r--r--core/java/com/android/internal/app/ActionBarImpl.java33
-rw-r--r--core/java/com/android/internal/widget/ActionBarView.java15
4 files changed, 144 insertions, 16 deletions
diff --git a/api/current.xml b/api/current.xml
index 16ba6be..3305a32 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -22045,6 +22045,32 @@
<parameter name="useLogo" type="boolean">
</parameter>
</method>
+<method name="setIcon"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="resId" type="int">
+</parameter>
+</method>
+<method name="setIcon"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="icon" type="android.graphics.drawable.Drawable">
+</parameter>
+</method>
<method name="setListNavigationCallbacks"
return="void"
abstract="true"
@@ -22060,6 +22086,32 @@
<parameter name="callback" type="android.app.ActionBar.OnNavigationListener">
</parameter>
</method>
+<method name="setLogo"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="resId" type="int">
+</parameter>
+</method>
+<method name="setLogo"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="logo" type="android.graphics.drawable.Drawable">
+</parameter>
+</method>
<method name="setNavigationMode"
return="void"
abstract="true"
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 class ActionBar {
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 @@ public class ActionBarImpl extends ActionBar {
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 class ActionBarView extends ViewGroup {
}
}
+ 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) {