--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using ElmSharp;
+using Tizen.Applications;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ class AdaptedFormsApplication : FormsApplication
+ {
+ public ApplicationLifecycle Lifecycle { get; set; }
+
+ protected override void OnPause()
+ {
+ base.OnPause();
+ Lifecycle?.SendPause();
+ }
+ protected override void OnPreCreate()
+ {
+ if (MainWindow == null)
+ {
+ base.OnPreCreate();
+ }
+ Lifecycle?.SendPreCreate();
+ }
+ protected override void OnResume()
+ {
+ base.OnResume();
+ Lifecycle?.SendResume();
+ }
+ protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
+ {
+ base.OnAppControlReceived(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnCreate()
+ {
+ base.OnCreate();
+ Lifecycle?.SendCreate();
+ }
+ protected override void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
+ {
+ base.OnDeviceOrientationChanged(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnLocaleChanged(LocaleChangedEventArgs e)
+ {
+ base.OnLocaleChanged(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnLowBattery(LowBatteryEventArgs e)
+ {
+ base.OnLowBattery(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnLowMemory(LowMemoryEventArgs e)
+ {
+ base.OnLowMemory(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
+ {
+ base.OnRegionFormatChanged(e);
+ Lifecycle?.Send(e);
+ }
+ protected override void OnTerminate()
+ {
+ base.OnTerminate();
+ Lifecycle?.SendTerminate();
+ }
+ }
+}
--- /dev/null
+using Tizen.Applications;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public abstract class ApplicationLifecycle
+ {
+ public FormsApplication FormsApplication { get; internal set; }
+
+ internal void SendPause() => OnPause();
+ internal void SendPreCreate() => OnPreCreate();
+ internal void SendResume() => OnResume();
+ internal void SendCreate() => OnCreate();
+ internal void SendTerminate() => OnTerminate();
+ internal void Send(AppControlReceivedEventArgs e) => OnAppControlReceived(e);
+ internal void Send(DeviceOrientationEventArgs e) => OnDeviceOrientationChanged(e);
+ internal void Send(LocaleChangedEventArgs e) => OnLocaleChanged(e);
+ internal void Send(LowBatteryEventArgs e) => OnLowBattery(e);
+ internal void Send(LowMemoryEventArgs e) => OnLowMemory(e);
+ internal void Send(RegionFormatChangedEventArgs e) => OnRegionFormatChanged(e);
+
+ protected virtual void OnPause()
+ {
+ }
+ protected virtual void OnPreCreate()
+ {
+ }
+ protected virtual void OnResume()
+ {
+ }
+ protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
+ {
+ }
+ protected virtual void OnCreate()
+ {
+ }
+ protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
+ {
+ }
+ protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
+ {
+ }
+ protected virtual void OnLowBattery(LowBatteryEventArgs e)
+ {
+ }
+ protected virtual void OnLowMemory(LowMemoryEventArgs e)
+ {
+ }
+ protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
+ {
+ }
+ protected virtual void OnTerminate()
+ {
+ }
+ }
+}
}
}
- public TizenDeviceInfo()
+ public TizenDeviceInfo() : this(getScreenWidth(), getScreenHeight())
{
- int width = 0;
- int height = 0;
+ }
- TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out width);
- TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out height);
+ static int getScreenWidth()
+ {
+ if (TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out int width))
+ {
+ return width;
+ }
+ else
+ {
+ throw new InvalidOperationException("Can not get screen.Width");
+ }
+ }
+ static int getScreenHeight()
+ {
+ if (TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out int height))
+ {
+ return height;
+ }
+ else
+ {
+ throw new InvalidOperationException("Can not get screen.Height");
+ }
+ }
+ TizenDeviceInfo(int width, int height)
+ {
+ pixelScreenSize = new Size(width, height);
scalingFactor = 1.0; // scaling is disabled, we're using pixels as Xamarin's geometry units
if (s_useDeviceIndependentPixel)
scalingFactor = s_dpi.Value / 160.0;
}
- pixelScreenSize = new Size(width, height);
scaledScreenSize = new Size(width / scalingFactor, height / scalingFactor);
profile = s_profile.Value;
}
+
+ public TizenDeviceInfo RefreshByDIP()
+ {
+ return new TizenDeviceInfo((int)pixelScreenSize.Width, (int)pixelScreenSize.Height);
+ }
}
static bool s_useDeviceIndependentPixel = false;
}
}
+ public static void Init(ApplicationLifecycle lifecycle, bool useDeviceIndependentPixel, Dictionary<Type, Func<IRegisterable>> customHandlers = null)
+ {
+ if (!IsInitialized)
+ {
+ Init();
+ }
+
+ s_useDeviceIndependentPixel = useDeviceIndependentPixel;
+
+ if (Device.info != null)
+ {
+ var info = ((TizenDeviceInfo)Device.info).RefreshByDIP();
+ ((TizenDeviceInfo)Device.info).Dispose();
+ Device.info = info;
+ }
+
+ var appAdapter = Context as AdaptedFormsApplication;
+ appAdapter.Lifecycle = lifecycle;
+ lifecycle.FormsApplication = appAdapter;
+
+ if (customHandlers != null)
+ StaticRegistrar.RegisterHandlers(customHandlers);
+ }
+
+ static void Init()
+ {
+ TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(typeof(View).Assembly);
+ var appAdapter = new AdaptedFormsApplication();
+ Init(appAdapter, false);
+ }
+
public static void Init(CoreApplication application)
{
Init(application, false);
var window = new PreloadedWindow();
TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out int width);
TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out int height);
+
+ Forms.Init();
+
+ var types = new[]
+ {
+ typeof(Application),
+ typeof(ContentPage),
+ typeof(NavigationPage),
+ typeof(Shell),
+ typeof(ContentPresenter),
+ typeof(ContentView),
+ typeof(ScrollView),
+ typeof(Frame),
+ typeof(TemplatedView),
+ typeof(StackLayout),
+ typeof(AbsoluteLayout),
+ typeof(RelativeLayout),
+ typeof(Grid),
+ typeof(FlexLayout),
+ typeof(Image),
+ typeof(Label),
+ typeof(BoxView),
+ typeof(Button),
+ typeof(ImageButton),
+ typeof(CheckBox),
+ typeof(Slider),
+ typeof(Stepper),
+ typeof(Switch),
+ typeof(DatePicker),
+ typeof(TimePicker),
+ typeof(Entry),
+ typeof(Editor),
+ typeof(ActivityIndicator),
+ typeof(ProgressBar),
+ typeof(CarouselView),
+ typeof(CollectionView),
+ typeof(ListView),
+ typeof(Picker),
+ typeof(TableView),
+ typeof(TextCell),
+ typeof(ImageCell),
+ typeof(SwitchCell),
+ typeof(EntryCell)
+ };
+
+ foreach (var type in types)
+ {
+ System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);
+ }
}
}