question

resicons avatar image
resicons asked resicons commented

how to get color code of items in inventory app?

I want to generate exactly same item color like inventory app does. I saw https://community.clover.com/questions/18381/is-there-a-way-to-color-code-the-modifiers.html and understand that clover did it by using an algorithm itself. Can you share it?

I also saw https://community.clover.com/questions/2526/item-colouring.html, but it doesn't seem to be right anymore, that thread has passed 4 years.

SandboxInventory
2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

resicons avatar image resicons commented ·

item with colors in inventory app:

follow the instruction from this link: https://community.clover.com/questions/2526/item-colouring.html I got this:


the colors are different from inventory app.

my code is something like this: https://onecompiler.com/java/3vp4sbecy

Any help would be appreciate.

0 Likes 0 ·
resicons avatar image resicons commented ·

hello, someone help me, please

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered resicons commented

I created a small example lib with colors in it here:

https://github.com/farble1670/clover-item-color


As Dan said, this is NOT part of the public Clover API. It is subject to change at any time. This is provided for example purposes only.

2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

resicons avatar image resicons commented ·

Thank you for such a detailed and informative answer! it has really helped me. Yes, I understand that at this time, item color code generation is not a part of Clover API, and it may change whenever Clover Apps update new versions. I hope you will consider to make it as a part of API in the future, I think a lot of developers want this. What a best answer, you save my day!

0 Likes 0 ·
resicons avatar image resicons commented ·

tried, it worked like a charm!

0 Likes 0 ·
Dan avatar image
Dan answered resicons commented

The color we use is an implementation detail and is subject to change at any point. It could be changed at any time for any reason without any notification/warning.
I poked around a bit and this is what I found, but no guarantees that this is partially/wholly accurate. It may help get you started.

// in a resource file
<color name="main_blue">#56B7E2</color>
<color name="main_blue_85">#D956B7E2</color>
<color name="main_blue_70">#B356B7E2</color>
<color name="main_red">#FB6264</color>
<color name="main_red_85">#D9FB6264</color>
<color name="main_red_70">#B3FB6264</color>
<color name="main_green">#6ADA99</color>
<color name="main_green_85">#D96ADA99</color>
<color name="main_green_70">#B36ADA99</color>
<color name="main_orange">#FCA468</color>
<color name="main_orange_85">#D9FCA468</color>
<color name="main_orange_70">#B3FCA468</color>
<color name="main_purple">#A175DB</color>
<color name="main_purple_85">#D9A175DB</color>
<color name="main_purple_70">#B3A175DB</color>
<color name="main_yellow">#EEDE77</color>  
<color name="main_yellow_85">#D9EEDE77</color>
<color name="main_yellow_70">#B3EEDE77</color>
<color name="main_light_orange">#F5C270</color>
<color name="main_light_green">#90D574</color>
<color name="main_light_green_85">#D990D574</color>
<color name="main_teal">#4EC3C6</color>
<color name="main_teal_85">#D94EC3C6</color>
<color name="main_violet">#7B97DF</color>
<color name="main_violet_85">#D97B97DF</color>
<color name="main_magenta">#CF6B9F</color>
<color name="main_magenta_85">#D9CF6B9F</color>
<color name="main_salmon">#FB8266</color>

// java
  public static final List<Integer> colors = new ArrayList<>(Arrays.asList(
      R.color.main_blue,
      R.color.main_green,
      R.color.main_orange,
      R.color.main_red,
      R.color.main_purple,
      R.color.main_yellow,
      R.color.main_salmon,
      R.color.main_light_orange,
      R.color.main_light_green,
      R.color.main_teal,
      R.color.main_violet,
      R.color.main_magenta,
      R.color.main_blue_85,
      R.color.main_green_85,
      R.color.main_orange_85,
      R.color.main_red_85,
      R.color.main_purple_85,
      R.color.main_yellow_85,
      R.color.main_light_green_85,
      R.color.main_teal_85,
      R.color.main_violet_85,
      R.color.main_magenta_85,
      R.color.main_blue_70,
      R.color.main_green_70,
      R.color.main_orange_70,
      R.color.main_red_70,
      R.color.main_purple_70,
      R.color.main_yellow_70));

private static Random RANDOM = new Random();

public static int colorInt(Context context, LineItem lineItem) {
  Reference item = lineItem.getItem();
  if (item != null && item.getId() != null) {
    RANDOM.setSeed(item.getId().hashCode());
  } else if (lineItem.getId() != null) {
    RANDOM.setSeed(lineItem.getId().hashCode());
  }
  return context.getResources().getColor(colors.get(RANDOM.nextInt(colors.size())));
}

// looks like we may default to Color.argb(255, 100, 100, 100) when we dont have an id to work with
2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

resicons avatar image resicons commented ·

Thank you for providing such a detailed answer! I will try this, you're the best!

0 Likes 0 ·
resicons avatar image resicons commented ·

tried, it worked like a charm!

0 Likes 0 ·

Welcome to the
Clover Developer Community