Example usage for android.widget FrameLayout setLongClickable

List of usage examples for android.widget FrameLayout setLongClickable

Introduction

In this page you can find the example usage for android.widget FrameLayout setLongClickable.

Prototype

public void setLongClickable(boolean longClickable) 

Source Link

Document

Enables or disables long click events for this view.

Usage

From source file:com.waz.zclient.ui.cursor.CursorToolbar.java

private void createItems() {
    LayoutInflater inflater = LayoutInflater.from(getContext());

    int diameter = getResources().getDimensionPixelSize(R.dimen.cursor__menu_button__diameter);
    int rightMargin;

    /*/*from ww  w  .  java  2s. c o  m*/
    As long as 4 mainItems are shown in the toolbar, they are spread out equally in phone
     */
    rightMargin = CursorUtils.getMarginBetweenCursorButtons(getContext());

    CursorIconButton cursorIconButton;

    for (int i = 0; i < cursorItems.size(); i++) {
        final CursorMenuItem item = cursorItems.get(i);
        final FrameLayout buttonContainer = new FrameLayout(getContext());
        buttonContainer.setId(item.resId);

        cursorIconButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
        cursorIconButton.setText(item.glyphResId);
        cursorIconButton
                .setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_graphite));

        switch (item) {
        case CAMERA:
            cursorIconButtonCamera = cursorIconButton;
            break;
        case AUDIO_MESSAGE:
            cursorIconButtonAudio = cursorIconButton;
            break;
        }

        if (item == CursorMenuItem.DUMMY) {
            cursorIconButton.initTextColor(ContextCompat.getColor(getContext(), R.color.transparent));
            cursorIconButton
                    .setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
            cursorIconButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
        }

        buttonContainer.setTag(item);

        buttonContainer.setLongClickable(true);

        buttonContainer.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                CursorMenuItem item = (CursorMenuItem) view.getTag();
                touchedButtonContainer = buttonContainer;
                if (callback != null && item == CursorMenuItem.AUDIO_MESSAGE) {
                    callback.onMotionEvent(item, motionEvent);
                }
                detector.onTouchEvent(motionEvent);
                return false;
            }
        });

        FrameLayout.LayoutParams paramsButton = new FrameLayout.LayoutParams(diameter, diameter);
        paramsButton.gravity = Gravity.CENTER;
        buttonContainer.addView(cursorIconButton, paramsButton);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(buttonWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);
        if (i < cursorItems.size() - 1) {
            params.rightMargin = rightMargin;
        }
        addView(buttonContainer, params);
    }
}