maui-linux/Xamarin.Forms.Platform.Tizen/TizenPlatformServices.cs

233 строки
5.5 KiB
C#
Исходник Обычный вид История

[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
using ElmSharp;
2017-12-04 17:30:43 +03:00
using System;
[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
using System.Collections.Generic;
2017-12-04 17:30:43 +03:00
using System.IO;
[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
using System.Linq;
using System.Net.Http;
2017-12-04 17:30:43 +03:00
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
using TAppControl = Tizen.Applications.AppControl;
2017-12-04 17:30:43 +03:00
namespace Xamarin.Forms.Platform.Tizen
{
internal class TizenPlatformServices : IPlatformServices
{
static MD5 checksum = MD5.Create();
static SynchronizationContext s_context;
public TizenPlatformServices()
{
s_context = SynchronizationContext.Current;
}
public class TizenTicker : Ticker
{
readonly Timer _timer;
public TizenTicker()
{
_timer = new Timer((object o) => HandleElapsed(o), this, Timeout.Infinite, Timeout.Infinite);
}
protected override void EnableTimer()
{
_timer.Change(16, 16);
}
protected override void DisableTimer()
{
_timer.Change(-1, -1);
}
void HandleElapsed(object state)
{
s_context.Post((o) => SendSignals(-1), null);
}
}
#region IPlatformServices implementation
public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
{
int pt;
// Actual font size depends on the target idiom.
2017-12-04 17:30:43 +03:00
switch (size)
{
case NamedSize.Micro:
pt = Device.Idiom == TargetIdiom.TV || Device.Idiom == TargetIdiom.Watch ? 24 : 19;
break;
2017-12-04 17:30:43 +03:00
case NamedSize.Small:
pt = Device.Idiom == TargetIdiom.TV ? 26 : (Device.Idiom == TargetIdiom.Watch ? 30 : 22);
break;
2017-12-04 17:30:43 +03:00
case NamedSize.Default:
case NamedSize.Medium:
pt = Device.Idiom == TargetIdiom.TV ? 28 : (Device.Idiom == TargetIdiom.Watch ? 32 : 25);
break;
2017-12-04 17:30:43 +03:00
case NamedSize.Large:
pt = Device.Idiom == TargetIdiom.TV ? 84 : (Device.Idiom == TargetIdiom.Watch ? 36 : 31);
break;
2017-12-04 17:30:43 +03:00
default:
2018-10-15 18:42:54 +03:00
throw new ArgumentOutOfRangeException(nameof(size));
2017-12-04 17:30:43 +03:00
}
return Forms.ConvertToDPFont(pt);
2017-12-04 17:30:43 +03:00
}
public void OpenUriAction(Uri uri)
{
[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
if (uri == null || uri.AbsoluteUri == null)
{
throw new ArgumentNullException(nameof(uri));
}
TAppControl tAppControl = new TAppControl() { Operation = "%", Uri = uri.AbsoluteUri };
var matchedApplications = TAppControl.GetMatchedApplicationIds(tAppControl);
2018-10-15 18:42:54 +03:00
if (matchedApplications.Any())
[Tizen] Slightly enhance tizen backend (#1800) * Add IVisualElementRenderer.GetNativeContentGeometry - GetNativeContentGeometry can be used to compute position of content. - It can fix invalid layout by root content that is not placed in (0,0) * Update focus policy explitly on MasterDetailPage - IsPresentedChangedEventArgs has been added. * Fixed renderer creation order - Fixed an issue where the current page location of CarouselPage changes when changing device orientation * Add static Forms.MainWindow Property * Fix ScrollView.ScrollToAsync doens't work * Fix MasterDetail crash issue - When MasterBehaivor was changed, does not working anymore Because wrong property update - Fix Layout issue when MasterBehavior was changed LayoutCallback was not called because geometry was not changed * Allow to user can change MasterPage ratio - To change the ration of MasterPage, use UpdateMasterPageRatio() in derrived renderer of MasterDetailPageRenderer. * Fix ViewInitialized event processing * Dispose modal renderer correctly * Fixed issue the button's of Date/TimePicker can not be selected. * Fix black scrren issue when application initialize * Refactoring DeviceOrientation for tizen backend - Use Device.Info.CurrentOrientation in MasterDetailPage - Orientation was decided by device screen ratio - PortraitXXX/LandscapeXXX was not used because it only defeind in iOS devices * Fix Date&TimePicker to get focused on TV - This commit includes the behavior change of Native.Editfield. - Text Input is activated when user select the field when it has focus on. * Fixed the Appearing / Disappearing Event Handling of Pages - Fixed a problem where Focus is moved to a page other than the current Page of TabbedPage & CarouselPage - Fixed an issue where Appearing & Disappearing Event of Master / Detail of MasterDetailPage was not called * Fix MasterDetailPage crash issue * Change API visibility of Forms's utility methods into public * Remove VisualElementRenderer.DoLayout to avoid any confusion * Refactor CellRenderer's implementation * Fix Completed event routine for Entry & Editor * Implement TizenPlatformServices.OpenUriAction * Refactor Platform, Forms and FormsApplication in Tizen backend * Refactor platform more flexible * Add LightweightPlatform
2018-02-07 13:33:14 +03:00
{
TAppControl.SendLaunchRequest(tAppControl);
return;
}
throw new PlatformNotSupportedException();
2017-12-04 17:30:43 +03:00
}
public void BeginInvokeOnMainThread(Action action)
{
s_context.Post((o) => action(), null);
}
public Ticker CreateTicker()
{
return new TizenTicker();
}
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
Timer timer = null;
bool invoking = false;
TimerCallback onTimeout = o =>
{
if (!invoking)
{
invoking = true;
BeginInvokeOnMainThread(() =>
{
if (!callback())
{
timer.Dispose();
}
invoking = false;
}
);
}
};
timer = new Timer(onTimeout, null, Timeout.Infinite, Timeout.Infinite);
// set interval separarately to prevent calling onTimeout before `timer' is assigned
timer.Change(interval, interval);
}
public async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(uri, cancellationToken))
return await response.Content.ReadAsStreamAsync();
}
public Assembly[] GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
public IIsolatedStorageFile GetUserStoreForApplication()
{
return new TizenIsolatedStorageFile();
}
static readonly char[] HexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public string GetMD5Hash(string input)
{
byte[] bin = checksum.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input));
char[] hex = new char[32];
for (var i = 0; i < 16; ++i)
{
hex[2 * i] = HexDigits[bin[i] >> 4];
hex[2 * i + 1] = HexDigits[bin[i] & 0xf];
}
return new string(hex);
}
public void QuitApplication()
{
Forms.Context.Exit();
}
public bool IsInvokeRequired
{
get
{
return !EcoreMainloop.IsMainThread;
}
}
public string RuntimePlatform => Device.Tizen;
#endregion
// In .NETCore, AppDomain is not supported. The list of the assemblies should be generated manually.
internal class AppDomain
{
public static AppDomain CurrentDomain { get; private set; }
2018-10-15 18:42:54 +03:00
readonly List<Assembly> _assemblies;
2017-12-04 17:30:43 +03:00
static AppDomain()
{
CurrentDomain = new AppDomain();
}
AppDomain()
{
_assemblies = new List<Assembly>();
// Add this renderer assembly to the list
_assemblies.Add(GetType().GetTypeInfo().Assembly);
}
internal void RegisterAssemblyRecursively(Assembly asm)
{
if (_assemblies.Contains(asm))
return;
_assemblies.Add(asm);
foreach (var refName in asm.GetReferencedAssemblies())
{
if (!refName.Name.StartsWith("System.") && !refName.Name.StartsWith("Microsoft.") && !refName.Name.StartsWith("mscorlib"))
{
try
{
Assembly refAsm = Assembly.Load(refName);
RegisterAssemblyRecursively(refAsm);
}
catch
{
Log.Warn("Reference Assembly can not be loaded. {0}", refName.FullName);
}
}
}
}
public Assembly[] GetAssemblies()
{
return _assemblies.ToArray();
}
}
public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
return Platform.GetNativeSize(view, widthConstraint, heightConstraint);
}
2017-12-04 17:30:43 +03:00
}
}