Making queue drawer trully slide by overriding touch listeners.

This commit is contained in:
Tristan Roux
2019-02-20 03:10:00 +01:00
parent 12cb9d960b
commit a37109ee71
6 changed files with 73 additions and 22 deletions

View File

@@ -756,7 +756,7 @@ namespace MusicApp
}
public void ShowSmallPlayer()
{
{
FindViewById<NestedScrollView>(Resource.Id.playerSheet).Visibility = ViewStates.Visible;
FindViewById(Resource.Id.playerContainer).Alpha = 0;
FindViewById(Resource.Id.smallPlayer).Alpha = 1;

View File

@@ -340,6 +340,7 @@
<Compile Include="Resources\Portable Class\DownloadQueue.cs" />
<Compile Include="Resources\Portable Class\DownloadQueueAdapter.cs" />
<Compile Include="Resources\Portable Class\FixedLinearLayoutManager.cs" />
<Compile Include="Resources\Portable Class\FixedNestedScrollView.cs" />
<Compile Include="Resources\Portable Class\PlayerBehavior.cs" />
<Compile Include="Resources\Portable Class\PlaylistHolder.cs" />
<Compile Include="Resources\Portable Class\PlaylistLocationAdapter.cs" />

View File

@@ -0,0 +1,48 @@
using Android.Content;
using Android.Runtime;
using Android.Support.V4.Widget;
using Android.Util;
using Android.Views;
using System;
[Register("MusicApp/FixedNestedScrollView")]
public class FixedNestedScrollView : NestedScrollView
{
public static bool PreventSlide = false;
public FixedNestedScrollView(Context context) : base(context) { }
public FixedNestedScrollView(Context context, IAttributeSet attrs) : base(context, attrs) { }
public FixedNestedScrollView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { }
protected FixedNestedScrollView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { }
////Overriden because DrawerLayout need to be measured with MeasureSpecMode EXACLTY
//protected override void MeasureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
//{
// //if (child is DrawerLayout)
// //{
// MarginLayoutParams lp = (MarginLayoutParams)child.LayoutParameters;
// int childWidthMeasureSpec = GetChildMeasureSpec(parentWidthMeasureSpec, PaddingLeft + PaddingRight + lp.LeftMargin + lp.RightMargin + widthUsed, lp.Width);
// int childHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(parentWidthMeasureSpec, MeasureSpecMode.Exactly);
// child.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
// Console.WriteLine("&Height: " + child.MeasuredHeight + " Child: " + child);
// //}
// //else
// // base.MeasureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentWidthMeasureSpec, heightUsed);
//}
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
if(PreventSlide)
return false;
return base.OnInterceptTouchEvent(ev);
}
public override bool OnTouchEvent(MotionEvent e)
{
if(PreventSlide)
return false;
return base.OnTouchEvent(e);
}
}

View File

@@ -11,7 +11,6 @@ using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V4.Widget;
using Android.Support.V7.Graphics;
using Android.Support.V7.Widget;
using Android.Text;
using Android.Text.Style;
using Android.Util;
@@ -41,7 +40,7 @@ namespace MusicApp
private ProgressBar spBar;
private TextView timer;
private ImageView view;
private DrawerLayout DrawerLayout;
public DrawerLayout DrawerLayout;
private bool prepared = false;
private readonly int[] timers = new int[] { 0, 2, 10, 30, 60, 120 };
private int checkedItem = 0;
@@ -179,7 +178,7 @@ namespace MusicApp
view.SetImageBitmap(drawable);
Palette.From(drawable).MaximumColorCount(28).Generate(this);
if(view.Width > 0)
if (view.Width > 0)
{
//The width of the view in pixel (we'll multiply this by 0.75f because the drawer has a width of 75%)
int width = (int)(view.Width * (float)drawable.Height / view.Height);
@@ -746,7 +745,10 @@ namespace MusicApp
public void OnDrawerStateChanged(int newState)
{
if (newState == DrawerLayout.StateDragging)
FixedNestedScrollView.PreventSlide = true;
else if(newState == DrawerLayout.StateSettling)
FixedNestedScrollView.PreventSlide = false;
}
}
}

View File

@@ -40,14 +40,6 @@ public class PlayerBehavior : BottomSheetBehavior
return base.OnStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type);
}
public override bool OnNestedPreFling(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, float velocityX, float velocityY)
{
if (PreventSlide)
return false;
return base.OnNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
}
public override void OnNestedPreScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, int dx, int dy, int[] consumed, int type)
{
if (PreventSlide)
@@ -63,4 +55,12 @@ public class PlayerBehavior : BottomSheetBehavior
base.OnStopNestedScroll(coordinatorLayout, child, target, type);
}
public override bool OnNestedPreFling(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, float velocityX, float velocityY)
{
if (PreventSlide)
return false;
return base.OnNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
}
}

View File

@@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
@@ -82,11 +82,11 @@
app:itemTextColor="@color/color_tint"
app:menu="@menu/bottom_items" />
<android.support.v4.widget.NestedScrollView
<MusicApp.FixedNestedScrollView
android:id="@+id/playerSheet"
android:fitsSystemWindows="true"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:elevation="6dp"
android:translationY="-56dp"
@@ -94,8 +94,8 @@
app:behavior_peekHeight="70dp"
app:layout_behavior="MusicApp.PlayerBehavior" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/playersHolder"
android:background="#2b5568"
android:fitsSystemWindows="true" >
@@ -198,10 +198,10 @@
<fragment
android:name="MusicApp.Player"
android:id="@+id/playerContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</MusicApp.FixedNestedScrollView>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/snackBar"