package fanch.multijeu.findwords.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;

import fanch.multijeu.R;

public class PlaceHolderButton extends LetterButton {


    public static final int STATE_HIDDEN=0;
    public static final int STATE_TIP=1;
    public static final int STATE_SHOWN=2;


    protected int mState=STATE_HIDDEN;

    public PlaceHolderButton(Context context) {
        super(context);
        setPlaceHolderBackground();
        setState(mState);
    }

    public PlaceHolderButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        setPlaceHolderBackground();
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs,R.styleable.LetterButton, 0, 0);
        setState(mState);
        try {
            mState = a.getInteger(R.styleable.LetterButton_state, 0);
        } finally {
            a.recycle();
        }

    }

    public int getState() {
        return mState;
    }

    public boolean isDiscover()
    {
        return mState==STATE_TIP || mState==STATE_SHOWN;
    }

    public void setState(int mState) {
        this.mState = mState;
        int alpha=0;
        switch(mState)
        {
            case STATE_HIDDEN:
                alpha=0;
                setPlaceHolderBackground();
                break;
            case STATE_TIP:
                setPlaceHolderBackground();
                alpha=60;
                break;
            case STATE_SHOWN:
            default:
                alpha=255;
                setLetterBackground();


        }
        setTextColor(Color.argb(alpha,0,0,0));
    }


    protected void setPlaceHolderBackground()
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(getResources().getDrawable(R.drawable.placeholder));
        }
    }



}
