2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 using System.Reflection;
24 namespace Tizen.NUI.EXaml
26 /// Internal used, will never be opened.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public static class EXamlExtensions
30 /// Internal used, will never be opened.
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public static TXaml LoadFromEXamlPath<TXaml>(this TXaml view, string path)
34 MainAssembly = view.GetType().Assembly;
35 //This EXaml file will be converted by Tizen.NUI.XamlBuild from the .xaml
36 string xamlScript = GetXamlFromPath(path);
37 LoadEXaml.Load(view, xamlScript);
41 /// Internal used, will never be opened.
42 [EditorBrowsable(EditorBrowsableState.Never)]
43 public static T LoadFromEXamlPath<T>(this T view, Type callingType)
45 if (null == callingType)
50 MainAssembly = view.GetType().Assembly;
52 string resourceName = callingType.Name + ".examl";
53 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
55 Tizen.Log.Fatal("NUI", "the resource path: " + resource);
56 int windowWidth = NUIApplication.GetDefaultWindow().Size.Width;
57 int windowHeight = NUIApplication.GetDefaultWindow().Size.Height;
59 string likelyResourcePath = resource + "layout/" + windowWidth.ToString() + "x" + windowHeight.ToString() + "/" + resourceName;
60 Tizen.Log.Fatal("NUI", "the resource path: " + likelyResourcePath);
62 if (!File.Exists(likelyResourcePath))
64 likelyResourcePath = resource + "layout/" + resourceName;
67 //Find the xaml file in the layout folder
68 if (File.Exists(likelyResourcePath))
70 StreamReader reader = new StreamReader(likelyResourcePath);
71 var xaml = reader.ReadToEnd();
75 LoadEXaml.Load(view, xaml);
81 /// Used for TCT and TC coverage, will never be opened.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public static T LoadFromEXaml<T>(this T view, string eXamlStr)
90 MainAssembly = view.GetType().Assembly;
92 LoadEXaml.Load(view, eXamlStr);
97 /// Internal used, will never be opened.
98 [EditorBrowsable(EditorBrowsableState.Never)]
99 public static Assembly MainAssembly
105 private static string GetXamlFromPath(string path)
109 if (File.Exists(path))
111 StreamReader reader = new StreamReader(path);
112 xaml = reader.ReadToEnd();