diff options
-rw-r--r-- | core/java/android/view/View.java | 2 | ||||
-rw-r--r-- | core/java/android/view/ViewGroup.java | 37 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | tests/HwAccelerationTest/res/layout/view_layers_5.xml | 48 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java | 121 |
5 files changed, 204 insertions, 13 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 1208b23..258a19c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -6953,7 +6953,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * well. This is usually true for a full invalidate, but may be set to false if the * View's contents or dimensions have not changed. */ - private void invalidate(boolean invalidateCache) { + void invalidate(boolean invalidateCache) { if (ViewDebug.TRACE_HIERARCHY) { ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); } diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 5508bbd..9ac955b 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -347,6 +347,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // views during a transition when they otherwise would have become gone/invisible private ArrayList<View> mVisibilityChangingChildren; + // Indicates whether this container will use its children layers to draw + @ViewDebug.ExportedProperty(category = "drawing") + private boolean mDrawLayers = true; + public ViewGroup(Context context) { super(context); initViewGroup(); @@ -2160,7 +2164,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager flags = mGroupFlags; if ((flags & FLAG_INVALIDATE_REQUIRED) == FLAG_INVALIDATE_REQUIRED) { - invalidate(); + invalidate(true); } if ((flags & FLAG_ANIMATION_DONE) == 0 && (flags & FLAG_NOTIFY_ANIMATION_LISTENER) == 0 && @@ -2216,7 +2220,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } } - invalidate(); + invalidate(true); } /** @@ -2275,7 +2279,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager boolean scalingRequired = false; boolean caching; - int layerType = child.getLayerType(); + int layerType = mDrawLayers ? child.getLayerType() : LAYER_TYPE_NONE; final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); if ((flags & FLAG_CHILDREN_DRAWN_WITH_CACHE) == FLAG_CHILDREN_DRAWN_WITH_CACHE || @@ -2552,10 +2556,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // invalidation is the trigger to recreate display lists, so if we're using // display lists to render, force an invalidate to allow the animation to // continue drawing another frame - invalidate(); + invalidate(true); if (a instanceof AlphaAnimation) { // alpha animations should cause the child to recreate its display list - child.invalidate(); + child.invalidate(true); } } @@ -2565,6 +2569,17 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } /** + * + * @param enabled True if children should be drawn with layers, false otherwise. + * + * @hide + */ + public void setChildrenLayersEnabled(boolean enabled) { + mDrawLayers = enabled; + invalidate(true); + } + + /** * By default, children are clipped to their bounds before drawing. This * allows view groups to override this behavior for animations, etc. * @@ -2596,7 +2611,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager final View[] children = mChildren; final int count = mChildrenCount; for (int i = 0; i < count; i++) { - children[i].setSelected(selected); } } @@ -2609,7 +2623,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager final View[] children = mChildren; final int count = mChildrenCount; for (int i = 0; i < count; i++) { - children[i].setActivated(activated); } } @@ -2802,7 +2815,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // therefore, we call requestLayout() on ourselves before, so that the child's request // will be blocked at our level requestLayout(); - invalidate(); + invalidate(true); addViewInner(child, index, params, false); } @@ -3084,7 +3097,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager public void removeView(View view) { removeViewInternal(view); requestLayout(); - invalidate(); + invalidate(true); } /** @@ -3116,7 +3129,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager public void removeViewAt(int index) { removeViewInternal(index, getChildAt(index)); requestLayout(); - invalidate(); + invalidate(true); } /** @@ -3128,7 +3141,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager public void removeViews(int start, int count) { removeViewsInternal(start, count); requestLayout(); - invalidate(); + invalidate(true); } private void removeViewInternal(View view) { @@ -3253,7 +3266,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager public void removeAllViews() { removeAllViewsInLayout(); requestLayout(); - invalidate(); + invalidate(true); } /** diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 2db4417..fc50334 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -89,6 +89,15 @@ </activity> <activity + android:name="ViewLayersActivity5" + android:label="_ViewLayers5"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="AlphaLayersActivity" android:label="_αLayers"> <intent-filter> diff --git a/tests/HwAccelerationTest/res/layout/view_layers_5.xml b/tests/HwAccelerationTest/res/layout/view_layers_5.xml new file mode 100644 index 0000000..653f3a8 --- /dev/null +++ b/tests/HwAccelerationTest/res/layout/view_layers_5.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:orientation="vertical" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1"> + + <Button + android:onClick="setLayerEnabled" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Enable layer" /> + + <Button + android:onClick="setLayerDisabled" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Disable layer" /> + + </LinearLayout> + + <ListView + android:id="@+id/list1" + android:layout_width="0dip" + android:layout_height="match_parent" + android:layout_weight="1" /> + +</LinearLayout> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java new file mode 100644 index 0000000..95a5b0d --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ViewLayersActivity5.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2011 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. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.os.Bundle; +import android.util.DisplayMetrics; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +@SuppressWarnings({"UnusedDeclaration"}) +public class ViewLayersActivity5 extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.view_layers_5); + + setupList(R.id.list1); + } + + public void setLayerDisabled(View v) { + ((ViewGroup) findViewById(R.id.list1).getParent()).setChildrenLayersEnabled(false); + } + + public void setLayerEnabled(View v) { + ((ViewGroup) findViewById(R.id.list1).getParent()).setChildrenLayersEnabled(true); + } + + private void setupList(int listId) { + final Paint p = new Paint(); + p.setColorFilter(new PorterDuffColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY)); + + final ListView list = (ListView) findViewById(listId); + list.setAdapter(new SimpleListAdapter(this)); + list.setLayerType(View.LAYER_TYPE_HARDWARE, p); + } + + private static class SimpleListAdapter extends ArrayAdapter<String> { + public SimpleListAdapter(Context context) { + super(context, android.R.layout.simple_list_item_1, DATA_LIST); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView v = (TextView) super.getView(position, convertView, parent); + final Resources r = getContext().getResources(); + final DisplayMetrics metrics = r.getDisplayMetrics(); + v.setCompoundDrawablePadding((int) (6 * metrics.density + 0.5f)); + v.setCompoundDrawablesWithIntrinsicBounds(r.getDrawable(R.drawable.icon), + null, null, null); + return v; + } + } + + private static final String[] DATA_LIST = { + "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", + "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", + "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", + "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", + "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", + "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", + "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria", + "Burkina Faso", "Burundi", "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde", + "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", + "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", + "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic", + "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", + "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", + "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland", + "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia", + "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", + "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", + "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", + "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", + "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", + "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", + "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", + "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", + "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", + "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", + "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas", + "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", + "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", + "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena", + "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", + "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", + "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", + "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", + "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", + "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", + "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", + "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda", + "Ukraine", "United Arab Emirates", "United Kingdom", + "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", + "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", + "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" + }; +} |