Skip to content

Instantly share code, notes, and snippets.

@hanleyhansen
Created June 8, 2013 21:35
Show Gist options
  • Save hanleyhansen/d7e5bb9654d97994dfdf to your computer and use it in GitHub Desktop.
Save hanleyhansen/d7e5bb9654d97994dfdf to your computer and use it in GitHub Desktop.
Drawing Hexagons
private View createPageView(final Group group) {
final RelativeLayout view = (RelativeLayout) View.inflate(getActivity(), R.layout.fragment_channel, null);
// http://stackoverflow.com/questions/2739971/overlay-two-images-in-android-to-set-an-imageview
Resources r = getResources();
Drawable mask = r.getDrawable(R.drawable.btn_group_mask);
StateListDrawable states = new StateListDrawable();
HexagonDrawable hexagon = null;
Drawable[] layers;
LayerDrawable layerDrawable;
hexagon = new HexagonDrawable();
hexagon.fill();
// http://stackoverflow.com/questions/4928772/android-color-darker
float[] hsv = new float[3];
int color = group.getUIColor();
Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f; // value component
color = Color.HSVToColor(hsv);
hexagon.setColor(color);
layers = new Drawable[2];
layers[0] = hexagon;
layers[1] = mask;
layerDrawable = new LayerDrawable(layers);
states.addState(new int[] { android.R.attr.state_pressed }, layerDrawable);
states.addState(new int[] { android.R.attr.state_focused }, layerDrawable);
hexagon = new HexagonDrawable();
hexagon.fill();
hexagon.setColor(group.getUIColor());
layers = new Drawable[2];
layers[0] = hexagon;
layers[1] = mask;
layerDrawable = new LayerDrawable(layers);
states.addState(new int[] {}, layerDrawable);
Button button = (Button) view.findViewById(R.id.group_button);
button.setBackground(states);
if (group.name != null) {
button.setText(group.name.toUpperCase());
} else {
button.setText("Unknown");
}
button.setTypeface(UIHelper.categoryButtonTypeface(getActivity()));
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCallback.onGroupSelect(group);
}
});
return view;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment