From 3f43dc55ba6f4a36ca1f7b49c0423834169df4b2 Mon Sep 17 00:00:00 2001 From: Thiago Rocha Date: Wed, 5 Aug 2015 10:39:34 -0300 Subject: [PATCH] Removing enums. Dismissing buttons dialog if the buttons sequence is not correct --- library/build.gradle | 2 +- .../io/kimo/konamicode/KonamiCodeLayout.java | 79 +++++++++---------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 25badfc..3cbb0e0 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ android { minSdkVersion 7 targetSdkVersion 22 versionCode 2 - versionName "1.1.2" + versionName "1.1.3" } buildTypes { release { diff --git a/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java b/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java index 92413bb..8b49266 100644 --- a/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java +++ b/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java @@ -17,6 +17,8 @@ public class KonamiCodeLayout extends FrameLayout implements KonamiSequenceListener { + public static final String TAG = KonamiCodeLayout.class.getSimpleName(); + /** * Callback - Interface that's executed when the code finishes */ @@ -24,21 +26,16 @@ public interface Callback { void onFinish(); } - /** - * Enumeration of swipe directions - */ - public enum Direction { - UP, DOWN, LEFT, RIGHT, NONE - } + public static final int NONE = -1; - /** - * Enumeration of the buttons - */ - public enum Button { - A, B, START, NONE - } + public static final int UP = 0; + public static final int DOWN = 1; + public static final int LEFT = 2; + public static final int RIGHT = 3; - public static final String TAG = KonamiCodeLayout.class.getSimpleName(); + public static final int A = 4; + public static final int B = 5; + public static final int START = 6; private Callback mCallback; @@ -52,19 +49,19 @@ public void onClick(View v) { int id = v.getId(); if(id == R.id.konami_button_a) { - mLastPressedButton = Button.A; + mLastPressedButton = A; } else if(id == R.id.konami_button_b) { - mLastPressedButton = Button.B; + mLastPressedButton = B; } else if(id == R.id.konami_button_start) { - mLastPressedButton = Button.START; + mLastPressedButton = START; } registerPress(); } }; - private Direction mLastSwipedDirection = Direction.NONE; - private Button mLastPressedButton = Button.NONE; + private int mLastSwipedDirection = NONE; + private int mLastPressedButton = NONE; private int mSwipeThreshold; private float mLastX; @@ -72,20 +69,15 @@ public void onClick(View v) { private float mStartX; private float mStartY; - private List mKonamiCodeDirectionsOrder = Arrays.asList(new Direction[]{ - Direction.UP, Direction.UP, - Direction.DOWN, Direction.DOWN, - Direction.LEFT, Direction.RIGHT, - Direction.LEFT, Direction.RIGHT - }); - - - private List