From c7bfb60270d19baf7ac8df85fe70a953debdc502 Mon Sep 17 00:00:00 2001 From: Myungki Lee Date: Wed, 6 Sep 2017 10:41:34 +0900 Subject: [PATCH] Initial update for shortcut Change-Id: I74dff0765b3ee6b334dfcb4ce58ba31b1bb0baca Signed-off-by: Myungki Lee --- pkg/Tizen.NET.Private.sln | 14 + .../Tizen.Applications.Shortcut.csproj | 12 + .../Tizen.Applications.Shortcut.sln | 21 ++ .../HomeShortcutInfo.cs | 29 +++ .../ShortcutEnumerations.cs | 110 ++++++++ .../ShortcutErrorFactory.cs | 41 +++ .../Tizen.Applications.Shortcut/ShortcutInfo.cs | 39 +++ .../Tizen.Applications.Shortcut/ShortcutManager.cs | 216 ++++++++++++++++ .../WidgetShortcutInfo.cs | 39 +++ .../HomeShortcutAddedInfo.cs | 34 +++ .../ShortcutAddedInfo.cs | 39 +++ .../ShortcutDeletedInfo.cs | 34 +++ .../ShortcutEventEnumerations.cs | 84 ++++++ .../ShortcutEventManager.cs | 281 +++++++++++++++++++++ .../ShortcutTemplate.cs | 49 ++++ .../WidgetShortcutAddedInfo.cs | 39 +++ .../interop/Interop.Libraries.cs | 23 ++ .../interop/Interop.Shortcut.cs | 124 +++++++++ 18 files changed, 1228 insertions(+) create mode 100644 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.csproj create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.sln create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/HomeShortcutInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutEnumerations.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutErrorFactory.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/WidgetShortcutInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/HomeShortcutAddedInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutAddedInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutDeletedInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventEnumerations.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutTemplate.cs create mode 100755 src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/WidgetShortcutAddedInfo.cs create mode 100755 src/Tizen.Applications.Shortcut/interop/Interop.Libraries.cs create mode 100755 src/Tizen.Applications.Shortcut/interop/Interop.Shortcut.cs diff --git a/pkg/Tizen.NET.Private.sln b/pkg/Tizen.NET.Private.sln index 8a6f048..55bf33f 100644 --- a/pkg/Tizen.NET.Private.sln +++ b/pkg/Tizen.NET.Private.sln @@ -169,6 +169,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.WebView", "..\src\Tiz EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.CallManager", "..\src\Tizen.CallManager\Tizen.CallManager.csproj", "{05DD16B8-2027-4728-AEB6-6296E7457533}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Applications.Shortcut", "..\src\Tizen.Applications.Shortcut\Tizen.Applications.Shortcut.csproj", "{4F6ECAC1-C311-42E2-A700-40347DD9830E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1178,5 +1180,17 @@ Global {05DD16B8-2027-4728-AEB6-6296E7457533}.Release|x64.Build.0 = Release|x64 {05DD16B8-2027-4728-AEB6-6296E7457533}.Release|x86.ActiveCfg = Release|x86 {05DD16B8-2027-4728-AEB6-6296E7457533}.Release|x86.Build.0 = Release|x86 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|x64.ActiveCfg = Debug|x64 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|x64.Build.0 = Debug|x64 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|x86.ActiveCfg = Debug|x86 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Debug|x86.Build.0 = Debug|x86 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|Any CPU.Build.0 = Release|Any CPU + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|x64.ActiveCfg = Release|x64 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|x64.Build.0 = Release|x64 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|x86.ActiveCfg = Release|x86 + {4F6ECAC1-C311-42E2-A700-40347DD9830E}.Release|x86.Build.0 = Release|x86 EndGlobalSection EndGlobal diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.csproj b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.csproj new file mode 100644 index 0000000..fe6ff34 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.csproj @@ -0,0 +1,12 @@ + + + + netstandard1.6 + + + + + + + + diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.sln b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.sln new file mode 100755 index 0000000..6899c5e --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.6 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Shortcut", "Tizen.Applications.Shortcut.csproj", "{002C0868-E774-4ACA-B033-83B91C3B2C57}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {002C0868-E774-4ACA-B033-83B91C3B2C57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {002C0868-E774-4ACA-B033-83B91C3B2C57}.Debug|Any CPU.Build.0 = Debug|Any CPU + {002C0868-E774-4ACA-B033-83B91C3B2C57}.Release|Any CPU.ActiveCfg = Release|Any CPU + {002C0868-E774-4ACA-B033-83B91C3B2C57}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/HomeShortcutInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/HomeShortcutInfo.cs new file mode 100755 index 0000000..2cbc7c2 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/HomeShortcutInfo.cs @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class that contains shortcut information. + /// + public class HomeShortcutInfo : ShortcutInfo + { + /// + /// Gets or sets the specific information for delivering to the viewer for creating a shortcut. + /// + public string Uri { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutEnumerations.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutEnumerations.cs new file mode 100755 index 0000000..c9c52cb --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutEnumerations.cs @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// Enumeration for sizes of shortcut widget. + /// + public enum ShortcutWidgetSize + { + /// + /// Type mask for the normal mode widget , don't use this value for specific size. + /// + WidgetDefault = 0x10000000, + + /// + /// 1by1 + /// + Widget1by1 = 0x10010000, + + /// + /// 2by1 + /// + Widget2by1 = 0x10020000, + + /// + /// 2by2 + /// + Widget2by2 = 0x10040000, + + /// + /// 4by1 + /// + Widget4by1 = 0x10080000, + + /// + /// 4by2 + /// + Widget4by2 = 0x10100000, + + /// + /// 4by3 + /// + Widget4by3 = 0x10200000, + + /// + /// 4by4 + /// + Widget4by4 = 0x10400000, + + /// + /// 4by5 + /// + Widget4by5 = 0x11000000, + + /// + /// 4by6 + /// + Widget4by6 = 0x12000000, + + /// + /// Type mask for the easy mode widget, don't use this value for specific size. + /// + EasyDefault = 0x30000000, + + /// + /// Easy mode 1by1 + /// + Easy1by1 = 0x30010000, + + /// + /// Easy mode 3by2 + /// + Easy3by1 = 0x30020000, + + /// + /// Easy mode 3by3 + /// + Easy3by3 = 0x30040000, + } + + /// + /// Enumeration for shortcut types. + /// + internal enum ShortcutType + { + /// + /// Launch the application itself. + /// + LaunchByApp = 0x00000000, + + /// + /// Launch the application with the given data(URI). + /// + LaunchByUri = 0x00000001, + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutErrorFactory.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutErrorFactory.cs new file mode 100755 index 0000000..4ed4850 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutErrorFactory.cs @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + using System; + + internal static class ShortcutErrorFactory + { + private const string LogTag = "Tizen.Applications.Shortcut"; + + internal static Exception GetException(Interop.Shortcut.ErrorCode err, string msg) + { + switch (err) + { + case Interop.Shortcut.ErrorCode.InvalidParameter: + return new ArgumentException(err + " error occurred."); + case Interop.Shortcut.ErrorCode.PermissionDenied: + return new UnauthorizedAccessException(err + " Permission denied (http://tizen.org/privilege/shortcut)"); + case Interop.Shortcut.ErrorCode.NotSupported: + return new NotSupportedException(err + " Not Supported (http://tizen.org/feature/shortcut)"); + default: + Log.Error(LogTag, msg); + return new InvalidOperationException(err + " error occurred."); + } + } + } +} diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutInfo.cs new file mode 100755 index 0000000..63fb8a6 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutInfo.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class to get information of the Shortcut. + /// + public class ShortcutInfo + { + /// + /// Gets or sets the name of the created shortcut icon. + /// + public string ShortcutName { get; set; } = string.Empty; + + /// + /// Gets or sets the absolute path of an icon file for this shortcut. + /// + public string IconPath { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether to allow or not to allow duplication. + /// + public bool IsAllowDuplicate { get; set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs new file mode 100755 index 0000000..22b3692 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/ShortcutManager.cs @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + using System; + using System.Threading.Tasks; + + /// + /// This class provides the some functions to add, delete shortcut. + /// + public static class ShortcutManager + { + private const string LogTag = "Tizen.Applications.Shortcut"; + + private static Interop.Shortcut.ResultCallback shortcutAddResult = null; + + private static Interop.Shortcut.ResultCallback widgetAddResult = null; + + private static Interop.Shortcut.ResultCallback shortcutDeleteResult = null; + + /// + /// Adds a shortcut on home-screen. + /// + /// 3 + /// Object that contain shortcut info. + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void Add(HomeShortcutInfo shortcut) + { + Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None; + + try + { + int type; + + if (shortcut.Uri == null || shortcut.Uri == String.Empty) + { + type = 0; + } + else + { + type = 1; + } + + if (shortcutAddResult == null) + { + shortcutAddResult = new Interop.Shortcut.ResultCallback(ShortcutAddResultCallback); + } + + err = Interop.Shortcut.AddToHome(shortcut.ShortcutName, type, shortcut.Uri, shortcut.IconPath, Convert.ToInt32(shortcut.IsAllowDuplicate), shortcutAddResult, IntPtr.Zero); + if (err != Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException(err, "unable to add shortcut"); + } + } + catch (Exception e) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message); + } + } + + /// + /// Adds a shortcut on home-screen. + /// + /// 3 + /// Object that contain shortcut info. + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void Add(WidgetShortcutInfo shortcut) + { + Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None; + + if (shortcut.Period < 0.0) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter"); + } + + try + { + if (widgetAddResult == null) + { + widgetAddResult = new Interop.Shortcut.ResultCallback(WidgetAddResultCallback); + } + + err = Interop.Shortcut.AddToWidget(shortcut.ShortcutName, shortcut.WidgetSize, shortcut.WidgetId, shortcut.IconPath, shortcut.Period, Convert.ToInt32(shortcut.IsAllowDuplicate), null, IntPtr.Zero); + if (err != Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException(err, "unable to add shortcut"); + } + } + catch (Exception e) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message); + } + } + + /// + /// Removes a shortcut from home by ShortcutName. + /// + /// 3 + /// Shortcut name string. + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void Delete(string shortcutName) + { + Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None; + + if (shortcutName == null) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter"); + } + + try + { + if (shortcutDeleteResult == null) + { + shortcutDeleteResult = new Interop.Shortcut.ResultCallback(DeleteResultCallback); + } + + err = Interop.Shortcut.Delete(shortcutName, shortcutDeleteResult, IntPtr.Zero); + if (err != Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException(err, "unable to delete shortcut"); + } + } + catch (Exception e) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message); + } + } + + /// + /// Removes a shortcut from home by ShortcutInfo. + /// + /// 3 + /// Object that contain shortcut info. + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void Delete(ShortcutInfo shortcut) + { + if (shortcut == null) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter"); + } + + try + { + Delete(shortcut.ShortcutName); + } + catch (Exception e) + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message); + } + } + + private static int ShortcutAddResultCallback(int ret, IntPtr data) + { + if (ret != (int)Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to add shortcut"); + } + + return 0; + } + + private static int WidgetAddResultCallback(int ret, IntPtr data) + { + if (ret != (int)Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to add widget"); + } + + return 0; + } + + private static int DeleteResultCallback(int ret, IntPtr data) + { + if (ret != (int)Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to delete shortcut"); + } + + return 0; + } + } +} diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/WidgetShortcutInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/WidgetShortcutInfo.cs new file mode 100755 index 0000000..4676c7c --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.Shortcut/WidgetShortcutInfo.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class that contains information about the widget. + /// + public class WidgetShortcutInfo : ShortcutInfo + { + /// + /// Gets or sets the Widget ID. + /// + public string WidgetId { get; set; } = string.Empty; + + /// + /// Gets or sets the size of widget. + /// + public ShortcutWidgetSize WidgetSize { get; set; } + + /// + /// Gets or sets the Update period in seconds. + /// + public double Period { get; set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/HomeShortcutAddedInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/HomeShortcutAddedInfo.cs new file mode 100755 index 0000000..d421fd3 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/HomeShortcutAddedInfo.cs @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class that contains shortcut information. + /// + public class HomeShortcutAddedInfo : ShortcutAddedInfo + { + /// + /// Gets the name of application. + /// + public string AppId { get; internal set; } = string.Empty; + + /// + /// Gets the specific information for creating a new shortcut. + /// + public string Uri { get; internal set; } = string.Empty; + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutAddedInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutAddedInfo.cs new file mode 100755 index 0000000..9a0756a --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutAddedInfo.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class for getting information of the Shortcut. + /// + public class ShortcutAddedInfo + { + /// + /// Gets the name of the created shortcut icon. + /// + public string ShortcutName { get; internal set; } = string.Empty; + + /// + /// Gets the absolute path of an icon file for this shortcut. + /// + public string IconPath { get; internal set; } = string.Empty; + + /// + /// Gets a value indicating whether to allow or not to allow duplication. + /// + public bool IsAllowDuplicate { get; internal set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutDeletedInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutDeletedInfo.cs new file mode 100755 index 0000000..6164dcb --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutDeletedInfo.cs @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class for getting information of the Shortcut. + /// + public class ShortcutDeletedInfo + { + /// + /// Gets the name of package. + /// + public string AppId { get; internal set; } = string.Empty; + + /// + /// Gets the name of the created shortcut icon. + /// + public string ShortcutName { get; internal set; } = string.Empty; + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventEnumerations.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventEnumerations.cs new file mode 100755 index 0000000..4a66f55 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventEnumerations.cs @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// Enumeration for values of shortcut response types. + /// + public enum ShortcutError + { + /// + /// Successful. + /// + None = Tizen.Internals.Errors.ErrorCode.None, + + /// + /// Invalid function parameter. + /// + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + + /// + /// Out of memory. + /// + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + + /// + /// Permission denied. + /// + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + + /// + /// I/O Error. + /// + IoError = Tizen.Internals.Errors.ErrorCode.IoError, + + /// + /// Not supported. + /// + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, + + /// + /// Device or resource busy. + /// + ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy, + + /// + /// There is no space to add a new shortcut. + /// + NoSpace = -0x01160000 | 0x01, + + /// + /// Shortcut is already added. + /// + Exist = -0x01160000 | 0x02, + + /// + /// Unrecoverable error. + /// + Fault = -0x01160000 | 0x04, + + /// + /// Not exist shortcut. + /// + NotExist = -0x01160000 | 0x08, + + /// + /// Connection not established or communication problem. + /// + COMM = -0x01160000 | 0x40 + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs new file mode 100755 index 0000000..08b818a --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutEventManager.cs @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + using System; + using System.Collections.Generic; + + /// + /// The callback function that is invoked when add request occurred + /// + /// Object that contain shortcut info to add. + /// The result of handling a shortcut add request + public delegate ShortcutError ShortcutAdded(ShortcutAddedInfo args); + + /// + /// The callback function that is invoked when delete request occurred + /// + /// Object that contain shortcut info to delete. + /// The result of handling a shortcut delete request + public delegate ShortcutError ShortcutDeleted(ShortcutDeletedInfo args); + + /// + /// This class provides a way to register callback function for shortcut add, delete events. + /// + public static class ShortcutEventManager + { + private static Interop.Shortcut.AddCallback shortcutAddCallback; + + private static Interop.Shortcut.DeleteCallback shortcutDeleteCallback; + + private static IList shortcutTemplates = new List(); + + private static ShortcutAdded shortcutAdded = null; + + private static ShortcutDeleted shortcutDeleted = null; + + /// + /// Registers a callback function to listen requests from applications. + /// + /// 3 + /// The callback function pointer that is invoked when Add() is requested + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// + /// Previous registered delegate function should be unregister. + /// + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void RegisterEventHandler(ShortcutAdded addedEvent) + { + shortcutAdded = addedEvent; + + if (shortcutAddCallback == null) + { + shortcutAddCallback = new Interop.Shortcut.AddCallback(AddCallback); + + Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutAddCallback(shortcutAddCallback, IntPtr.Zero); + if (err != Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException(err, "unable to register callback"); + } + } + } + + /// + /// Registers a callback function to listen requests from applications. + /// + /// 3 + /// The callback function pointer that is invoked when Delete() is requested + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// + /// Previous registered delegate function should be unregister. + /// + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void RegisterEventHandler(ShortcutDeleted deletedEvent) + { + shortcutDeleted = deletedEvent; + + if (shortcutDeleteCallback == null) + { + shortcutDeleteCallback = new Interop.Shortcut.DeleteCallback(DeleteCallback); + + Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutDeleteCallback(shortcutDeleteCallback, IntPtr.Zero); + if (err != Interop.Shortcut.ErrorCode.None) + { + throw ShortcutErrorFactory.GetException(err, "unable to register callback"); + } + } + } + + /// + /// Unregisters a callback for the shortcut request. + /// + /// 3 + /// The callback function pointer that used for RegisterCallback + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void UnregisterEventHandler(ShortcutAdded addedEvent) + { + if (shortcutAdded.Equals(addedEvent)) + { + shortcutAdded = null; + + if (shortcutAddCallback != null) + { + Interop.Shortcut.UnsetShortcutAddCallback(); + shortcutAddCallback = null; + } + } + else + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null); + } + } + + /// + /// Unregisters a callback for the shortcut request. + /// + /// 3 + /// The callback function pointer that used for RegisterCallback + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static void UnregisterEventHandler(ShortcutDeleted deletedEvent) + { + if (shortcutDeleted.Equals(deletedEvent)) + { + shortcutDeleted = null; + + if (shortcutDeleteCallback != null) + { + Interop.Shortcut.UnsetShortcutDeleteCallback(); + shortcutDeleteCallback = null; + } + } + else + { + throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null); + } + } + + /// + /// Gets the preset list of shortcut template from the installed package. + /// + /// 3 + /// Application ID. + /// The List of ShortcutTemplate. + /// http://tizen.org/feature/shortcut + /// http://tizen.org/privilege/shortcut + /// Thrown when argument is invalid. + /// Thrown in case of permission denied. + /// Thrown in case of any internal error. + /// Thrown when Shortcut is not supported. + public static IEnumerable GetTemplateList(string appId) + { + shortcutTemplates.Clear(); + + Interop.Shortcut.ListCallback callback = (appName, iconPath, shortcutName, extrakey, extraData, user_data) => + { + ShortcutTemplate template = new ShortcutTemplate + { + AppId = appName, + ShortcutName = shortcutName, + IconPath = iconPath, + ExtraKey = extrakey, + ExtraData = extraData, + }; + + shortcutTemplates.Add(template); + + return 0; + }; + + Interop.Shortcut.GetList(appId, callback, IntPtr.Zero); + + return shortcutTemplates; + } + + private static int AddCallback(string appId, string shortcutName, int type, string contentInfo, string iconPath, int processId, double period, bool isAllowDuplicate, IntPtr data) + { + ShortcutError err; + + if (type == (int)ShortcutType.LaunchByApp || type == (int)ShortcutType.LaunchByUri) + { + HomeShortcutAddedInfo shortcutInfo = new HomeShortcutAddedInfo + { + ShortcutName = shortcutName, + IconPath = iconPath, + IsAllowDuplicate = isAllowDuplicate, + AppId = appId, + }; + + if (contentInfo != null && contentInfo != String.Empty) + { + shortcutInfo.Uri = contentInfo; + } + + if (shortcutAdded != null) + { + err = shortcutAdded(shortcutInfo); + } + else + { + err = ShortcutError.IoError; + } + } + else + { + WidgetShortcutAddedInfo shortcutInfo = new WidgetShortcutAddedInfo + { + ShortcutName = shortcutName, + IconPath = iconPath, + IsAllowDuplicate = isAllowDuplicate, + WidgetId = appId, + WidgetSize = (ShortcutWidgetSize)type, + Period = period, + }; + + if (shortcutAdded != null) + { + err = shortcutAdded(shortcutInfo); + } + else + { + err = ShortcutError.IoError; + } + } + + return (int)err; + } + + private static int DeleteCallback(string appId, string shortcutName, int processId, IntPtr data) + { + ShortcutError err = ShortcutError.None; + + ShortcutDeletedInfo deletedInfo = new ShortcutDeletedInfo + { + AppId = appId, + ShortcutName = shortcutName, + }; + + if (shortcutDeleted != null) + { + err = shortcutDeleted(deletedInfo); + } + else + { + err = ShortcutError.IoError; + } + + return (int)err; + } + } +} diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutTemplate.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutTemplate.cs new file mode 100755 index 0000000..73b8167 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/ShortcutTemplate.cs @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class that contains the preset list of shortcut template from the installed package. + /// + public class ShortcutTemplate + { + /// + /// Gets the Application ID. + /// + public string AppId { get; internal set; } = string.Empty; + + /// + /// Gets the name of the created shortcut icon. + /// + public string ShortcutName { get; internal set; } = string.Empty; + + /// + /// Gets the absolute path of an icon file for this shortcut. + /// + public string IconPath { get; internal set; } = string.Empty; + + /// + /// Gets the user data. A property of shortcut element in manifest file. + /// + public string ExtraKey { get; internal set; } = string.Empty; + + /// + /// Gets the user data. A property of shortcut element in manifest file. + /// + public string ExtraData { get; internal set; } = string.Empty; + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/WidgetShortcutAddedInfo.cs b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/WidgetShortcutAddedInfo.cs new file mode 100755 index 0000000..b0b5a6c --- /dev/null +++ b/src/Tizen.Applications.Shortcut/Tizen.Applications.ShortcutEvent/WidgetShortcutAddedInfo.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +namespace Tizen.Applications.Shortcut +{ + /// + /// A class that contains information about the widget. + /// + public class WidgetShortcutAddedInfo : ShortcutAddedInfo + { + /// + /// Gets the Widget ID. + /// + public string WidgetId { get; internal set; } = string.Empty; + + /// + /// Gets the size of widget. + /// + public ShortcutWidgetSize WidgetSize { get; internal set; } + + /// + /// Gets the Update period in seconds. + /// + public double Period { get; internal set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Shortcut/interop/Interop.Libraries.cs b/src/Tizen.Applications.Shortcut/interop/Interop.Libraries.cs new file mode 100755 index 0000000..55784e1 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/interop/Interop.Libraries.cs @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Shortcut = "libshortcut.so.0"; + } +} diff --git a/src/Tizen.Applications.Shortcut/interop/Interop.Shortcut.cs b/src/Tizen.Applications.Shortcut/interop/Interop.Shortcut.cs new file mode 100755 index 0000000..95ad3b5 --- /dev/null +++ b/src/Tizen.Applications.Shortcut/interop/Interop.Shortcut.cs @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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; +using System.Runtime.InteropServices; + +using Tizen.Applications.Shortcut; + +internal static partial class Interop +{ + internal static partial class Shortcut + { + internal delegate int AddCallback(string appId, string shortcutName, int type, string contentInfo, string iconPath, int processId, double period, bool isAllowDuplicate, IntPtr data); + + internal delegate int DeleteCallback(string appId, string shortcutName, int processId, IntPtr data); + + internal delegate int ResultCallback(int ret, IntPtr data); + + internal delegate int ListCallback(string package_name, string icon, string name, string extra_key, string extra_data, IntPtr user_data); + + /// + /// Enumeration for values of shortcut response types. + /// + internal enum ErrorCode : int + { + /// + /// Successful + /// + None = Tizen.Internals.Errors.ErrorCode.None, + + /// + /// Invalid function parameter + /// + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + + /// + /// Out of memory + /// + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + + /// + /// Permission denied + /// + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + + /// + /// I/O Error + /// + IoError = Tizen.Internals.Errors.ErrorCode.IoError, + + /// + /// Not supported + /// + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, + + /// + /// Device or resource busy + /// + ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy, + + /// + /// There is no space to add a new shortcut + /// + NoSpace = -0x01160000 | 0x01, + + /// + /// Shortcut is already added + /// + Exist = -0x01160000 | 0x02, + + /// + /// Unrecoverable error + /// + Fault = -0x01160000 | 0x04, + + /// + /// Not exist shortcut + /// + NotExist = -0x01160000 | 0x08, + + /// + /// Connection not established or communication problem + /// + COMM = -0x01160000 | 0x40 + } + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_add_to_home")] + internal static extern ErrorCode AddToHome(string name, int type, string uri, string icon, int dubplicate, ResultCallback result, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_add_to_home_widget")] + internal static extern ErrorCode AddToWidget(string name, ShortcutWidgetSize size, string widgetId, string icon, double period, int dubplicate, ResultCallback result, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_remove_from_home")] + internal static extern ErrorCode Delete(string name, ResultCallback result, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_get_list")] + internal static extern ErrorCode GetList(string name, ListCallback list, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_set_request_cb")] + internal static extern ErrorCode SetShortcutAddCallback(AddCallback cb, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_unset_request_cb")] + internal static extern ErrorCode UnsetShortcutAddCallback(); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_set_remove_cb")] + internal static extern ErrorCode SetShortcutDeleteCallback(DeleteCallback cb, IntPtr data); + + [DllImport(Libraries.Shortcut, EntryPoint = "shortcut_unset_remove_cb")] + internal static extern ErrorCode UnsetShortcutDeleteCallback(); + } +} -- 2.7.4