2121import android .util .TypedValue ;
2222import com .androidplot .ui .*;
2323import com .androidplot .ui .widget .Widget ;
24+ import com .androidplot .xy .XYStepMode ;
25+ import com .androidplot .xy .XYStepModel ;
2426
2527/**
2628 * Methods for applying styleable attributes.
@@ -112,7 +114,7 @@ public static void configureSize(TypedArray attrs, Size model, int heightSizeLay
112114
113115 private static void configureSizeMetric (TypedArray attrs , SizeMetric model , int typeAttr , int valueAttr ) {
114116
115- final float value = getFloatOrDimenValue (attrs , valueAttr , model .getValue ());
117+ final float value = getIntFloatDimenValue (attrs , valueAttr , model .getValue ()). floatValue ( );
116118 final SizeLayoutType sizeLayoutType =
117119 getSizeLayoutType (attrs , typeAttr , model .getLayoutType ());
118120
@@ -146,35 +148,38 @@ public static void configureWidget(TypedArray attrs, Widget widget, int heightSi
146148 * @param yLayoutValueAttr
147149 * @param anchorPositionAttr
148150 */
149- public static void configurePositionMetrics (TypedArray attrs , PositionMetrics metrics , int xLayoutStyleAttr , int xLayoutValueAttr ,
150- int yLayoutStyleAttr , int yLayoutValueAttr , int anchorPositionAttr ) {
151+ public static void configurePositionMetrics (TypedArray attrs , PositionMetrics metrics , int xLayoutStyleAttr ,
152+ int xLayoutValueAttr , int yLayoutStyleAttr , int yLayoutValueAttr ,
153+ int anchorPositionAttr ) {
151154 if (attrs != null ) {
152155 metrics .getXPositionMetric ().set (
153- getFloatOrDimenValue (attrs , xLayoutValueAttr , metrics .getXPositionMetric ().getValue ()),
156+ getIntFloatDimenValue (attrs , xLayoutValueAttr , metrics .getXPositionMetric ().getValue ()). floatValue ( ),
154157 getXLayoutStyle (attrs , xLayoutStyleAttr , metrics .getXPositionMetric ().getLayoutType ()));
155158
156159 metrics .getYPositionMetric ().set (
157- getFloatOrDimenValue (attrs , yLayoutValueAttr , metrics .getYPositionMetric ().getValue ()),
160+ getIntFloatDimenValue (attrs , yLayoutValueAttr , metrics .getYPositionMetric ().getValue ()). floatValue ( ),
158161 getYLayoutStyle (attrs , yLayoutStyleAttr , metrics .getYPositionMetric ().getLayoutType ()));
159162 metrics .setAnchor (getAnchorPosition (attrs , anchorPositionAttr , metrics .getAnchor ()));
160163 }
161164 }
162165
163166 /**
164- * Convenience method to retrieve float values from xml that can be entered as either a float or a dimen.
167+ * Convenience method to retrieve values from xml that can be entered as a int, float or dimen.
165168 * @param attrs
166169 * @param valueAttr
167170 * @param defaultValue
168171 * @return
169172 */
170- private static float getFloatOrDimenValue (TypedArray attrs , int valueAttr , float defaultValue ) {
171- float result = defaultValue ;
173+ private static Number getIntFloatDimenValue (TypedArray attrs , int valueAttr , Number defaultValue ) {
174+ Number result = defaultValue ;
172175 if (attrs != null && attrs .hasValue (valueAttr )) {
173176 final int valueType = attrs .peekValue (valueAttr ).type ;
174177 if (valueType == TypedValue .TYPE_DIMENSION ) {
175- result = attrs .getDimension (valueAttr , defaultValue );
178+ result = attrs .getDimension (valueAttr , defaultValue .floatValue ());
179+ } else if (valueType == TypedValue .TYPE_INT_DEC ) {
180+ result = attrs .getInt (valueAttr , defaultValue .intValue ());
176181 } else if (valueType == TypedValue .TYPE_FLOAT ) {
177- result = attrs .getFloat (valueAttr , defaultValue );
182+ result = attrs .getFloat (valueAttr , defaultValue . floatValue () );
178183 } else {
179184 throw new IllegalArgumentException ("Invalid value type - must be float or dimension." );
180185 }
@@ -193,4 +198,11 @@ private static YLayoutStyle getYLayoutStyle(TypedArray attrs, int attr, YLayoutS
193198 private static AnchorPosition getAnchorPosition (TypedArray attrs , int attr , AnchorPosition defaultValue ) {
194199 return AnchorPosition .values ()[attrs .getInt (attr , defaultValue .ordinal ())];
195200 }
201+
202+ public static void configureStep (TypedArray attrs , XYStepModel model , int stepModeAttr , int stepValueAttr ) {
203+ if (attrs != null ) {
204+ model .setMode (XYStepMode .values ()[attrs .getInt (stepModeAttr , model .getMode ().ordinal ())]);
205+ model .setValue (getIntFloatDimenValue (attrs , stepValueAttr , model .getValue ()).doubleValue ());
206+ }
207+ }
196208}
0 commit comments