summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs
new file mode 100644
index 00000000..cbaaa2b7
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs
@@ -0,0 +1,78 @@
+using System.ComponentModel;
+using Android.Content;
+using Android.Views;
+using AView = Android.Views.View;
+using AColor = Android.Graphics.Color;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ public class TextCellRenderer : CellRenderer
+ {
+ internal TextCellView View { get; private set; }
+
+ protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
+ {
+ if ((View = convertView as TextCellView) == null)
+ View = new TextCellView(context, item);
+
+ UpdateMainText();
+ UpdateDetailText();
+ UpdateHeight();
+ UpdateIsEnabled();
+ View.SetImageVisible(false);
+
+ return View;
+ }
+
+ protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
+ {
+ if (args.PropertyName == TextCell.TextProperty.PropertyName || args.PropertyName == TextCell.TextColorProperty.PropertyName)
+ UpdateMainText();
+ else if (args.PropertyName == TextCell.DetailProperty.PropertyName || args.PropertyName == TextCell.DetailColorProperty.PropertyName)
+ UpdateDetailText();
+ else if (args.PropertyName == Cell.IsEnabledProperty.PropertyName)
+ UpdateIsEnabled();
+ else if (args.PropertyName == "RenderHeight")
+ UpdateHeight();
+ }
+
+ void UpdateDetailText()
+ {
+ var cell = (TextCell)Cell;
+ View.DetailText = cell.Detail;
+ View.SetDetailTextColor(cell.DetailColor);
+ }
+
+ void UpdateHeight()
+ {
+ View.SetRenderHeight(Cell.RenderHeight);
+ }
+
+ void UpdateIsEnabled()
+ {
+ var cell = (TextCell)Cell;
+ View.SetIsEnabled(cell.IsEnabled);
+ }
+
+ void UpdateMainText()
+ {
+ var cell = (TextCell)Cell;
+ View.MainText = cell.Text;
+
+ if (!TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cell))
+ View.SetDefaultMainTextColor(Color.Accent);
+ else
+ View.SetDefaultMainTextColor(Color.Default);
+
+ View.SetMainTextColor(cell.TextColor);
+ }
+
+ // ensure we don't get other people's BaseCellView's
+ internal class TextCellView : BaseCellView
+ {
+ public TextCellView(Context context, Cell cell) : base(context, cell)
+ {
+ }
+ }
+ }
+} \ No newline at end of file