[Android] Workaround for support library crash

Geoffrey Métais git at videolan.org
Thu Mar 5 13:13:51 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  5 13:13:25 2015 +0100| [36752a94f3d6aa2ebd944b7b3f68b41daaaadb69] | committer: Geoffrey Métais

Workaround for support library crash

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=36752a94f3d6aa2ebd944b7b3f68b41daaaadb69
---

 vlc-android/res/layout/main.xml                    |    4 +-
 .../src/org/videolan/vlc/gui/MainActivity.java     |   18 +++----
 .../org/videolan/vlc/widget/HackyDrawerLayout.java |   56 ++++++++++++++++++++
 3 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/vlc-android/res/layout/main.xml b/vlc-android/res/layout/main.xml
index f78d4f1..174c0e6 100644
--- a/vlc-android/res/layout/main.xml
+++ b/vlc-android/res/layout/main.xml
@@ -5,7 +5,7 @@
     android:layout_height="match_parent"
     android:orientation="vertical">
 
-    <android.support.v4.widget.DrawerLayout
+    <org.videolan.vlc.widget.HackyDrawerLayout
         android:id="@+id/root_container"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
@@ -81,7 +81,7 @@
 
         <!-- The navigation drawer -->
         <include layout="@layout/sidebar"/>
-    </android.support.v4.widget.DrawerLayout>
+    </org.videolan.vlc.widget.HackyDrawerLayout>
 
     <include layout="@layout/toolbar"/>
 </FrameLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index ed08ff2..0423eda 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -41,7 +41,6 @@ import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.view.MenuItemCompat;
-import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.ActionBarActivity;
 import android.support.v7.app.ActionBarDrawerToggle;
@@ -53,7 +52,6 @@ import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
@@ -69,7 +67,6 @@ import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.vlc.BuildConfig;
 import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.MediaLibrary;
-import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.audio.AudioService;
@@ -88,6 +85,7 @@ import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
 import org.videolan.vlc.util.WeakHandler;
+import org.videolan.vlc.widget.HackyDrawerLayout;
 import org.videolan.vlc.widget.SlidingPaneLayout;
 
 import java.util.Arrays;
@@ -113,7 +111,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
     private AudioPlayer mAudioPlayer;
     private AudioServiceController mAudioController;
     private SlidingPaneLayout mSlidingPane;
-    private DrawerLayout mRootContainer;
+    private HackyDrawerLayout mRootContainer;
     private ListView mListView;
     private ActionBarDrawerToggle mDrawerToggle;
     private View mSideMenu;
@@ -219,7 +217,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
         mInfoProgress = (ProgressBar) findViewById(R.id.info_progress);
         mInfoText = (TextView) findViewById(R.id.info_text);
         mAudioPlayerFilling = findViewById(R.id.audio_player_filling);
-        mRootContainer = (DrawerLayout) findViewById(R.id.root_container);
+        mRootContainer = (HackyDrawerLayout) findViewById(R.id.root_container);
 
         /* Set up the action bar */
         prepareActionBar();
@@ -954,7 +952,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
                 if (resId != 0)
                     mSlidingPane.setShadowResource(resId);
                 mAudioPlayer.setHeaderVisibilities(false, false, true, true, true);
-                mRootContainer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
+                mRootContainer.setDrawerLockMode(HackyDrawerLayout.LOCK_MODE_UNLOCKED);
                 removeTipViewIfDisplayed();
                 mAudioPlayer.showAudioPlayerTips();
             }
@@ -962,13 +960,13 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
             @Override
             public void onPanelOpenedEntirely() {
                 mSlidingPane.setShadowDrawable(null);
-                mRootContainer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
+                mRootContainer.setDrawerLockMode(HackyDrawerLayout.LOCK_MODE_UNLOCKED);
             }
 
             @Override
             public void onPanelClosed() {
                 mAudioPlayer.setHeaderVisibilities(true, true, false, false, false);
-                mRootContainer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
+                mRootContainer.setDrawerLockMode(HackyDrawerLayout.LOCK_MODE_LOCKED_CLOSED);
                 mAudioPlayer.showPlaylistTips();
             }
 
@@ -984,8 +982,8 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
             removeTipViewIfDisplayed();
             View v = LayoutInflater.from(this).inflate(layoutId, null);
             mRootContainer.addView(v,
-                    new DrawerLayout.LayoutParams(DrawerLayout.LayoutParams.MATCH_PARENT,
-                            DrawerLayout.LayoutParams.MATCH_PARENT));
+                    new HackyDrawerLayout.LayoutParams(HackyDrawerLayout.LayoutParams.MATCH_PARENT,
+                            HackyDrawerLayout.LayoutParams.MATCH_PARENT));
 
             v.setOnClickListener(new View.OnClickListener() {
                 @Override
diff --git a/vlc-android/src/org/videolan/vlc/widget/HackyDrawerLayout.java b/vlc-android/src/org/videolan/vlc/widget/HackyDrawerLayout.java
new file mode 100644
index 0000000..e2be90c
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/widget/HackyDrawerLayout.java
@@ -0,0 +1,56 @@
+/*
+ * *************************************************************************
+ *  HackyDrawerLayout.java
+ * **************************************************************************
+ *  Copyright © 2015 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.widget;
+
+import android.content.Context;
+import android.support.v4.widget.DrawerLayout;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+/*
+ * Workaround for support lib bug, see https://code.google.com/p/android/issues/detail?id=60464
+ */
+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);
+    }
+
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        try {
+            return super.onInterceptTouchEvent(ev);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            return false;
+        }
+    }
+}



More information about the Android mailing list