Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Plot crashes when setting color from resource id #88

Open
planetmarshall opened this issue Nov 13, 2018 · 2 comments
Open

Android Plot crashes when setting color from resource id #88

planetmarshall opened this issue Nov 13, 2018 · 2 comments
Assignees
Labels

Comments

@planetmarshall
Copy link

planetmarshall commented Nov 13, 2018

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
       LineAndPointFormatter profileFormatter = new LineAndPointFormatter(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

private static int parseIntAttr(String value) {
        if (Character.isDigit(value.charAt(0))) {
            return Integer.parseInt(value);
        } else if (value.startsWith(RESOURCE_ID_PREFIX)) {
            // it's a resId
            return Color.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)

@halfhp
Copy link
Owner

halfhp commented Nov 14, 2018

Thanks for the report - will investigate. Fig does in fact support the use of resource id's so off the top of my head I'm not sure where things are breaking here.

@halfhp halfhp self-assigned this Nov 14, 2018
@halfhp
Copy link
Owner

halfhp commented Jul 20, 2019

Found the bug in Fig. Expect to have it fixed for the 1.5.8 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants