package pw.cloudef.rpg; import com.andretietz.android.controller.InputView; import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v7.content.res.AppCompatResources; import android.util.AttributeSet; public class Button extends InputView { private static final int BUTTON_COUNT = 1; private Drawable[][] drawables = new Drawable[BUTTON_COUNT][2]; private int[][] resources = new int[BUTTON_COUNT][2]; public Button(Context context) { super(context); } public Button(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public Button(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public Button(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(context, attrs); } protected void init(Context context, AttributeSet attrs) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ActionView, 0, R.style.default_actionview); super.init(context, attrs, R.style.default_actionview); try { resources[0][0] = a.getResourceId(R.styleable.ActionView_button1_enabled, R.drawable.action_usual); resources[0][1] = a.getResourceId(R.styleable.ActionView_button1_pressed, R.drawable.action_pressed); } finally { a.recycle(); } } @Override protected Drawable getStateDrawable(int buttonIndex, ButtonState state) { if (null == drawables[buttonIndex][state.ordinal()]) { drawables[buttonIndex][state.ordinal()] = AppCompatResources .getDrawable(getContext(), resources[buttonIndex][state.ordinal()]); } return drawables[buttonIndex][state.ordinal()]; } @Override protected int getButtonCount() { return BUTTON_COUNT; } }