[Android] [PATCH] Extend DrawerLayout to prevent crash
Geoffrey Métais
geoffrey.metais at gmail.com
Thu Dec 11 14:55:36 CET 2014
Hack to prevent ArrayIndexOutOfBoundsException from DrawerLayout
found here: https://code.google.com/p/android/issues/detail?id=60464#c5
---
vlc-android/res/layout/main.xml | 4 +-
.../org/videolan/vlc/gui/HackyDrawerLayout.java | 66 ++++++++++++++++++++++
.../src/org/videolan/vlc/gui/MainActivity.java | 4 +-
3 files changed, 70 insertions(+), 4 deletions(-)
create mode 100644 vlc-android/src/org/videolan/vlc/gui/HackyDrawerLayout.java
diff --git a/vlc-android/res/layout/main.xml b/vlc-android/res/layout/main.xml
index 9a7b7ea..818656d 100644
--- a/vlc-android/res/layout/main.xml
+++ b/vlc-android/res/layout/main.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<android.support.v4.widget.DrawerLayout
+<org.videolan.vlc.gui.HackyDrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_container"
android:layout_width="match_parent"
@@ -77,4 +77,4 @@
<!-- The navigation drawer -->
<include layout="@layout/sidebar"/>
-</android.support.v4.widget.DrawerLayout>
+</org.videolan.vlc.gui.HackyDrawerLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/HackyDrawerLayout.java b/vlc-android/src/org/videolan/vlc/gui/HackyDrawerLayout.java
new file mode 100644
index 0000000..7771f65
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/HackyDrawerLayout.java
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * HackyDrawerLayout.java
+ *****************************************************************************
+ * Copyright © 2011-2012 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+package org.videolan.vlc.gui;
+
+import android.content.Context;
+import android.support.v4.widget.DrawerLayout;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+/*
+ Hack to prevent ArrayIndexOutOfBoundsException from DrawerLayout
+ found here: https://code.google.com/p/android/issues/detail?id=60464#c5
+ */
+public class HackyDrawerLayout extends DrawerLayout {
+
+ public HackyDrawerLayout(Context context) {
+ super(context);
+ }
+
+ public HackyDrawerLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public HackyDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ private boolean mIsDisallowIntercept = false;
+
+ @Override
+ public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+ // keep the info about if the innerViews do requestDisallowInterceptTouchEvent
+ mIsDisallowIntercept = disallowIntercept;
+ super.requestDisallowInterceptTouchEvent(disallowIntercept);
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ // the incorrect array size will only happen in the multi-touch scenario.
+ if (ev.getPointerCount() > 1 && mIsDisallowIntercept) {
+ requestDisallowInterceptTouchEvent(false);
+ boolean handled = super.dispatchTouchEvent(ev);
+ requestDisallowInterceptTouchEvent(true);
+ return handled;
+ } else {
+ return super.dispatchTouchEvent(ev);
+ }
+ }
+}
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 14ea5e1..93c8702 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -112,7 +112,7 @@ public class MainActivity extends ActionBarActivity {
private AudioPlayer mAudioPlayer;
private AudioServiceController mAudioController;
private SlidingPaneLayout mSlidingPane;
- private DrawerLayout mRootContainer;
+ private HackyDrawerLayout mRootContainer;
private ListView mListView;
private ActionBarDrawerToggle mDrawerToggle;
@@ -223,7 +223,7 @@ public class MainActivity extends ActionBarActivity {
mInfoProgress = (ProgressBar) v_main.findViewById(R.id.info_progress);
mInfoText = (TextView) v_main.findViewById(R.id.info_text);
mAudioPlayerFilling = v_main.findViewById(R.id.audio_player_filling);
- mRootContainer = (DrawerLayout) v_main.findViewById(R.id.root_container);
+ mRootContainer = (HackyDrawerLayout) v_main.findViewById(R.id.root_container);
/* Set up the action bar */
prepareActionBar();
--
1.9.1
More information about the Android
mailing list