Modify SizeUtil for font size calculation for the TV product.
authorcskim <charles0.kim@samsung.com>
Tue, 11 Apr 2017 23:06:30 +0000 (08:06 +0900)
committercskim <charles0.kim@samsung.com>
Wed, 12 Apr 2017 11:44:26 +0000 (20:44 +0900)
Change-Id: Ic07bebe4eacc89b90d0eef822ab000687ed55ea8
Signed-off-by: cskim <charles0.kim@samsung.com>
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.cs
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.Tizen.csproj
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.cs
TVMediaHub/TVMediaHub.Tizen/Utils/DbgPort.cs [new file with mode: 0644]
TVMediaHub/TVMediaHub.Tizen/Utils/SizeUtils.cs
TVMediaHub/TVMediaHub.Tizen/Utils/SystemSettingsPort.cs [new file with mode: 0644]

index 605c121..8288094 100644 (file)
@@ -8,7 +8,10 @@ namespace TVMediaHub.Tizen
         protected override void OnCreate()
         {
             base.OnCreate();
-            var app = new App(MainWindow.ScreenSize.Width, MainWindow.ScreenSize.Height, ElmSharp.Elementary.GetScale());
+            var app = new App(MainWindow.ScreenSize.Width,
+                MainWindow.ScreenSize.Height,
+                MainWindow.ScreenDpi.X,
+                ElmSharp.Elementary.GetScale());
             LoadApplication(app);
         }
 
index 6524de5..cde5e39 100755 (executable)
     <Compile Include="TVMediaHub.cs" />
     <Compile Include="TVMediaHub.Tizen.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Utils\DbgPort.cs" />
     <Compile Include="Utils\NinePatch.xaml.cs">
       <DependentUpon>NinePatch.xaml</DependentUpon>
     </Compile>
     <Compile Include="Utils\NinePatchImageRenderer.cs" />
     <Compile Include="Utils\SizeUtils.cs" />
+    <Compile Include="Utils\SystemSettingsPort.cs" />
     <Compile Include="ViewModels\ImageTabViewModel.cs" />
     <Compile Include="ViewModels\MediaHubMainPageViewModel.cs" />
     <Compile Include="ViewModels\MusicTabViewModel.cs" />
index 9767d04..2b424d8 100755 (executable)
@@ -32,13 +32,21 @@ namespace TVMediaHub
         /// <see cref="MainPage"/>
         /// <param name="screenWidth">Screen Width</param>
         /// <param name="screenHeight">Screen Height</param>
+        /// <param name="dpi">Screen DPI</param>
         /// <param name="scaleRatio">Scale ratio</param>
-        public App(int screenWidth, int screenHeight, double scaleRatio)
+        public App(int screenWidth, int screenHeight, int dpi, double scaleRatio)
         {
             SizeUtils.ScreenWidth = screenWidth;
             SizeUtils.ScreenHeight = screenHeight;
+            SizeUtils.Dpi = dpi;
             SizeUtils.ScaleRatio = scaleRatio;
 
+            string modelName;
+            if (SystemSettingsPort.GetSystemModelName(out modelName))
+            {
+                SizeUtils.SetModelName(modelName);
+            }
+
             MainPage = new NavigationPage(new Tizen.Views.MediaHubMainPage());
         }
 
diff --git a/TVMediaHub/TVMediaHub.Tizen/Utils/DbgPort.cs b/TVMediaHub/TVMediaHub.Tizen/Utils/DbgPort.cs
new file mode 100644 (file)
index 0000000..19ed167
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using Tizen;
+using System.Runtime.CompilerServices;
+
+namespace TVMediaHub.Tizen.Utils
+{
+    /// <summary>
+    /// Platform dependent implementation for the Logging.
+    /// </summary>
+    public class DbgPort
+    {
+        /// <summary>
+        /// A Logging Tag
+        /// </summary>
+        public static string TAG = "mediahub";
+
+        /// <summary>
+        /// Displays a log message which developer want to check
+        /// </summary>
+        /// <param name="message"> A debugging message </param>
+        /// <param name="file"> A file name that debugging message is exist </param>
+        /// <param name="func"> A function name that debugging message is exist </param>
+        /// <param name="line"> A line number that debugging message is exist </param>
+        public static void D(string message, [CallerFilePath] System.String file = "", [CallerMemberName] System.String func = "", [CallerLineNumber] System.Int32 line = 0)
+        {
+            Log.Debug(TAG, message, file, func, line);
+
+        }
+
+        /// <summary>
+        /// Displays a error log message
+        /// </summary>
+        /// <param name="message"> A debugging message </param>
+        /// <param name="file"> A file name that debugging message is exist </param>
+        /// <param name="func"> A function name that debugging message is exist </param>
+        /// <param name="line"> A line number that debugging message is exist </param>
+        public static void E(string message, [CallerFilePath] System.String file = "", [CallerMemberName] System.String func = "", [CallerLineNumber] System.Int32 line = 0)
+        {
+            Log.Error(TAG, message, file, func, line);
+        }
+    }
+}
\ No newline at end of file
index f0ea361..946c8dd 100644 (file)
  */
 
 using System;
