-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
SecondActivity.cs
111 lines (92 loc) · 2.82 KB
/
SecondActivity.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using Android.App;
using Android.OS;
#if __ANDROID_29__
using AndroidX.Fragment.App;
using Fragment = AndroidX.Fragment.App.Fragment;
using FragmentTransaction = AndroidX.Fragment.App.FragmentTransaction;
#else
using Android.Support.V4.App;
using Fragment = Android.Support.V4.App.Fragment;
using FragmentTransaction = Android.Support.V4.App.FragmentTransaction;
#endif
using Android.Views;
using Embedding.XF;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View;
using Button = Android.Widget.Button;
namespace Embedding.Droid
{
[Activity(Label = "SecondActivity")]
public class SecondActivity : FragmentActivity
{
Fragment _hello;
Fragment _alertsAndActionSheets;
Fragment _openUri;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView (Resource.Layout.Second);
var ft = SupportFragmentManager.BeginTransaction();
ft.Replace(Resource.Id.fragment_frame_layout, new SecondFragment(), "main");
ft.Commit();
}
void ShowEmbeddedPageFragment(Fragment fragment)
{
FragmentTransaction ft = SupportFragmentManager.BeginTransaction();
ft.AddToBackStack(null);
ft.Replace(Resource.Id.fragment_frame_layout, fragment, "hello");
ft.Commit();
}
public void ShowHello()
{
if (_hello == null)
{
_hello = new Hello().CreateSupportFragment(this);
}
ShowEmbeddedPageFragment(_hello);
}
public void ShowAlertsAndActionSheets()
{
if (_alertsAndActionSheets== null)
{
_alertsAndActionSheets = new AlertsAndActionSheets().CreateSupportFragment(this);
}
ShowEmbeddedPageFragment(_alertsAndActionSheets);
}
public void ShowOpenUri()
{
if (_openUri == null)
{
_openUri = new OpenUri().CreateSupportFragment(this);
}
ShowEmbeddedPageFragment(_openUri );
}
}
public class SecondFragment : Fragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.SecondFragment, container, false);
var showEmbeddedButton = view.FindViewById<Button>(Resource.Id.showEmbeddedButton);
var showAlertsActionSheets = view.FindViewById<Button>(Resource.Id.showAlertsActionSheets);
var showOpenUri = view.FindViewById<Button>(Resource.Id.showOpenUri);
showEmbeddedButton.Click += ShowEmbeddedClick;
showAlertsActionSheets.Click += ShowAlertsActionSheetsClick;
showOpenUri.Click += ShowOpenUriClick;
return view;
}
void ShowAlertsActionSheetsClick(object sender, EventArgs eventArgs)
{
((SecondActivity)Activity).ShowAlertsAndActionSheets();
}
void ShowEmbeddedClick(object sender, EventArgs e)
{
((SecondActivity)Activity).ShowHello();
}
void ShowOpenUriClick(object sender, EventArgs e)
{
((SecondActivity)Activity).ShowOpenUri();
}
}
}