From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- src/pw/cloudef/rpg/Button.java | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/pw/cloudef/rpg/Button.java (limited to 'src/pw/cloudef/rpg/Button.java') diff --git a/src/pw/cloudef/rpg/Button.java b/src/pw/cloudef/rpg/Button.java new file mode 100644 index 0000000..5d444a4 --- /dev/null +++ b/src/pw/cloudef/rpg/Button.java @@ -0,0 +1,60 @@ +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; + } +} -- cgit v1.2.3