diff options
author | Adam Powell <adamp@google.com> | 2010-08-11 17:26:10 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-11 17:26:10 -0700 |
commit | 943fbb4f4006273ae5983da42143d721ae05dfd4 (patch) | |
tree | d51436252fab6758c38ac10c1ae2f52c35223df8 | |
parent | 73b77af86131cd4dad16c32ba1898028ce08da36 (diff) | |
parent | 6b336f835d637853800b94689375a03f337139a4 (diff) | |
download | frameworks_base-943fbb4f4006273ae5983da42143d721ae05dfd4.zip frameworks_base-943fbb4f4006273ae5983da42143d721ae05dfd4.tar.gz frameworks_base-943fbb4f4006273ae5983da42143d721ae05dfd4.tar.bz2 |
Merge "ActionBar overlay mode, height fetching, show/hide"
-rw-r--r-- | api/current.xml | 70 | ||||
-rw-r--r-- | core/java/android/app/ActionBar.java | 29 | ||||
-rw-r--r-- | core/java/android/view/Window.java | 14 | ||||
-rw-r--r-- | core/java/com/android/internal/app/ActionBarImpl.java | 21 | ||||
-rw-r--r-- | core/java/com/android/internal/view/menu/ActionMenuView.java | 3 | ||||
-rw-r--r-- | core/java/com/android/internal/widget/ActionBarView.java | 11 | ||||
-rw-r--r-- | core/res/res/layout-xlarge/screen_action_bar_overlay.xml | 47 | ||||
-rw-r--r-- | core/res/res/layout/screen_action_bar_overlay.xml | 53 | ||||
-rwxr-xr-x | core/res/res/values/attrs.xml | 10 | ||||
-rw-r--r-- | core/res/res/values/public.xml | 1 | ||||
-rw-r--r-- | core/res/res/values/styles.xml | 2 | ||||
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneWindow.java | 10 |
12 files changed, 262 insertions, 9 deletions
diff --git a/api/current.xml b/api/current.xml index 64ac66f..dbbdb7b 100644 --- a/api/current.xml +++ b/api/current.xml @@ -10580,6 +10580,17 @@ visibility="public" > </field> +<field name="windowActionBarOverlay" + type="int" + transient="false" + volatile="false" + value="16843558" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="windowActionBarStyle" type="int" transient="false" @@ -20936,6 +20947,17 @@ visibility="public" > </method> +<method name="getHeight" + return="int" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="getNavigationMode" return="int" abstract="true" @@ -20980,6 +21002,17 @@ visibility="public" > </method> +<method name="hide" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="insertTab" return="void" abstract="true" @@ -20995,6 +21028,17 @@ <parameter name="position" type="int"> </parameter> </method> +<method name="isShowing" + return="boolean" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <method name="newTab" return="android.app.ActionBar.Tab" abstract="true" @@ -21287,6 +21331,17 @@ <parameter name="resId" type="int"> </parameter> </method> +<method name="show" + return="void" + abstract="true" + native="false" + synchronized="false" + static="false" + final="false" + deprecated="not deprecated" + visibility="public" +> +</method> <field name="DISPLAY_HIDE_HOME" type="int" transient="false" @@ -201148,7 +201203,7 @@ visibility="public" > </field> -<field name="FEATURE_ACTION_MODE_OVERLAY" +<field name="FEATURE_ACTION_BAR_OVERLAY" type="int" transient="false" volatile="false" @@ -201159,6 +201214,17 @@ visibility="public" > </field> +<field name="FEATURE_ACTION_MODE_OVERLAY" + type="int" + transient="false" + volatile="false" + value="10" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="FEATURE_CONTEXT_MENU" type="int" transient="false" @@ -201185,7 +201251,7 @@ type="int" transient="false" volatile="false" - value="10" + value="11" static="true" final="true" deprecated="not deprecated" diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java index d33494b..38086f0 100644 --- a/core/java/android/app/ActionBar.java +++ b/core/java/android/app/ActionBar.java @@ -18,6 +18,7 @@ package android.app; import android.graphics.drawable.Drawable; import android.view.View; +import android.view.Window; import android.widget.SpinnerAdapter; /** @@ -383,6 +384,34 @@ public abstract class ActionBar { public abstract void selectTab(Tab tab); /** + * Retrieve the current height of the ActionBar. + * + * @return The ActionBar's height + */ + public abstract int getHeight(); + + /** + * Show the ActionBar if it is not currently showing. + * If the window hosting the ActionBar does not have the feature + * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application + * content to fit the new space available. + */ + public abstract void show(); + + /** + * Hide the ActionBar if it is not currently showing. + * If the window hosting the ActionBar does not have the feature + * {@link Window#FEATURE_ACTION_BAR_OVERLAY} it will resize application + * content to fit the new space available. + */ + public abstract void hide(); + + /** + * @return <code>true</code> if the ActionBar is showing, <code>false</code> otherwise. + */ + public abstract boolean isShowing(); + + /** * Callback interface for ActionBar navigation events. */ public interface NavigationCallback { diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index f32ff77..36f6bb2 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -64,14 +64,24 @@ public abstract class Window { */ public static final int FEATURE_ACTION_BAR = 8; /** + * Flag for requesting an Action Bar that overlays window content. + * Normally an Action Bar will sit in the space above window content, but if this + * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over + * the window content itself. This is useful if you would like your app to have more control + * over how the Action Bar is displayed, such as letting application content scroll beneath + * an Action Bar with a transparent background or otherwise displaying a transparent/translucent + * Action Bar over application content. + */ + public static final int FEATURE_ACTION_BAR_OVERLAY = 9; + /** * Flag for specifying the behavior of action modes when an Action Bar is not present. * If overlay is enabled, the action mode UI will be allowed to cover existing window content. */ - public static final int FEATURE_ACTION_MODE_OVERLAY = 9; + public static final int FEATURE_ACTION_MODE_OVERLAY = 10; /** * Flag for requesting this window to be hardware accelerated, if possible. */ - public static final int FEATURE_HARDWARE_ACCELERATED = 10; + public static final int FEATURE_HARDWARE_ACCELERATED = 11; /** Flag for setting the progress bar's visibility to VISIBLE */ public static final int PROGRESS_VISIBILITY_ON = -1; /** Flag for setting the progress bar's visibility to GONE */ diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 6b52409..0be42d6 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -397,6 +397,27 @@ public class ActionBarImpl extends ActionBar { trans.commit(); } + @Override + public int getHeight() { + return mActionView.getHeight(); + } + + @Override + public void show() { + // TODO animate! + mAnimatorView.setVisibility(View.VISIBLE); + } + + @Override + public void hide() { + // TODO animate! + mAnimatorView.setVisibility(View.GONE); + } + + public boolean isShowing() { + return mAnimatorView.getVisibility() == View.VISIBLE; + } + /** * @hide */ diff --git a/core/java/com/android/internal/view/menu/ActionMenuView.java b/core/java/com/android/internal/view/menu/ActionMenuView.java index 1357251..d00a99e 100644 --- a/core/java/com/android/internal/view/menu/ActionMenuView.java +++ b/core/java/com/android/internal/view/menu/ActionMenuView.java @@ -20,6 +20,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.util.AttributeSet; +import android.view.Gravity; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.LinearLayout; @@ -82,6 +83,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo if (p instanceof LayoutParams) { LayoutParams lp = (LayoutParams) p; return lp.leftMargin == mItemMargin && lp.rightMargin == mItemMargin && + lp.gravity == Gravity.CENTER_VERTICAL && lp.width == LayoutParams.WRAP_CONTENT && lp.height == LayoutParams.WRAP_CONTENT; } return false; @@ -93,6 +95,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo LayoutParams.WRAP_CONTENT); params.leftMargin = mItemMargin; params.rightMargin = mItemMargin; + params.gravity = Gravity.CENTER_VERTICAL; return params; } diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index c641441..3c40bb0 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -118,7 +118,6 @@ public class ActionBarView extends ViewGroup { super(context, attrs); final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - mContentHeight = (int) (CONTENT_HEIGHT_DIP * metrics.density + 0.5f); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar); @@ -157,14 +156,18 @@ public class ActionBarView extends ViewGroup { LayoutInflater inflater = LayoutInflater.from(context); mCustomNavView = (View) inflater.inflate(customNavId, null); mNavigationMode = ActionBar.NAVIGATION_MODE_CUSTOM; + addView(mCustomNavView); } + final int padding = a.getDimensionPixelSize(R.styleable.ActionBar_padding, + (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f)); + setPadding(padding, padding, padding, padding); + mContentHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, + (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f)) - padding * 2; + a.recycle(); // TODO: Set this in the theme - int padding = (int) (CONTENT_PADDING_DIP * metrics.density + 0.5f); - setPadding(padding, padding, padding, padding); - mSpacing = (int) (CONTENT_SPACING_DIP * metrics.density + 0.5f); mActionSpacing = (int) (CONTENT_ACTION_SPACING_DIP * metrics.density + 0.5f); diff --git a/core/res/res/layout-xlarge/screen_action_bar_overlay.xml b/core/res/res/layout-xlarge/screen_action_bar_overlay.xml new file mode 100644 index 0000000..d0277f0 --- /dev/null +++ b/core/res/res/layout-xlarge/screen_action_bar_overlay.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- +This is an optimized layout for a screen with +the Action Bar enabled overlaying application content. +--> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:fitsSystemWindows="true"> + <FrameLayout android:id="@android:id/content" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + <ViewAnimator android:id="@+id/action_bar_animator" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="top" + android:inAnimation="@anim/push_down_in" + android:outAnimation="@anim/push_down_out"> + <com.android.internal.widget.ActionBarView + android:id="@+id/action_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="?android:attr/windowActionBarStyle" /> + <com.android.internal.widget.ActionBarContextView + android:id="@+id/action_context_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </ViewAnimator> + <ImageView android:src="?android:attr/windowContentOverlay" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/action_bar_animator" /> +</RelativeLayout> diff --git a/core/res/res/layout/screen_action_bar_overlay.xml b/core/res/res/layout/screen_action_bar_overlay.xml new file mode 100644 index 0000000..cb1ffc5 --- /dev/null +++ b/core/res/res/layout/screen_action_bar_overlay.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- +This is an optimized layout for a screen with +the Action Bar enabled overlaying application content. +--> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:fitsSystemWindows="true"> + <FrameLayout android:id="@android:id/content" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + <ViewAnimator android:id="@+id/action_bar_animator" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="top" + android:inAnimation="@anim/push_down_in" + android:outAnimation="@anim/push_down_out"> + <com.android.internal.widget.ActionBarView + android:id="@+id/action_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="?android:attr/windowActionBarStyle" /> + <com.android.internal.widget.ActionBarContextView + android:id="@+id/action_context_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </ViewAnimator> + <ImageView android:src="?android:attr/windowContentOverlay" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/action_bar_animator" /> + <LinearLayout android:id="@+id/lower_action_context_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + style="?android:attr/windowActionBarStyle" + android:visibility="gone" /> +</RelativeLayout> diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 97c5822..a8c7842 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -248,6 +248,11 @@ in place of the usual title bar. --> <attr name="windowActionBar" format="boolean" /> + <!-- Flag indicating whether this window's Action Bar should overlay + application content. Does nothing if the window would not + have an Action Bar. --> + <attr name="windowActionBarOverlay" format="boolean" /> + <!-- Reference to a style for the Action Bar --> <attr name="windowActionBarStyle" format="reference" /> @@ -999,6 +1004,7 @@ <attr name="windowActionBar" /> <attr name="windowActionBarStyle" /> <attr name="windowActionModeOverlay" /> + <attr name="windowActionBarOverlay" /> </declare-styleable> <!-- The set of attributes that describe a AlertDialog's theme. --> @@ -3987,6 +3993,10 @@ <attr name="background" /> <!-- Specifies a layout for custom navigation. Overrides navigationMode. --> <attr name="customNavigationLayout" format="reference" /> + <!-- Specifies a fixed height. --> + <attr name="height" /> + <!-- Specifies padding around all sides. --> + <attr name="padding" /> </declare-styleable> </resources> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 99263d7..dee1cbc 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1315,6 +1315,7 @@ <public type="attr" name="propertyName" /> <public type="attr" name="ordering" /> <public type="attr" name="fragment" /> + <public type="attr" name="windowActionBarOverlay" /> <public type="id" name="home" /> <!-- Context menu ID for the "Select text..." menu item to switch to text diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index e0dc3a9..0e7509e 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -889,6 +889,8 @@ <item name="android:background">@android:drawable/action_bar_background</item> <item name="android:displayOptions">useLogo</item> <item name="android:divider">@android:drawable/action_bar_divider</item> + <item name="android:height">56dip</item> + <item name="android:padding">3dip</item> </style> <style name="Widget.ActionButton"> diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 8a6428b..9e4015b 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -2247,6 +2247,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { requestFeature(FEATURE_ACTION_BAR); } + if (a.getBoolean(com.android.internal.R.styleable.Window_windowActionBarOverlay, false)) { + requestFeature(FEATURE_ACTION_BAR_OVERLAY); + } + if (a.getBoolean(com.android.internal.R.styleable.Window_windowActionModeOverlay, false)) { requestFeature(FEATURE_ACTION_MODE_OVERLAY); } @@ -2333,7 +2337,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { if (mIsFloating) { layoutResource = com.android.internal.R.layout.dialog_title; } else if ((features & (1 << FEATURE_ACTION_BAR)) != 0) { - layoutResource = com.android.internal.R.layout.screen_action_bar; + if ((features & (1 << FEATURE_ACTION_BAR_OVERLAY)) != 0) { + layoutResource = com.android.internal.R.layout.screen_action_bar_overlay; + } else { + layoutResource = com.android.internal.R.layout.screen_action_bar; + } } else { layoutResource = com.android.internal.R.layout.screen_title; } |