Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is posible to set others click event listeners like onLongClickListener on option item? #117

Closed
dengue8830 opened this issue May 7, 2017 · 12 comments

Comments

@dengue8830
Copy link

Im working on an option in my bmb that allows the user to record a voice message like Whatsapp or Telegram, and i can't find the way to set listeners like onLongClickListener or onTouchListener on the bmb option item.

I know that this is a so specific need, so i understand if is no possible.

Great work with this project!

@Nightonke
Copy link
Owner

Emm... Maybe the getBoomButton(int index) method can help. It helps to get the boom-button of BMB. Then you can set onLongClickListener for the boom-buttons(notice that the boom-button may be null). But, maybe adding a onLongClickListener will conflict the original listener inside boom-button, which means the click-event may be strange... I didn't try it, but I hope you can tell whether the conflict happens if you do so.

@dengue8830
Copy link
Author

dengue8830 commented May 7, 2017

getBoomButton(int index) allways get me null, getBoomButtons().size() allways get zero, what i am doing wrong?

I have a fragment

layout

<com.nightonke.boommenu.BoomMenuButton
android:id="@+id/bmb_opciones_programa"
android:layout_width="0dp"
android:layout_height="0dp"
app:bmb_backgroundEffect="false"
app:bmb_buttonEnum="ham"
app:bmb_inFragment="true"/>

java

private BoomMenuButton mOpcionesProgramaBmb;

@OverRide
public View onCreateView...
mOpcionesProgramaBmb = (BoomMenuButton) view.findViewById(R.id.bmb_opciones_programa);
mOpcionesProgramaBmb.setPiecePlaceEnum(PiecePlaceEnum.HAM_1);
mOpcionesProgramaBmb.setButtonPlaceEnum(ButtonPlaceEnum.HAM_1);
mOpcionesProgramaBmb.addBuilder(new HamButton.Builder()
.normalImageRes(R.drawable.ic_textsms_white_48dp)
.normalColor(ContextCompat.getColor(getContext(), R.color.accent))
.highlightedColor(ContextCompat.getColor(getContext(), R.color.accent))
.normalText(getContext().getString(R.string.opcion_mensaje_programa_titulo))
.subNormalText(getContext().getString(R.string.opcion_mensaje_programa_subtitulo)));

    Log.w("size", mOpcionesProgramaBmb.getBoomButtons().size()+"");// zero D: 

Same result if i put the Log in the

@OverRide
public void onResume()

@Nightonke
Copy link
Owner

Because the boom-buttons are created when BMB is clicked. So I suggest you to use getBoomButton(int index) after the BMB is clicked. You can use the OnBoomListener to detect the will-boom event.

@dengue8830
Copy link
Author

dengue8830 commented May 7, 2017

haa ok

i tried with the BoomButton, the event is triggered only if i touch in the margin of the item. So i thought to attach the event to the child view of the BoomButton, but i have the same result. There is any way to get deeper child view's? Or may be is the BoomButton layout who is intercepting the event.

@OverRide
public void onBoomDidShow...
Log.e("size", mOpcionesProgramaBmb.getBoomButtons().size()+""); // 1
BoomButton bb = mOpcionesProgramaBmb.getBoomButton(0);
Log.e("child count", bb.getChildCount()+""); // 1
View childView = bb.getChildAt(0);
childView.setOnClickListener...// same if i put bb.setOnClickListener...

@Nightonke
Copy link
Owner

Yes, you can get the child views of a boom-button by its methods:

    /**
     * Get the image view of a boom button.
     *
     * @return image view
     */
    public ImageView getImageView() {
        return image;
    }

    /**
     * Get the text view of a boom button.
     *
     * @return text view
     */
    public TextView getTextView() {
        return text;
    }

    /**
     * Get the sub text view of a boom button.
     *
     * @return sub text view
     */
    public TextView getSubTextView() {
        return subText;
    }

@dengue8830
Copy link
Author

dengue8830 commented May 7, 2017

yay, it works. But i have to attach the event to the three main components to give the experience of record a message touching the BoomButton

View.OnClickListener click = ...
BoomButton bb = mOpcionesProgramaBmb.getBoomButton(0);
bb.getImageView().setOnClickListener(click);
bb.getTextView().setOnClickListener(click);
bb.getSubTextView().setOnClickListener(click);

This will be enough for now, but if we could get access to the layout field we could attach the event to one single element.

Thanks bro, you rock

@Nightonke
Copy link
Owner

@dengue8830
Since version 2.1.0, you can get the layout field by method getLayout of boom-button.

@dengue8830
Copy link
Author

Awsome, great work with this release.
Thanks

@Gnanendra18
Copy link

Gnanendra18 commented Jun 6, 2017

Hi,
When I am trying to set listener on boombutton layout, it is giving null pointer exception. I didn't get what the problem is? Please explain.

@Override
            public void onBoomDidShow() {
                bmb.getBoomButton(0).getLayout().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
                        //startActivity(new Intent());
                    }
                });
            }

@Nightonke
Copy link
Owner

Hey, @Gnanendra18 Could you please provide the crash-log? Thanks.

@herdigiorgi
Copy link

try {
     Field f = mMenuButton.getClass().getDeclaredField("button");
     f.setAccessible(true);
     FrameLayout buttonFrameLayout = (FrameLayout) f.get(mMenuButton);
     buttonFrameLayout.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             // CLICK EVENT HERE
         }
     });
 }catch(Exception e) {
     throw new RuntimeException(e);
 }

It works, but is very ugly, can you expose the button layout?

Nightonke added a commit that referenced this issue Sep 11, 2017
1. Expose the 'button' layout of boom-button for #117.
2. Boom-button is able to access from builder.
@Nightonke
Copy link
Owner

Hey, @hernanex3 . The button layout is exposed since version 2.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants