Skip to content

Android Plot crashes when setting color from resource id #88

Description

@planetmarshall

Summary

Applying a style where a color is specified as a resource ID causes an App using Android Plot to crash.

Expected Results

With a style resource such as

<config
linePaint.color="@color/accent_blue"
/>

Applying the style in a formatter should apply the specified color resource.

Actual Results

Applying the style in a formatter causes the app to crash.

Steps to Reproduce

  1. Define a color resource
  2. Define a style xml resource as above referring to the color resource
  3. Apply the style resource using
LineAndPointFormatterprofileFormatter = newLineAndPointFormatter(this, R.xml.style);

Reproduced in

Androidplot 1.5.6
Google Pixel with Android 9 (API Level 28)
Compile SDK Version 26
Android Build tools 28.0.2

Stacktrace

 Caused by: java.lang.IllegalArgumentException: Unknown color
at android.graphics.Color.parseColor(Color.java:1400)
at com.halfhp.fig.Fig.parseIntAttr(Fig.java:58)
at com.halfhp.fig.Fig.inflateParams(Fig.java:163)
at com.halfhp.fig.Fig.configure(Fig.java:283)
at com.halfhp.fig.Fig.configure(Fig.java:208)
at com.halfhp.fig.Fig.configure(Fig.java:234)
at com.halfhp.fig.Fig.configure(Fig.java:253)
at com.androidplot.ui.Formatter.configure(Formatter.java:52)

Notes

The issue appears to be caused by the following code in Fig.java

privatestaticintparseIntAttr(Stringvalue) {
if (Character.isDigit(value.charAt(0))) {
returnInteger.parseInt(value);
} elseif (value.startsWith(RESOURCE_ID_PREFIX)) {
// it's a resIdreturnColor.parseColor(value);
...

However, the Android Color.parseColor function does not accept resource IDs:

https://developer.android.com/reference/android/graphics/Color#parseColor(java.lang.String)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions