BoomMenu Android Library

repository·master·Indexed 26 days ago

https://github.com/nightonke/boommenu

An Android library for creating animated, high-interaction menu buttons to replace static action bar menus. It supports various styles including Circle, Hamburger (Ham), List, and Share, with customizable animation paths, durations, and rotation degrees. The library provides a Builder pattern for configuration and supports integration within Action Bars, Fragments, and lists (RecyclerView/ListView).

Tokens
5.7K
Snippets
8
Records
19
Agent score
71%

What's inside BoomMenu

  1. Overview of BoomMenu features

    master

    BoomMenu is an Android library designed to replace standard menu buttons with animated, interactive menu buttons. It supports various styles including:

    • Circle Button: A circular menu expansion.
    • Hamburger Button: A classic hamburger menu animation.
    • List Style: Menu items appearing in a list format.
    • Share Style: Specialized menu for sharing actions.

    Key capabilities include custom animation durations, rotation degrees, dimming effects, and support for use within lists (since version 1.0.4).

  2. Overview of BoomMenu

    master
    BoomMenu is an Android library that provides animated, explosive menu button effects. It replaces standard, static menu buttons with dynamic animations such as Circle, Hamburger (Ham), List, and Share styles. It is designed to be easily integrated into Action Bars, Floating Action Buttons, Lists, or used via a Builder pattern.
  3. Use BoomMenuButton in a List (RecyclerView/ListView)

    master

    When using BoomMenuButton inside a list item, you must use delayed initialization to ensure the view is attached and ready. Use .postDelayed() within your adapter's getView or onBindViewHolder method.

    Configuration for Lists:

    • Set app:boom_inList="true" in the XML layout for the button.
    • Use setSubButtonShadowOffset(float x, float y) to adjust shadows for list items.
    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
        // ...
        viewHolder.circleBoomMenuButton.postDelayed(new Runnable() {
            @Override
            public void run() {
                viewHolder.circleBoomMenuButton.init(
                    circleSubButtonDrawables, 
                    circleSubButtonTexts,     
                    subButtonColors,          
                    ButtonType.CIRCLE,        
                    BoomType.PARABOLA,        
                    PlaceType.CIRCLE_3_1,     
                    null, null, null, null, null, null, null
                );
            }
        }, 1);
        // ...
    }
  4. Integrate BoomMenuButton in an ActionBar

    master

    To use BoomMenu in a custom ActionBar:

    1. Create a custom layout (e.g., custom_actionbar.xml) containing a BoomMenuButton with app:boom_inActionBar="true".
    2. Apply the custom view in onCreate():
      • Inflate the layout.
      • Set up the ActionBar using mActionBar.setCustomView(mCustomView).
      • Enable custom view display with mActionBar.setDisplayShowCustomEnabled(true).
      • Set listeners for sub-button clicks and animations.
    3. Initialize the button in onWindowFocusChanged() as described in the Quick Start guide.
    // Inside onCreate()
    ActionBar mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);
    
    mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
    // ... find views ...
    boomMenuButtonInActionBar = (BoomMenuButton) mCustomView.findViewById(R.id.boom);
    boomMenuButtonInActionBar.setOnSubButtonClickListener(this);
    boomMenuButtonInActionBar.setAnimatorListener(this);
    
    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
  5. Integrate BoomMenu in a List (RecyclerView/ListView)

    master

    When using BoomMenu inside a list item, you must:

    1. Set app:boom_inList="true" in the XML for the BoomMenuButton.
    2. Initialize the button inside the Adapter's getView() (or equivalent) using postDelayed. This ensures the view is attached and ready for the animation logic.

    Example implementation in Adapter:

    @Override
    public View getView(int position, View convertView, final ViewGroup parent) {
        // ... inside ViewHolder logic
        viewHolder.circleBoomMenuButton.postDelayed(new Runnable() {
            @Override
            public void run() {
                viewHolder.circleBoomMenuButton.init(
                        circleSubButtonDrawables, 
                        circleSubButtonTexts,     
                        subButtonColors,          
                        ButtonType.CIRCLE,        
                        BoomType.PARABOLA,        
                        PlaceType.CIRCLE_3_1,     
                        null, null, null, null, null, null, null
                );
            }
        }, 1);
        return convertView;
    }
  6. Install BoomMenu via Gradle or Maven

    master

    To use BoomMenu in your Android project, add the dependency to your build configuration.

    Note: This documentation refers to version 1.0.9. For newer versions, it is strongly suggested to use the documentation available on the project's Wiki.

    ### Gradle
    ```gradle
    dependencies {
        ...
        compile 'com.nightonke:boommenu:1.0.9'
        ...
    }

    Maven

    <dependency>
      <groupId>com.nightonke</groupId>
      <artifactId>boommenu</artifactId>
      <version>1.0.9</version>
      <type>pom</type>
    </dependency>
  7. Integrate BoomMenu in Action Bar

    master

    To use BoomMenu within a custom Action Bar:

    1. Create a custom layout (e.g., custom_actionbar.xml) containing a BoomMenuButton with app:boom_inActionBar="true".
    2. In your Activity's onCreate(), inflate the custom layout and set it as the Action Bar's custom view using mActionBar.setCustomView(mCustomView).
    3. Enable custom view display with mActionBar.setDisplayShowCustomEnabled(true).
    4. Initialize the button in onWindowFocusChanged() as per the standard initialization steps.
    // Inside onCreate()
    ActionBar mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    
    LayoutInflater mInflater = LayoutInflater.from(this);
    mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
    
    boomMenuButtonInActionBar = (BoomMenuButton) mCustomView.findViewById(R.id.boom);
    boomMenuButtonInActionBar.setOnSubButtonClickListener(this);
    boomMenuButtonInActionBar.setAnimatorListener(this);
    
    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
  8. Explore BoomMenu usage guides and features

    master

    BoomMenu (BMB) provides various ways to implement animated menu buttons. Detailed implementation guides are available in the project Wiki for the following patterns:

    • Button Styles:
      • Simple Circle Button (image only)
      • Text Inside Circle Button (text and image)
      • Text Outside Circle Button (text and image outside)
      • Ham Button (title, subtitle, and image)
      • Share Style
    • Customization & Layout:
      • Custom Position (customize number and positions of pieces/buttons)
      • Button Place Alignments (place buttons anywhere on screen)
      • Attributes for BMB or Pieces (change size or margins of dots)
      • Cache Optimization & Boom Area (limit boom to parent-view)
    • Animations:
      • Different Ways to Boom (various animation paths)
      • Ease Animations for Buttons (cute ease-in/out animations)
      • Other Animation Attributes (delay, duration, rotate-degrees, frames)
      • Different Order for Buttons
    • Integration & Control:
      • Use BMB in Action Bar or Tool Bar
      • Use BMB in List (RecyclerView/ListView considerations)
      • Use BMB in Fragment
      • Control BMB (programmatic boom/re-boom)
      • Click Event and Listener (handling button clicks or animation states)
      • Change Boom Buttons Dynamically
      • Fade Views (adding faded views on BMB)
  9. Quick Start: Use BoomMenu in 3 Steps

    master

    To implement a basic BoomMenuButton, follow these three steps:

    1. Add the view to your XML layout: Use com.nightonke.boommenu.BoomMenuButton. You can configure properties like app:boom_inActionBar, app:boom_button_color, and app:boom_button_pressed_color.
    2. Find the view in onCreate(): Use findViewById to get the instance.
    3. Initialize in onWindowFocusChanged(): Call .init() with your sub-button assets and configuration parameters to ensure the view is ready for animation.

    Note: The init() method requires non-null drawables for sub-buttons.

    <com.nightonke.boommenu.BoomMenuButton
        android:id="@+id/boom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_margin="20dp"
        app:boom_inActionBar="false"
        app:boom_button_color="@color/colorPrimary"
        app:boom_button_pressed_color="@color/colorPrimary"
        />
    // 2. Get view
    boomMenuButton = (BoomMenuButton)findViewById(R.id.boom);
    
    // 3. Initialize
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        
        boomMenuButton.init(
                subButtonDrawables, // Non-null
                subButtonTexts,     // Can be null
                subButtonColors,    // Normal and pressed states
                ButtonType.HAM,     
                BoomType.PARABOLA,  
                PlaceType.HAM_3_1, 
                null, null, null,   // Ease types (move, scale, rotate) for showing
                null, null, null,  // Ease types (move, scale, rotate) for dismissing
                null                // Rotation degree
        );
    }
  10. Handle Sub-Button Clicks and Animation Events

    master

    Sub-Button Click Listener

    Implement OnSubButtonClickListener to respond to user interactions with specific sub-buttons.

    boomMenuButton.setOnSubButtonClickListener(new BoomMenuButton.OnSubButtonClickListener() {
        @Override
        public void onClick(int buttonIndex) {
            // buttonIndex is the index of the clicked sub-button
        }
    });

    Animation Listener

    Implement AnimatorListener to track the lifecycle of the menu's expansion and collapse animations.

    boomMenuButton.setAnimatorListener(new BoomMenuButton.AnimatorListener() {
        @Override
        public void toShow() { /* Before expansion starts */ }
        @Override
        public void showing(float fraction) { /* Expansion in progress (0.0 to 1.0) */ }
        @Override
        public void showed() { /* Expansion finished */ }
        @Override
        public void toHide() { /* Before hiding starts */ }
        @Override
        public void hiding(float fraction) { /* Hiding in progress (0.0 to 1.0) */ }
        @Override
        public void hided() { /* Hiding finished */ }
    });
  11. Query BoomMenuButton State and Control Dismissal

    master

    Check Current State

    Use these methods to determine if the menu is currently animating or open:

    • isClosed(): Returns true if the menu is closed.
    • isClosing(): Returns true if the menu is currently performing the hide animation.
    • isOpen(): Returns true if the menu is open.
    • isOpening(): Returns true if the menu is currently performing the show animation.

    Manual Dismissal

    • dismiss(): Forces the menu to perform the hide animation. Returns true if the animation can be executed, false if the menu is already animating or in an invalid state.
  12. Initialize BoomMenuButton using BoomMenuButton.Builder

    master

    The Builder pattern provides a fluent API to configure all aspects of the BoomMenuButton at once. This is often cleaner than calling multiple setter methods.

    Key Builder Methods:

    • .addSubButton(view, drawable, color, text): Adds an individual sub-button.
    • .button(ButtonType): Sets the main button shape (e.g., ButtonType.HAM or ButtonType.CIRCLE).
    • .boom(BoomType): Sets the explosion animation type.
    • .place(PlaceType): Sets the sub-button arrangement.
    • .autoDismiss(boolean): Controls if sub-buttons hide after a click.
    • .init(boomMenuButton): Finalizes and applies the configuration to the target view.
    new BoomMenuButton.Builder()
            .addSubButton(this, R.drawable.boom, subButtonColors[0], "BoomMenuButton")
            .addSubButton(this, R.drawable.java, subButtonColors[1], "View source code")
            .frames(80)
            .duration(800)
            .delay(100)
            .showOrder(OrderType.RANDOM)
            .hideOrder(OrderType.RANDOM)
            .button(ButtonType.HAM)
            .boom(BoomType.PARABOLA_2)
            .place(PlaceType.HAM_3_1)
            .showMoveEase(EaseType.EaseOutBack)
            .hideMoveEase(EaseType.EaseOutCirc)
            .showScaleEase(EaseType.EaseOutBack)
            .hideScaleType(EaseType.EaseOutCirc)
            .rotateDegree(720)
            .autoDismiss(true)
            .cancelable(true)
            .dim(DimType.DIM_6)
            .clickEffect(ClickEffectType.RIPPLE)
            .init(boomMenuButton);