[Android] Fix app crashing at startup on Android 19

Nicolas Pomepuy git at videolan.org
Thu May 7 12:16:59 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May  4 08:57:59 2020 +0200| [e6906bc3da34ec5d3607dd481128fcc8cfba6b21] | committer: Nicolas Pomepuy

Fix app crashing at startup on Android 19

Fixes #1318

> https://code.videolan.org/videolan/vlc-android/commit/e6906bc3da34ec5d3607dd481128fcc8cfba6b21
---

 application/mediadb/build.gradle                   |  2 ++
 .../res/drawable/bottom_navigation_background.xml  |  4 +--
 .../drawable/bottom_navigation_background_dark.xml | 36 ++++++++++++++++++++++
 application/vlc-android/res/layout/main.xml        |  2 +-
 application/vlc-android/res/values/styles.xml      |  4 +--
 .../src/org/videolan/vlc/gui/SecondaryActivity.kt  | 10 ++++++
 6 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/application/mediadb/build.gradle b/application/mediadb/build.gradle
index e63397158..70ecb619c 100644
--- a/application/mediadb/build.gradle
+++ b/application/mediadb/build.gradle
@@ -58,6 +58,8 @@ android {
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+
+    // fixme When we update to 1.2.0 remember to remove the workaround in SecondaryActivity.applyOverrideConfiguration
     implementation 'androidx.appcompat:appcompat:1.1.0'
     implementation "androidx.core:core-ktx:$rootProject.ext.androidxCoreVersion"
     testImplementation 'junit:junit:4.12'
diff --git a/application/resources/src/main/res/drawable/bottom_navigation_background.xml b/application/resources/src/main/res/drawable/bottom_navigation_background.xml
index abebb5149..eb525a77f 100644
--- a/application/resources/src/main/res/drawable/bottom_navigation_background.xml
+++ b/application/resources/src/main/res/drawable/bottom_navigation_background.xml
@@ -25,12 +25,12 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item>
         <shape android:shape="rectangle">
-            <solid android:color="?attr/card_border" />
+            <solid android:color="@color/grey300" />
         </shape>
     </item>
     <item android:top="1dp">
         <shape android:shape="rectangle">
-            <solid android:color="?attr/bottom_navigation_background" />
+            <solid android:color="@color/white" />
         </shape>
     </item>
 </layer-list>
diff --git a/application/resources/src/main/res/drawable/bottom_navigation_background_dark.xml b/application/resources/src/main/res/drawable/bottom_navigation_background_dark.xml
new file mode 100644
index 000000000..462e71ce9
--- /dev/null
+++ b/application/resources/src/main/res/drawable/bottom_navigation_background_dark.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ *************************************************************************
+  ~  bottom_navigation_background_dark.xml
+  ~ **************************************************************************
+  ~ Copyright © 2020 VLC authors and VideoLAN
+  ~ Author: Nicolas POMEPUY
+  ~ 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.
+  ~ ***************************************************************************
+  ~
+  ~
+  -->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="rectangle">
+            <solid android:color="@color/grey300" />
+        </shape>
+    </item>
+    <item android:top="1dp">
+        <shape android:shape="rectangle">
+            <solid android:color="@color/grey875" />
+        </shape>
+    </item>
+</layer-list>
diff --git a/application/vlc-android/res/layout/main.xml b/application/vlc-android/res/layout/main.xml
index 910c2e5b4..24f2be927 100644
--- a/application/vlc-android/res/layout/main.xml
+++ b/application/vlc-android/res/layout/main.xml
@@ -53,7 +53,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="bottom"
-            android:background="@drawable/bottom_navigation_background"
+            android:background="?attr/bottom_navigation_background"
             app:elevation="16dp"
             app:itemIconTint="@color/bottom_navigation_selector"
             app:itemRippleColor="@color/orange500focus"
diff --git a/application/vlc-android/res/values/styles.xml b/application/vlc-android/res/values/styles.xml
index 0bdce6319..b642d6b30 100644
--- a/application/vlc-android/res/values/styles.xml
+++ b/application/vlc-android/res/values/styles.xml
@@ -41,7 +41,7 @@
         <item name="actionModeBackground">@color/grey400</item>
         <item name="item_footer">@color/grey300</item>
         <item name="background_default">@color/white</item>
-        <item name="bottom_navigation_background">@color/white</item>
+        <item name="bottom_navigation_background">@drawable/bottom_navigation_background</item>
         <item name="bottom_navigation_color">@color/grey700</item>
         <item name="progress_indeterminate_tint">@color/white</item>
         <item name="header_background">@color/whitetransparent_ea</item>
@@ -167,7 +167,7 @@
         <item name="windowActionModeOverlay">true</item>
         <item name="actionModeBackground">@color/grey875</item>
         <item name="background_default">@color/black</item>
-        <item name="bottom_navigation_background">@color/grey875</item>
+        <item name="bottom_navigation_background">@drawable/bottom_navigation_background_dark</item>
         <item name="bottom_navigation_color">@color/grey500</item>
         <item name="header_background">@color/blacktransparent</item>
         <item name="background_default_darker">@color/grey875</item>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
index 3d7e85d4b..7d2588bb8 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.kt
@@ -24,6 +24,8 @@
 package org.videolan.vlc.gui
 
 import android.content.Intent
+import android.content.res.Configuration
+import android.os.Build
 import android.os.Bundle
 import android.os.Parcelable
 import android.view.MenuItem
@@ -94,6 +96,14 @@ class SecondaryActivity : ContentActivity() {
         }
     }
 
+    //Workaround to avoid a crash with webviews. See https://stackoverflow.com/a/60854445/2732052 and https://stackoverflow.com/a/58131421/2732052
+    override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
+        if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode ==  applicationContext.resources.configuration.uiMode)) {
+            return
+        }
+        super.applyOverrideConfiguration(overrideConfiguration)
+    }
+
     override fun forceLoadVideoFragment() {
         val fragmentId = intent.getStringExtra(KEY_FRAGMENT)
         fetchSecondaryFragment(fragmentId)



More information about the Android mailing list