Skip to content

Commit

Permalink
MaterialDrawer: use a HackyDrawerLayout to catch exceptions, linked t…
Browse files Browse the repository at this point in the history
…o chrisbanes/PhotoView, closes #28
  • Loading branch information
quentin-st committed Oct 18, 2015
1 parent 1b87ac0 commit 42ab442
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ private void initDrawer() {
this.drawerItems.get(DrawerMenuItem.Support),
this.drawerItems.get(DrawerMenuItem.Donate));

builder.withDrawerLayout(R.layout.material_drawer);

builder.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int index, IDrawerItem iDrawerItem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.chteuchteu.munin.ui;

import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class HackyDrawerLayout extends DrawerLayout {
public HackyDrawerLayout(Context context) {
super(context);
}

public HackyDrawerLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ex) {
//ex.printStackTrace();
return false;
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ public HackyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException ex) {
//ex.printStackTrace();
return false;
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (Throwable t) {
//t.printStackTrace();
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
return false;
}
}
Expand Down
6 changes: 6 additions & 0 deletions muninforAndroid/src/main/res/layout/material_drawer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<com.chteuchteu.munin.ui.HackyDrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/material_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />

0 comments on commit 42ab442

Please sign in to comment.