+using Tizen;
 
 namespace TVMediaHub.Tizen.Utils
 {
-
     /// <summary>
     /// A class provides Size metric related functions
     /// </summary>
@@ -68,11 +68,56 @@ namespace TVMediaHub.Tizen.Utils
         public static int ScreenWidth { set; get; }
 
         /// <summary>
+        /// Device DPI
+        /// </summary>
+        public static double Dpi { set; get; }
+
+        /// <summary>
         /// Font Scale ratio
         /// </summary>
         public static double ScaleRatio { set; get; }
 
         /// <summary>
+        /// Platform Model enumerations
+        /// </summary>
+        private enum PlatformModel
+        {
+            TV,
+            Emulator,
+            Other,
+        }
+
+        /// <summary>
+        /// Platform Model Name
+        /// </summary>
+        private static PlatformModel ModelName = PlatformModel.TV;
+
+        /// <summary>
+        /// Set model name of running device.
+        /// </summary>
+        /// <param name="modelName">a model name</param>
+        public static void SetModelName(string modelName)
+        {
+            if (modelName == null)
+            {
+                return;
+            }
+
+            DbgPort.D("ModelName is " + modelName);
+            switch (modelName.ToLower()[0])
+            {
+                case 'e':
+                    ModelName = PlatformModel.Emulator;
+                    break;
+
+                default:
+                case 'x':
+                    ModelName = PlatformModel.Other;
+                    break;
+            }
+        }
+
+        /// <summary>
         /// A method provides a converted height size.
         /// </summary>
         /// <param name="heightBaseSize">A height value in BaseScreen ratio</param>
@@ -99,7 +144,20 @@ namespace TVMediaHub.Tizen.Utils
         /// <returns>A date</returns>
         public static int GetFontSize(int fontBaseSize)
         {
-            return Convert.ToInt32(((double)((double)fontBaseSize / (double)BaseScreenHeight) * (double)(ScreenHeight)) * ScaleRatio);
+            switch (ModelName)
+            {
+                case PlatformModel.Emulator:
+                    DbgPort.D("Emulator, Font size = " + fontBaseSize + " => " + ((double)((double)fontBaseSize / (double)BaseScreenHeight) * (double)ScreenHeight) * ScaleRatio);
+                    return Convert.ToInt32(((double)((double)fontBaseSize / (double)BaseScreenHeight) * (double)ScreenHeight) * ScaleRatio);
+
+                default:
+                case PlatformModel.Other:
+                case PlatformModel.TV:
+                    // TODO : Remove this if the TV/Other device's dpi is correctly changed.
+                    double tempAdjustmentRatio = 0.3D;
+                    DbgPort.D("TV/Other, Font size = " + fontBaseSize + " => " + ((double)((double)fontBaseSize / (double)BaseScreenHeight) * (double)ScreenHeight) * ScaleRatio * tempAdjustmentRatio);
+                    return Convert.ToInt32(((double)((double)fontBaseSize / (double)BaseScreenHeight) * (double)ScreenHeight) * ScaleRatio * tempAdjustmentRatio);
+            }
         }
     }
 }
diff --git a/TVMediaHub/TVMediaHub.Tizen/Utils/SystemSettingsPort.cs b/TVMediaHub/TVMediaHub.Tizen/Utils/SystemSettingsPort.cs
new file mode 100644 (file)
index 0000000..6eb0508
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System.Runtime.InteropServices;
+
+
+namespace TVMediaHub.Tizen.Utils
+{
+    public class SystemSettingsPort
+    {
+        public static readonly int ErrorNone = 0;
+        public static readonly string KeyModelName = "http://tizen.org/system/model_name";
+
+        internal class SystemInfo
+        {
+            [DllImport("libcapi-system-info.so.0", EntryPoint = "system_info_get_platform_string", CallingConvention = CallingConvention.Cdecl)]
+            internal static extern int SystemInfoGetPlatformString(string key, out string value);
+        }
+
+
+        public static bool GetSystemModelName(out string modelName)
+        {
+            if (SystemInfo.SystemInfoGetPlatformString(KeyModelName, out modelName) != ErrorNone)
+            {
+                modelName = "";
+                return false;
+            }
+
+            return true;
+        }
+    }
+}