summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Extensions.cs
blob: c326555ae9f323c1ccb17db7b6f56b274ddce51c (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
´╗┐using Android.Content.Res;
using Android.Views;

namespace Xamarin.Forms.Platform.Android
{
	public static class Extensions
	{
		internal static IMenuItem FindMenuItemByNameOrIcon(this IMenu menu, string menuName, string iconName)
		{
			if (menu.Size() == 1)
				return menu.GetItem(0);

			for (var i = 0; i < menu.Size(); i++)
			{
				IMenuItem menuItem = menu.GetItem(i);
				if (menuItem.TitleFormatted != null && menuName == menuItem.TitleFormatted.ToString())
					return menuItem;

				if (!string.IsNullOrEmpty(iconName))
				{
					// TODO : search by iconName
				}
			}
			return null;
		}

		internal static DeviceOrientation ToDeviceOrientation(this Orientation orientation)
		{
			switch (orientation)
			{
				case Orientation.Landscape:
					return DeviceOrientation.Landscape;
				case Orientation.Portrait:
					return DeviceOrientation.Portrait;
				default:
					return DeviceOrientation.Other;
			}
		}
	}
}