[Android] Create an AppBarLayout behavior preventing the toolbar expansion
Nicolas Pomepuy
git at videolan.org
Thu Mar 17 13:50:50 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Mar 17 08:54:23 2022 +0100| [7629f8ada6fedecfabbdf0c4ad95bffadcef73a8] | committer: Nicolas Pomepuy
Create an AppBarLayout behavior preventing the toolbar expansion
> https://code.videolan.org/videolan/vlc-android/commit/7629f8ada6fedecfabbdf0c4ad95bffadcef73a8
---
.../vlc-android/res/layout/playlist_activity.xml | 3 +-
.../gui/helpers/ExpandStateAppBarLayoutBehavior.kt | 44 ++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/res/layout/playlist_activity.xml b/application/vlc-android/res/layout/playlist_activity.xml
index 6e81b400b..cad94f33f 100644
--- a/application/vlc-android/res/layout/playlist_activity.xml
+++ b/application/vlc-android/res/layout/playlist_activity.xml
@@ -23,7 +23,8 @@
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/info_appbar_height"
- android:fitsSystemWindows="true">
+ android:fitsSystemWindows="true"
+ vlc:layout_behavior="org.videolan.vlc.gui.helpers.ExpandStateAppBarLayoutBehavior">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ExpandStateAppBarLayoutBehavior.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ExpandStateAppBarLayoutBehavior.kt
new file mode 100644
index 000000000..bdf3c6771
--- /dev/null
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ExpandStateAppBarLayoutBehavior.kt
@@ -0,0 +1,44 @@
+/*
+ * ************************************************************************
+ * DisableableAppBarLayoutBehavior.java
+ * *************************************************************************
+ * Copyright © 2022 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.
+ * **************************************************************************
+ *
+ *
+ */
+package org.videolan.vlc.gui.helpers
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.MotionEvent
+import android.view.View
+import androidx.coordinatorlayout.widget.CoordinatorLayout
+import com.google.android.material.appbar.AppBarLayout
+
+class ExpandStateAppBarLayoutBehavior(context: Context, attrs: AttributeSet) : AppBarLayout.Behavior(context, attrs) {
+ var scrollEnabled = true
+
+ override fun onStartNestedScroll(parent: CoordinatorLayout, child: AppBarLayout, directTargetChild: View, target: View, nestedScrollAxes: Int, type: Int): Boolean {
+ return scrollEnabled && super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type)
+ }
+
+ override fun onTouchEvent(parent: CoordinatorLayout, child: AppBarLayout, ev: MotionEvent): Boolean {
+ if (!scrollEnabled) return false
+ return super.onTouchEvent(parent, child, ev)
+ }
+}
\ No newline at end of file
More information about the Android
mailing list