Skip to content

Instantly share code, notes, and snippets.

@vidia
Created February 16, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidia/311f36e27cd4df8c805d5adb9851c361 to your computer and use it in GitHub Desktop.
Save vidia/311f36e27cd4df8c805d5adb9851c361 to your computer and use it in GitHub Desktop.
@ColorInt
private int getColorForNode(Node node) {
//Set the color of the node item.
if(node.getEdges().getIn().length <= 1 && node.getEdges().getOut().length <= 1) {
//This is either a green process or a yes/no question answer.
//we need to check the previous node to see what we are.
Node[] previousNodes = mAlgorithmGraph.getPreviousNodes(node);
if(previousNodes.length == 0) {
//this is the first node, so it has to be a process at this point.
return 0x8BCCA5;
} if(previousNodes.length == 1) {
//there is one parent node to this one, so we check how many outer links it has.
int numberOfOutEdges = previousNodes[0].getEdges().getOut().length;
if(numberOfOutEdges > 1) {
//the previous node is a question, so this needs to be purple.
return 0xE1BEE7;
}
return 0x8BCCA5;
}
return 0x8BCCA5;
} else if (node.getEdges().getOut().length > 1) {
//Question node.
return 0x82B1FF;
} else if(node.getEdges().getOut().length == 0) {
//final node.
return 0xFF8A80;
}
throw new IllegalStateException("The provided node doesn't " +
"have a possible color and should be checked. " +
"Node ID:" + node.getId());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment