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

can not disable the view #72

Open
yikuo123 opened this issue Aug 26, 2015 · 1 comment
Open

can not disable the view #72

yikuo123 opened this issue Aug 26, 2015 · 1 comment

Comments

@yikuo123
Copy link

the method "setEnabled" does not work, is there any way to disable it?

@jcady
Copy link

jcady commented Feb 21, 2016

+1 I don't know how to disable it, would be useful to know.

Edit: I did a workaround. Put all the views in a custom view container. Override the onInterceptTouchEvent method and return true if the color picker is disabled, false otherwise.

Now when you want to disable the picker, use setEnabled on the picker (and setAlpha on the custom view container too if you want).

public class ColorPickerLinearLayout extends LinearLayout
{
    public interface OnInterceptTouchEventListener
    {
        boolean onInterceptTouchEvent(MotionEvent event);
    }

    private OnInterceptTouchEventListener mInterceptTouchEventListener;

    public ColorPickerLinearLayout(Context context)
    {
        this(context, null);
    }

    public ColorPickerLinearLayout(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public ColorPickerLinearLayout(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public void setOnInterceptTouchEventListener(OnInterceptTouchEventListener interceptTouchEventListener)
    {
        mInterceptTouchEventListener = interceptTouchEventListener;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event)
    {
        if (mInterceptTouchEventListener != null)
        {
            return mInterceptTouchEventListener.onInterceptTouchEvent(event);
        }

        return false;
    }
}

To use it:

mColorPickerLayout.setOnInterceptTouchEventListener(new ColorPickerLinearLayout.OnInterceptTouchEventListener()
{
    @Override
    public boolean onInterceptTouchEvent(MotionEvent event)
    {
        //Don't pass on the touch event if we're disabled
        return !mColorPicker.isEnabled();
    }
});

//Enable
mColorPicker.setEnabled(true);
mColorPickerLayout.setAlpha(1.0f);

//Disable
mColorPicker.setEnabled(false);
mColorPickerLayout.setAlpha(0.3f);

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

No branches or pull requests

2 participants