Skip to content
This repository has been archived by the owner on Jun 5, 2018. It is now read-only.

Commit

Permalink
Fix possible unable to load drawable in DrawableCompat.loadDrawable
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shatunov committed Apr 5, 2014
1 parent 8dfe309 commit 5e6ec8e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\:https://services.gradle.org/distributions/gradle-1.10-all.zip
distributionUrl=http\:https://services.gradle.org/distributions/gradle-1.11-all.zip
10 changes: 3 additions & 7 deletions library/src/org/holoeverywhere/drawable/DrawableCompat.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package org.holoeverywhere.drawable;

import android.content.Context;
Expand Down Expand Up @@ -132,7 +131,7 @@ public static Drawable getDrawable(TypedArray array, int index) {

public static Drawable loadDrawable(Resources res, TypedValue value)
throws NotFoundException {
if (value == null || value.resourceId <= 0) {
if (value == null || value.resourceId == 0) {
return null;
}
final long key = (long) value.assetCookie << 32 | value.data;
Expand Down Expand Up @@ -186,8 +185,6 @@ public static interface StateStub {
public static interface IStateOverlay extends StateStub {
public void refreshDrawableState();

public void invalidate();

public int[] superOnCreateDrawableState(int extraSpace);
}

Expand Down Expand Up @@ -220,9 +217,8 @@ public boolean isActivated() {

@Override
public void setActivated(boolean activated) {
if (isActivated() != activated) {
if (getFlag(FLAG_ACTIVATED) != activated) {
setFlag(FLAG_ACTIVATED, activated);
mOverlayInterface.invalidate();
mOverlayInterface.refreshDrawableState();
}
}
Expand All @@ -239,7 +235,7 @@ public int[] onCreateDrawableState(int extraSpace) {
extraSpace += 1;
int[] state = mOverlayInterface.superOnCreateDrawableState(extraSpace);
state = ViewCompat.mergeDrawableStates(state, new int[]{
mOverlayInterface.isActivated() ? android.R.attr.state_activated : -android.R.attr.state_activated
getFlag(FLAG_ACTIVATED) ? android.R.attr.state_activated : -android.R.attr.state_activated
});
return state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package org.holoeverywhere.drawable;

import android.content.res.Resources;
Expand All @@ -14,7 +13,7 @@
import java.io.IOException;

public class StateListDrawable extends DrawableContainer {
static final class StateListState extends DrawableContainerState {
static final class StateListState extends DrawableContainer.DrawableContainerState {
int[][] mStateSets;

StateListState(StateListState orig, StateListDrawable owner, Resources res) {
Expand Down Expand Up @@ -199,7 +198,8 @@ public void inflate(Resources r, XmlPullParser parser,
throw new XmlPullParserException(
parser.getPositionDescription()
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
+ "child tag defining a drawable"
);
}
dr = DrawableCompat.createFromXmlInner(r, parser, attrs);
}
Expand Down
65 changes: 36 additions & 29 deletions library/src/org/holoeverywhere/widget/LinearLayout.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package org.holoeverywhere.widget;

import android.annotation.TargetApi;
Expand All @@ -14,6 +13,7 @@
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import org.holoeverywhere.R;
import org.holoeverywhere.drawable.DrawableCompat;

Expand Down Expand Up @@ -567,10 +567,12 @@ void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
maxAscent[INDEX_FILL] != -1) {
final int ascent = Math.max(maxAscent[INDEX_FILL],
Math.max(maxAscent[INDEX_CENTER_VERTICAL],
Math.max(maxAscent[INDEX_TOP], maxAscent[INDEX_BOTTOM])));
Math.max(maxAscent[INDEX_TOP], maxAscent[INDEX_BOTTOM]))
);
final int descent = Math.max(maxDescent[INDEX_FILL],
Math.max(maxDescent[INDEX_CENTER_VERTICAL],
Math.max(maxDescent[INDEX_TOP], maxDescent[INDEX_BOTTOM])));
Math.max(maxDescent[INDEX_TOP], maxDescent[INDEX_BOTTOM]))
);
maxHeight = Math.max(maxHeight, ascent + descent);
}
if (useLargestChild &&
Expand Down Expand Up @@ -618,8 +620,9 @@ void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
delta -= share;
final int childHeightMeasureSpec = getChildMeasureSpec(
heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
+ lp.bottomMargin,
lp.height);
+ lp.bottomMargin,
lp.height
);
if (lp.width != 0 || widthMode != MeasureSpec.EXACTLY) {
int childWidth = child.getMeasuredWidth() + share;
if (childWidth < 0) {
Expand All @@ -630,8 +633,9 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
childHeightMeasureSpec);
} else {
child.measure(MeasureSpec.makeMeasureSpec(
share > 0 ? share : 0, MeasureSpec.EXACTLY),
childHeightMeasureSpec);
share > 0 ? share : 0, MeasureSpec.EXACTLY),
childHeightMeasureSpec
);
}
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child) & MEASURED_STATE_MASK;
Expand Down Expand Up @@ -672,10 +676,12 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
maxAscent[INDEX_FILL] != -1) {
final int ascent = Math.max(maxAscent[INDEX_FILL],
Math.max(maxAscent[INDEX_CENTER_VERTICAL],
Math.max(maxAscent[INDEX_TOP], maxAscent[INDEX_BOTTOM])));
Math.max(maxAscent[INDEX_TOP], maxAscent[INDEX_BOTTOM]))
);
final int descent = Math.max(maxDescent[INDEX_FILL],
Math.max(maxDescent[INDEX_CENTER_VERTICAL],
Math.max(maxDescent[INDEX_TOP], maxDescent[INDEX_BOTTOM])));
Math.max(maxDescent[INDEX_TOP], maxDescent[INDEX_BOTTOM]))
);
maxHeight = Math.max(maxHeight, ascent + descent);
}
} else {
Expand All @@ -693,7 +699,8 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
child.measure(
MeasureSpec.makeMeasureSpec(largestChildWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
MeasureSpec.EXACTLY));
MeasureSpec.EXACTLY)
);
}
}
}
Expand All @@ -704,8 +711,9 @@ heightMeasureSpec, getPaddingTop() + getPaddingBottom() + lp.topMargin
maxHeight += getPaddingTop() + getPaddingBottom();
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
setMeasuredDimensionCompat(widthSizeAndState | childState & MEASURED_STATE_MASK,
ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec,
childState << MEASURED_HEIGHT_STATE_SHIFT));
ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec,
childState << MEASURED_HEIGHT_STATE_SHIFT)
);
if (matchHeight) {
forceUniformHeight(count, widthMeasureSpec);
}
Expand Down Expand Up @@ -867,7 +875,8 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
delta -= share;
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
getPaddingLeft() + getPaddingRight() +
lp.leftMargin + lp.rightMargin, lp.width);
lp.leftMargin + lp.rightMargin, lp.width
);
if (lp.height != 0 || heightMode != MeasureSpec.EXACTLY) {
int childHeight = child.getMeasuredHeight() + share;
if (childHeight < 0) {
Expand All @@ -878,7 +887,8 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
} else {
child.measure(childWidthMeasureSpec,
MeasureSpec.makeMeasureSpec(share > 0 ? share : 0,
MeasureSpec.EXACTLY));
MeasureSpec.EXACTLY)
);
}
if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
childState |= getChildMeasuredState(child)
Expand Down Expand Up @@ -924,27 +934,24 @@ void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
}
maxWidth += getPaddingLeft() + getPaddingRight();
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());

