summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/ActionSheetRenderer.cs
blob: 8c937f4c3b9c0b14dbd96cbb519bb4f6b5c34958 (plain)
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
´╗┐using System;
using Android.App;
using Android.Graphics;
using Android.OS;
using Android.Views;
using Android.Widget;
using AButton = Android.Widget.Button;
using AView = Android.Views.View;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Platform.Android
{
	[Obsolete("ActionSheet now uses default implementation.")]
	public class ActionSheetRenderer : Dialog, AView.IOnClickListener
	{
		readonly ActionSheetArguments _arguments;
		readonly LinearLayout _layout;

		internal ActionSheetRenderer(ActionSheetArguments actionSheetArguments) : base(Forms.Context)
		{
			_arguments = actionSheetArguments;
			_layout = new LinearLayout(Context);
		}

		void AView.IOnClickListener.OnClick(AView v)
		{
			var button = (AButton)v;
			_arguments.SetResult(button.Text);
			Hide();
		}

		public override void Cancel()
		{
			base.Cancel();
			_arguments.SetResult(null);
		}

		public override void OnAttachedToWindow()
		{
			base.OnAttachedToWindow();
			Window.SetGravity(GravityFlags.CenterVertical);
			Window.SetLayout(-1, -2);
		}

		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			SetCanceledOnTouchOutside(true);

			_layout.Orientation = Orientation.Vertical;

			using (var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent))
				SetContentView(_layout, layoutParams);

			if (_arguments.Destruction != null)
			{
				AButton destruct = AddButton(_arguments.Destruction);
				destruct.Background.SetColorFilter(new Color(1, 0, 0, 1).ToAndroid(), PorterDuff.Mode.Multiply);
			}

			foreach (string button in _arguments.Buttons)
				AddButton(button);

			if (_arguments.Cancel != null)
			{
				AButton cancel = AddButton(_arguments.Cancel);
				cancel.Background.SetColorFilter(new Color(0.5, 0.5, 0.5, 1).ToAndroid(), PorterDuff.Mode.Multiply);
			}

			SetTitle(_arguments.Title);
		}

		AButton AddButton(string name)
		{
			var button = new AButton(Context) { Text = name };
			button.SetOnClickListener(this);

			_layout.AddView(button);

			return button;
		}
	}
}