bitwarden-android/src/Android/Controls/ExtendedSwitchCellRenderer.cs

65 lines
2.1 KiB
C#
Raw Normal View History

2016-05-19 06:55:30 +03:00
using Android.Content;
using System.ComponentModel;
using Android.Views;
using Bit.Android.Controls;
using Bit.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
2016-08-23 01:59:15 +03:00
using Android.Widget;
2016-05-19 06:55:30 +03:00
[assembly: ExportRenderer(typeof(ExtendedSwitchCell), typeof(ExtendedSwitchCellRenderer))]
namespace Bit.Android.Controls
{
public class ExtendedSwitchCellRenderer : SwitchCellRenderer
{
2016-08-19 03:20:18 +03:00
protected BaseCellView View { get; private set; }
2016-05-19 06:55:30 +03:00
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
{
2016-08-19 03:20:18 +03:00
var View = base.GetCellCore(item, convertView, parent, context) as SwitchCellView;
2016-05-19 06:55:30 +03:00
var extendedCell = (ExtendedSwitchCell)item;
if(View != null)
{
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
2016-08-19 03:20:18 +03:00
if(item.IsEnabled)
{
View.SetMainTextColor(Color.Black);
}
else
{
View.SetMainTextColor(Color.FromHex("777777"));
2016-08-19 03:20:18 +03:00
}
2016-08-23 01:59:15 +03:00
if(View.ChildCount > 1)
{
var layout = View.GetChildAt(1) as LinearLayout;
if(layout != null && layout.ChildCount > 0)
{
var textView = layout.GetChildAt(0) as TextView;
if(textView != null)
{
textView.TextSize = (float)Device.GetNamedSize(NamedSize.Medium, typeof(Label));
}
}
}
2016-05-19 06:55:30 +03:00
}
return View;
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
base.OnCellPropertyChanged(sender, args);
var cell = (ExtendedSwitchCell)Cell;
if(args.PropertyName == ExtendedSwitchCell.BackgroundColorProperty.PropertyName)
{
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
}
}
}
}