Theming for more VectorDrawable attrs, add attrs to test app

BUG: 13878079
Change-Id: Ibcc8d67446c44cd8f681230fc484c7dc7411ffab
This commit is contained in:
Alan Viverette
2014-04-08 17:12:43 -07:00
parent 2989c2cb5c
commit 7f1ab7a43f
5 changed files with 170 additions and 98 deletions

View File

@@ -247,7 +247,7 @@ package android {
field public static final int actionBarTabBarStyle = 16843508; // 0x10102f4
field public static final int actionBarTabStyle = 16843507; // 0x10102f3
field public static final int actionBarTabTextStyle = 16843509; // 0x10102f5
field public static final int actionBarTheme = 16843836; // 0x101043c
field public static final int actionBarTheme = 16843837; // 0x101043d
field public static final int actionBarWidgetTheme = 16843671; // 0x1010397
field public static final int actionButtonStyle = 16843480; // 0x10102d8
field public static final int actionDropDownStyle = 16843479; // 0x10102d7
@@ -290,7 +290,7 @@ package android {
field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
field public static final int alwaysRetainTaskState = 16843267; // 0x1010203
field public static final int angle = 16843168; // 0x10101a0
field public static final int animate = 16843822; // 0x101042e
field public static final int animate = 16843823; // 0x101042f
field public static final int animateFirstView = 16843477; // 0x10102d5
field public static final int animateLayoutChanges = 16843506; // 0x10102f2
field public static final int animateOnClick = 16843356; // 0x101025c
@@ -377,19 +377,19 @@ package android {
field public static final int clipChildren = 16842986; // 0x10100ea
field public static final int clipOrientation = 16843274; // 0x101020a
field public static final int clipToPadding = 16842987; // 0x10100eb
field public static final int clipToPath = 16843821; // 0x101042d
field public static final int clipToPath = 16843822; // 0x101042e
field public static final int codes = 16843330; // 0x1010242
field public static final int collapseColumns = 16843083; // 0x101014b
field public static final int color = 16843173; // 0x10101a5
field public static final int colorActivatedHighlight = 16843664; // 0x1010390
field public static final int colorBackground = 16842801; // 0x1010031
field public static final int colorBackgroundCacheHint = 16843435; // 0x10102ab
field public static final int colorButtonNormal = 16843828; // 0x1010434
field public static final int colorButtonNormalColored = 16843830; // 0x1010436
field public static final int colorButtonPressed = 16843829; // 0x1010435
field public static final int colorButtonPressedColored = 16843831; // 0x1010437
field public static final int colorControlActivated = 16843827; // 0x1010433
field public static final int colorControlNormal = 16843826; // 0x1010432
field public static final int colorButtonNormal = 16843829; // 0x1010435
field public static final int colorButtonNormalColored = 16843831; // 0x1010437
field public static final int colorButtonPressed = 16843830; // 0x1010436
field public static final int colorButtonPressedColored = 16843832; // 0x1010438
field public static final int colorControlActivated = 16843828; // 0x1010434
field public static final int colorControlNormal = 16843827; // 0x1010433
field public static final int colorFocusedHighlight = 16843663; // 0x101038f
field public static final int colorForeground = 16842800; // 0x1010030
field public static final int colorForegroundInverse = 16843270; // 0x1010206
@@ -757,7 +757,7 @@ package android {
field public static final int layout_x = 16843135; // 0x101017f
field public static final int layout_y = 16843136; // 0x1010180
field public static final int left = 16843181; // 0x10101ad
field public static final int limitTo = 16843823; // 0x101042f
field public static final int limitTo = 16843824; // 0x1010430
field public static final int lineSpacingExtra = 16843287; // 0x1010217
field public static final int lineSpacingMultiplier = 16843288; // 0x1010218
field public static final int lines = 16843092; // 0x1010154
@@ -867,11 +867,11 @@ package android {
field public static final int permissionFlags = 16843719; // 0x10103c7
field public static final int permissionGroup = 16842762; // 0x101000a
field public static final int permissionGroupFlags = 16843717; // 0x10103c5
field public static final int persistable = 16843832; // 0x1010438
field public static final int persistable = 16843833; // 0x1010439
field public static final int persistent = 16842765; // 0x101000d
field public static final int persistentDrawingCache = 16842990; // 0x10100ee
field public static final deprecated int phoneNumber = 16843111; // 0x1010167
field public static final int pinned = 16843825; // 0x1010431
field public static final int pinned = 16843826; // 0x1010432
field public static final int pivotX = 16843189; // 0x10101b5
field public static final int pivotY = 16843190; // 0x10101b6
field public static final int popupAnimationStyle = 16843465; // 0x10102c9
@@ -936,7 +936,7 @@ package android {
field public static final int required = 16843406; // 0x101028e
field public static final int requiredAccountType = 16843734; // 0x10103d6
field public static final int requiredForAllUsers = 16843728; // 0x10103d0
field public static final int requiredForProfile = 16843824; // 0x1010430
field public static final int requiredForProfile = 16843825; // 0x1010431
field public static final int requiresFadingEdge = 16843685; // 0x10103a5
field public static final int requiresSmallestWidthDp = 16843620; // 0x1010364
field public static final int resizeMode = 16843619; // 0x1010363
@@ -1022,7 +1022,7 @@ package android {
field public static final int shrinkColumns = 16843082; // 0x101014a
field public static final deprecated int singleLine = 16843101; // 0x101015d
field public static final int singleUser = 16843711; // 0x10103bf
field public static final int slideEdge = 16843835; // 0x101043b
field public static final int slideEdge = 16843836; // 0x101043c
field public static final int smallIcon = 16843422; // 0x101029e
field public static final int smallScreens = 16843396; // 0x1010284
field public static final int smoothScrollbar = 16843313; // 0x1010231
@@ -1075,10 +1075,11 @@ package android {
field public static final int stretchMode = 16843030; // 0x1010116
field public static final int stroke = 16843811; // 0x1010423
field public static final int strokeLineCap = 16843820; // 0x101042c
field public static final int strokeLineJoin = 16843821; // 0x101042d
field public static final int strokeOpacity = 16843812; // 0x1010424
field public static final int strokeWidth = 16843813; // 0x1010425
field public static final int subtitle = 16843473; // 0x10102d1
field public static final int subtitleTextAppearance = 16843834; // 0x101043a
field public static final int subtitleTextAppearance = 16843835; // 0x101043b
field public static final int subtitleTextStyle = 16843513; // 0x10102f9
field public static final int subtypeExtraValue = 16843674; // 0x101039a
field public static final int subtypeId = 16843713; // 0x10103c1
@@ -1194,7 +1195,7 @@ package android {
field public static final int tintMode = 16843798; // 0x1010416
field public static final int title = 16843233; // 0x10101e1
field public static final int titleCondensed = 16843234; // 0x10101e2
field public static final int titleTextAppearance = 16843833; // 0x1010439
field public static final int titleTextAppearance = 16843834; // 0x101043a
field public static final int titleTextStyle = 16843512; // 0x10102f8
field public static final int toAlpha = 16843211; // 0x10101cb
field public static final int toDegrees = 16843188; // 0x10101b4

View File

@@ -2131,6 +2131,7 @@
<public type="attr" name="trimPathEnd" />
<public type="attr" name="trimPathOffset" />
<public type="attr" name="strokeLineCap" />
<public type="attr" name="strokeLineJoin" />
<public type="attr" name="clipToPath" />
<public type="attr" name="animate" />
<public type="attr" name="limitTo" />

View File

@@ -846,11 +846,11 @@ public class VectorDrawable extends Drawable {
}
if (vPath.mStrokeColor != 0) {
if (vPath.mStrokelineJoin != null) {
mStrokePaint.setStrokeJoin(vPath.mStrokelineJoin);
if (vPath.mStrokeLineJoin != null) {
mStrokePaint.setStrokeJoin(vPath.mStrokeLineJoin);
}
if (vPath.mStrokelineCap != null) {
mStrokePaint.setStrokeCap(vPath.mStrokelineCap);
if (vPath.mStrokeLineCap != null) {
mStrokePaint.setStrokeCap(vPath.mStrokeLineCap);
}
mStrokePaint.setStrokeMiter(vPath.mStrokeMiterlimit * scale);
mStrokePaint.setColor(vPath.mStrokeColor);
@@ -1324,8 +1324,8 @@ public class VectorDrawable extends Drawable {
boolean mAnimated = false;
boolean mClip = false;
Paint.Cap mStrokelineCap = null;
Paint.Join mStrokelineJoin = null;
Paint.Cap mStrokeLineCap = null;
Paint.Join mStrokeLineJoin = null;
float mStrokeMiterlimit = 4;
private VNode[] mNode = null;
@@ -1382,61 +1382,93 @@ public class VectorDrawable extends Drawable {
}
}
public String getID(){
public String getID() {
return mId;
}
private Paint.Cap getStrokeLineCap(int id, Paint.Cap defValue) {
switch (id) {
case LINECAP_BUTT:
return Paint.Cap.BUTT;
case LINECAP_ROUND:
return Paint.Cap.ROUND;
case LINECAP_SQUARE:
return Paint.Cap.SQUARE;
default:
return defValue;
}
}
private Paint.Join getStrokeLineJoin(int id, Paint.Join defValue) {
switch (id) {
case LINEJOIN_MITER:
return Paint.Join.MITER;
case LINEJOIN_ROUND:
return Paint.Join.ROUND;
case LINEJOIN_BEVEL:
return Paint.Join.BEVEL;
default:
return defValue;
}
}
public void inflate(Resources r, AttributeSet attrs, Theme theme) {
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.VectorDrawablePath);
final int[] themeAttrs = a.extractThemeAttrs();
mThemeAttrs = themeAttrs;
mClip = a.getBoolean(R.styleable.VectorDrawablePath_clipToPath, false);
mId = a.getString(R.styleable.VectorDrawablePath_name);
mNode = parsePath(a.getString(R.styleable.VectorDrawablePath_pathData));
// NOTE: The set of attributes loaded here MUST match the
// set of attributes loaded in applyTheme.
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_clipToPath] == 0) {
mClip = a.getBoolean(R.styleable.VectorDrawablePath_clipToPath, mClip);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_name] == 0) {
mId = a.getString(R.styleable.VectorDrawablePath_name);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_pathData] == 0) {
mNode = parsePath(a.getString(R.styleable.VectorDrawablePath_pathData));
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_fill] == 0) {
mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, 0);
mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, mFillColor);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_fillOpacity] == 0) {
mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_rotation] == 0) {
mRotate = a.getFloat(R.styleable.VectorDrawablePath_rotation, mRotate);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_pivotX] == 0) {
mPivotX = a.getFloat(R.styleable.VectorDrawablePath_pivotX, mPivotX);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_pivotY] == 0) {
mPivotY = a.getFloat(R.styleable.VectorDrawablePath_pivotY, mPivotY);
}
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_fillOpacity] == 0) {
mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, Float.NaN);
|| themeAttrs[R.styleable.VectorDrawablePath_strokeLineCap] == 0) {
mStrokeLineCap = getStrokeLineCap(
a.getInt(R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
}
mRotate = a.getFloat(R.styleable.VectorDrawablePath_rotation, 0);
mPivotX = a.getFloat(R.styleable.VectorDrawablePath_pivotX, 0);
mPivotY = a.getFloat(R.styleable.VectorDrawablePath_pivotY, 0);
final int lineCap = a.getInt(R.styleable.VectorDrawablePath_strokeLineCap, 0);
switch (lineCap) {
case LINECAP_BUTT:
mStrokelineCap = Paint.Cap.BUTT;
break;
case LINECAP_ROUND:
mStrokelineCap = Paint.Cap.ROUND;
break;
case LINECAP_SQUARE:
mStrokelineCap = Paint.Cap.SQUARE;
break;
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_strokeLineJoin] == 0) {
mStrokeLineJoin = getStrokeLineJoin(
a.getInt(R.styleable.VectorDrawablePath_strokeLineJoin, -1), mStrokeLineJoin);
}
final int lineJoin = a.getInt(R.styleable.VectorDrawablePath_strokeLineJoin, 0);
switch (lineJoin) {
case LINEJOIN_MITER:
mStrokelineJoin = Paint.Join.MITER;
break;
case LINEJOIN_ROUND:
mStrokelineJoin = Paint.Join.ROUND;
break;
case LINEJOIN_BEVEL:
mStrokelineJoin = Paint.Join.BEVEL;
break;
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_strokeMiterLimit] == 0) {
mStrokeMiterlimit = a.getFloat(
R.styleable.VectorDrawablePath_strokeMiterLimit, mStrokeMiterlimit);
}
mStrokeMiterlimit = a.getFloat(R.styleable.VectorDrawablePath_strokeMiterLimit,
mStrokeMiterlimit);
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_stroke] == 0) {
mStrokeColor = a.getColor(R.styleable.VectorDrawablePath_stroke, mStrokeColor);
}
@@ -1444,14 +1476,30 @@ public class VectorDrawable extends Drawable {
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_strokeOpacity] == 0) {
mStrokeOpacity = a.getFloat(
R.styleable.VectorDrawablePath_strokeOpacity, Float.NaN);
R.styleable.VectorDrawablePath_strokeOpacity, mStrokeOpacity);
}
mStrokeWidth = a.getFloat(R.styleable.VectorDrawablePath_strokeWidth, 0);
mTrimPathEnd = a.getFloat(R.styleable.VectorDrawablePath_trimPathEnd, 1);
mTrimPathOffset = a.getFloat(R.styleable.VectorDrawablePath_trimPathOffset, 0);
mTrimPathStart = a.getFloat(R.styleable.VectorDrawablePath_trimPathStart, 0);
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_strokeWidth] == 0) {
mStrokeWidth = a.getFloat(R.styleable.VectorDrawablePath_strokeWidth, mStrokeWidth);
}
if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_trimPathEnd] == 0) {
mTrimPathEnd = a.getFloat(R.styleable.VectorDrawablePath_trimPathEnd, mTrimPathEnd);
}
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_trimPathOffset] == 0) {
mTrimPathOffset = a.getFloat(
R.styleable.VectorDrawablePath_trimPathOffset, mTrimPathOffset);
}
if (themeAttrs == null
|| themeAttrs[R.styleable.VectorDrawablePath_trimPathStart] == 0) {
mTrimPathStart = a.getFloat(
R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);
}
// TODO: Consider replacing this with existing state attributes.
final int[] states = {
R.styleable.VectorDrawablePath_state_activated,
R.styleable.VectorDrawablePath_state_checkable,
@@ -1489,22 +1537,39 @@ public class VectorDrawable extends Drawable {
final TypedArray a = t.resolveAttributes(
mThemeAttrs, R.styleable.VectorDrawablePath, 0, 0);
if (a.hasValue(R.styleable.VectorDrawablePath_fill)) {
mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, 0);
mClip = a.getBoolean(R.styleable.VectorDrawablePath_clipToPath, mClip);
if (a.hasValue(R.styleable.VectorDrawablePath_name)) {
mId = a.getString(R.styleable.VectorDrawablePath_name);
}
if (a.hasValue(R.styleable.VectorDrawablePath_fillOpacity)) {
mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, Float.NaN);
if (a.hasValue(R.styleable.VectorDrawablePath_pathData)) {
mNode = parsePath(a.getString(R.styleable.VectorDrawablePath_pathData));
}
if (a.hasValue(R.styleable.VectorDrawablePath_stroke)) {
mStrokeColor = a.getColor(R.styleable.VectorDrawablePath_stroke, mStrokeColor);
}
mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, mFillColor);
mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);
if (a.hasValue(R.styleable.VectorDrawablePath_strokeOpacity)) {
mStrokeOpacity = a.getFloat(
R.styleable.VectorDrawablePath_strokeOpacity, Float.NaN);
}
mRotate = a.getFloat(R.styleable.VectorDrawablePath_rotation, mRotate);
mPivotX = a.getFloat(R.styleable.VectorDrawablePath_pivotX, mPivotX);
mPivotY = a.getFloat(R.styleable.VectorDrawablePath_pivotY, mPivotY);
mStrokeLineCap = getStrokeLineCap(a.getInt(
R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
mStrokeLineJoin = getStrokeLineJoin(a.getInt(
R.styleable.VectorDrawablePath_strokeLineJoin, -1), mStrokeLineJoin);
mStrokeMiterlimit = a.getFloat(
R.styleable.VectorDrawablePath_strokeMiterLimit, mStrokeMiterlimit);
mStrokeColor = a.getColor(R.styleable.VectorDrawablePath_stroke, mStrokeColor);
mStrokeOpacity = a.getFloat(
R.styleable.VectorDrawablePath_strokeOpacity, mStrokeOpacity);
mStrokeWidth = a.getFloat(R.styleable.VectorDrawablePath_strokeWidth, mStrokeWidth);
mTrimPathEnd = a.getFloat(R.styleable.VectorDrawablePath_trimPathEnd, mTrimPathEnd);
mTrimPathOffset = a.getFloat(
R.styleable.VectorDrawablePath_trimPathOffset, mTrimPathOffset);
mTrimPathStart = a.getFloat(
R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);
updateColorAlphas();
}
@@ -1626,8 +1691,8 @@ public class VectorDrawable extends Drawable {
mTrimPathStart = p1.mTrimPathStart;
mTrimPathEnd = p1.mTrimPathEnd;
mTrimPathOffset = p1.mTrimPathOffset;
mStrokelineCap = p1.mStrokelineCap;
mStrokelineJoin = p1.mStrokelineJoin;
mStrokeLineCap = p1.mStrokeLineCap;
mStrokeLineJoin = p1.mStrokeLineJoin;
mStrokeMiterlimit = p1.mStrokeMiterlimit;
mNumberOfStates = p1.mNumberOfStates;
for (int i = 0; i < mNumberOfStates; i++) {
@@ -1664,13 +1729,13 @@ public class VectorDrawable extends Drawable {
returnPath.mTrimPathOffset = t1 * p1.mTrimPathOffset + t * p2.mTrimPathOffset;
returnPath.mStrokeMiterlimit =
t1 * p1.mStrokeMiterlimit + t * p2.mStrokeMiterlimit;
returnPath.mStrokelineCap = p1.mStrokelineCap;
if (returnPath.mStrokelineCap == null) {
returnPath.mStrokelineCap = p2.mStrokelineCap;
returnPath.mStrokeLineCap = p1.mStrokeLineCap;
if (returnPath.mStrokeLineCap == null) {
returnPath.mStrokeLineCap = p2.mStrokeLineCap;
}
returnPath.mStrokelineJoin = p1.mStrokelineJoin;
if (returnPath.mStrokelineJoin == null) {
returnPath.mStrokelineJoin = p2.mStrokelineJoin;
returnPath.mStrokeLineJoin = p1.mStrokeLineJoin;
if (returnPath.mStrokeLineJoin == null) {
returnPath.mStrokeLineJoin = p2.mStrokeLineJoin;
}
returnPath.mFillRule = p1.mFillRule;

View File

@@ -17,7 +17,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.test.dynamic" >
<uses-sdk android:minSdkVersion="11" />
<uses-sdk android:minSdkVersion="20" />
<application
android:hardwareAccelerated="true"

View File

@@ -17,8 +17,8 @@
android:trigger="state_checked" android:versionCode="1" >
<size
android:height="64dp"
android:width="64dp" />
android:height="48dp"
android:width="48dp" />
<viewport
android:viewportHeight="480"
@@ -28,42 +28,47 @@
<path
android:name="check"
android:pathData="m20,200l100,90l180,-180l-35,-35l-145,145l-60,-60l-40,40z"
android:fill="#ffff00ff"
android:stroke="#FF00FF00"
android:strokeWidth="5" />
android:fill="?android:attr/colorControlActivated" />
</group>
<group>
<path
android:name="box1"
android:pathData="m127,171l37,38l33,-31l-37,-40l-1,3l-2,0l-30,30z"
android:fill="#ffffffff"
android:stroke="#FF00FF00"
android:strokeWidth="5" />
android:fill="?android:attr/colorControlActivated"
android:stroke="?android:attr/colorControlActivated"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
<group>
<path
android:name="box2"
android:pathData="m127,171l37,38l33,-31l-37,-40l-1,3l-2,0l-30,30z"
android:fill="#ff000000"
android:rotation="46.757"
android:pivotX="162"
android:pivotY="173.5"
android:stroke="#FF00FF00"
android:strokeWidth="5" />
android:fill="?attr/android:colorControlNormal"
android:stroke="?attr/android:colorControlNormal"
android:strokeWidth="3"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
<group>
<path
android:name="box3"
android:pathData="m187,147l-1,55l-49,-1l2,-53l48,0z"
android:stroke="#FF000000"
android:strokeWidth="4" />
android:stroke="?attr/android:colorControlNormal"
android:strokeWidth="10"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
<group>
<path
android:name="box4"
android:pathData="m248,74l0,164l-177,0l1,-165l173,-1l3,2z"
android:stroke="#FF000000"
android:strokeWidth="30" />
android:stroke="?attr/android:colorControlNormal"
android:strokeWidth="30"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
</group>
<animation