Pages

HexaCode

When designing an interface for an app or a website, the hex values for colors are needed. I just wanted a tool that allowed me to play around with hex values and see the result color. The main purpose for coding this was to experiment with WebView in Android. It also felt like a fun little 2-3 hours why-not-just-do-it project.
The three Slide bars correspond to Red, Green and Blue values respectively. First of all, a html script with background color information based on SlideBar inputs is generated. The Web View then uses the generated html script to build a html web-page.
Users can also use the EditText and Submit button to input hex values. Initially, I had not planned on putting this functionality. I later decided to add it because several people were giving bad ratings to similar app in the appstore for missing it. Also, it was a fairly simple addition.






Option 1: Slide the SeekBars to get required values. 

For example, when Red SeekBar is changed:


public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {

 String red = Integer.toHexString(arg1);
 if (red.length() == 1) {
  red = "0" + red;
 }

 String green = Integer.toHexString(greenSeekBar.getProgress());
 if (green.length() == 1) {
  green = "0" + green;
 }

 String blue = Integer.toHexString(blueSeekBar.getProgress());
 if (blue.length() == 1) {
  blue = "0" + blue;
 }

 color = "<!DOCTYPE html><html><body bgcolor=" + red + green + blue + "></body></html>";

 htmlDisplay.loadData(color, "text/html", null);
 result.setText("#" + red + green + blue); 
}

Option 2: Use the EditText to enter the value. 

This option will change the SeekBars position to input values. Once that happens, request has been deduced to act similarly as Option 1.


String Input = input.getText().toString() + "";
if ((Input.length() == 6) && (Input.matches("[0-9A-Fa-f]+"))) {
 redSeekBar.setProgress(Integer.parseInt(Input.substring(0, 2), 16));
 greenSeekBar.setProgress(Integer.parseInt(Input.substring(2, 4), 16));
 blueSeekBar.setProgress(Integer.parseInt(Input.substring(4, 6), 16));
} else {
 input.setText("ERROR!");
}

Ayush Subedi

Coffee Connoisseur