setMeasuredDimensionCompat(ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
heightSizeAndState);
setMeasuredDimensionCompat(ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState), heightSizeAndState);
if (matchWidth) {
forceUniformWidth(count, heightMeasureSpec);
}
}

private void setMeasuredDimensionCompat(int measuredWidth,
int measuredHeight) {
if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
measuredWidth &= MEASURED_SIZE_MASK;
measuredHeight &= MEASURED_SIZE_MASK;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}
private void setMeasuredDimensionCompat(int measuredWidth, int measuredHeight) {
if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
measuredWidth &= MEASURED_SIZE_MASK;
measuredHeight &= MEASURED_SIZE_MASK;
}
setMeasuredDimension(measuredWidth, measuredHeight);
}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private int getChildMeasuredState(final View child) {
return child.getMeasuredState();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private int getChildMeasuredState(final View child) {
return child.getMeasuredState();
}

@Override
protected void onDraw(Canvas canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private void calculateGridSizes(float numbersRadius, float xCenter, float yCente
* The numbers need to be drawn in a 7x7 grid, representing the points on the Unit Circle.
*/
float offset1 = numbersRadius;
// cos(30) = a / r => r * cos(30) = a => r * √3/2 = a
// cos(30) = a / r => r * cos(30) = a => r * sqrt(3)/2 = a
float offset2 = numbersRadius * ((float) Math.sqrt(3)) / 2f;
// sin(30) = o / r => r * sin(30) = o => r / 2 = a
float offset3 = numbersRadius / 2f;
Expand Down

0 comments on commit 5e6ec8e

Please sign in to comment.