diff options
author | Adam Powell <adamp@google.com> | 2010-11-09 21:28:59 -0800 |
---|---|---|
committer | Adam Powell <adamp@google.com> | 2010-11-11 14:53:29 -0800 |
commit | 021aad952bee3ac9ee4a98c09f1a012359088dd2 (patch) | |
tree | da02b1eba3c84ea6cbc95ace97c0ad7f9a52b17e | |
parent | d781089731127bd9199d47f53b170895868b8750 (diff) | |
download | frameworks_base-021aad952bee3ac9ee4a98c09f1a012359088dd2.zip frameworks_base-021aad952bee3ac9ee4a98c09f1a012359088dd2.tar.gz frameworks_base-021aad952bee3ac9ee4a98c09f1a012359088dd2.tar.bz2 |
First pass at styling progress bars for Holo.
Added attribute to let scale drawables size based on the intrinsic
width and height as a minimum. This helps prevent artifacts when
some 9-patches are used in situations like progress bars.
Change-Id: I168a232d3225afe9b5578a05a9b8634a1084404c
20 files changed, 104 insertions, 11 deletions
diff --git a/api/current.xml b/api/current.xml index 504dab4..bf5c8a0 100644 --- a/api/current.xml +++ b/api/current.xml @@ -1949,7 +1949,7 @@ type="int" transient="false" volatile="false" - value="16843554" + value="16843555" static="true" final="true" deprecated="not deprecated" @@ -1960,7 +1960,7 @@ type="int" transient="false" volatile="false" - value="16843553" + value="16843554" static="true" final="true" deprecated="not deprecated" @@ -1971,7 +1971,7 @@ type="int" transient="false" volatile="false" - value="16843555" + value="16843556" static="true" final="true" deprecated="not deprecated" @@ -9396,7 +9396,7 @@ type="int" transient="false" volatile="false" - value="16843557" + value="16843558" static="true" final="true" deprecated="not deprecated" @@ -9407,7 +9407,7 @@ type="int" transient="false" volatile="false" - value="16843556" + value="16843557" static="true" final="true" deprecated="not deprecated" @@ -9898,6 +9898,17 @@ visibility="public" > </field> +<field name="useIntrinsicSizeAsMinimum" + type="int" + transient="false" + volatile="false" + value="16843553" + static="true" + final="true" + deprecated="not deprecated" + visibility="public" +> +</field> <field name="useLevel" type="int" transient="false" @@ -246052,7 +246063,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="t" type="T"> +<parameter name="arg0" type="T"> </parameter> </method> </interface> diff --git a/core/res/res/drawable-hdpi/progress_bg_holo_dark.9.png b/core/res/res/drawable-hdpi/progress_bg_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..192df6d --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_bg_holo_dark.9.png diff --git a/core/res/res/drawable-hdpi/progress_bg_holo_light.9.png b/core/res/res/drawable-hdpi/progress_bg_holo_light.9.png Binary files differnew file mode 100644 index 0000000..223416d --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_bg_holo_light.9.png diff --git a/core/res/res/drawable-hdpi/progress_primary_holo_dark.9.png b/core/res/res/drawable-hdpi/progress_primary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..1a59124 --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_primary_holo_dark.9.png diff --git a/core/res/res/drawable-hdpi/progress_primary_holo_light.9.png b/core/res/res/drawable-hdpi/progress_primary_holo_light.9.png Binary files differnew file mode 100644 index 0000000..f119c6a --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_primary_holo_light.9.png diff --git a/core/res/res/drawable-hdpi/progress_secondary_holo_dark.9.png b/core/res/res/drawable-hdpi/progress_secondary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..3c6c5ed --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_secondary_holo_dark.9.png diff --git a/core/res/res/drawable-hdpi/progress_secondary_holo_light.9.png b/core/res/res/drawable-hdpi/progress_secondary_holo_light.9.png Binary files differnew file mode 100644 index 0000000..cab3888 --- /dev/null +++ b/core/res/res/drawable-hdpi/progress_secondary_holo_light.9.png diff --git a/core/res/res/drawable-mdpi/progress_bg_holo_dark.9.png b/core/res/res/drawable-mdpi/progress_bg_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..316af64 --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_bg_holo_dark.9.png diff --git a/core/res/res/drawable-mdpi/progress_bg_holo_light.9.png b/core/res/res/drawable-mdpi/progress_bg_holo_light.9.png Binary files differnew file mode 100644 index 0000000..e286136 --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_bg_holo_light.9.png diff --git a/core/res/res/drawable-mdpi/progress_primary_holo_dark.9.png b/core/res/res/drawable-mdpi/progress_primary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..0502669 --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_primary_holo_dark.9.png diff --git a/core/res/res/drawable-mdpi/progress_primary_holo_light.9.png b/core/res/res/drawable-mdpi/progress_primary_holo_light.9.png Binary files differnew file mode 100644 index 0000000..1ba9e34 --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_primary_holo_light.9.png diff --git a/core/res/res/drawable-mdpi/progress_secondary_holo_dark.9.png b/core/res/res/drawable-mdpi/progress_secondary_holo_dark.9.png Binary files differnew file mode 100644 index 0000000..a2fe2b3 --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_secondary_holo_dark.9.png diff --git a/core/res/res/drawable-mdpi/progress_secondary_holo_light.9.png b/core/res/res/drawable-mdpi/progress_secondary_holo_light.9.png Binary files differnew file mode 100644 index 0000000..3b264ab --- /dev/null +++ b/core/res/res/drawable-mdpi/progress_secondary_holo_light.9.png diff --git a/core/res/res/drawable/progress_horizontal_holo_dark.xml b/core/res/res/drawable/progress_horizontal_holo_dark.xml new file mode 100644 index 0000000..ff270b3 --- /dev/null +++ b/core/res/res/drawable/progress_horizontal_holo_dark.xml @@ -0,0 +1,32 @@ +<?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. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:id="@android:id/background" + android:drawable="@android:drawable/progress_bg_holo_dark" /> + + <item android:id="@android:id/secondaryProgress"> + <scale android:scaleWidth="100%" + android:drawable="@android:drawable/progress_secondary_holo_dark" /> + </item> + + <item android:id="@android:id/progress"> + <scale android:scaleWidth="100%" + android:drawable="@android:drawable/progress_primary_holo_dark" /> + </item> + +</layer-list> diff --git a/core/res/res/drawable/progress_horizontal_holo_light.xml b/core/res/res/drawable/progress_horizontal_holo_light.xml new file mode 100644 index 0000000..4935185 --- /dev/null +++ b/core/res/res/drawable/progress_horizontal_holo_light.xml @@ -0,0 +1,32 @@ +<?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. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:id="@android:id/background" + android:drawable="@android:drawable/progress_bg_holo_light" /> + + <item android:id="@android:id/secondaryProgress"> + <scale android:scaleWidth="100%" + android:drawable="@android:drawable/progress_secondary_holo_light" /> + </item> + + <item android:id="@android:id/progress"> + <scale android:scaleWidth="100%" + android:drawable="@android:drawable/progress_primary_holo_light" /> + </item> + +</layer-list> diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 5d3dc03..115e59d 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -3021,6 +3021,10 @@ </attr> <!-- Reference to a drawable resource to draw with the specified scale. --> <attr name="drawable" /> + <!-- Use the drawable's intrinsic width and height as minimum size values. + Useful if the target drawable is a 9-patch or otherwise should not be scaled + down beyond a minimum size. --> + <attr name="useIntrinsicSizeAsMinimum" format="boolean" /> </declare-styleable> <declare-styleable name="ClipDrawable"> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index ff12e8f..a1b9dc9 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1364,6 +1364,7 @@ <public type="attr" name="exitFadeDuration" /> <public type="attr" name="selectableItemBackground" /> <public type="attr" name="autoAdvanceViewId" /> + <public type="attr" name="useIntrinsicSizeAsMinimum" /> <public type="anim" name="animator_fade_in" /> <public type="anim" name="animator_fade_out" /> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index f63805b..457175b 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -1359,6 +1359,9 @@ </style> <style name="Widget.Holo.ProgressBar.Horizontal" parent="Widget.ProgressBar.Horizontal"> + <item name="android:progressDrawable">@android:drawable/progress_horizontal_holo_dark</item> + <item name="android:minHeight">16dip</item> + <item name="android:maxHeight">16dip</item> </style> <style name="Widget.Holo.ProgressBar.Small" parent="Widget.ProgressBar.Horizontal"> @@ -1383,8 +1386,8 @@ <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@android:drawable/scrubber_progress_horizontal_holo_dark</item> <item name="android:indeterminateDrawable">@android:drawable/scrubber_progress_horizontal_holo_dark</item> - <item name="android:minHeight">16dip</item> - <item name="android:maxHeight">16dip</item> + <item name="android:minHeight">6dip</item> + <item name="android:maxHeight">6dip</item> <item name="android:thumb">@android:drawable/scrubber_control_holo</item> <item name="android:thumbOffset">16dip</item> <item name="android:focusable">true</item> @@ -1646,6 +1649,7 @@ </style> <style name="Widget.Holo.Light.ProgressBar.Horizontal" parent="Widget.ProgressBar.Horizontal"> + <item name="android:progressDrawable">@android:drawable/progress_horizontal_holo_light</item> </style> <style name="Widget.Holo.Light.ProgressBar.Small" parent="Widget.ProgressBar.Small"> diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 501cca9..b6cce7e 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -21,7 +21,10 @@ import org.xmlpull.v1.XmlPullParserException; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.*; +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.PixelFormat; +import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index b623d80..dcaf20b 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -95,6 +95,8 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { float sw = getPercent(a, com.android.internal.R.styleable.ScaleDrawable_scaleWidth); float sh = getPercent(a, com.android.internal.R.styleable.ScaleDrawable_scaleHeight); int g = a.getInt(com.android.internal.R.styleable.ScaleDrawable_scaleGravity, Gravity.LEFT); + boolean min = a.getBoolean( + com.android.internal.R.styleable.ScaleDrawable_useIntrinsicSizeAsMinimum, false); Drawable dr = a.getDrawable(com.android.internal.R.styleable.ScaleDrawable_drawable); a.recycle(); @@ -116,6 +118,7 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { mScaleState.mScaleWidth = sw; mScaleState.mScaleHeight = sh; mScaleState.mGravity = g; + mScaleState.mUseIntrinsicSizeAsMin = min; if (dr != null) { dr.setCallback(this); } @@ -206,15 +209,16 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { @Override protected void onBoundsChange(Rect bounds) { final Rect r = mTmpRect; + final boolean min = mScaleState.mUseIntrinsicSizeAsMin; int level = getLevel(); int w = bounds.width(); - final int iw = 0; //mScaleState.mDrawable.getIntrinsicWidth(); if (mScaleState.mScaleWidth > 0) { + final int iw = min ? mScaleState.mDrawable.getIntrinsicWidth() : 0; w -= (int) ((w - iw) * (10000 - level) * mScaleState.mScaleWidth / 10000); } int h = bounds.height(); - final int ih = 0; //mScaleState.mDrawable.getIntrinsicHeight(); if (mScaleState.mScaleHeight > 0) { + final int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0; h -= (int) ((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000); } Gravity.apply(mScaleState.mGravity, w, h, bounds, r); @@ -258,6 +262,7 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { float mScaleWidth; float mScaleHeight; int mGravity; + boolean mUseIntrinsicSizeAsMin; private boolean mCheckedConstantState; private boolean mCanConstantState; @@ -273,6 +278,7 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { mScaleWidth = orig.mScaleWidth; mScaleHeight = orig.mScaleHeight; mGravity = orig.mGravity; + mUseIntrinsicSizeAsMin = orig.mUseIntrinsicSizeAsMin; mCheckedConstantState = mCanConstantState = true; } } |