Get rid of the extended themes.
We now decide whether to use a bitmap background based on whether the
window's drawing is hardware accelerated. To do this, there is a new
"state_accelerated" that state list drawables can be parameterized on,
and the standard window background uses this to select a solid color
or bitmap drawable as appropriate.
Introduces a little hackery to have wm preview windows pretend like
they are hardware accelerated even if they aren't, so the preview looks
closer to the actual app.
Also Add a DialogWhenLarge variation for the light theme.
Change-Id: I215a79d5df65ba3eed52ab363cade9d8218a6588
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index a54f342..dd0f477 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -79,7 +79,7 @@
void executeAppTransition();
void setAppStartingWindow(IBinder token, String pkg, int theme,
CharSequence nonLocalizedLabel, int labelRes,
- int icon, IBinder transferFrom, boolean createIfNeeded);
+ int icon, int windowFlags, IBinder transferFrom, boolean createIfNeeded);
void setAppWillBeHidden(IBinder token);
void setAppVisibility(IBinder token, boolean visible);
void startAppFreezingScreen(IBinder token, int configChanges);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 026f1a0..be49255 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -1258,6 +1258,7 @@
static final int VIEW_STATE_ENABLED = 1 << 3;
static final int VIEW_STATE_PRESSED = 1 << 4;
static final int VIEW_STATE_ACTIVATED = 1 << 5;
+ static final int VIEW_STATE_ACCELERATED = 1 << 6;
static final int[] VIEW_STATE_IDS = new int[] {
R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED,
@@ -1266,9 +1267,14 @@
R.attr.state_enabled, VIEW_STATE_ENABLED,
R.attr.state_pressed, VIEW_STATE_PRESSED,
R.attr.state_activated, VIEW_STATE_ACTIVATED,
+ R.attr.state_accelerated, VIEW_STATE_ACCELERATED,
};
static {
+ if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) {
+ throw new IllegalStateException(
+ "VIEW_STATE_IDs array length does not match ViewDrawableStates style array");
+ }
int[] orderedIds = new int[VIEW_STATE_IDS.length];
for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) {
int viewState = R.styleable.ViewDrawableStates[i];
@@ -7176,6 +7182,8 @@
//System.out.println("Attached! " + this);
mAttachInfo = info;
mWindowAttachCount++;
+ // We will need to evaluate the drawable state at least once.
+ mPrivateFlags |= DRAWABLE_STATE_DIRTY;
if (mFloatingTreeObserver != null) {
info.mTreeObserver.merge(mFloatingTreeObserver);
mFloatingTreeObserver = null;
@@ -7190,6 +7198,10 @@
if (vis != GONE) {
onWindowVisibilityChanged(vis);
}
+ if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) {
+ // If nobody has evaluated the drawable state yet, then do it now.
+ refreshDrawableState();
+ }
}
void dispatchDetachedFromWindow() {
@@ -8562,6 +8574,12 @@
if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED;
if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED;
if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED;
+ if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested) {
+ // This is set if HW acceleration is requested, even if the current
+ // process doesn't allow it. This is just to allow app preview
+ // windows to better match their app.
+ viewStateIndex |= VIEW_STATE_ACCELERATED;
+ }
drawableState = VIEW_STATE_SETS[viewStateIndex];
@@ -10503,6 +10521,7 @@
Surface mSurface;
boolean mHardwareAccelerated;
+ boolean mHardwareAccelerationRequested;
HardwareRenderer mHardwareRenderer;
/**
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index e04916f..1972692 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -467,19 +467,25 @@
}
private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) {
- // Only enable hardware acceleration if we are not in the system process
- // The window manager creates ViewRoots to display animated preview windows
- // of launching apps and we don't want those to be hardware accelerated
- if (!HardwareRenderer.sRendererDisabled) {
- // Try to enable hardware acceleration if requested
- if (attrs != null &&
- (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {
+ mAttachInfo.mHardwareAccelerated = false;
+ mAttachInfo.mHardwareAccelerationRequested = false;
+
+ // Try to enable hardware acceleration if requested
+ if (attrs != null &&
+ (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {
+ // Only enable hardware acceleration if we are not in the system process
+ // The window manager creates ViewRoots to display animated preview windows
+ // of launching apps and we don't want those to be hardware accelerated
+ if (!HardwareRenderer.sRendererDisabled) {
final boolean translucent = attrs.format != PixelFormat.OPAQUE;
if (mAttachInfo.mHardwareRenderer != null) {
mAttachInfo.mHardwareRenderer.destroy(true);
}
mAttachInfo.mHardwareRenderer = HardwareRenderer.createGlRenderer(2, translucent);
- mAttachInfo.mHardwareAccelerated = mAttachInfo.mHardwareRenderer != null;
+ mAttachInfo.mHardwareAccelerated = mAttachInfo.mHardwareAccelerationRequested
+ = mAttachInfo.mHardwareRenderer != null;
+ } else if (HardwareRenderer.isAvailable()) {
+ mAttachInfo.mHardwareAccelerationRequested = true;
}
}
}
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 9fadc58..d5d9a2e 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -428,6 +428,10 @@
mHardwareAccelerated = hardwareAccelerated;
}
+ public boolean isHardwareAccelerated() {
+ return mHardwareAccelerated;
+ }
+
public final void addView(View view, ViewGroup.LayoutParams params) {
// Let this throw an exception on a bad params.
WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params;
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index c657a1c..f9e7d18 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -65,6 +65,14 @@
*/
public void removeViewImmediate(View view);
+ /**
+ * Return true if this window manager is configured to request hardware
+ * accelerated windows. This does <em>not</em> guarantee that they will
+ * actually be accelerated, since that depends on the device supporting them.
+ * @hide
+ */
+ public boolean isHardwareAccelerated();
+
public static class LayoutParams extends ViewGroup.LayoutParams
implements Parcelable {
/**
diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java
index 0973599..07953d6 100644
--- a/core/java/android/view/WindowManagerImpl.java
+++ b/core/java/android/view/WindowManagerImpl.java
@@ -80,6 +80,10 @@
return mWindowManager;
}
+ public boolean isHardwareAccelerated() {
+ return false;
+ }
+
public void addView(View view)
{
addView(view, new WindowManager.LayoutParams(
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index 4deff5e..5a9cd97 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -473,6 +473,7 @@
* no data is found in the resource.
* @param labelRes The resource ID the application would like to use as its name.
* @param icon The resource ID the application would like to use as its icon.
+ * @param windowFlags Window layout flags.
*
* @return Optionally you can return the View that was used to create the
* window, for easy removal in removeStartingWindow.
@@ -481,7 +482,7 @@
*/
public View addStartingWindow(IBinder appToken, String packageName,
int theme, CharSequence nonLocalizedLabel,
- int labelRes, int icon);
+ int labelRes, int icon, int windowFlags);
/**
* Called when the first window of an application has been displayed, while
diff --git a/core/res/res/drawable/screen_background_selector_dark.xml b/core/res/res/drawable/screen_background_selector_dark.xml
new file mode 100644
index 0000000..2a81669
--- /dev/null
+++ b/core/res/res/drawable/screen_background_selector_dark.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_accelerated="false"
+ android:drawable="@android:drawable/screen_background_dark" />
+ <item android:drawable="@android:drawable/background_holo_dark" />
+</selector>
diff --git a/core/res/res/drawable/screen_background_selector_light.xml b/core/res/res/drawable/screen_background_selector_light.xml
new file mode 100644
index 0000000..6992cad
--- /dev/null
+++ b/core/res/res/drawable/screen_background_selector_light.xml
@@ -0,0 +1,21 @@
+<?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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_accelerated="false"
+ android:drawable="@android:drawable/screen_background_light" />
+ <item android:drawable="@android:drawable/background_holo_light" />
+</selector>
diff --git a/core/res/res/values-large/themes.xml b/core/res/res/values-large/themes.xml
index cdf58fe..8f9b03d 100644
--- a/core/res/res/values-large/themes.xml
+++ b/core/res/res/values-large/themes.xml
@@ -19,4 +19,6 @@
<resources>
<style name="Theme.Holo.DialogWhenLarge" parent="@android:style/Theme.Holo.Dialog">
</style>
+ <style name="Theme.Holo.Light.DialogWhenLarge" parent="@android:style/Theme.Holo.Light.Dialog">
+ </style>
</resources>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 65a580b..9348822 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -34,9 +34,11 @@
<!-- Color that matches (as closely as possible) the window background. -->
<attr name="colorBackground" format="color" />
<!-- This is a hint for a solid color that can be used for caching
- rendered views. This will be the color of the background when
- there is a solid background color; it will be null when the
- background is a texture or translucent. -->
+ rendered views. This should be the color of the background when
+ there is a solid background color; it should be null when the
+ background is a texture or translucent. When a device is able
+ to use accelerated drawing (thus setting state_accelerated), the
+ cache hint is ignored and always assumed to be transparent. -->
<attr name="colorBackgroundCacheHint" format="color" />
<!-- Default disabled alpha for widgets that set enabled/disabled alpha programmatically. -->
<attr name="disabledAlpha" format="float" />
@@ -227,8 +229,13 @@
<!-- ============= -->
<eat-comment />
- <!-- Drawable to use as the overall window background. There are a
- few special considerations you should use when settings this
+ <!-- Drawable to use as the overall window background. As of
+ {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this may
+ be a selector that uses state_accelerated to pick a non-solid
+ color when running on devices that can draw such a bitmap
+ with complex compositing on top at 60fps.
+
+ <p>There are a few special considerations to use when setting this
drawable:
<ul>
<li> This information will be used to infer the pixel format
@@ -3396,16 +3403,24 @@
marked it as being of interest. This is an alternative representation of
state_checked for when the state should be propagated down the view hierarchy. -->
<attr name="state_activated" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_active" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_single" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_first" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_middle" format="boolean" />
- <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable}.-->
<attr name="state_last" format="boolean" />
+ <!-- State value for {@link android.graphics.drawable.StateListDrawable StateListDrawable},
+ indicating that the Drawable is in a view that is hardware accelerated.
+ This means that the device can at least render a full-screen scaled
+ bitmap with one layer of text and bitmaps composited on top of it
+ at 60fps. When this is set, the colorBackgroundCacheHint will be
+ ignored even if it specifies a solid color, since that optimization
+ is not needed. -->
+ <attr name="state_accelerated" format="boolean" />
</declare-styleable>
<declare-styleable name="ViewDrawableStates">
<attr name="state_pressed" />
@@ -3414,6 +3429,7 @@
<attr name="state_window_focused" />
<attr name="state_enabled" />
<attr name="state_activated" />
+ <attr name="state_accelerated" />
</declare-styleable>
<!-- State array representing a menu item that is currently checked. -->
<declare-styleable name="MenuItemCheckedState">
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 3eb980f..6e14527 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1375,6 +1375,7 @@
<public type="attr" name="indeterminateProgressStyle" />
<public type="attr" name="progressBarPadding" />
<public type="attr" name="animationResolution" />
+ <public type="attr" name="state_accelerated" />
<public type="anim" name="animator_fade_in" />
<public type="anim" name="animator_fade_out" />
@@ -1442,6 +1443,7 @@
<public type="style" name="Widget.FragmentBreadCrumbs" />
<public type="style" name="Theme.Holo.DialogWhenLarge" />
+ <public type="style" name="Theme.Holo.Light.DialogWhenLarge" />
<public type="string" name="selectTextMode" />
</resources>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 8082f6b..88e755f 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -123,7 +123,7 @@
<item name="galleryItemBackground">@android:drawable/gallery_item_background</item>
<!-- Window attributes -->
- <item name="windowBackground">@android:drawable/screen_background_dark</item>
+ <item name="windowBackground">@android:drawable/screen_background_selector_dark</item>
<item name="windowFrame">@null</item>
<item name="windowNoTitle">false</item>
<item name="windowFullscreen">false</item>
@@ -279,7 +279,7 @@
default theme, you should try to assume little more than that the
background will be a light color. -->
<style name="Theme.Light">
- <item name="windowBackground">@drawable/screen_background_light</item>
+ <item name="windowBackground">@android:drawable/screen_background_selector_light</item>
<item name="colorBackground">@android:color/background_light</item>
<item name="colorForeground">@color/bright_foreground_light</item>
<item name="colorForegroundInverse">@android:color/bright_foreground_light_inverse</item>
@@ -736,7 +736,6 @@
<item name="galleryItemBackground">@android:drawable/gallery_item_background</item>
<!-- Window attributes -->
- <item name="windowBackground">?android:attr/colorBackground</item>
<item name="windowFrame">@null</item>
<item name="windowNoTitle">false</item>
<item name="windowFullscreen">false</item>
@@ -972,7 +971,6 @@
<item name="galleryItemBackground">@android:drawable/gallery_item_background</item>
<!-- Window attributes -->
- <item name="windowBackground">?android:attr/colorBackground</item>
<item name="windowFrame">@null</item>
<item name="windowNoTitle">false</item>
<item name="windowFullscreen">false</item>
@@ -1220,6 +1218,12 @@
<item name="textAppearanceInverse">@android:style/TextAppearance.Holo.Light.Inverse</item>
</style>
+ <!-- Theme for a window that will be displayed either full-screen on
+ smaller screens (small, normal) or as a dialog on larger screens
+ (large, xlarge) -->
+ <style name="Theme.Holo.Light.DialogWhenLarge" parent="@android:style/Theme.Holo.Light">
+ </style>
+
<!-- Holo light theme for alert dialog windows, which is used by the
{@link android.app.AlertDialog} class. This is basically a dialog
but sets the background to empty so it can do two-tone backgrounds.