forked from Sweekriti91/XamCast
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MyMiniPlayerRenderer.cs
68 lines (55 loc) · 1.92 KB
/
MyMiniPlayerRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Android.App;
using Android.Content;
using Android.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using XamCast;
using XamCast.Droid.Renderers;
[assembly: ExportRenderer(typeof(MyMiniPlayer), typeof(MyMiniPlayerRenderer))]
namespace XamCast.Droid.Renderers
{
public class MyMiniPlayerRenderer : ViewRenderer<MyMiniPlayer, global::Android.Views.View>
{
LinearLayout linearLayout;
global::Android.Views.View view;
Activity activity;
public MyMiniPlayerRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<MyMiniPlayer> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
activity = this.Context as Activity;
view.Dispose();
linearLayout.Dispose();
}
if (e.NewElement != null)
{
if (Control == null)
{
activity = this.Context as Activity;
view = activity.LayoutInflater.Inflate(Resource.Layout.miniplayerLayout, null);
linearLayout = view.FindViewById<LinearLayout>(Resource.Layout.miniplayerLayout);
SetNativeControl(view);
}
}
}
protected override void Dispose(bool disposing)
{
var fm = Control.Context.GetFragmentManager();
var xmlFragment = fm.FindFragmentById(Resource.Id.castMiniController);
if (xmlFragment != null)
{
fm.BeginTransaction().Remove(xmlFragment).Commit();
}
base.Dispose(disposing);
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);
}
}
}