diff --git a/library/src/main/java/io/kimo/konamicode/KonamiCode.java b/library/src/main/java/io/kimo/konamicode/KonamiCode.java index 4395051..f69e459 100644 --- a/library/src/main/java/io/kimo/konamicode/KonamiCode.java +++ b/library/src/main/java/io/kimo/konamicode/KonamiCode.java @@ -4,6 +4,7 @@ import android.content.Context; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -87,13 +88,27 @@ public KonamiCode install() { View currentView = rootView.getChildAt(0); rootView.removeView(currentView); + //match parent params + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ); + + FrameLayout gestureDelegate = new FrameLayout(context); + gestureDelegate.addView(currentView, layoutParams); + + //necessary view that passes all touch events up to the parent viewgroup + gestureDelegate.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + return true; + } + }); + KonamiCodeLayout konamiCodeLayout = new KonamiCodeLayout(context); - konamiCodeLayout.addView(currentView); + konamiCodeLayout.addView(gestureDelegate); - rootView.addView(konamiCodeLayout, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT) - ); + rootView.addView(konamiCodeLayout, layoutParams); konamiCodeLayout.setCallback(callback); diff --git a/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java b/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java index 6f71da9..92413bb 100644 --- a/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java +++ b/library/src/main/java/io/kimo/konamicode/KonamiCodeLayout.java @@ -40,7 +40,6 @@ public enum Button { public static final String TAG = KonamiCodeLayout.class.getSimpleName(); - //final callback private Callback mCallback; private AlertDialog buttonDialog; @@ -90,20 +89,20 @@ public void onClick(View v) { public KonamiCodeLayout(Context context) { super(context); - initalizeValiables(); + init(); } public KonamiCodeLayout(Context context, AttributeSet attrs) { super(context, attrs); - initalizeValiables(); + init(); } public KonamiCodeLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - initalizeValiables(); + init(); } - private void initalizeValiables() { + private void init() { ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext()); mSwipeThreshold = viewConfiguration.getScaledTouchSlop(); @@ -170,6 +169,17 @@ else if (Math.abs(diffY) > mSwipeThreshold) { return super.onInterceptTouchEvent(ev); } + @Override + public boolean onTouchEvent(MotionEvent event) { + + View child = getChildAt(0); + if(child == null) { + return false; + } else { + return child.dispatchTouchEvent(event); + } + } + @Override public boolean onSwipeSequenceAchieved() { return mSwipes.equals(mKonamiCodeDirectionsOrder);