get Brightness, get Hex Name : Hex « Date Type « Android






get Brightness, get Hex Name

 
//package android.Utils;

import android.graphics.Color;

 class colorCalculation {
  public static int[] getBrightness(int number) {
    int[] brightness = new int[8];
    for (int i = 0; i < 8; i++) {
      brightness[i] = number % 3;
      number = number / 3;
    }

    return brightness;
  }

  public static float[] setLedBrightness(int[] number) {
    float[] ledbrightness = new float[8];
    for (int i = 0; i < 8; i++) {
      switch (number[i]) {
      case 0:
        ledbrightness[i] = 0;
        break;
      case 1:
        ledbrightness[i] = 0.1f;
        break;
      case 2:
        ledbrightness[i] = 1f;
        break;
      }

    }
    return ledbrightness;
  }


    public static String getHexName (int color)
    {
      int r = Color.red(color);
      int g = Color.green(color);
      int b = Color.blue(color);
      
      String rHex = Integer.toString (r, 16);
      String gHex = Integer.toString (g, 16);
      String bHex = Integer.toString (b, 16);        

      return (rHex.length() == 2 ? "" + rHex : "0" + rHex) +
             (gHex.length() == 2 ? "" + gHex : "0" + gHex) +
             (bHex.length() == 2 ? "" + bHex : "0" + bHex);
    }
}

   
  








Related examples in the same category

1.Hex Dump
2.converts given byte array to a hex string
3.converts given hex string to a byte array (ex: "0D0A" => {0x0D, 0x0A,})
4.Color name and its hex value
5.hex To Decimal
6.Get Hex string out of byte array
7.String to Hex
8.Convenience method to convert a byte to a hex string.
9.Convenience method to convert a byte array to a hex string.
10.Convert a byte[] array to readable string format. This makes the "hex" readable!
11.Decode Unicode Hex
12.byte Array To Hex String