Skip to content

Commit

Permalink
Adding withDrawerLayout method on builder
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokimo committed Jul 28, 2015
1 parent 47fae33 commit 950c0f5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions library/src/main/java/io/kimo/konamicode/KonamiCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void onFinish() {
dialog.dismiss();
}
};
protected boolean hasDrawerLayout;

/**
* Konami Code's builder
Expand Down Expand Up @@ -125,6 +127,11 @@ public Builder into(@NonNull View view) {
return this;
}

public Builder withDrawerLayout(boolean hasDrawerLayout) {
this.hasDrawerLayout = hasDrawerLayout;
return this;
}

/**
* withSwipeThreshold - distance of the swipe movment
* @param value
Expand Down Expand Up @@ -182,8 +189,14 @@ private void configureGestureListener() {
directionsListener = new DirectionListener(dialog, swipeThreshold, swipeVelocityThreshold);
gestureListener = new GestureDetectorCompat(context, directionsListener);

// get the first child of the root view
View targetView = rootView.getChildAt(0);
View targetView;
if (hasDrawerLayout) {
DrawerLayout drawerLayout = (DrawerLayout) rootView.getChildAt(0);
targetView = drawerLayout.getChildAt(0);
} else {
targetView = rootView.getChildAt(0);
}

targetView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Expand Down

0 comments on commit 950c0f5

Please sign in to comment.