Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Tizen] Adds the Unified Theme Manager (#11779)
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava committed Aug 17, 2020
1 parent 5edac1f commit 78b4b15
Show file tree
Hide file tree
Showing 66 changed files with 1,902 additions and 495 deletions.
10 changes: 3 additions & 7 deletions Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
using System.Collections.Generic;
using System.Globalization;
using ElmSharp;
using EColor = ElmSharp.Color;

namespace Xamarin.Forms.Platform.Tizen
{
public class EntryCellRenderer : ViewCellRenderer
{
static readonly double s_defaultHeight = 65;
static readonly EColor s_defaultLabelColor = EColor.Black;

readonly Dictionary<EvasObject, VisualElement> _cacheCandidate = new Dictionary<EvasObject, VisualElement>();

public EntryCellRenderer()
Expand All @@ -23,7 +19,7 @@ protected override EvasObject OnGetContent(Cell cell, string part)
{
var entryCell = cell as EntryCell;
int pixelHeight = Forms.ConvertToScaledPixel(entryCell.RenderHeight);
pixelHeight = pixelHeight > 0 ? pixelHeight : Forms.ConvertToPixel(s_defaultHeight);
pixelHeight = pixelHeight > 0 ? pixelHeight : this.GetDefaultHeightPixel();

var label = new Label()
{
Expand Down Expand Up @@ -90,7 +86,7 @@ protected override EvasObject OnReusableContent(Cell cell, string part, EvasObje
var layout = _cacheCandidate[old];
layout.BindingContext = cell;
int height = Forms.ConvertToScaledPixel(cell.RenderHeight);
height = height > 0 ? height : Forms.ConvertToPixel(s_defaultHeight);
height = height > 0 ? height : this.GetDefaultHeightPixel();
old.MinimumHeight = height;
return old;
}
Expand All @@ -99,7 +95,7 @@ class DefaultColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((Color)value).IsDefault ? s_defaultLabelColor : value;
return ((Color)value).IsDefault ? ThemeConstants.EntryCell.ColorClass.DefaultLabelColor : value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
8 changes: 3 additions & 5 deletions Xamarin.Forms.Platform.Tizen/Cells/ImageCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ namespace Xamarin.Forms.Platform.Tizen
{
public class ImageCellRenderer : TextCellRenderer
{
const int _defaultHeight = 55;

public ImageCellRenderer() : this(Device.Idiom == TargetIdiom.Watch ? "1icon_2text" : (Device.Idiom == TargetIdiom.Phone ? "double_label" : "default"))
public ImageCellRenderer() : this(ThemeManager.GetImageCellRendererStyle())
{
ImagePart = "elm.swallow.icon";
ImagePart = this.GetImagePart();
}

protected ImageCellRenderer(string style) : base(style)
Expand All @@ -26,7 +24,7 @@ protected override EvasObject OnGetContent(Cell cell, string part)
int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight);
if (pixelSize <= 0)
{
pixelSize = Forms.ConvertToPixel(_defaultHeight);
pixelSize = this.GetDefaultHeightPixel();
}

var image = new Native.Image(Forms.NativeParent)
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Forms.Platform.Tizen/Cells/SwitchCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ protected SwitchCellRenderer(string style) : base(style)
{
}

public SwitchCellRenderer() : this(Device.Idiom == TargetIdiom.Watch ? "1text.1icon.1" : "default")
public SwitchCellRenderer() : this(ThemeManager.GetSwitchCellRendererStyle())
{
MainPart = "elm.text";
SwitchPart = Device.Idiom == TargetIdiom.Watch ? "elm.icon" : "elm.swallow.end";
MainPart = this.GetMainPart();
SwitchPart = this.GetSwitchPart();
}

protected string MainPart { get; set; }
Expand Down
21 changes: 6 additions & 15 deletions Xamarin.Forms.Platform.Tizen/Cells/TextCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class TextCellRenderer : CellRenderer
{
bool _groupMode = false;
// TextCell.Detail property is not supported on TV profile due to UX limitation.
public TextCellRenderer() : this(Device.Idiom == TargetIdiom.Phone || Device.Idiom == TargetIdiom.Watch ? "double_label" : "default") { }
public TextCellRenderer() : this(ThemeManager.GetTextCellRendererStyle()) { }

protected TextCellRenderer(string style) : base(style)
{
MainPart = "elm.text";
DetailPart = "elm.text.sub";
MainPart = this.GetMainPart();
DetailPart = this.GetDetailPart();
}

protected string MainPart { get; set; }
Expand All @@ -24,18 +24,9 @@ public override void SetGroupMode(bool enable)
return;

_groupMode = enable;
if (enable)
{
Class = null;
Style = "group_index";
DetailPart = "elm.text.end";
}
else
{
Class = null;
Style = Device.Idiom == TargetIdiom.Phone ? "double_label" : "default";
DetailPart = "elm.text.sub";
}
Class = null;
Style = ThemeManager.GetTextCellGroupModeStyle(enable);
DetailPart = this.GetDetailPart();
}

protected override Span OnGetText(Cell cell, string part)
Expand Down
4 changes: 2 additions & 2 deletions Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Xamarin.Forms.Platform.Tizen
public class ViewCellRenderer : CellRenderer
{
readonly Dictionary<EvasObject, ViewCell> _cacheCandidate = new Dictionary<EvasObject, ViewCell>();
public ViewCellRenderer() : base("full")
public ViewCellRenderer() : base(ThemeManager.GetViewCellRendererStyle())
{
MainContentPart = "elm.swallow.content";
MainContentPart = this.GetMainContentPart();
}

protected string MainContentPart { get; set; }
Expand Down
7 changes: 4 additions & 3 deletions Xamarin.Forms.Platform.Tizen/FormsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using DeviceOrientation = Xamarin.Forms.Internals.DeviceOrientation;
using ElmSharp.Wearable;
using Specific = Xamarin.Forms.PlatformConfiguration.TizenSpecific.Application;
using Xamarin.Forms.Platform.Tizen.Native;

namespace Xamarin.Forms.Platform.Tizen
{
Expand Down Expand Up @@ -181,7 +182,7 @@ void UpdateOverlayContent()
(renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
nativeView = renderer?.NativeView;
}
Forms.BaseLayout.SetPartContent("elm.swallow.overlay", nativeView);
Forms.BaseLayout.SetOverlayPart(nativeView);
}

void SetPage(Page page)
Expand Down Expand Up @@ -217,8 +218,8 @@ void InitializeWindow()
var conformant = new Conformant(MainWindow);
conformant.Show();

var layout = new ELayout(conformant);
layout.SetTheme("layout", "application", "default");
var layout = new ApplicationLayout(conformant);

layout.Show();

BaseLayout = layout;
Expand Down
28 changes: 6 additions & 22 deletions Xamarin.Forms.Platform.Tizen/Native/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public virtual ESize Measure(int availableWidth, int availableHeight)
if (Image != null)
MinimumWidth += Image.Geometry.Width;

var rawSize = TextHelper.GetRawTextBlockSize(this);
var rawSize = this.GetTextBlockNativeSize();
return new ESize(rawSize.Width + MinimumWidth , Math.Max(MinimumHeight, rawSize.Height));
}
}
Expand Down Expand Up @@ -230,25 +230,16 @@ void ApplyTextAndStyle()
/// <param name="textStyle">Style applied to the formattedText.</param>
void SetInternalTextAndStyle(string formattedText, string textStyle)
{
string emission = "elm,state,text,visible";

bool isVisible = true;
if (string.IsNullOrEmpty(formattedText))
{
formattedText = null;
textStyle = null;
emission = "elm,state,text,hidden";
isVisible = false;
}

base.Text = formattedText;

var textblock = EdjeObject["elm.text"];

if (textblock != null)
{
textblock.TextStyle = textStyle;
}

EdjeObject.EmitSignal(emission, "elm");
this.SetTextBlockStyle(textStyle);
this.SendTextVisibleSignal(isVisible);
}

/// <summary>
Expand All @@ -268,14 +259,7 @@ void ApplyImage(Image image)
/// </summary>
void SetInternalImage()
{
if (_image == null)
{
SetPartContent("icon", null);
}
else
{
SetPartContent("icon", _image);
}
this.SetIconPart(_image);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ protected override ViewHolder CreateViewHolder()
{
return new ViewHolder(this)
{
FocusedColor = ElmSharp.Color.Transparent,
SelectedColor = ElmSharp.Color.Transparent,
FocusedColor = ThemeConstants.CarouselView.ColorClass.DefaultFocusedColor,
SelectedColor = ThemeConstants.CarouselView.ColorClass.DefaultSelectedColor,
};
}
ESize ICollectionViewController.GetItemSize(int widthConstraint, int heightConstraint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public IndicatorView(EvasObject parent) : base(parent)
{
AutoHide = false;
IsHorizontal = true;
Style = "pagecontrol";
if (Device.Idiom == TargetIdiom.Watch)
Style = "circle";
this.SetStyledIndex();
}

public event EventHandler<SelectedPositionChangedEventArgs> SelectedPosition;
Expand Down Expand Up @@ -55,18 +53,7 @@ void ApplyStyle()
{
foreach (var item in _list)
{
if (_list.Count % 2 == 0)
{
int position = EvenMiddleItem - (_list.Count / 2) + _list.IndexOf(item);
string itemStyle = "item/even_" + position;
item.Style = itemStyle;
}
else
{
int position = OddMiddleItem - (_list.Count / 2) + _list.IndexOf(item);
string itemStyle = "item/odd_" + position;
item.Style = itemStyle;
}
item.SetIndexItemStyle(_list.Count, _list.IndexOf(item), EvenMiddleItem, OddMiddleItem);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public enum ViewHolderState

public class ViewHolder : Box
{
static readonly EColor s_defaultFocusEffectColor = EColor.FromRgba(244, 244, 244, 200);
static readonly EColor s_defaultSelectedColor = EColor.FromRgba(227, 242, 253, 200);

ERectangle _background;
Button _focusArea;
EvasObject _content;
Expand All @@ -32,8 +29,8 @@ public ViewHolder(EvasObject parent) : base(parent)
public EColor FocusedColor { get; set; }
public EColor SelectedColor { get; set; }

EColor EffectiveFocusedColor => FocusedColor == EColor.Default ? s_defaultFocusEffectColor : FocusedColor;
EColor EffectiveSelectedColor => SelectedColor == EColor.Default ? s_defaultSelectedColor : FocusedColor;
EColor EffectiveFocusedColor => FocusedColor == EColor.Default ? ThemeConstants.CollectionView.ColorClass.DefaultFocusedColor : FocusedColor;
EColor EffectiveSelectedColor => SelectedColor == EColor.Default ? ThemeConstants.CollectionView.ColorClass.DefaultSelectedColor : SelectedColor;

EColor FocusSelectedColor
{
Expand Down Expand Up @@ -107,7 +104,7 @@ protected void Initialize(EvasObject parent)
_focusArea = new Button(parent);
_focusArea.Color = EColor.Transparent;
_focusArea.BackgroundColor = EColor.Transparent;
_focusArea.SetPartColor("effect", EColor.Transparent);
_focusArea.SetEffectColor(EColor.Transparent);
_focusArea.Clicked += OnClicked;
_focusArea.Focused += OnFocused;
_focusArea.Unfocused += OnFocused;
Expand Down
17 changes: 7 additions & 10 deletions Xamarin.Forms.Platform.Tizen/Native/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ protected virtual void OnDismissed()
/// <param name="title">New dialog title.</param>
protected virtual void ApplyTitle(string title)
{
SetPartText("title,text", title);
this.SetTitleTextPart(title);
}

protected virtual void ApplyTitleColor(EColor color)
{
SetPartColor(Device.Idiom == TargetIdiom.TV ? "text_title" : "text_maintitle", color);
this.SetTitleColor(color);
}

/// <summary>
Expand All @@ -253,26 +253,23 @@ protected virtual void ApplyButton(ButtonPosition position, EButton button)
{
if (button != null)
{
button.Style = "popup";
button.SetPopupStyle();
}

string part;
switch (position)
{
case ButtonPosition.Positive:
part = "button3";
this.SetButton3Part(button, true);
break;

case ButtonPosition.Neutral:
part = "button2";
this.SetButton2Part(button, true);
break;

default:
part = "button1";
this.SetButton1Part(button, true);
break;
}

SetPartContent(part, button, true);
}

/// <summary>
Expand All @@ -281,7 +278,7 @@ protected virtual void ApplyButton(ButtonPosition position, EButton button)
/// <param name="content">New dialog content.</param>
protected virtual void ApplyContent(EvasObject content)
{
SetPartContent("default", content, true);
this.SetContentPart(content, true);
}

protected virtual void ApplyMessage(string message)
Expand Down
Loading

0 comments on commit 78b4b15

Please sign in to comment.