Skip to content

Click Event and Listener

Weiping Huang edited this page Mar 28, 2017 · 7 revisions

Listener for clicking each button or animation-states. Check the demo for more details.

Listener in Each Builder

You can add a simple listener for each boom-button by adding listeners to each builder of them.

for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i++) {
    SimpleCircleButton.Builder builder = new SimpleCircleButton.Builder()
            .listener(new OnBMClickListener() {
                @Override
                public void onBoomButtonClick(int index) {
                    // When the boom-button corresponding this builder is clicked.
                    Toast.makeText(SimpleCircleButtonActivity.this, "Clicked " + index, Toast.LENGTH_SHORT).show();
                }
            });
    bmb.addBuilder(builder);
}

Listener for BMB

If you want to manager all the click events in a method, you can use OnBoomListener / OnBoomListenerAdapter:

// Use OnBoomListener to listen all methods
bmb.setOnBoomListener(new OnBoomListener() {
    @Override
    public void onClicked(int index, BoomButton boomButton) {
        // If you have implement listeners for boom-buttons in builders,
        // then you shouldn't add any listener here for duplicate callbacks.
    }

    @Override
    public void onBackgroundClick() {
        textViewForAnimation.setText("Click background!!!");
    }

    @Override
    public void onBoomWillHide() {
        textViewForAnimation.setText("Will RE-BOOM!!!");
    }

    @Override
    public void onBoomDidHide() {
        textViewForAnimation.setText("Did RE-BOOM!!!");
    }

    @Override
    public void onBoomWillShow() {
        textViewForAnimation.setText("Will BOOM!!!");
    }

    @Override
    public void onBoomDidShow() {
        textViewForAnimation.setText("Did BOOM!!!");
    }
});

Or in OnBoomListenerAdapter(Optional listener):

// Use OnBoomListenerAdapter to listen part of methods
bmb.setOnBoomListener(new OnBoomListenerAdapter() {
    @Override
    public void onBoomWillShow() {
        super.onBoomWillShow();
        // logic here
    }
});

State of BMB

Get the states of BMB by:

bmb.isBoomed();    // Whether the BMB is boomed.
bmb.isReBoomed();  // Whether the BMB is re-boomed.

Re-boom BMB When Back-Button is Clicked

BMB will re-boom when it's boomed and back-button is clicked. If you don't want this happen:

bmb.setBackPressListened(false);

Or in xml:

app:bmb_backPressListened="false"

Notice that BMB will requestFocus when it's going to boom. So if you need to take the focus back, you should use requestFocus for your own view.

Clone this wiki locally