-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSlidingPaneLayoutActivity.cs
90 lines (75 loc) · 3.05 KB
/
SlidingPaneLayoutActivity.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using Android.App;
using Android.OS;
using Android.Support.V4.Widget;
using Android.Widget;
namespace DrawerSample
{
[Activity(Label = "SlidingPane Sample", Icon = "@drawable/icon")]
public class SlidingPaneLayoutActivity : Activity
{
private SlidingPaneLayout _slidingLayout;
private ListView _list;
private TextView _content;
private string _title, _drawerTitle;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.SlidingPaneLayout);
_slidingLayout = FindViewById<SlidingPaneLayout>(Resource.Id.sliding_pane_layout);
_list = FindViewById<ListView>(Resource.Id.left_pane);
_content = FindViewById<TextView>(Resource.Id.content_text);
_slidingLayout.PanelOpened += (sender, args) =>
{
ActionBar.SetHomeButtonEnabled(false);
ActionBar.SetDisplayHomeAsUpEnabled(false);
ActionBar.Title = _drawerTitle;
};
_slidingLayout.PanelClosed += (sender, args) =>
{
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);
ActionBar.Title = _title;
};
_slidingLayout.OpenPane();
_list.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1,
Shakespeare.Titles);
_list.ItemClick += (sender, args) =>
{
_content.Text = Shakespeare.Dialogue[args.Position];
_title = Shakespeare.Titles[args.Position];
_slidingLayout.SmoothSlideClosed();
};
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);
_title = Shakespeare.Titles[0];
_drawerTitle = "Pick a title";
_slidingLayout.ViewTreeObserver.GlobalLayout += FirstLayoutListener;
}
private void FirstLayoutListener(object sender, EventArgs args)
{
if (_slidingLayout.CanSlide() && !_slidingLayout.IsOpen)
{
ActionBar.SetDisplayHomeAsUpEnabled(true);
ActionBar.SetHomeButtonEnabled(true);
ActionBar.Title = _title;
}
else
{
ActionBar.SetHomeButtonEnabled(false);
ActionBar.SetDisplayHomeAsUpEnabled(false);
ActionBar.Title = _drawerTitle;
}
_slidingLayout.ViewTreeObserver.GlobalLayout -= FirstLayoutListener;
}
public override bool OnOptionsItemSelected(Android.Views.IMenuItem item)
{
if (item.ItemId == Android.Resource.Id.Home && !_slidingLayout.IsOpen)
{
_slidingLayout.SmoothSlideOpen();
return true;
}
return base.OnOptionsItemSelected(item);
}
}
}