0

I'm trying to avoid using rgb values, so this method:

public LineAndPointFormatter(Integer lineColor, Integer vertexColor, Integer fillColor) {
     this(lineColor, vertexColor, fillColor, FillDirection.BOTTOM);
}

where I'm supposed to pass in:

LineAndPointFormatter lpf = new LineAndPointFormatter(Color.rgb(0, 0, 200), null, Color.rgb(0, 0, 80));

is working just fine, but I want to use this method:

public LineAndPointFormatter(Context ctx, int xmlCfgId) {
    // prevent configuration of classes derived from this one:
    if (getClass().equals(LineAndPointFormatter.class)) {
        Configurator.configure(ctx, this, xmlCfgId);
    }
}

so I can use the colors.xml resource ID and manage all graph colors by setting "colorID" then passing it in later (colorID is showing up as -65536 in the log or some variation of that depending on ). This code is inside a class that's extending Fragment, so I'm wondering if I'm getting the Context correct..

Here are some of the things I've tried:

LineAndPointFormatter seriesFormat = new LineAndPointFormatter(getActivity().getApplicationContext(), getResources().getColor(R.color.blue));

LineAndPointFormatter seriesFormat = new LineAndPointFormatter(getActivity().getApplicationContext(), colorID);

LineAndPointFormatter seriesFormat = new LineAndPointFormatter(getActivity().getApplicationContext(), getResources().getColor(colorID));

and so on..

I'll keep pluggin away, but if anyone is using the Context version of LineAndPointFormatter, maybe you've run into a similar problem?

The exception looks like this:

05-14 12:47:25.917: E/AndroidRuntime(14023): android.content.res.Resources$NotFoundException: Resource ID #0xff0000ff

Do I have to rewrite my colors into the #ff0000ff format??

EDIT: Added colors.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="transparent_white">#66FFFFFF</color>
<color name="yellow">#FFFF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="red">#FF0000</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="olive">#808000</color>
<color name="purple">#800080</color>
<color name="maroon">#800000</color>
<color name="aqua">#00FFFF</color>
<color name="lime">#00FF00</color>
<color name="teal">#008080</color>
<color name="green">#008000</color>
<color name="blue">#0000ff</color>
<color name="navy">#000080</color>
<color name="black">#000000</color>
</resources>
whyoz
  • 5,168
  • 47
  • 53
  • Hi whyoz, could you post the content of your xml file corresponding to xmlCfgId – Nick May 15 '13 at 15:48
  • @Nick, I added colors.xml, and just to update, I did add the transparency format of #ff0000ff and that produced the same errors. – whyoz May 15 '13 at 17:08

1 Answers1

2

I think the problem is that you are using an xml resource which contains elements not related to the object being configured by the "configurator". Configurator uses reflection to figure out how to map your xml values to the members of the associated object. To this end, it is important that xml file only contain elements for actual members of the object being configured and that those elements share the same name of those members.

In your example above you are trying to configure a LineAndPointFormatter using an xml file containing elements with names like silver, gray etc. which do not exist. Instead you should store your config in a separate xml file looking something like this:

<?xml version="1.0" encoding="utf-8"?>
<config vertexPaint.color="#00FF00"
        linePaint.color="#00FF00"
        linePaint.strokeWidth="2dp"/>

Once you've defined this file something you can try (I've not personally tried this but assume it should work) is to reference your values in colors.xml so that when you adjust your definition of the color gray for example, it is adjusted globally.

Nick
  • 8,181
  • 4
  • 38
  • 63
  • I will try this out as soon as I can! For now, I'm just adding setR, setG, and setB into my object which is working great. I've really enjoyed working with AndroidPlot so far, so I really want to give back and add pieces of help on SO as questions arise, even if I plan to answer my own question...you're a busy guy, so I want to help as much as I can. – whyoz May 15 '13 at 18:12
  • Do you have a problem with users posting here instead of http://androidplot.com/forum/ ? I followed up with a post on your forum then copied it here as a question with the intent to answer my own question in great detail. – whyoz May 22 '13 at 17:32
  • Not at all - in fact I think SOF is probably the better place to ask these sorts of technical questions. – Nick May 22 '13 at 17:35
  • I bring this up because a moderator removed my post, maybe because it was the exact same as the forum? – whyoz May 22 '13 at 17:48
  • That's odd. I can assure you it was not removed by anybody associated with androidplot.com – Nick May 22 '13 at 18:09