### Complete Example Activity (Kotlin) Source: https://github.com/skydoves/colorpickerview/blob/main/docs/sliders/alpha-slidebar.md A complete Kotlin Activity demonstrating the setup and usage of ColorPickerView and AlphaSlideBar, including attaching the slider and handling color changes. ```kotlin class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val colorPickerView = findViewById(R.id.colorPickerView) val alphaSlideBar = findViewById(R.id.alphaSlideBar) // Attach the alpha slider to the color picker colorPickerView.attachAlphaSlider(alphaSlideBar) colorPickerView.setColorListener(ColorEnvelopeListener { envelope, fromUser -> // The color includes alpha value from the slider val colorWithAlpha = envelope.color }) } } ``` -------------------------------- ### Complete Implementation Example Source: https://github.com/skydoves/colorpickerview/blob/main/docs/preference.md A full example showing how to integrate ColorPickerView with sliders and automatic state persistence in an Activity. ```kotlin class MainActivity : AppCompatActivity() { private lateinit var colorPickerView: ColorPickerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) colorPickerView = findViewById(R.id.colorPickerView) val alphaSlideBar = findViewById(R.id.alphaSlideBar) val brightnessSlideBar = findViewById(R.id.brightnessSlideBar) // Attach sliders colorPickerView.attachAlphaSlider(alphaSlideBar) colorPickerView.attachBrightnessSlider(brightnessSlideBar) // Enable automatic state persistence colorPickerView.setPreferenceName("MainColorPicker") colorPickerView.setLifecycleOwner(this) colorPickerView.setColorListener(ColorEnvelopeListener { envelope, fromUser -> updateUI(envelope) }) } private fun updateUI(envelope: ColorEnvelope) { // Update your UI } } ``` -------------------------------- ### Complete Example Layout Source: https://github.com/skydoves/colorpickerview/blob/main/docs/sliders/alpha-slidebar.md An example of a complete layout integrating ColorPickerView and AlphaSlideBar, suitable for an Android Activity. ```xml ``` -------------------------------- ### Install ColorPickerView Dependency Source: https://github.com/skydoves/colorpickerview/blob/main/docs/getting-started.md Add the library dependency to your module's build.gradle file. ```groovy dependencies { implementation("com.github.skydoves:colorpickerview:2.4.0") } ``` ```kotlin dependencies { implementation("com.github.skydoves:colorpickerview:2.4.0") } ``` -------------------------------- ### Start Gallery Intent Source: https://github.com/skydoves/colorpickerview/blob/main/README.md Initiate an intent to open the device's gallery for image selection. This code should be followed by handling the result in onActivityResult. ```java Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, REQUEST_CODE_GALLERY); ``` -------------------------------- ### Set Initial Color Source: https://github.com/skydoves/colorpickerview/blob/main/docs/getting-started.md Configures the starting color for the selector and slide bars, which is only effective with the default HSV palette. ```xml app:initialColor="@color/colorPrimary" ``` ```kotlin colorPickerView.setInitialColor(color) // or using a color resource colorPickerView.setInitialColorRes(R.color.colorPrimary) ``` -------------------------------- ### Color Preview Layout Source: https://github.com/skydoves/colorpickerview/blob/main/docs/alphatileview.md A layout example demonstrating how to use AlphaTileView for a simple color preview alongside a TextView to display the hex code. ```xml ``` -------------------------------- ### Handle onRefresh Updates Source: https://github.com/skydoves/colorpickerview/blob/main/docs/flagview.md Example implementation of the onRefresh method to update UI components with color data. ```kotlin override fun onRefresh(colorEnvelope: ColorEnvelope) { // Update your views with the new color information hexCodeTextView.text = "#${colorEnvelope.hexCode}" colorPreview.setBackgroundColor(colorEnvelope.color) // Access ARGB values val argb = colorEnvelope.argb alphaText.text = "A: ${argb[0]}" redText.text = "R: ${argb[1]}" greenText.text = "G: ${argb[2]}" blueText.text = "B: ${argb[3]}" } ``` -------------------------------- ### Attach and Control BrightnessSlideBar Source: https://context7.com/skydoves/colorpickerview/llms.txt Provides code examples for programmatically attaching a BrightnessSlideBar to ColorPickerView and setting its selector position to adjust brightness. ```java BrightnessSlideBar brightnessSlideBar = findViewById(R.id.brightnessSlideBar); colorPickerView.attachBrightnessSlider(brightnessSlideBar); ``` ```java brightnessSlideBar.setSelectorPosition(1.0f); ``` ```java colorPickerView.attachAlphaSlider(alphaSlideBar); colorPickerView.attachBrightnessSlider(brightnessSlideBar); ``` -------------------------------- ### Set Initial Color for ColorPickerDialog in Kotlin Source: https://github.com/skydoves/colorpickerview/blob/main/docs/color-picker-dialog.md Demonstrates how to set a specific starting color for the ColorPickerDialog by accessing the colorPickerView property of the builder before showing the dialog. ```kotlin val builder = ColorPickerDialog.Builder(this) .setTitle("Select Color") .setPositiveButton("OK", ColorEnvelopeListener { envelope, _ -> // Handle selection }) .setNegativeButton("Cancel") { dialog, _ -> dialog.dismiss() } // Set initial color builder.colorPickerView.setInitialColor(currentColor) builder.show() ``` -------------------------------- ### Custom FlagView with AlphaTileView Source: https://github.com/skydoves/colorpickerview/blob/main/docs/alphatileview.md Example of a custom `FlagView` that incorporates `AlphaTileView` to display color information, including the hex code. ```kotlin class CustomFlag(context: Context, layout: Int) : FlagView(context, layout) { private val alphaTileView: AlphaTileView = findViewById(R.id.flag_color_preview) private val hexCodeText: TextView = findViewById(R.id.flag_hex_code) override fun onRefresh(colorEnvelope: ColorEnvelope) { alphaTileView.setPaintColor(colorEnvelope.color) hexCodeText.text = "#${colorEnvelope.hexCode}" } } ``` -------------------------------- ### Custom Flag View Implementation Source: https://github.com/skydoves/colorpickerview/blob/main/docs/flagview.md Extends FlagView to create a custom layout for displaying color information. This example shows how to update a TextView with the hex code and an AlphaTileView with the selected color. Ensure the layout XML (e.g., layout_flag.xml) defines the TextView and AlphaTileView. ```kotlin class CustomFlag(context: Context, layout: Int) : FlagView(context, layout) { private val textView: TextView = findViewById(R.id.flag_color_code) private val alphaTileView: AlphaTileView = findViewById(R.id.flag_color_layout) override fun onRefresh(colorEnvelope: ColorEnvelope) { textView.text = "#${colorEnvelope.hexCode}" alphaTileView.setPaintColor(colorEnvelope.color) } } ``` -------------------------------- ### Initial Color Configuration Source: https://github.com/skydoves/colorpickerview/blob/main/docs/preference.md Set an initial color that applies only on the first launch before saved preferences take precedence. ```kotlin colorPickerView.setPreferenceName("MyColorPicker") colorPickerView.setInitialColor(Color.BLUE) ``` -------------------------------- ### Get AlphaSlideBar Selected Value Source: https://github.com/skydoves/colorpickerview/blob/main/docs/sliders/alpha-slidebar.md Retrieves the current selected X-coordinate (position) of the selector on the AlphaSlideBar. ```kotlin val selectedX = alphaSlideBar.selectedX ``` -------------------------------- ### ShapeAppearancePathProvider.ShapeAppearancePathSpec Constructor Source: https://github.com/skydoves/colorpickerview/blob/main/app/src/release/generated/baselineProfiles/baseline-prof.txt Constructor for ShapeAppearancePathSpec. ```APIDOC ## ShapeAppearancePathProvider.ShapeAppearancePathSpec Constructor ### Description Constructor for ShapeAppearancePathSpec. ### Parameters - `shapeAppearanceModel` (ShapeAppearanceModel) - Required - The shape appearance model. - `path` (Path) - Required - The path to be drawn. - `pathListener` (PathListener) - Optional - A listener for path events. - `interpolation` (float) - Required - The interpolation factor. - `bounds` (RectF) - Required - The bounds of the shape. ``` -------------------------------- ### Implement ColorPickerDialog in MainActivity Source: https://github.com/skydoves/colorpickerview/blob/main/docs/color-picker-dialog.md Demonstrates the full lifecycle of a color picker dialog, including button listeners, color envelope handling, and UI updates. ```kotlin class MainActivity : AppCompatActivity() { private var selectedColor: Int = Color.WHITE override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) findViewById