### Implement OnCheckListener Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example demonstrating how to set an OnCheckListener on a CheckBox to react to state changes. ```java checkbox.setOncheckListener(new CheckBox.OnCheckListener() { @Override public void onCheck(CheckBox view, boolean check) { if(check) { enableFeature(); } else { disableFeature(); } } }); ``` -------------------------------- ### Programmatic Usage of ProgressBarIndeterminateDeterminate Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/progress-bars.md This example demonstrates how to use ProgressBarIndeterminateDeterminate programmatically. It shows initialization, starting the indeterminate state, and then updating to determinate progress. ```java ProgressBarIndeterminateDeterminate progress = (ProgressBarIndeterminateDeterminate) findViewById(R.id.progress); // Starts indeterminate progress.show(); // Later, start reporting progress progress.setProgress(25); // Stops animation, shows 25% progress.setProgress(50); // Updates to 50% progress.setProgress(100); // Completes ``` -------------------------------- ### Implement OnClickListener Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of how to implement the OnClickListener interface for a button. ```java button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { performAction(); } }); ``` -------------------------------- ### Float Small Button Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md Example of how to declare a Float Small Button in XML layout. ```xml ``` -------------------------------- ### Switch Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a Switch component. ```xml ``` -------------------------------- ### Create and Configure Dialog Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Example demonstrating the creation of a dialog, adding a cancel button, and setting a new message. ```java Dialog dialog = new Dialog(context, "Confirm", "Delete this item?"); dialog.addCancelButton("NO"); dialog.setMessage("Processing... this may take a moment"); ``` -------------------------------- ### Implement ColorSelector OnColorSelectedListener Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of creating and showing a ColorSelector with a custom OnColorSelectedListener to process the selected color. The listener receives the color as an ARGB integer. ```java ColorSelector picker = new ColorSelector( context, Color.BLUE, new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { // Color selected int red = (color >> 16) & 0xFF; int green = (color >> 8) & 0xFF; int blue = (color >> 0) & 0xFF; applyColor(red, green, blue); } } ); picker.show(); ``` -------------------------------- ### Create and Configure Dialog with Cancel Callback Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Example showing how to create a dialog with a cancel button that also has a click listener to handle user interaction. ```java Dialog dialog = new Dialog(context, "Confirm", "Delete this item?"); dialog.addCancelButton("Cancel", new View.OnClickListener() { @Override public void onClick(View v) { // User clicked cancel } }); ``` -------------------------------- ### Initialize Sliders with Starting Color Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Initializes the R, G, and B sliders with the corresponding values from a starting color. Each slider is configured with a min of 0 and a max of 255, spanning the full RGB color space. ```java int r = (this.color >> 16) & 0xFF; int g = (this.color >> 8) & 0xFF; int b = (this.color >> 0) & 0xFF; red.setValue(r); green.setValue(g); blue.setValue(b); red.setOnValueChangedListener(this); green.setOnValueChangedListener(this); blue.setOnValueChangedListener(this); ``` -------------------------------- ### Determinate Progress Bar Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a determinate progress bar. ```xml ``` -------------------------------- ### Flat Button XML Layout Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md Example of how to define a Flat Button in your XML layout file. ```xml ``` -------------------------------- ### Programmatic Usage of Material Design Switch Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/switch.md Demonstrates how to get a reference to a Switch, set its initial state, add a listener for state changes, customize its color, and toggle it programmatically. ```java // Get reference Switch switchView = (Switch) findViewById(R.id.switchView); // Set initial state switchView.setChecked(false); // Start OFF // Add listener for user changes switchView.setOncheckListener(new Switch.OnCheckListener() { @Override public void onCheck(Switch view, boolean check) { updateUI(check); } }); // Customize color switchView.setBackgroundColor(Color.parseColor("#FF5722")); // Toggle programmatically (no listener callback) switchView.setChecked(!switchView.isCheck()); // Read state boolean isOn = switchView.isCheck(); ``` -------------------------------- ### Settings Screen with Controls Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/README.md Create a settings screen layout using ScrollView, LinearLayout, TextView, Switch, and Slider components. This example demonstrates how to structure UI elements for settings. ```xml ``` -------------------------------- ### Checkbox Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a CheckBox component. ```xml ``` -------------------------------- ### Parse Standard Android XML Attributes Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Retrieve standard Android attributes like 'background' from XML. This example shows how to get color resources and direct color integer values. ```java // Color from resource int background = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); if(background != -1) { setBackgroundColor(getResources().getColor(background)); } // Color from hex background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); if(background != -1) { setBackgroundColor(background); } ``` -------------------------------- ### Implement SnackBar OnHideListener Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of setting an OnHideListener for a SnackBar to execute code when the snackbar is dismissed. This listener is triggered by auto-timeout, manual dismiss, or outside touch. ```java SnackBar snackbar = new SnackBar(activity, "Item deleted", "Undo", new View.OnClickListener() { @Override public void onClick(View v) { // User clicked UNDO button restoreItem(); } } ); snackbar.setOnhideListener(new SnackBar.OnHideListener() { @Override public void onHide() { // Snackbar is gone (but item was already deleted unless undo was clicked) resetUI(); } }); snackbar.show(); ``` -------------------------------- ### Example Usage of ColorSelector Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Demonstrates how to create and show a ColorSelector instance. It sets an initial blue color and provides a callback to update a view's background color upon selection. ```java ColorSelector colorPicker = new ColorSelector( context, Color.BLUE, new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { myView.setBackgroundColor(color); } } ); colorPicker.show(); ``` -------------------------------- ### Slider Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a Slider component with custom min and max values. ```xml ``` -------------------------------- ### Custom Button Subclass Implementation Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button.md Example of a custom Button subclass (ButtonFlat) demonstrating how to set default properties, parse XML attributes, and initialize the view. ```java public class ButtonFlat extends Button { protected void setDefaultProperties(){ minHeight = 36; minWidth = 88; rippleSize = 3; setMinimumHeight(Utils.dpToPx(minHeight, getResources())); setMinimumWidth(Utils.dpToPx(minWidth, getResources())); setBackgroundResource(R.drawable.background_transparent); } protected void setAttributes(AttributeSet attrs){ // Parse XML and configure button } } ``` -------------------------------- ### Indeterminate Progress Bar Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for an indeterminate progress bar. ```xml ``` -------------------------------- ### Dialog Usage Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md Java code to create and show a basic Dialog. Includes examples for setting button listeners and accessing buttons. ```java Dialog dialog = new Dialog(Context context,String title, String message); dialog.show(); // Set accept click listenner dialog.setOnAcceptButtonClickListener(View.OnClickListener onAcceptButtonClickListener); // Set cancel click listenner dialog.setOnCancelButtonClickListener(View.OnClickListener onCancelButtonClickListener); // Acces to accept button ButtonFlat acceptButton = dialog.getButtonAccept(); // Acces to cancel button ButtonFlat cancelButton = dialog.getButtonCancel(); ``` -------------------------------- ### ButtonFlat setAttributes Implementation Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button.md Example implementation of setAttributes in ButtonFlat, parsing text and background color attributes from XML. ```java protected void setAttributes(AttributeSet attrs) { // Parse text attribute String text = attrs.getAttributeValue(ANDROIDXML, "text"); if(text != null) { textButton = new TextView(getContext()); textButton.setText(text.toUpperCase()); // ... add to layout } // Parse background color int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); if(background != -1) setBackgroundColor(background); } ``` -------------------------------- ### Programmatic Usage of ButtonFloat Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Demonstrates how to get a reference to a ButtonFloat, set its icon, handle click events, control visibility, and customize its appearance programmatically. ```java // Get reference ButtonFloat fab = (ButtonFloat) findViewById(R.id.buttonFloat); // Set icon Drawable icon = getResources().getDrawable(R.drawable.ic_add); fab.setDrawableIcon(icon); // Set click listener fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivity.this, CreateActivity.class)); } }); // Control visibility fab.show(); // Slide in from bottom fab.hide(); // Slide out to bottom // Check state if(fab.isShow()) { fab.hide(); } else { fab.show(); } // Customize appearance fab.setBackgroundColor(Color.parseColor("#FF5722")); fab.setRippleColor(Color.parseColor("#FFB74D")); ``` -------------------------------- ### show() Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/snackbar.md Displays the snackbar with a slide-up animation. It appears at the bottom of the screen and starts its auto-dismiss timer if one is set. ```APIDOC ## show() ### Description Displays the snackbar with slide-up animation at the bottom of the screen. ### Method ```java public void show() ``` ### Behavior - Shows the snackbar at bottom of screen - Applies slide-up animation - Starts auto-dismiss timer (if not indeterminate) - Animation: R.anim.snackbar_show_animation ### Example ```java SnackBar snackbar = new SnackBar(activity, "Item saved"); snackbar.show(); ``` ``` -------------------------------- ### Indeterminate Determinate Progress Bar Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for an indeterminate determinate progress bar. ```xml ``` -------------------------------- ### CustomView onAnimationStart Method Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Called when an animation begins on this view. Override in subclasses to respond to animation start. ```java protected void onAnimationStart() ``` -------------------------------- ### Rectangle Button XML Layout Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md Example of how to define a Rectangle Button in your XML layout file. ```xml ``` -------------------------------- ### Apply Material Design Spacing and Padding Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/configuration.md Utilize the Material Design 8dp grid system for spacing and padding, with standard values including 8dp, 16dp, and 24dp. This example shows padding on a LinearLayout containing Material Design components. ```xml ``` -------------------------------- ### Example Usage of setEnabled Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Demonstrates how to programmatically enable and disable a CustomView instance. Disabling grays out the view, while re-enabling restores its original appearance. ```java CustomView view = (CustomView) findViewById(R.id.myview); view.setEnabled(false); // Disable and gray out view.setEnabled(true); // Re-enable with previous color ``` -------------------------------- ### Programmatic Usage Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/checkbox.md This section covers how to get a reference to the Checkbox, set its initial state, add listeners, customize its appearance, and programmatically change or read its state. ```APIDOC ## Programmatic Usage ### Get Reference Obtain a reference to the Checkbox view using its ID. ```java CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox); ``` ### Set Initial State Set the initial checked state of the checkbox. ```java checkbox.setChecked(true); ``` ### Add Listener Implement an `OnCheckListener` to respond to state changes. ```java checkbox.setOncheckListener(new CheckBox.OnCheckListener() { @Override public void onCheck(CheckBox view, boolean check) { // Handle check state change } }); ``` ### Customize Color Change the background color of the checkbox. ```java checkbox.setBackgroundColor(Color.parseColor("#FF5722")); ``` ### Change State Programmatically Programmatically set the checked state. ```java checkbox.setChecked(false); ``` ### Read State Check the current checked state of the checkbox. ```java boolean isChecked = checkbox.isCheck(); ``` ``` -------------------------------- ### Circular Indeterminate Progress Bar Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a circular indeterminate progress bar. ```xml ``` -------------------------------- ### Slider with Number Indicator Example Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/README.md XML declaration for a Slider component that shows a number indicator. ```xml ``` -------------------------------- ### CustomView Subclass Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Subclasses must call the super constructor. Example shown for a view with Context and AttributeSet. ```java public MyView(Context context, AttributeSet attrs) { super(context, attrs); } ``` -------------------------------- ### Customize Button and Text Colors Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md This example illustrates how to customize the background colors of the accept and cancel buttons, as well as modify the text size and color of the dialog's title and message. ```java Dialog dialog = new Dialog(context, "Action Required", "What do you want?"); dialog.addCancelButton("Cancel"); // Style buttons dialog.getButtonAccept().setBackgroundColor(Color.parseColor("#FF5722")); dialog.getButtonCancel().setBackgroundColor(Color.parseColor("#9E9E9E")); // Custom text styling dialog.getTitleTextView().setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); dialog.getMessageTextView().setTextColor(Color.parseColor("#666666")); dialog.show(); ``` -------------------------------- ### Implement Switch OnCheckListener Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of setting an OnCheckListener on a Switch view. This callback is triggered when the user releases touch after dragging the switch, if its state has changed. ```java switchView.setOncheckListener(new Switch.OnCheckListener() { @Override public void onCheck(Switch view, boolean check) { if(check) { startService(); } else { stopService(); } } }); ``` -------------------------------- ### Set Dialog Button Click Listeners Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of setting custom click listeners for the accept and cancel buttons on a dialog. Ensure the dialog is shown after setting listeners. ```java Dialog dialog = new Dialog(context, "Confirm", "Delete?"); dialog.addCancelButton("NO"); dialog.setOnAcceptButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteItem(); } }); dialog.setOnCancelButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // User clicked NO } }); dialog.show(); ``` -------------------------------- ### Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-flat.md Initializes a new instance of the ButtonFlat class. ```APIDOC ## Constructor ### Description Initializes a new instance of the ButtonFlat class. ### Signature ```java public ButtonFlat(Context context, AttributeSet attrs) ``` ### Parameters #### Path Parameters - **context** (Context) - Required - Application context - **attrs** (AttributeSet) - Required - XML layout attributes ``` -------------------------------- ### Space-Constrained Layout with ButtonFloatSmall Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/button-float-small.md Shows how to embed a ButtonFloatSmall within a CardView for space-constrained environments. This example illustrates positioning and styling a small FAB within a container. ```xml ``` -------------------------------- ### Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Initializes a new instance of the Dialog class with a context, title, and message. ```APIDOC ## Constructor Dialog(Context context, String title, String message) ### Description Initializes a new instance of the Dialog class. ### Parameters #### Path Parameters - **context** (Context) - Required - Application context - **title** (String) - Required - Dialog title (can be null) - **message** (String) - Required - Dialog message/content ``` -------------------------------- ### Custom Text View Layout Parameters Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-rectangle.md Programmatically set layout parameters for the text view within a ButtonRectangle to control its position and margins. This example demonstrates centering the text and applying 5dp margins. ```java LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); textButton.setLayoutParams(params); ``` -------------------------------- ### Form with Custom Actions Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/README.md Set up a form with a primary action (large FAB) for submission and secondary actions (small FABs) for saving as a draft or deleting. ```java // Main action (large FAB) ButtonFloat fab = (ButtonFloat) findViewById(R.id.fab); fab.setOnClickListener(v -> submitForm()); // Secondary actions (small FABs) ButtonFloatSmall save = (ButtonFloatSmall) findViewById(R.id.fab_save); save.setOnClickListener(v -> saveAsDraft()); ButtonFloatSmall delete = (ButtonFloatSmall) findViewById(R.id.fab_delete); delete.setOnClickListener(v -> deleteForm()); ``` -------------------------------- ### Get TextView Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-rectangle.md Retrieves the internal TextView instance used by the ButtonRectangle. ```java public TextView getTextView() ``` -------------------------------- ### Get Button Text Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-flat.md Retrieves the current text displayed on the button. ```Java public String getText() ``` ```Java String currentText = button.getText(); ``` -------------------------------- ### SnackBar Constructors Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/snackbar.md Provides documentation for creating SnackBar instances, with options for including an action button or just displaying text. ```APIDOC ## SnackBar Constructors ### With Action Button ```java public SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener) ``` #### Parameters * **activity** (Activity) - Required - Parent activity * **text** (String) - Required - Message text * **buttonText** (String) - Required - Action button label * **onClickListener** (View.OnClickListener) - Required - Button click callback ### Text Only (No Button) ```java public SnackBar(Activity activity, String text) ``` #### Parameters * **activity** (Activity) - Required - Parent activity * **text** (String) - Required - Message text ``` -------------------------------- ### Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/switch.md Initializes a new instance of the Switch view. It can be used in Java code or defined in XML layouts. ```APIDOC ## Constructor ### Description Initializes a new instance of the Switch view. ### Signature ```java public Switch(Context context, AttributeSet attrs) ``` ### Parameters #### Path Parameters - **context** (Context) - Required - Application context - **attrs** (AttributeSet) - Required - XML layout attributes ``` -------------------------------- ### Get Slider Maximum Value Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/slider.md Retrieves the maximum allowed value for the slider. ```Java public int getMax() ``` -------------------------------- ### Basic Color Selection Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Instantiate ColorSelector with an initial color and a listener to handle color selection events. Call show() to display the picker. ```java ColorSelector colorPicker = new ColorSelector( MainActivity.this, Color.RED, new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { myView.setBackgroundColor(color); } } ); colorPicker.show(); ``` -------------------------------- ### Get Slider Minimum Value Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/slider.md Retrieves the minimum allowed value for the slider. ```Java public int getMin() ``` -------------------------------- ### Get Switch State Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/switch.md Query the current state of the switch to determine if it is currently ON or OFF. ```Java public boolean isCheck() ``` ```Java if(switchView.isCheck()) { // Handle ON state } ``` -------------------------------- ### Get Ripple Speed Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-flat.md Retrieves the current speed at which the ripple effect expands. ```Java public float getRippleSpeed() ``` -------------------------------- ### show() Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Animates the FAB into view with a bounce effect over 1500 milliseconds. This method is used to make the FAB visible. ```APIDOC ## show() ### Description Animate the FAB into view with bounce interpolation over 1500ms. ### Animation - Duration: 1500ms - Interpolator: BounceInterpolator - Target: showPosition (calculated from initial Y coordinate) - Sets `isShow = true` ### Example ```java fab.show(); ``` ``` -------------------------------- ### Avoid Creating Dialogs in Loops Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/configuration.md Demonstrates the correct way to show dialogs to prevent performance issues. Always instantiate dialogs once and reuse them. ```java // BAD for(int i = 0; i < 100; i++) { Dialog d = new Dialog(context, "Title", "Message"); d.show(); } // GOOD Dialog d = new Dialog(context, "Title", "Message"); d.show(); ``` -------------------------------- ### Basic Color Selection Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Instantiate and show the ColorSelector with an initial color. ```APIDOC ## Programmatic Usage - Basic Color Selection ### Description Instantiate the `ColorSelector` with a context, an initial color, and a listener for color selection events. Then, call `show()` to display the color picker. ### Method Signature `ColorSelector(Context context, Integer initialColor, ColorSelector.OnColorSelectedListener listener)` ### Parameters * `context` (Context) - The activity context. * `initialColor` (Integer) - The initial color to display. Can be `null` to start with black. * `listener` (ColorSelector.OnColorSelectedListener) - A callback interface to receive the selected color. ### Usage Example ```java ColorSelector colorPicker = new ColorSelector( MainActivity.this, Color.RED, new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { myView.setBackgroundColor(color); } } ); colorPicker.show(); ``` ``` -------------------------------- ### Get Value Changed Listener Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/slider.md Retrieves the currently registered listener for value changes. ```Java public OnValueChangedListener getOnValueChangedListener() ``` -------------------------------- ### Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Initializes a new instance of the CustomView class with the specified context and attributes. ```APIDOC ## Constructor ### Description Initializes a new instance of the CustomView class. ### Signature ```java public CustomView(Context context, AttributeSet attrs) ``` ### Parameters #### Path Parameters - **context** (Context) - Required - Application context - **attrs** (AttributeSet) - Required - XML layout attributes ``` -------------------------------- ### Secondary FAB in Stack Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/button-float-small.md Demonstrates how to implement multiple secondary actions using ButtonFloatSmall components within a layout. Each small FAB is associated with a specific click listener for its action. ```java ButtonFloat primary = (ButtonFloat) findViewById(R.id.fab_primary); primary.setOnClickListener(v -> addItem()); ButtonFloatSmall secondary1 = (ButtonFloatSmall) findViewById(R.id.fab_secondary1); secondary1.setOnClickListener(v -> editItem()); ButtonFloatSmall secondary2 = (ButtonFloatSmall) findViewById(R.id.fab_secondary2); secondary2.setOnClickListener(v -> shareItem()); ``` -------------------------------- ### Hide Dialog Title Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Example of how to hide the dialog's title by calling `setTitle` with a null value. ```java dialog.setTitle("Confirm Action"); // Later: dialog.setTitle(null); // Hide title ``` -------------------------------- ### Convert DP to PX for Margins and Padding Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/utils.md Demonstrates runtime conversion of DP values to PX for common UI spacing properties like margins and padding. ```java int margin = Utils.dpToPx(16, getResources()); int padding = Utils.dpToPx(8, getResources()); int radius = Utils.dpToPx(4, getResources()); ``` -------------------------------- ### Get Slider Value Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/slider.md Retrieves the current value of the slider. The value is always between the minimum and maximum limits. ```Java Slider slider = (Slider) findViewById(R.id.slider); int currentValue = slider.getValue(); ``` -------------------------------- ### Get Button Text Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-rectangle.md Retrieves the current text displayed on the button. This method is inherited from the Button class. ```java public String getText() ``` -------------------------------- ### Programmatic Usage of ButtonFloatSmall Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/button-float-small.md Shows how to instantiate, configure, and set up event listeners for a ButtonFloatSmall programmatically in Java. This includes setting the icon, click listener, and background color. ```java ButtonFloatSmall fab = (ButtonFloatSmall) findViewById(R.id.fabSecondary); // Set icon Drawable icon = getResources().getDrawable(R.drawable.ic_edit); fab.setDrawableIcon(icon); // Set click listener fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editItem(); } }); // Customize color fab.setBackgroundColor(Color.parseColor("#FF5722")); ``` -------------------------------- ### show Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Displays the dialog on the screen with animations. The dialog content slides in from the top, and the background fades in. ```APIDOC ## show() ### Description Display the dialog with animations. ### Method Signature ```java public void show() ``` ### Animations - Dialog content: R.anim.dialog_main_show_amination (slide in from top) - Background: R.anim.dialog_root_show_amin (fade in) ### Request Example ```java Dialog dialog = new Dialog(context, "Delete?", "This cannot be undone"); dialog.show(); ``` ``` -------------------------------- ### ButtonFloat Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Initializes a new instance of the ButtonFloat class. ```APIDOC ## ButtonFloat Constructor ### Description Initializes a new instance of the ButtonFloat class. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```java public ButtonFloat(Context context, AttributeSet attrs) ``` ### Parameters - **context** (Context) - Required - Application context - **attrs** (AttributeSet) - Required - XML layout attributes ``` -------------------------------- ### ColorSelector Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Initializes a new instance of the ColorSelector dialog. ```APIDOC ## ColorSelector Constructor ### Description Initializes a new instance of the ColorSelector dialog with a specified context, initial color, and a listener for color selection events. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Method Signature ```java public ColorSelector(Context context, Integer color, OnColorSelectedListener onColorSelectedListener) ``` ### Parameters - **context** (Context) - Required - Application context. - **color** (Integer) - Optional - Initial color to display. If null, black is used. - **onColorSelectedListener** (OnColorSelectedListener) - Required - Callback interface to handle color selection events. ``` -------------------------------- ### getRelativeLeft Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/utils.md Get the absolute left position of a view relative to the screen root, accounting for parent view positions. ```APIDOC ## getRelativeLeft(View myView) ### Description Get the absolute left position of a view relative to the screen root (accounting for parent positions). ### Method Signature `public static int getRelativeLeft(View myView)` ### Parameters #### Path Parameters - **myView** (View) - Required - The view to measure ### Returns `int` - X coordinate from screen left ### Purpose Calculate absolute screen position for X coordinate (similar to getRelativeTop for Y). ### Example ```java // Get the absolute X position of a view on screen Slider slider = findViewById(R.id.mySlider); int screenLeft = Utils.getRelativeLeft(slider); // Used internally by Slider to calculate indicator position numberIndicator.indicator.x = event.getX(); numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() / 2; ``` ### Visual Example ``` Screen (X=0) ├─ NavigationDrawer (width=280) ├─ Main Content (X=280) │ ├─ Card (X=280, within parent left=0) │ ├─ Button (X=300, within parent left=20) │ ↓ │ getRelativeLeft() = 300 (20 + 280) ``` ``` -------------------------------- ### getRelativeTop Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/utils.md Get the absolute top position of a view relative to the screen root, accounting for parent view positions. ```APIDOC ## getRelativeTop(View myView) ### Description Get the absolute top position of a view relative to the screen root (accounting for parent positions). ### Method Signature `public static int getRelativeTop(View myView)` ### Parameters #### Path Parameters - **myView** (View) - Required - The view to measure ### Returns `int` - Y coordinate from screen top ### Purpose Calculate absolute screen position for a view nested inside parent layouts. ### How it works 1. Checks if view is the root content view 2. If yes, return its getTop() 3. If no, add its getTop() to parent's getRelativeTop() (recursive) ### Example ```java // Get the absolute Y position of a view on screen View button = findViewById(R.id.myButton); int screenTop = Utils.getRelativeTop(button); // This accounts for: // - Button's top within its parent // - Parent's top within its parent // - All the way up to the root view ``` ### Visual Example ``` Screen (Y=0) ├─ ActionBar (Y=0, top=0) ├─ Content LinearLayout (Y=56, top=56) │ ├─ ImageView (Y=56, within parent top=0) │ ├─ Button (Y=256, within parent top=200) │ ↓ │ getRelativeTop() = 256 (200 + 56) ``` ``` -------------------------------- ### Color Selection with Null Initial Color Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Initialize ColorSelector with null to start with black. Use a listener to apply the selected color. ```java ColorSelector colorPicker = new ColorSelector( context, null, // Start with black new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { applyColor(color); } } ); colorPicker.show(); ``` -------------------------------- ### Stacked FABs with ButtonFloatSmall Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/button-float-small.md Demonstrates how to stack multiple ButtonFloatSmall components above a primary ButtonFloat. Use `layout_above` to position elements relative to each other. ```xml ``` -------------------------------- ### Get TextView Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-flat.md Accesses the internal TextView component used for displaying the button's text. Useful for advanced text styling. ```Java public TextView getTextView() ``` ```Java TextView tv = button.getTextView(); tv.setTextSize(18f); ``` -------------------------------- ### isShow() Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Checks and returns the current visibility state of the FAB. Returns true if the FAB is currently shown, and false otherwise. ```APIDOC ## isShow() ### Description Query whether the FAB is in the visible state. ### Returns boolean - true if FAB is shown, false if hidden ### Example (No example provided in source) ``` -------------------------------- ### ColorSelector Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/README.md RGB color picker with live preview. ```APIDOC ## ColorSelector ### Description An RGB color picker component that provides a live preview of the selected color. ### Usage ```java ColorSelector colorPicker = new ColorSelector(context); colorPicker.setOnColorChangedListener((r, g, b) -> { /* update UI */ }); // Add to layout ``` ``` -------------------------------- ### ProgressBarIndeterminateDeterminate Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/progress-bars.md Represents a hybrid progress bar that starts as indeterminate and becomes determinate when progress is explicitly set. It handles the transition between these states automatically. ```APIDOC ## ProgressBarIndeterminateDeterminate ### Description A hybrid progress bar that starts indeterminate and converts to determinate when progress is explicitly set. It automatically stops the indeterminate animation upon the first `setProgress()` call and then updates the determinate progress. ### Constructor ```java public ProgressBarIndeterminateDeterminate(Context context, AttributeSet attrs) ``` ### Methods #### `setProgress(int progress)` Overrides the parent method to handle the animation switching logic. This method is used to set the progress value, which triggers the transition from indeterminate to determinate if it hasn't happened already. - **progress** (int) - Required - The progress value to set (0-100). ### Programmatic Usage Example ```java // Assuming 'progress' is an instance of ProgressBarIndeterminateDeterminate // Initially, the progress bar shows an indeterminate animation. progress.show(); // Later, when progress is known, set the progress value. progress.setProgress(25); // Stops animation and displays 25% progress.setProgress(50); // Updates the display to 50% progress.setProgress(100); // Completes the progress bar ``` ### XML Usage Example ```xml ``` ``` -------------------------------- ### Style Accept Button Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Shows how to access the accept button and modify its appearance, such as setting its background color. ```java ButtonFlat acceptBtn = dialog.getButtonAccept(); acceptBtn.setBackgroundColor(Color.parseColor("#4CAF50")); ``` -------------------------------- ### Create Dialog with Both Callbacks Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md This snippet demonstrates creating a dialog with both a cancel and an accept button, each having its own click listener. This is useful for scenarios requiring distinct actions for confirmation and cancellation. ```java Dialog dialog = new Dialog( context, "Save Changes", "You have unsaved changes. Save before closing?" ); dialog.addCancelButton("Discard", new View.OnClickListener() { @Override public void onClick(View v) { closeWithoutSaving(); } }); dialog.setOnAcceptButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveAndClose(); } }); dialog.show(); ``` -------------------------------- ### Get FAB Drawable Icon Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Retrieves the Drawable object currently displayed as the FAB's icon. This is useful for inspecting or reusing the icon. ```java public Drawable getDrawableIcon() ``` -------------------------------- ### Measure View Positions Using getLocationOnScreen and Utils Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/utils.md Illustrates two methods for obtaining view positions: using getLocationOnScreen for absolute screen coordinates and Utils for relative positioning within the hierarchy. ```java // Get absolute position of a view int[] location = new int[2]; view.getLocationOnScreen(location); int absoluteX = location[0]; int absoluteY = location[1]; // OR use Utils (accounts for parent hierarchy) int relativeY = Utils.getRelativeTop(view); int relativeX = Utils.getRelativeLeft(view); ``` -------------------------------- ### Get FAB Icon ImageView Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Retrieves the internal ImageView used for the FAB's icon. This allows for direct manipulation of the icon's properties. ```java public ImageView getIcon() ``` ```java ImageView icon = fab.getIcon(); icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ``` -------------------------------- ### Show Dialog Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Displays the dialog with animations. The content slides in from the top and the background fades in. ```java public void show() ``` ```java Dialog dialog = new Dialog(context, "Delete?", "This cannot be undone"); dialog.show(); ``` -------------------------------- ### Implement Slider OnValueChangedListener Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/types.md Example of setting an OnValueChangedListener on a Slider. This callback fires continuously during drag events. Keep implementations lightweight to avoid performance issues. ```java slider.setOnValueChangedListener(new Slider.OnValueChangedListener() { @Override public void onValueChanged(int value) { updateDisplay("Value: " + value); } }); ``` -------------------------------- ### Extracting RGB Values and Using ColorSelector Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Shows how to parse an RGB color string, extract its components, and then use the ColorSelector. ```APIDOC ## Programmatic Usage - Extracting RGB Values ### Description This example demonstrates parsing a color string (e.g., "#FF5722") into its RGB components (red, green, blue). It then initializes a `ColorSelector` with this color and shows how to handle the selected color in the listener. ### Method Signature `ColorSelector(Context context, Integer initialColor, ColorSelector.OnColorSelectedListener listener)` ### Parameters * `context` (Context) - The activity context. * `initialColor` (Integer) - The color to initialize the picker with, parsed from a string. * `listener` (ColorSelector.OnColorSelectedListener) - A callback interface to receive the selected color. ### Usage Example ```java int selectedColor = Color.parseColor("#FF5722"); int red = (selectedColor >> 16) & 0xFF; // 255 int green = (selectedColor >> 8) & 0xFF; // 87 int blue = (selectedColor >> 0) & 0xFF; // 34 ColorSelector picker = new ColorSelector(context, selectedColor, new ColorSelector.OnColorSelectedListener() { @Override public void onColorSelected(int color) { // Use selected color } } ); picker.show(); ``` ``` -------------------------------- ### Rendering Logic for ProgressBarDeterminate Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/progress-bars.md Illustrates the calculation for rendering the progress width based on current progress and total width. ```java double progressPercent = (double)progress / (double)totalWidth; int progressWidth = (int) (getWidth() * progressPercent); ``` -------------------------------- ### Track Animation State Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/custom-view.md Use a boolean flag to track whether an animation is currently in progress. Set the flag to true when the animation starts and to false when it ends. ```java boolean animation = false; @Override protected void onAnimationStart() { super.onAnimationStart(); animation = true; // Animation in progress } @Override protected void onAnimationEnd() { super.onAnimationEnd(); animation = false; // Animation complete } ``` -------------------------------- ### ProgressBarIndeterminate Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/progress-bars.md A linear indeterminate progress bar that continuously animates to show ongoing activity without a specific completion percentage. It starts automatic animation on creation and cannot be controlled programmatically. ```APIDOC ## ProgressBarIndeterminate **Full class name:** `com.gc.materialdesign.views.ProgressBarIndeterminate` **Extends:** `ProgressBarDeterminate` Linear indeterminate progress bar that continuously animates to show ongoing activity without a specific completion percentage. ### Constructor ```java public ProgressBarIndeterminate(Context context, AttributeSet attrs) ``` ### Behavior On creation, starts automatic animation: 1. Sets progress to 60% 2. Applies scale animation (R.anim.progress_indeterminate_animation) 3. Animates the progress bar left to right with ObjectAnimator 4. Repeats with increasing speed (3 iterations) **Animation Details:** - Duration: 1200ms (first cycle), 400ms (final cycle) - Repeats automatically - Bar accelerates and reverses each cycle ### XML Usage ```xml ``` ### Note Cannot control progress programmatically (it's indeterminate). Use ProgressBarDeterminate if you need to show percentage. ``` -------------------------------- ### ButtonFlat Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-flat.md The constructor for ButtonFlat requires a Context and AttributeSet. ```Java public ButtonFlat(Context context, AttributeSet attrs) ``` -------------------------------- ### Programmatic ScrollView Usage Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/scroll-view.md Get a reference to the ScrollView and use its methods to scroll to the top or a specific position. Child Material Design components like ButtonFlat will work automatically. ```java ScrollView scrollView = (ScrollView) findViewById(R.id.scroll); // No special setup required - just use like normal ScrollView scrollView.scrollTo(0, 0); // Scroll to top scrollView.smoothScrollTo(0, 100); // Smooth scroll // All child Material Design components work automatically ButtonFlat button = (ButtonFlat) findViewById(R.id.button1); button.setOnClickListener(...); // Ripple effect works! ``` -------------------------------- ### Create Simple Confirmation Dialog Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/dialog.md Use this to create a basic confirmation dialog with a title, message, and a single 'NO' cancel button. The accept button's click listener should be set to handle the primary action. ```java Dialog dialog = new Dialog(MainActivity.this, "Confirm", "Delete this item?"); dialog.addCancelButton("NO"); dialog.setOnAcceptButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteItem(); } }); dialog.show(); ``` -------------------------------- ### Unit Test Material Design Button Color Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/configuration.md Example of a unit test for a Material Design ButtonFlat component using Robolectric. This test verifies the button's background color. ```java @RunWith(RobolectricTestRunner.class) public class ButtonFlatTest { @Test public void testButtonColor() { ButtonFlat button = new ButtonFlat(Robolectric.buildActivity(Activity.class).create().get(), null); button.setBackgroundColor(Color.RED); assertEquals(Color.RED, button.backgroundColor); } } ``` -------------------------------- ### Update and Resize Preview Square Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/color-selector.md Finds the color view and sets its background color to the currently selected color. It also ensures the view is displayed as a square by setting its height equal to its width. ```java colorView = findViewById(R.id.viewColor); colorView.setBackgroundColor(color); // Resize to square colorView.post(new Runnable() { @Override public void run() { LayoutParams params = (LayoutParams) colorView.getLayoutParams(); params.height = colorView.getWidth(); colorView.setLayoutParams(params); } }); ``` -------------------------------- ### Initialize CheckBox with Context and Attributes Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/checkbox.md Constructor for creating a CheckBox instance, typically used when inflating from XML or programmatically. ```java public CheckBox(Context context, AttributeSet attrs) ``` -------------------------------- ### ButtonFloat Constructor Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/api-reference/button-float.md Initializes a new instance of the ButtonFloat class. Requires the application context and attribute set for XML inflation. ```Java public ButtonFloat(Context context, AttributeSet attrs) ``` -------------------------------- ### Set Up XML Namespace for Material Design Components Source: https://github.com/navasmdc/materialdesignlibrary/blob/master/_autodocs/configuration.md Add the Material Design namespace to your layout's root element to utilize Material Design components. ```xml ```