Android Color Hue Saturation Value Dialog using Basic4Android

Another tutorial for Color Dialog is this what we called Color Hue and Saturation Value Dialog. This Color HSV Dialog is different from the typical Color Dialog because it only has RGB Color. But this one uses the Hue and Saturation Values of the Color Dialog. First, you need to create one button and named it Button1. Next, named your layout name as "Main". Declare first your variable in the Sub_Global like this:
  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4. Dim Button1 As Button
  5. Dim bmp As Bitmap
  6. End Sub
I have initialized bmp as Bitmap because I wanted to have an icon to my Color HSV Dialog. Here's the full code for this tutorial:
  1. Sub Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4.  
  5. End Sub
  6.  
  7. Sub Globals
  8. 'These global variables will be redeclared each time the activity is created.
  9. 'These variables can only be accessed from this module.
  10.  
  11. Dim Button1 As Button
  12. Dim bmp As Bitmap
  13. End Sub
  14.  
  15. Sub Activity_Create(FirstTime As Boolean)
  16. 'Do not forget to load the layout file created with the visual designer. For example:
  17. 'Activity.LoadLayout("Layout1")
  18. Activity.LoadLayout("Main")
  19. bmp.InitializeSample(File.DirAssets, "bermoy.jpg",48,48)
  20. Activity.Title = "Color Dialog HSV - Lyndon Bermoy"
  21.  
  22. End Sub
  23.  
  24. Sub Activity_Resume
  25.  
  26. End Sub
  27.  
  28. Sub Activity_Pause (UserClosed As Boolean)
  29.  
  30. End Sub
  31.  
  32. Sub Button1_Click
  33. Dim cd As ColorDialogHSV
  34. Dim color As Int
  35. cd.Hue = 180
  36. cd.Saturation = 0.5
  37. cd.Value = 0.5
  38. ret = cd.Show("B4A Color HSV Dialog HSV", "Yes", "No", "Maybe", bmp)
  39. ToastMessageShow(ret & " : " & cd.RGB, False)
  40. Activity.color = cd.RGB
  41. End Sub
Note: cd - our variable used for initiating ColorDialogHSV for Hue and Saturation values. color - the variable used as the color in terms of integer value. cd.Hue = 180 - a syntax used in the default value of our Hue Color is at 180. cd.Saturation = 0.5 - a syntax used in the default value of our Saturation Color is at 0.5. cd.Value = 0.5 - a syntax used in the default value of our Saturation Color is at 0.5. ret - our variable in object that is used for the input dialog in color. Activity.color = cd.RGB - a syntax in which when you chose the color for HSV and then clicked it, the background of the activity will also changed in corresponds to the value of HSV color. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment