<Compile Include="../Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/EventNotification.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications.CoreBackend/ICoreBackend.cs" />
<Compile Include="../Tizen.Applications.Alarm/Interop/Interop.Alarm.cs" />
<Compile Include="../Tizen.Applications.MessagePort/Tizen.Applications.Messages/MessagePort.cs" />
<Compile Include="../Tizen.Applications.MessagePort/Tizen.Applications.Messages/MessagePortErrorFactory.cs" />
<Compile Include="../Tizen.Applications.MessagePort/Tizen.Applications.Messages/MessageReceivedEventArgs.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/Notification.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/NotificationEnumerations.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/NotificationErrorFactory.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/NotificationManager.cs" />
<Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/Package.cs" />
<Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/PackageCertificate.cs" />
<Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/PackageEventState.cs" />
<Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/PackageType.cs" />
<Compile Include="../Tizen.Applications.Preference/Tizen.Applications/Preference.cs" />
<Compile Include="../Tizen.Applications.Preference/Tizen.Applications/PreferenceChangedEventArgs.cs" />
- <Compile Include="../Tizen.Applications.Notification/Tizen.Applications/ProgressNotification.cs" />
<Compile Include="./Properties\AssemblyInfo.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/ReceivedAppControl.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/RegionFormatChangedEventArgs.cs" />
<Compile Include="../Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs" />
<Compile Include="../Tizen.Applications.ToastMessage/Tizen.Applications/ToastMessage.cs" />
<Compile Include="../Tizen.Applications.ToastMessage/Tizen.Applications/ToastMessageErrorFactory.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/Notification.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationSafeHandle.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBinder.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySet.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationAccessorySetBinder.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationActiveStyle.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationButtonAction.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationEnumerations.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationErrorFactory.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationIndicatorStyle.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationLockStyle.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationMakerBase.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationManager.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgress.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationProgressBinder.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationReplyAction.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyle.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationStyleBinder.cs" />
+ <Compile Include="../Tizen.Applications.Notification/Tizen.Applications.Notifications/NotificationBigPictureStyle.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Tizen.Applications.project.json" />
{
"dependencies": {
"NETStandard.Library": "1.6.0",
- "Tizen": "1.0.2"
+ "Tizen": "1.0.3"
},
"frameworks": {
"netstandard1.3": {}
}
-}
+}
\ No newline at end of file
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * 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.
*/
using System;
+using System.ComponentModel;
using System.Runtime.InteropServices;
using Tizen.Applications;
using Tizen.Applications.Notifications;
internal static class Notification
{
[DllImport(Libraries.Notification, EntryPoint = "notification_create")]
- internal static extern SafeNotificationHandle Create(NotificationType type);
+ internal static extern IntPtr Create(NotificationType type);
[DllImport(Libraries.Notification, EntryPoint = "notification_free")]
- internal static extern int Destroy(IntPtr handle);
+ internal static extern NotificationError Destroy(IntPtr handle);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_text")]
- internal static extern int GetText(SafeNotificationHandle handle, NotiText type, out IntPtr text);
+ internal static extern NotificationError GetTextReferenceType(NotificationSafeHandle handle, NotificationText type, out IntPtr text);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_text")]
- internal static extern int SetText(SafeNotificationHandle handle, NotiText type, string text, string key, int args);
+ internal static extern NotificationError SetText(NotificationSafeHandle handle, NotificationText type, string text, string key, int args);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_image")]
- internal static extern int GetImage(SafeNotificationHandle handle, NotiImage type, out IntPtr text);
+ internal static extern NotificationError GetImageReferenceType(NotificationSafeHandle handle, NotificationImage type, out IntPtr path);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_image")]
- internal static extern int SetImage(SafeNotificationHandle handle, NotiImage type, string text);
+ internal static extern NotificationError SetImage(NotificationSafeHandle handle, NotificationImage type, string path);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_time")]
- internal static extern int GetTime(SafeNotificationHandle handle, out int time);
+ internal static extern NotificationError GetTime(NotificationSafeHandle handle, out int time);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_time")]
- internal static extern int SetTime(SafeNotificationHandle handle, int time);
+ internal static extern NotificationError SetTime(NotificationSafeHandle handle, int time);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_insert_time")]
- internal static extern int GetInsertTime(SafeNotificationHandle handle, out long time);
+ internal static extern NotificationError GetInsertTime(NotificationSafeHandle handle, out long time);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_sound")]
- internal static extern int GetSound(SafeNotificationHandle handle, out SoundOption type, out IntPtr path);
+ internal static extern NotificationError GetSoundReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_sound")]
- internal static extern int SetSound(SafeNotificationHandle handle, SoundOption type, string path);
+ internal static extern NotificationError SetSound(NotificationSafeHandle handle, AccessoryOption type, string path);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_vibration")]
- internal static extern int GetVibration(SafeNotificationHandle handle, out VibrationOption type, out IntPtr path);
+ internal static extern NotificationError GetVibrationReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_vibration")]
- internal static extern int SetVibration(SafeNotificationHandle handle, VibrationOption type, string path);
+ internal static extern NotificationError SetVibration(NotificationSafeHandle handle, AccessoryOption type, string path);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_led")]
- internal static extern int GetLed(SafeNotificationHandle handle, out LedOption type, out int color);
+ internal static extern NotificationError GetLed(NotificationSafeHandle handle, out AccessoryOption type, out int color);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_led")]
- internal static extern int SetLed(SafeNotificationHandle handle, LedOption type, int color);
+ internal static extern NotificationError SetLed(NotificationSafeHandle handle, AccessoryOption type, int color);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_led_time_period")]
- internal static extern int GetLedTimePeriod(SafeNotificationHandle handle, out int on, out int off);
+ internal static extern NotificationError GetLedTimePeriod(NotificationSafeHandle handle, out int onMillisecond, out int offMillisecond);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_led_time_period")]
- internal static extern int SetLedTimePeriod(SafeNotificationHandle handle, int on, int off);
+ internal static extern NotificationError SetLedTimePeriod(NotificationSafeHandle handle, int onMillisecond, int offMillisecond);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_launch_option")]
- internal static extern int GetAppControl(SafeNotificationHandle handle, LaunchOption type, out SafeAppControlHandle apphandle);
+ internal static extern NotificationError GetAppControl(NotificationSafeHandle handle, LaunchOption type, out SafeAppControlHandle apphandle);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_launch_option")]
- internal static extern int SetAppControl(SafeNotificationHandle handle, LaunchOption type, SafeAppControlHandle appHandle);
+ internal static extern NotificationError SetAppControl(NotificationSafeHandle handle, LaunchOption type, SafeAppControlHandle appHandle);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_event_handler")]
- internal static extern int GetEventHandler(SafeNotificationHandle handle, int type, out SafeAppControlHandle appHandle);
+ internal static extern NotificationError GetEventHandler(NotificationSafeHandle handle, int type, out SafeAppControlHandle appHandle);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_event_handler")]
- internal static extern int SetEventHandler(SafeNotificationHandle handle, int type, SafeAppControlHandle appHandle);
+ internal static extern NotificationError SetEventHandler(NotificationSafeHandle handle, int type, SafeAppControlHandle appHandle);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_property")]
- internal static extern int GetProperties(SafeNotificationHandle handle, out int flags);
+ internal static extern NotificationError GetProperties(NotificationSafeHandle handle, out int flags);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_property")]
- internal static extern int SetProperties(SafeNotificationHandle handle, int flags);
+ internal static extern NotificationError SetProperties(NotificationSafeHandle handle, int flags);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_display_applist")]
- internal static extern int GetApplist(SafeNotificationHandle handle, out int flags);
+ internal static extern NotificationError GetApplist(NotificationSafeHandle handle, out int flags);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_display_applist")]
- internal static extern int SetApplist(SafeNotificationHandle handle, int flags);
+ internal static extern NotificationError SetApplist(NotificationSafeHandle handle, int flags);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_size")]
- internal static extern int GetProgressSize(SafeNotificationHandle handle, out double value);
+ internal static extern NotificationError GetProgressSize(NotificationSafeHandle handle, out double size);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_size")]
- internal static extern int SetProgressSize(SafeNotificationHandle handle, double value);
+ internal static extern NotificationError SetProgressSize(NotificationSafeHandle handle, double size);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_progress")]
- internal static extern int GetProgress(SafeNotificationHandle handle, out double value);
+ internal static extern NotificationError GetProgress(NotificationSafeHandle handle, out double progress);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_progress")]
- internal static extern int SetProgress(SafeNotificationHandle handle, double value);
+ internal static extern NotificationError SetProgress(NotificationSafeHandle handle, double progress);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_layout")]
- internal static extern int GetLayout(SafeNotificationHandle handle, out NotiLayout type);
+ internal static extern NotificationError GetLayout(NotificationSafeHandle handle, out NotificationLayout layout);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_layout")]
- internal static extern int SetLayout(SafeNotificationHandle handle, NotiLayout type);
+ internal static extern NotificationError SetLayout(NotificationSafeHandle handle, NotificationLayout layout);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_type")]
- internal static extern int GetType(SafeNotificationHandle handle, out NotificationType type);
+ internal static extern NotificationError GetType(NotificationSafeHandle handle, out NotificationType type);
[DllImport(Libraries.Notification, EntryPoint = "notification_update")]
- internal static extern int Update(SafeNotificationHandle handle);
+ internal static extern NotificationError Update(NotificationSafeHandle handle);
[DllImport(Libraries.Notification, EntryPoint = "notification_delete")]
- internal static extern int Delete(SafeNotificationHandle handle);
+ internal static extern NotificationError Delete(NotificationSafeHandle handle);
[DllImport(Libraries.Notification, EntryPoint = "notification_delete_all")]
- internal static extern int DeleteAll(int type);
+ internal static extern NotificationError DeleteAll(int type);
[DllImport(Libraries.Notification, EntryPoint = "notification_post")]
- internal static extern int Post(SafeNotificationHandle handle);
+ internal static extern NotificationError Post(NotificationSafeHandle handle);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_pkgname")]
- internal static extern int GetPackageName(SafeNotificationHandle handle, out IntPtr name);
+ internal static extern NotificationError GetPackageName(NotificationSafeHandle handle, out IntPtr name);
- [DllImport(Libraries.Notification, EntryPoint = "notification_add_button")]
- internal static extern int AddButton(SafeNotificationHandle handle, int index);
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_event_handler")]
+ internal static extern NotificationError AddButtonAction(NotificationSafeHandle handle, ButtonIndex type, SafeAppControlHandle appcontrol);
[DllImport(Libraries.Notification, EntryPoint = "notification_remove_button")]
- internal static extern int RemoveButton(SafeNotificationHandle handle, int index);
+ internal static extern NotificationError RemoveButton(NotificationSafeHandle handle, ButtonIndex index);
[DllImport(Libraries.Notification, EntryPoint = "notification_set_tag")]
- internal static extern int SetTag(SafeNotificationHandle handle, string tag);
+ internal static extern NotificationError SetTag(NotificationSafeHandle handle, string tag);
[DllImport(Libraries.Notification, EntryPoint = "notification_get_tag")]
- internal static extern int GetTag(SafeNotificationHandle handle, out IntPtr tag);
+ internal static extern NotificationError GetTagReferenceType(NotificationSafeHandle handle, out IntPtr tag);
[DllImport(Libraries.Notification, EntryPoint = "notification_load_by_tag")]
- internal static extern SafeNotificationHandle Load(string text);
+ internal static extern IntPtr Load(string text);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_id")]
+ internal static extern NotificationError GetID(NotificationSafeHandle handle, out int groupID, out int privID);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_priv_id")]
+ internal static extern NotificationError SetID(NotificationSafeHandle handle, int privID);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_save_as_template")]
+ internal static extern NotificationError SaveTemplate(NotificationSafeHandle handle, string name);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_create_from_template")]
+ internal static extern IntPtr LoadTemplate(string name);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_noti_block_state")]
+ internal static extern NotificationError GetBlockState(out NotificationBlockState status);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_auto_remove")]
+ internal static extern NotificationError SetAutoRemove(NotificationSafeHandle handle, bool autoRemove);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_auto_remove")]
+ internal static extern NotificationError GetAutoRemove(NotificationSafeHandle handle, out bool autoRemove);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_ongoing_value_type")]
+ internal static extern NotificationError SetProgressType(NotificationSafeHandle handle, ProgressCategory category);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_value_type")]
+ internal static extern NotificationError GetProgressType(NotificationSafeHandle handle, out ProgressCategory category);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_ongoing_flag")]
+ internal static extern NotificationError SetOngoingFlag(NotificationSafeHandle handle, bool flag);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_flag")]
+ internal static extern NotificationError GetProgressFlag(NotificationSafeHandle handle, bool flag);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_ongoing_flag")]
+ internal static extern NotificationError GetProgressFlag(NotificationSafeHandle handle, out bool flag);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_text_input")]
+ internal static extern NotificationError SetPlaceHolderLength(NotificationSafeHandle handle, int length);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_text_input_max_length")]
+ internal static extern NotificationError GetPlaceHolderLength(NotificationSafeHandle handle, out int length);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_hide_timeout")]
+ internal static extern NotificationError GetHideTime(NotificationSafeHandle handle, out int timeout);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_hide_timeout")]
+ internal static extern NotificationError SetHideTime(NotificationSafeHandle handle, int timeout);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_delete_timeout")]
+ internal static extern NotificationError GetDeleteTime(NotificationSafeHandle handle, out int timeout);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_delete_timeout")]
+ internal static extern NotificationError SetDeleteTime(NotificationSafeHandle handle, int timeout);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_extension_image_size")]
+ internal static extern NotificationError SetBigPictureSize(NotificationSafeHandle handle, int size);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_extension_image_size")]
+ internal static extern NotificationError GetBigPictureSize(NotificationSafeHandle handle, out int size);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_set_extention_data")]
+ internal static extern NotificationError SetExtentionData(NotificationSafeHandle handle, string key, SafeBundleHandle bundleHandle);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_extention_data")]
+ internal static extern NotificationError GetExtentionData(NotificationSafeHandle handle, string key, out SafeBundleHandle bundleHandle);
+
+ [DllImport(Libraries.Notification, EntryPoint = "notification_get_args")]
+ internal static extern NotificationError GetExtentionBundle(NotificationSafeHandle handle, out IntPtr args, out IntPtr group_args);
+
+ internal static NotificationError GetText(NotificationSafeHandle handle, NotificationText type, out string text)
+ {
+ NotificationError ret;
+ IntPtr ptr;
+ ret = GetTextReferenceType(handle, type, out ptr);
+
+ if (ptr == IntPtr.Zero)
+ {
+ text = null;
+ }
+ else
+ {
+ text = Marshal.PtrToStringAnsi(ptr);
+ }
+
+ return ret;
+ }
- internal sealed class SafeNotificationHandle : SafeHandle
+ internal static NotificationError GetImage(NotificationSafeHandle handle, NotificationImage type, out string path)
{
- public SafeNotificationHandle()
- : base(IntPtr.Zero, true)
+ NotificationError ret;
+ IntPtr ptr;
+ ret = GetImageReferenceType(handle, type, out ptr);
+
+ if (ptr == IntPtr.Zero)
+ {
+ path = null;
+ }
+ else
{
+ path = Marshal.PtrToStringAnsi(ptr);
}
- public override bool IsInvalid
+ return ret;
+ }
+
+ internal static NotificationError GetSound(NotificationSafeHandle handle, out AccessoryOption type, out string path)
+ {
+ NotificationError ret;
+ IntPtr ptr;
+ ret = GetSoundReferenceType(handle, out type, out ptr);
+
+ if (ptr == IntPtr.Zero)
{
- get { return this.handle == IntPtr.Zero; }
+ path = null;
}
+ else
+ {
+ path = Marshal.PtrToStringAnsi(ptr);
+ }
+
+ return ret;
+ }
- protected override bool ReleaseHandle()
+ internal static NotificationError GetVibration(NotificationSafeHandle handle, out AccessoryOption type, out string path)
+ {
+ NotificationError ret;
+ IntPtr ptr;
+ ret = GetVibrationReferenceType(handle, out type, out ptr);
+
+ if (ptr == IntPtr.Zero)
+ {
+ path = null;
+ }
+ else
+ {
+ path = Marshal.PtrToStringAnsi(ptr);
+ }
+
+ return ret;
+ }
+
+ internal static NotificationError GetTag(NotificationSafeHandle handle, out string tag)
+ {
+ NotificationError ret;
+ IntPtr ptr;
+ ret = GetTagReferenceType(handle, out ptr);
+
+ if (ptr == IntPtr.Zero)
{
- Notification.Destroy(this.handle);
- this.SetHandle(IntPtr.Zero);
- return true;
+ tag = null;
}
+ else
+ {
+ tag = Marshal.PtrToStringAnsi(ptr);
+ }
+
+ return ret;
}
}
}
-using System;
+using System;
using System.Reflection;
using System.Runtime.InteropServices;
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Compile Include="Interop\Interop.Libraries.cs" />
<Compile Include="Interop\Interop.Notification.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Tizen.Applications\EventNotification.cs" />
- <Compile Include="Tizen.Applications\Notification.cs" />
- <Compile Include="Tizen.Applications\NotificationEnumerations.cs" />
- <Compile Include="Tizen.Applications\NotificationErrorFactory.cs" />
- <Compile Include="Tizen.Applications\NotificationManager.cs" />
- <Compile Include="Tizen.Applications\ProgressNotification.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationSafeHandle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationBinder.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationBigPictureStyle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationProgressBinder.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationStyleBinder.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationAccessorySetBinder.cs" />
+ <Compile Include="Tizen.Applications.Notifications\Notification.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationButtonAction.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationReplyAction.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationEnumerations.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationErrorFactory.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationMakerBase.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationProgress.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationActiveStyle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationIndicatorStyle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationLockStyle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationStyle.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationManager.cs" />
+ <Compile Include="Tizen.Applications.Notifications\NotificationAccessorySet.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Tizen.Applications.Notification.project.json" />
{
"dependencies": {
- "NETStandard.Library": "1.6.0",
- "Tizen": "1.0.2"
+ "NETStandard.Library": "1.6.1",
+ "Tizen": "1.0.3"
},
"frameworks": {
"netstandard1.3": {}
}
-}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification : IDisposable
+ {
+ internal static readonly string LogTag = "Tizen.Applications.Notification";
+
+ private NotificationSafeHandle safeHandle;
+ private bool disposed = false;
+
+ private IDictionary<string, StyleBase> styleDictionary;
+ private IDictionary<string, Bundle> extenderDictionary;
+ private int count = 0;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Notification"/> class.
+ /// </summary>
+ public Notification()
+ {
+ styleDictionary = new Dictionary<string, StyleBase>();
+ extenderDictionary = new Dictionary<string, Bundle>();
+ }
+
+ /// <summary>
+ /// Gets or sets Tag of Notification.
+ /// </summary>
+ public string Tag { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets Title of Notification.
+ /// </summary>
+ public string Title { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets icon of Notification.
+ /// </summary>
+ public string Icon { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets sub icon of Notification.
+ /// This SubIcon is displayed in Icon you set.
+ /// </summary>
+ public string SubIcon { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets content of Notification.
+ /// </summary>
+ public string Content { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets a value indicating whether TimeStamp of Notification is Visible or not.
+ /// Default to true.
+ /// </summary>
+ public bool IsTimeStampVisible { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets TimeStamp of Notification.
+ /// </summary>
+ /// <remarks>
+ /// If you don't set TimeStamp, It will be set value that time when the notification is posted.
+ /// TimeStamp requires NotificationManager.Post() to be called.
+ /// If you set IsVisibleTimeStamp property is false, TimeStamp is not Visible in Notification.
+ /// </remarks>
+ public DateTime TimeStamp { get; set; }
+
+ /// <summary>
+ /// Gets or sets Action which is invoked when notification is clicked
+ /// </summary>
+ /// <remarks>
+ /// If you set it to null, the already set AppControl will be removed and nothing will happen when you click on notification.
+ /// </remarks>
+ /// <seealso cref="Tizen.Applications.AppControl"></seealso>
+ public AppControl Action { get; set; }
+
+ /// <summary>
+ /// Gets or sets Count which is displayed at the right side of notification.
+ /// </summary>
+ /// <remarks>
+ /// You must set only positive number.
+ /// If you set count to negative number, This property throw exception.
+ /// </remarks>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public int Count
+ {
+ get
+ {
+ return count;
+ }
+
+ set
+ {
+ if (value < 0)
+ {
+ Log.Error(LogTag, "Count value is negative");
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The Count must be a positive integer.");
+ }
+
+ count = value;
+ }
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool IsOngoing { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets property
+ /// </summary>
+ /// <seealso cref="Tizen.Applications.Notifications.NotificationProperty"></seealso>
+ public NotificationProperty Property { get; set; } = NotificationProperty.None;
+
+ /// <summary>
+ /// Gets or sets <see cref="Notification.ProgressType"/> object for display at notification
+ /// </summary>
+ /// <seealso cref="Tizen.Applications.Notifications.Notification.ProgressType"></seealso>
+ public ProgressType Progress { get; set; }
+
+ /// <summary>
+ /// Gets or sets <see cref="Notification.AccessorySet"/> which is included vibration, led and sound option to be applied at Notification.
+ /// </summary>
+ /// <remarks>
+ /// If you set it to null, the already set AccessorySet will be initialized.
+ /// </remarks>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "Notification",
+ /// Content = "Hello Tizen",
+ /// Icon = "Icon path",
+ /// Count = 3
+ /// };
+ ///
+ /// Notification.AccessorySet accessory = new Notification.AccessorySet
+ /// {
+ /// SoundOption = AccessoryOption.Custom,
+ /// SoundPath = "Sound File Path",
+ /// IsVibration = true,
+ /// LedOption = AccessoryOption.Custom,
+ /// LedOnMs = 100;
+ /// LedOffMs = 50;
+ /// LedColor = Color.Lime
+ /// };
+ ///
+ /// notification.Accessory = accessory;
+ ///
+ /// NotificationManager.Post(notification);
+ /// </code>
+ /// </example>
+ public AccessorySet Accessory { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether notification is displayed on default viewer.
+ /// If you set false and add style, you can see only style notification.
+ /// </summary>
+ public bool IsDisplay { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets NotificationSafeHandle
+ /// </summary>
+ internal NotificationSafeHandle Handle
+ {
+ get
+ {
+ return safeHandle;
+ }
+
+ set
+ {
+ if (value == null)
+ {
+ Log.Error(LogTag, "Invalid argument NotificationSafeHandle");
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to set NotificationSafeHandle");
+ }
+
+ safeHandle = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets Private ID
+ /// </summary>
+ internal int PrivID { get; set; } = -1;
+
+ /// <summary>
+ /// Method to add various style to be applied to notification.
+ /// </summary>
+ /// <remarks>
+ /// The user always see about valid notification style. If you add style which is not supported in platform,
+ /// this method has no effect.
+ /// </remarks>
+ /// <param name="style">The style to be applied to notification</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "Notification",
+ /// Content = "Hello Tizen",
+ /// Icon = "Icon path",
+ /// Count = 3
+ /// };
+ ///
+ /// Notification.LockStyle lockStyle = new Notification.LockStyle
+ /// {
+ /// IconPath = "Icon path",
+ /// ThumbnailPath = "Thumbnail Path"
+ /// };
+ ///
+ /// notification.AddStyle(lockStyle);
+ ///
+ /// NotificationManager.Post(notification);
+ /// </code>
+ /// </example>
+ public void AddStyle(StyleBase style)
+ {
+ if (style == null)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+
+ if (styleDictionary.ContainsKey(style.Key) == true)
+ {
+ Log.Info(LogTag, "The Style is existed, so extender data is replaced");
+ styleDictionary.Remove(style.Key);
+ styleDictionary.Add(style.Key, style);
+ }
+ else
+ {
+ styleDictionary.Add(style.Key, style);
+ }
+ }
+
+ /// <summary>
+ /// Method to remove style you already added.
+ /// </summary>
+ /// <typeparam name="T">Type of notification style to be queried</typeparam>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public void RemoveStyle<T>() where T : Notification.StyleBase, new()
+ {
+ T type = new T();
+
+ if (styleDictionary.ContainsKey(type.Key))
+ {
+ styleDictionary.Remove(type.Key);
+ }
+ else
+ {
+ Log.Error(LogTag, "Sytle Can't be removed, there is no style matched input key");
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+ }
+
+ /// <summary>
+ /// Method to get style you already added.
+ /// </summary>
+ /// <typeparam name="T">Type of notification style to be queried</typeparam>
+ /// <returns>
+ /// The Notification.Style object associated with the given style
+ /// </returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public T GetStyle<T>() where T : Notification.StyleBase, new()
+ {
+ T type = new T();
+ StyleBase style = null;
+
+ styleDictionary.TryGetValue(type.Key, out style);
+
+ if (style == null)
+ {
+ Log.Error(LogTag, "Invalid Style");
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+ else
+ {
+ return style as T;
+ }
+ }
+
+ /// <summary>
+ /// Method to set extender data to add extra data
+ /// </summary>
+ /// <remarks>
+ /// The type of extra data is Bundle.
+ /// </remarks>
+ /// <param name="key">The key of the extra data you want to add.</param>
+ /// <param name="value">The value you want to add.</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "Notification",
+ /// Content = "Hello Tizen",
+ /// Icon = "Icon path",
+ /// };
+ ///
+ /// Bundle bundle = new Bundle();
+ /// bundle.AddItem("key", "value");
+ ///
+ /// notification.SetExtender("firstKey", bundle);
+ /// </code>
+ /// </example>
+ public void SetExtender(string key, Bundle value)
+ {
+ if (value == null || value.SafeBundleHandle.IsInvalid || string.IsNullOrEmpty(key))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+
+ if (extenderDictionary.ContainsKey(key) == true)
+ {
+ Log.Info(LogTag, "The key is existed, so extender data is replaced");
+ extenderDictionary.Remove(key);
+ extenderDictionary.Add(key, value);
+ }
+ else
+ {
+ extenderDictionary.Add(key, value);
+ }
+ }
+
+ /// <summary>
+ /// Method to remove extender you already added.
+ /// </summary>
+ /// <remarks>
+ /// The type of extra data is Bundle.
+ /// </remarks>
+ /// <param name="key">The key of the extra data to add.</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public void RemoveExtender(string key)
+ {
+ if (string.IsNullOrEmpty(key))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+
+ if (extenderDictionary.ContainsKey(key))
+ {
+ extenderDictionary.Remove(key);
+ }
+ else
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+ }
+
+ /// <summary>
+ /// Method to get extender data you already set
+ /// </summary>
+ /// <param name="key">The key of the extra data to get.</param>
+ /// <returns>Bundle Object that include extender data</returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public Bundle GetExtender(string key)
+ {
+ if (string.IsNullOrEmpty(key))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+
+ Bundle bundle;
+ if (extenderDictionary.TryGetValue(key, out bundle) == false)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered : " + key);
+ }
+
+ return bundle;
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ internal void Dispose(bool disposing)
+ {
+ if (disposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ Handle.Dispose();
+ }
+
+ disposed = true;
+ }
+
+ internal IDictionary<string, StyleBase> GetStyleDictionary()
+ {
+ return styleDictionary;
+ }
+
+ internal IDictionary<string, Bundle> GetExtenderDictionary()
+ {
+ return extenderDictionary;
+ }
+
+ internal StyleBase GetStyle(string key)
+ {
+ if (string.IsNullOrEmpty(key))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "Key is null or empty");
+ }
+
+ StyleBase style = null;
+ bool ret = styleDictionary.TryGetValue(key, out style);
+ if (ret == false)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The Style object matched input key is not existed");
+ }
+
+ return style;
+ }
+
+ internal void Make()
+ {
+ NotificationBinder.BindObject(this);
+
+ foreach (string key in GetExtenderDictionary().Keys)
+ {
+ Log.Info(LogTag, "Start to bind Notification.ExtenderData to SafeHandle");
+ Interop.Notification.SetExtentionData(Handle, key, extenderDictionary[key].SafeBundleHandle);
+ }
+
+ foreach (Notification.StyleBase style in styleDictionary.Values)
+ {
+ Log.Info(LogTag, "Start to bind Notification.Style to SafeHandle [" + style.Key + "]");
+ style.Make(this);
+ }
+
+ if (Accessory != null)
+ {
+ Log.Info(LogTag, "Start to bind Notification.AccessetSet to SafeHandle");
+ Accessory.Make(this);
+ }
+
+ if (Progress != null)
+ {
+ Log.Info(LogTag, "Start to bind Notification.Progress to SafeHandle");
+ Progress.Make(this);
+ }
+ }
+
+ internal Notification Build()
+ {
+ IntPtr extention = IntPtr.Zero;
+ IntPtr extentionBundlePtr = IntPtr.Zero;
+
+ NotificationBinder.BindSafeHandle(this);
+
+ Interop.Notification.GetExtentionBundle(Handle, out extention, out extentionBundlePtr);
+
+ if (extention != IntPtr.Zero)
+ {
+ Bundle bundle = new Bundle(new SafeBundleHandle(extention, false));
+ foreach (string key in bundle.Keys)
+ {
+ SafeBundleHandle sbh;
+ Interop.Notification.GetExtentionData(Handle, key, out sbh);
+ extenderDictionary.Add(key, new Bundle(sbh));
+ }
+ }
+
+ ProgressBinder.BindSafeHandle(this);
+ AccessorySetBinder.BindSafeHandle(this);
+ IndicatorBinder.BindSafeHandle(this);
+ ActiveBinder.BindSafeHandle(this);
+ LockBinder.BindSafehandle(this);
+ BigPictureBinder.BindSafeHandle(this);
+
+ return this;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using Tizen.Common;
+
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for Notification AccessorySet which is included vibration, led, sound option
+ /// </summary>
+ public sealed class AccessorySet : MakerBase
+ {
+ /// <summary>
+ /// Gets or sets the sound option. Default to AccessoryOption.Off.
+ /// </summary>
+ /// <remarks>
+ /// If you set AccessoryOption.Custom and not set SoundPath, then turn on the default sound.
+ /// </remarks>
+ public AccessoryOption SoundOption { get; set; } = AccessoryOption.Off;
+
+ /// <summary>
+ /// Gets or sets the sound path, It will play on the sound file you set.
+ /// </summary>
+ public string SoundPath { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether vibration is operated. Default to false.
+ /// </summary>
+ public bool CanVibrate { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets the led option. Default to AccessoryOption.Off.
+ /// </summary>
+ /// <remarks>
+ /// If you set AccessoryOption.Custom and not set LedColor, then turn on the LED with default color.
+ /// </remarks>
+ public AccessoryOption LedOption { get; set; } = AccessoryOption.Off;
+
+ /// <summary>
+ /// Gets or sets the led on time period that you would like the LED on the device to blink. as well as the rate
+ /// </summary>
+ /// <remarks>
+ /// Default value of LedOnMillisecond is 0.
+ /// The rate is specified in terms of the number of Milliseconds to be on.
+ /// You should always set LedOnMillisecond with LedOffMillisecond. Otherwise, it may not operate normally.
+ /// </remarks>
+ public int LedOnMillisecond { get; set; }
+
+ /// <summary>
+ /// Gets or sets the led on time period that you would like the LED on the device to blink. as well as the rate.
+ /// </summary>
+ /// <remarks>
+ /// The rate is specified in terms of the number of Milliseconds to be off.
+ /// You should always set LedOffMillisecond with LedOnMillisecond. Otherwise, it may not operate normally.
+ /// </remarks>
+ public int LedOffMillisecond { get; set; }
+
+ /// <summary>
+ /// Gets or sets the led color that you would like the LED on the device to blink.
+ /// </summary>
+ /// <remarks>
+ /// If you want to set LedColor, you should always set LedOption is AccessoryOption.Custom. Otherwise, it may operate default led color.
+ /// </remarks>
+ public Color LedColor { get; set; }
+
+ internal override void Make(Notification notification)
+ {
+ AccessorySetBinder.BindObject(notification);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using Tizen.Common;
+
+ internal static class AccessorySetBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ BindLedToHandle(notification);
+ BindSoundToHandle(notification);
+ BindVibrationToHandle(notification);
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ Notification.AccessorySet accessory = new Notification.AccessorySet();
+ BindHandleToLed(notification, accessory);
+ BindHandleToSound(notification, accessory);
+ BindHandleToVibration(notification, accessory);
+ notification.Accessory = accessory;
+ }
+
+ private static void BindLedToHandle(Notification notification)
+ {
+ NotificationError ret = NotificationError.None;
+ Notification.AccessorySet accessory = notification.Accessory;
+
+ ret = Interop.Notification.SetLed(notification.Handle, accessory.LedOption, 0);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set led");
+ }
+
+ ret = Interop.Notification.SetLedTimePeriod(notification.Handle, accessory.LedOnMillisecond, accessory.LedOffMillisecond);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set led period");
+ }
+
+ if (notification.Accessory.LedOption == AccessoryOption.Custom)
+ {
+ Color color = accessory.LedColor;
+ ret = Interop.Notification.SetLed(notification.Handle, AccessoryOption.Custom, color.GetArgb());
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set led color");
+ }
+ }
+ }
+
+ private static void BindVibrationToHandle(Notification notification)
+ {
+ Notification.AccessorySet accessory = notification.Accessory;
+ if (accessory.CanVibrate == false)
+ {
+ Interop.Notification.SetVibration(notification.Handle, AccessoryOption.Off, null);
+ }
+ else
+ {
+ Interop.Notification.SetVibration(notification.Handle, AccessoryOption.On, null);
+ }
+ }
+
+ private static void BindSoundToHandle(Notification notification)
+ {
+ Notification.AccessorySet accessory = notification.Accessory;
+
+ if (accessory.SoundOption == AccessoryOption.Custom && string.IsNullOrEmpty(accessory.SoundPath))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "If the option is set to Custom, the path must also be set.");
+ }
+
+ NotificationError ret = Interop.Notification.SetSound(notification.Handle, accessory.SoundOption, accessory.SoundPath);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set sound");
+ }
+ }
+
+ private static void BindHandleToLed(Notification notification, Notification.AccessorySet accessory)
+ {
+ AccessoryOption type;
+ int argb;
+ Interop.Notification.GetLed(notification.Handle, out type, out argb);
+
+ accessory.LedOption = type;
+ if (type == AccessoryOption.Custom)
+ {
+ accessory.LedColor = new Color(argb >> 16 & 255, argb >> 8 & 255, argb >> 0 & 255, argb >> 24 & 255);
+ }
+
+ int onMillisecond, offMillisecond;
+ Interop.Notification.GetLedTimePeriod(notification.Handle, out onMillisecond, out offMillisecond);
+ accessory.LedOnMillisecond = onMillisecond;
+ accessory.LedOffMillisecond = offMillisecond;
+ }
+
+ private static void BindHandleToSound(Notification notification, Notification.AccessorySet accessory)
+ {
+ AccessoryOption type;
+ string path;
+
+ Interop.Notification.GetSound(notification.Handle, out type, out path);
+
+ accessory.SoundOption = type;
+ if (type == AccessoryOption.Custom)
+ {
+ accessory.SoundPath = path;
+ }
+ }
+
+ private static void BindHandleToVibration(Notification notification, Notification.AccessorySet accessory)
+ {
+ AccessoryOption type;
+ string path;
+
+ Interop.Notification.GetVibration(notification.Handle, out type, out path);
+ if (type == AccessoryOption.Off)
+ {
+ accessory.CanVibrate = false;
+ }
+ else
+ {
+ accessory.CanVibrate = true;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System.Collections.Generic;
+
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for generating Active style notification
+ /// </summary>
+ public sealed class ActiveStyle : StyleBase
+ {
+ private IDictionary<ButtonIndex, ButtonAction> buttonDictionary;
+ private int hideTimeout = 0;
+ private int deleteTimeout = 0;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ActiveStyle"/> class.
+ /// </summary>
+ public ActiveStyle()
+ {
+ buttonDictionary = new Dictionary<ButtonIndex, ButtonAction>();
+ }
+
+ /// <summary>
+ /// Gets or sets an absolute path for an image file to display on the background of active notification
+ /// </summary>
+ public string BackgroundImage { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the active notification is removed automatically. Default value is true.
+ /// </summary>
+ /// <remarks>
+ /// IsAutoRemove option lets the active notification be removed several seconds after it shows.
+ /// When 'IsAutoRemove' is set as false, the active notification will not be removed as long as the user removes
+ /// the active notification or the app which posted the active notification removes the active notification.
+ /// </remarks>>
+ public bool IsAutoRemove { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets a ReplyAction to this active notification style.
+ /// </summary>
+ /// <remarks>
+ /// When you add a ReplyAction to the ActiveStyle, the notification UI will show a ReplyAction with button.
+ /// If you set null parameter, ReplyAction is disappeared.
+ /// </remarks>
+ /// <example>
+ /// <code>
+ ///
+ /// ButtonAction button = new ButtonAction
+ /// {
+ /// Index = ButtonIndex.First,
+ /// Text = "Yes"
+ /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
+ /// };
+ ///
+ /// ReplyAction reply = new ReplyAction
+ /// {
+ /// ParentIndex = ButtonIndex.First;
+ /// PlaceHolderText = "Please write your reply."
+ /// ReplyMax = 160,
+ /// Button = new ButtonAction
+ /// {
+ /// Text = "Yes",
+ /// ImagePath = "image path"
+ /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
+ /// };
+ /// };
+ ///
+ /// ActiveStyle active = new ActiveStyle
+ /// {
+ /// AutoRemove = true,
+ /// BackgroundImage = "image path",
+ /// ReplyAction = reply
+ /// };
+ ///
+ /// active.AddButtonAction(button);
+ /// </code>
+ /// </example>
+ public ReplyAction ReplyAction { get; set; }
+
+ /// <summary>
+ /// Gets the key of ActiveStyle
+ /// </summary>
+ internal override string Key
+ {
+ get
+ {
+ return "Active";
+ }
+ }
+
+ /// <summary>
+ /// Method to set times to hide or delete notification.
+ /// </summary>
+ /// <remarks>
+ /// The time settings for hiding and deleting are only reflected on Tizen TV.
+ /// If you use this API on other profile, this time settings have no effect
+ /// </remarks>
+ /// <param name="hideTime">The value in second when the notification can be hidden from the notification viewer after notification is posted</param>
+ /// <param name="deleteTime">The value in second when the notification can be deleted from the notification list in setting application after notification is posted</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public void SetRemoveTime(int hideTime, int deleteTime)
+ {
+ if (hideTime < 0 || deleteTime < 0)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument");
+ }
+
+ hideTimeout = hideTime;
+ deleteTimeout = deleteTime;
+ }
+
+ /// <summary>
+ /// Method to get times to hide or delete notification.
+ /// </summary>
+ /// <param name="hideTime">The value in second when the notification can be hidden from the notification viewer after notification is posted</param>
+ /// <param name="deleteTime">The value in second when the notification can be deleted from the notification list in setting application after notification is posted</param>
+ public void GetRemoveTime(out int hideTime, out int deleteTime)
+ {
+ hideTime = hideTimeout;
+ deleteTime = deleteTimeout;
+ }
+
+ /// <summary>
+ /// Method to add a button to the active notification style.
+ /// Buttons are displayed on the notification.
+ /// </summary>
+ /// <remarks>
+ /// If you add button that has same index, the button is replaced to latest adding button.
+ /// If you don't set an index on ButtonAction, the index is set sequentially from zero.
+ /// </remarks>
+ /// <param name="button">An ButtonAction for appear to the notification</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <example>
+ /// <code>
+ ///
+ /// ButtonAction button = new ButtonAction
+ /// {
+ /// Index = 0,
+ /// Text = "Yes"
+ /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
+ /// };
+ ///
+ /// ActiveStyle active = new ActiveStyle
+ /// {
+ /// IsAutoRemove = true,
+ /// BackgroundImage = "image path",
+ /// };
+ ///
+ /// active.AddButtonAction(button);
+ ///
+ /// </code>
+ /// </example>
+ public void AddButtonAction(ButtonAction button)
+ {
+ if (button == null)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid ButtonAction object");
+ }
+
+ if (button.Index == ButtonIndex.None)
+ {
+ button.Index = (ButtonIndex)buttonDictionary.Count;
+ buttonDictionary.Add(button.Index, button);
+ }
+ else if (button.Index >= ButtonIndex.First)
+ {
+ if (buttonDictionary.ContainsKey(button.Index))
+ {
+ buttonDictionary.Remove(button.Index);
+ }
+
+ buttonDictionary.Add(button.Index, button);
+ }
+ }
+
+ /// <summary>
+ /// Remove the ButtonAction you already add.
+ /// </summary>
+ /// <param name="index">The index to remove a button</param>
+ /// <returns>true if the element is successfully found and removed; otherwise, false</returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public bool RemoveButtonAction(ButtonIndex index)
+ {
+ bool ret = buttonDictionary.Remove(index);
+
+ if (ret == false)
+ {
+ Log.Debug(Notification.LogTag, "Invalid key, there is no button matched input index");
+ }
+ else
+ {
+ Log.Debug(Notification.LogTag, "The button was removed.");
+ }
+
+ return ret;
+ }
+
+ /// <summary>
+ /// Gets the ButtonAction of the active notification.
+ /// </summary>
+ /// <param name="index">The index to get a button you already add</param>
+ /// <returns>The ButtonAction object which is you already add</returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public ButtonAction GetButtonAction(ButtonIndex index)
+ {
+ ButtonAction button = null;
+
+ if (buttonDictionary.ContainsKey(index) == true)
+ {
+ buttonDictionary.TryGetValue(index, out button);
+ }
+ else
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value is not existed.");
+ }
+
+ return button;
+ }
+
+ internal ICollection<ButtonAction> GetButtonAction()
+ {
+ return buttonDictionary.Values;
+ }
+
+ internal override void Make(Notification notification)
+ {
+ ActiveBinder.BindObject(notification);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for generating BigPicture style notification
+ /// </summary>
+ public sealed class BigPictureStyle : StyleBase
+ {
+ /// <summary>
+ /// Gets or sets the absolute path for a big picture image file to display on BigPicture style of the notification.
+ /// </summary>
+ public string ImagePath { get; set; }
+
+ /// <summary>
+ /// Gets or sets the absolute path for a big picture image size to display on BigPicture style of the notification.
+ /// </summary>
+ /// <value>
+ /// This value is only height size.
+ /// </value>>
+ public int ImageSize { get; set; }
+
+ /// <summary>
+ /// Gets or sets the content text to display on BigPicture style of the notification.
+ /// </summary>
+ public string Content { get; set; }
+
+ /// <summary>
+ /// Gets the key of BigPictureStyle
+ /// </summary>
+ internal override string Key
+ {
+ get
+ {
+ return "BigPicture";
+ }
+ }
+
+ internal override void Make(Notification notification)
+ {
+ BigPictureBinder.BindObject(notification);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+
+ internal static class NotificationBinder
+ {
+ private static readonly int DoNotShowTimeStamp = -1;
+
+ internal static void BindObject(Notification notification)
+ {
+ BindNotificationSafeHandle(notification);
+ BindNotificationText(notification);
+ BindNotificationTime(notification);
+
+ Interop.Notification.SetID(notification.Handle, notification.PrivID);
+
+ if (notification.IsDisplay)
+ {
+ Interop.Notification.SetApplist(notification.Handle, (int)NotificationDisplayApplist.Tray);
+ }
+ else
+ {
+ Interop.Notification.SetApplist(notification.Handle, 0);
+ }
+
+ if (notification.IsOngoing == true)
+ {
+ Log.Info(Notification.LogTag, "Start to set IsOngoing to SafeHandle");
+ Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Ongoing);
+ Interop.Notification.SetOngoingFlag(notification.Handle, true);
+ }
+
+ if (string.IsNullOrEmpty(notification.Tag) != true)
+ {
+ Interop.Notification.SetTag(notification.Handle, notification.Tag);
+ }
+
+ if (notification.Action != null && notification.Action.SafeAppControlHandle.IsInvalid == false)
+ {
+ Interop.Notification.SetAppControl(notification.Handle, LaunchOption.AppControl, notification.Action.SafeAppControlHandle);
+ }
+
+ Interop.Notification.SetProperties(notification.Handle, (int)notification.Property);
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ int privID, groupID;
+ Interop.Notification.GetID(notification.Handle, out groupID, out privID);
+ notification.PrivID = privID;
+
+ NotificationLayout layout;
+ Interop.Notification.GetLayout(notification.Handle, out layout);
+ NotificationType type;
+ Interop.Notification.GetType(notification.Handle, out type);
+ if (layout == NotificationLayout.Ongoing && type == NotificationType.Ongoing)
+ {
+ notification.IsOngoing = true;
+ }
+
+ int appList;
+ Interop.Notification.GetApplist(notification.Handle, out appList);
+ if ((appList & (int)NotificationDisplayApplist.Tray) == 0)
+ {
+ notification.IsDisplay = false;
+ }
+
+ BindSafeHandleText(notification);
+ BindSafeHandleTime(notification);
+ BindSafeHandleTag(notification);
+ BindSafeHandleAction(notification);
+ }
+
+ private static void BindNotificationSafeHandle(Notification notification)
+ {
+ IntPtr ptr;
+ NotificationError ret;
+
+ if (notification.Handle != null && notification.Handle.IsInvalid == false)
+ {
+ notification.Handle.Dispose();
+ }
+
+ if (notification.IsOngoing == true || notification.Progress != null)
+ {
+ ptr = Interop.Notification.Create(NotificationType.Ongoing);
+ }
+ else
+ {
+ ptr = Interop.Notification.Create(NotificationType.Basic);
+ }
+
+ if (ptr == IntPtr.Zero)
+ {
+ ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+ throw NotificationErrorFactory.GetException(ret, "Unable to create IntPtr Notification");
+ }
+
+ notification.Handle = new NotificationSafeHandle(ptr, true);
+ }
+
+ private static void BindNotificationText(Notification notification)
+ {
+ Interop.Notification.SetText(notification.Handle, NotificationText.Title, notification.Title, null, -1);
+ Interop.Notification.SetText(notification.Handle, NotificationText.Content, notification.Content, null, -1);
+ Interop.Notification.SetImage(notification.Handle, NotificationImage.Icon, notification.Icon);
+ Interop.Notification.SetImage(notification.Handle, NotificationImage.SubIcon, notification.SubIcon);
+ Interop.Notification.SetText(notification.Handle, NotificationText.EventCount, notification.Count.ToString(), null, -1);
+ }
+
+ private static void BindNotificationTime(Notification notification)
+ {
+ if (notification.IsTimeStampVisible == true)
+ {
+ if (notification.TimeStamp != DateTime.MinValue)
+ {
+ TimeSpan datatime = notification.TimeStamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ Interop.Notification.SetTime(notification.Handle, (int)datatime.TotalSeconds);
+ }
+ }
+ else
+ {
+ Interop.Notification.SetTime(notification.Handle, DoNotShowTimeStamp);
+ }
+ }
+
+ private static void BindSafeHandleText(Notification notification)
+ {
+ string text;
+ Interop.Notification.GetText(notification.Handle, NotificationText.Title, out text);
+ if (string.IsNullOrEmpty(text) == false)
+ {
+ notification.Title = text;
+ }
+
+ Interop.Notification.GetText(notification.Handle, NotificationText.Content, out text);
+ if (string.IsNullOrEmpty(text) == false)
+ {
+ notification.Content = text;
+ }
+
+ string path;
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.Icon, out path);
+ if (string.IsNullOrEmpty(path) == false)
+ {
+ notification.Icon = path;
+ }
+
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.SubIcon, out path);
+ if (string.IsNullOrEmpty(path) == false)
+ {
+ notification.SubIcon = path;
+ }
+
+ Interop.Notification.GetText(notification.Handle, NotificationText.EventCount, out text);
+ if (string.IsNullOrEmpty(text) == false)
+ {
+ try
+ {
+ notification.Count = int.Parse(text);
+ }
+ catch (Exception ex)
+ {
+ Log.Error(Notification.LogTag, ex.ToString());
+ }
+ }
+ }
+
+ private static void BindSafeHandleTime(Notification notification)
+ {
+ int time;
+
+ Interop.Notification.GetTime(notification.Handle, out time);
+
+ if (time == DoNotShowTimeStamp)
+ {
+ notification.IsTimeStampVisible = false;
+ }
+ else
+ {
+ notification.IsTimeStampVisible = true;
+
+ if (time != 0)
+ {
+ notification.TimeStamp = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local)).AddSeconds(time).ToLocalTime();
+ }
+ }
+ }
+
+ private static void BindSafeHandleTag(Notification notification)
+ {
+ string text;
+ Interop.Notification.GetTag(notification.Handle, out text);
+ if (string.IsNullOrEmpty(text) != true)
+ {
+ notification.Tag = text;
+ }
+ }
+
+ private static void BindSafeHandleProperty(Notification notification)
+ {
+ int property;
+ Interop.Notification.GetProperties(notification.Handle, out property);
+ notification.Property = (NotificationProperty)property;
+ }
+
+ private static void BindSafeHandleAction(Notification notification)
+ {
+ SafeAppControlHandle appcontrol = null;
+ Interop.Notification.GetAppControl(notification.Handle, LaunchOption.AppControl, out appcontrol);
+ if (appcontrol != null && appcontrol.IsInvalid == false)
+ {
+ notification.Action = new AppControl(appcontrol);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class to help you set button on Active style of Notification
+ /// </summary>
+ /// <remarks>
+ /// It must include a Text, an Index, an ImagePath, and an Action to be invoked when user select the button.
+ /// </remarks>>
+ public sealed class ButtonAction : MakerBase
+ {
+ /// <summary>
+ /// Gets or sets the index of Button which is appeared at Notification.
+ /// </summary>
+ public ButtonIndex Index { get; set; } = ButtonIndex.None;
+
+ /// <summary>
+ /// Gets or sets the text describing the button
+ /// </summary>
+ public string Text { get; set; }
+
+ /// <summary>
+ /// Gets or sets the image path that represent the button
+ /// </summary>
+ public string ImagePath { get; set; }
+
+ /// <summary>
+ /// Gets or sets the action which is invoked when button is clicked
+ /// </summary>
+ /// <value>
+ /// If you don't set Action, nothing happens when button is clicked.
+ /// </value>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <example>
+ /// <code>
+ /// ButtonAction button = new ButtonAction
+ /// {
+ /// Index = ButtonIndex.First,
+ /// text = "Yes",
+ /// ImagePath = "image path",
+ /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
+ /// };
+ /// </code>
+ /// </example>
+ /// <seealso cref="Tizen.Applications.AppControl"></seealso>
+ public AppControl Action { get; set; }
+
+ internal override void Make(Notification notification)
+ {
+ int enumIndex = (int)NotificationText.FirstButton + (int)Index;
+
+ Interop.Notification.SetText(notification.Handle, (NotificationText)enumIndex, Text, null, -1);
+ enumIndex = (int)NotificationImage.FirstButton + (int)Index;
+ Interop.Notification.SetImage(notification.Handle, (NotificationImage)enumIndex, ImagePath);
+ if (Action != null && Action.SafeAppControlHandle.IsInvalid == false)
+ {
+ Interop.Notification.SetEventHandler(notification.Handle, (int)Index, Action.SafeAppControlHandle);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+
+ /// <summary>
+ /// Enumeration for Progress category
+ /// </summary>
+ public enum ProgressCategory
+ {
+ /// <summary>
+ /// Value for percent type
+ /// </summary>
+ Percent,
+
+ /// <summary>
+ /// Value for time type
+ /// </summary>
+ Time,
+
+ /// <summary>
+ /// Value for pending type which is not updated progress current value
+ /// </summary>
+ PendingBar
+ }
+
+ /// <summary>
+ /// Enumeration for Accessory option
+ /// </summary>
+ public enum AccessoryOption
+ {
+ /// <summary>
+ /// Value for off accessory option
+ /// </summary>
+ Off = -1,
+
+ /// <summary>
+ /// Value for on accessory option
+ /// </summary>
+ On,
+
+ /// <summary>
+ /// Value for custom accessory option
+ /// </summary>
+ Custom
+ }
+
+ /// <summary>
+ /// Enumeration for Button Index
+ /// </summary>
+ public enum ButtonIndex
+ {
+ /// <summary>
+ /// Value for default button index
+ /// </summary>
+ None = -1,
+
+ /// <summary>
+ /// Value for first button index
+ /// </summary>
+ First,
+
+ /// <summary>
+ /// Value for second button index
+ /// </summary>
+ Second,
+
+ /// <summary>
+ /// Value for third button index
+ /// </summary>
+ Third
+ }
+
+ /// <summary>
+ /// Enumeration for notification particular property
+ /// </summary>
+ [Flags]
+ public enum NotificationProperty
+ {
+ /// <summary>
+ /// Value for adjust nothing
+ /// </summary>
+ None = 0x00,
+
+ /// <summary>
+ /// Value for display only SIM card inserted
+ /// </summary>
+ DisplayOnlySimmode = 0x01,
+
+ /// <summary>
+ /// Value for disable application launch when it selected
+ /// </summary>
+ DisableAppLaunch = 0x02,
+
+ /// <summary>
+ /// Value for disable auto delete when it selected
+ /// </summary>
+ DisableAutoDelete = 0x04,
+
+ /// <summary>
+ /// Value for deleted when device is rebooted even though notification is not set Ongoing
+ /// </summary>
+ VolatileDisplay = 0x100
+ }
+
+ /// <summary>
+ /// Enumeration for block state
+ /// </summary>
+ public enum NotificationBlockState
+ {
+ /// <summary>
+ /// Value to check the app is allowed to post notification
+ /// </summary>
+ Allowed = 0,
+
+ /// <summary>
+ /// Value to check the app is not allowed to post any notification
+ /// </summary>
+ Blocked,
+
+ /// <summary>
+ /// Value to check do not disturb mode which is user set
+ /// </summary>
+ DoNotDisturb
+ }
+
+ internal enum NotificationType
+ {
+ None = -1,
+ Basic = 0,
+ Ongoing,
+ }
+
+ internal enum NotificationEventType
+ {
+ FirstButton = 0,
+ SecondButton,
+ ThirdButton,
+ ClickOnIcon = 6,
+ ClockOnThumbnail = 7,
+ ClickOnTextInputButton = 8
+ }
+
+ internal enum NotificationLayout
+ {
+ None = 0,
+ SingleEvent = 1,
+ Thumbnail = 3,
+ Ongoing = 4,
+ Progress = 5,
+ Extension = 6
+ }
+
+ internal enum NotificationText
+ {
+ Title = 0,
+ Content,
+ EventCount = 3,
+ FirstMainText,
+ FirstSubText,
+ SecondMainText,
+ SecondSubText,
+ FirstButton = 13,
+ SeceondButton = 14,
+ ThirdButton = 15,
+ PlaceHolder = 19,
+ InputButton = 20,
+ BigPicture = 21,
+ }
+
+ internal enum NotificationImage
+ {
+ Icon = 0,
+ IconForIndicator,
+ IconForLock,
+ Thumbnail,
+ ThumbnailForLock,
+ SubIcon,
+ Background,
+ FirstButton = 12,
+ SecondButton,
+ ThirdButton,
+ TextInputButton = 18,
+ BigPicture = 19,
+ }
+
+ internal enum LaunchOption
+ {
+ AppControl = 1
+ }
+
+ [Flags]
+ internal enum NotificationDisplayApplist
+ {
+ Tray = 0x00000001,
+ Ticker = 0x00000002,
+ Lock = 0x00000004,
+ Indicator = 0x00000008,
+ Active = 0x00000010,
+ All = 0x0000000f,
+ }
+}
* limitations under the License.
*/
-using System;
-
namespace Tizen.Applications.Notifications
{
+ using System;
+ using System.Runtime.CompilerServices;
+
internal enum NotificationError
{
None = Tizen.Internals.Errors.ErrorCode.None,
internal static class NotificationErrorFactory
{
- private const string _logTag = "Tizen.Applications.Notification";
-
- internal static Exception GetException(NotificationError ret, string msg)
+ internal static Exception GetException(NotificationError ret, string msg, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
{
+ Log.Error(Notification.LogTag, memberName + " : " + lineNumber);
+
switch (ret)
{
case NotificationError.InvalidParameter:
- Log.Error(_logTag, msg);
+ Log.Error(Notification.LogTag, msg);
return new ArgumentException(ret + " error occurred.");
+ case NotificationError.PermissionDenied:
+ throw new UnauthorizedAccessException("Permission denied (http://tizen.org/privilege/notification)");
default:
- Log.Error(_logTag, msg);
+ Log.Error(Notification.LogTag, msg);
return new InvalidOperationException(ret + " error occurred.");
}
}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for generating Indicator style notification
+ /// </summary>
+ public sealed class IndicatorStyle : StyleBase
+ {
+ /// <summary>
+ /// Gets or sets an absolute path for an image file.
+ /// If you set IconPath, you can see the icon on the right side of indicator.
+ /// </summary>
+ public string IconPath { get; set; }
+
+ /// <summary>
+ /// Gets or sets a sub text for displaying Indicator style
+ /// </summary>
+ public string SubText { get; set; }
+
+ /// <summary>
+ /// Gets the key of IndicatorStyle
+ /// </summary>
+ internal override string Key
+ {
+ get
+ {
+ return "Indicator";
+ }
+ }
+
+ internal override void Make(Notification notification)
+ {
+ IndicatorBinder.BindObject(notification);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for generating Lock style notification
+ /// </summary>
+ public sealed class LockStyle : StyleBase
+ {
+ /// <summary>
+ /// Gets or sets an absolute path for an image file to display on the icon of Lock style
+ /// </summary>
+ public string IconPath { get; set; }
+
+ /// <summary>
+ /// Gets or sets an absolute path for a thumbnail image file to display on Lock style
+ /// </summary>
+ public string ThumbnailPath { get; set; }
+
+ /// <summary>
+ /// Gets the key of LockStyle
+ /// </summary>
+ internal override string Key
+ {
+ get
+ {
+ return "Lock";
+ }
+ }
+
+ internal override void Make(Notification notification)
+ {
+ LockBinder.BindObject(notification);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System.ComponentModel;
+
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// An object that help notification make to SafeHandle.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract class MakerBase
+ {
+ internal abstract void Make(Notification notification);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+ using System.ComponentModel;
+
+ /// <summary>
+ /// NotificationManager class to post, update, delete and get Notification.
+ /// </summary>
+ public static class NotificationManager
+ {
+ /// <summary>
+ /// Posts a new Notification.
+ /// </summary>
+ /// <param name="notification">Notification to post</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ ///
+ /// Notification.AccessorySet accessory = new Notification.AccessorySet
+ /// {
+ /// SoundOption = AccessoryOption.On,
+ /// CanVibrate = true
+ /// };
+ /// notification.Accessory = accessory;
+ ///
+ /// // do something
+ ///
+ /// NotificationManager.Post(notification);
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static void Post(Notification notification)
+ {
+ if (notification == null)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
+ }
+
+ notification.Make();
+
+ NotificationError ret = Interop.Notification.Post(notification.Handle);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "post notification failed");
+ }
+
+ int priv_id, group_id;
+ Interop.Notification.GetID(notification.Handle, out group_id, out priv_id);
+ notification.PrivID = priv_id;
+ }
+
+ /// <summary>
+ /// Updates a posted Notification.
+ /// </summary>
+ /// <param name="notification">Notification to update</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// string tag = "first tag";
+ ///
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = tag
+ /// };
+ ///
+ /// Notification.AccessorySet accessory = new Notification.AccessorySet
+ /// {
+ /// LedOption = AccessoryOption.On,
+ /// VibrationOption = AccessoryOption.Custom,
+ /// VibrationPath = "vibration absolute path"
+ /// }
+ /// notification.Accessory = accessory;
+ ///
+ /// NotificationManager.Post(notification);
+ ///
+ /// // do something
+ ///
+ /// Notification loadNotification = NotificationManager.Load(tag);
+ ///
+ /// loadNotification.Progress = new ProgressType(ProgressCategory.Percent, 0.0. 100.0);
+ ///
+ /// Thread thread = new Thread(new ParameterizedThreadStart(UpdateProgress));
+ /// thread.IsBackground = true;
+ /// thread.Start(notification);
+ ///
+ /// ...
+ ///
+ /// static void UpdateProgress(Object obj)
+ /// {
+ /// Notification notification = (Notification)obj;
+ ///
+ /// for (double current = 1.0; current <= 100.0; current = current + 1.0)
+ /// {
+ /// notification.Progress.ProgressCurrent = current;
+ /// NotificationManager.Update(notification);
+ /// Thread.Sleep(300);
+ /// }
+ /// }
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <pre>
+ /// Post method should be called on the Notification object.
+ /// </pre>
+ public static void Update(Notification notification)
+ {
+ if (notification == null || notification.Handle == null || notification.Handle.IsInvalid)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
+ }
+
+ notification.Make();
+ NotificationError ret = Interop.Notification.Update(notification.Handle);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "update notification failed");
+ }
+ }
+
+ /// <summary>
+ /// Deletes a posted Notification.
+ /// </summary>
+ /// <param name="notification">Notification to remove</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ /// NotificationManager.Post(notification);
+ ///
+ /// // do something
+ ///
+ /// NotificationManager.Delete(notification);
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ /// <pre>
+ /// Post method should be called on the Notification object.
+ /// </pre>
+ public static void Delete(Notification notification)
+ {
+ if (notification == null || notification.Handle == null || notification.Handle.IsInvalid)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
+ }
+
+ NotificationError ret = Interop.Notification.Delete(notification.Handle);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "delete notification failed");
+ }
+ }
+
+ /// <summary>
+ /// Removes all posted Notification of calling application.
+ /// </summary>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// Notification firstNotification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ /// NotificationManager.Post(firstNotification);
+ ///
+ /// Notification secondNotification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "second notification"
+ /// };
+ /// NotificationManager.Post(secondNotification);
+ /// NotificationManager.DeleteAll();
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static void DeleteAll()
+ {
+ NotificationError ret;
+
+ ret = Interop.Notification.DeleteAll((int)NotificationType.Basic);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "delete all notifications failed of Noti type");
+ }
+
+ ret = Interop.Notification.DeleteAll((int)NotificationType.Ongoing);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "delete all notifications failed of Ongoing type");
+ }
+ }
+
+ /// <summary>
+ /// Searches for a posted notification which has the inputted tag and isn't deleted not yet.
+ /// </summary>
+ /// <remarks>
+ /// Load method should be called only for notifications which have been posted using NotificationManager.Post method.
+ /// If two or more notifications share the same tag, the notification posted most recently is returned.
+ /// </remarks>
+ /// <param name="tag">Tag used to query</param>
+ /// <returns>Notification Object with inputted tag</returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid or when the tag does not exist</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ /// NotificationManager.Post(notification);
+ ///
+ /// // do someting
+ ///
+ /// Notification loadNotification = NotificationManager.Load("first notification");
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static Notification Load(string tag)
+ {
+ IntPtr ptr = IntPtr.Zero;
+
+ if (string.IsNullOrEmpty(tag))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid parameter entered");
+ }
+
+ ptr = Interop.Notification.Load(tag);
+
+ if (ptr == IntPtr.Zero)
+ {
+ NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+ Log.Error(Notification.LogTag, "unable to load Notification : " + ret.ToString());
+ if (ret == NotificationError.DbError)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the tag does not exist");
+ }
+ else
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to load Notification");
+ }
+ }
+
+ Notification notification = new Notification
+ {
+ Handle = new NotificationSafeHandle(ptr, true)
+ }.Build();
+
+ return notification;
+ }
+
+ /// <summary>
+ /// Saves a notification template to the notification database
+ /// </summary>
+ /// <param name="notification">Notification to save as template</param>
+ /// <param name="name">Template name</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when can't save as template</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ ///
+ /// Notification.Accessory accessory = new Notification.Accessory
+ /// {
+ /// LedOption = AccessoryOption.On,
+ /// VibrationOption = AccessoryOption.Custom,
+ /// VibrationPath = "vibration absolute path"
+ /// }
+ /// notification.setAccessory(accessory);
+ ///
+ /// // do something
+ ///
+ /// NotificationManager.Post(notification);
+ ///
+ /// Notification.LockStyle style = new Notification.LockStyle
+ /// {
+ /// IconPath = "icon path",
+ /// ThumbnailPath = "Thumbnail path"
+ /// }
+ /// notification.AddStyle(style);
+ /// NotificationManager.SaveTemplate(notification, "firstTemplate");
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static void SaveTemplate(Notification notification, string name)
+ {
+ if (notification == null || string.IsNullOrEmpty(name))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to save template");
+ }
+
+ notification.Make();
+
+ NotificationError ret = Interop.Notification.SaveTemplate(notification.Handle, name);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "save as template failed");
+ }
+ }
+
+ /// <summary>
+ /// Loads a notification template from the notification database
+ /// </summary>
+ /// <param name="name">Template name</param>
+ /// <returns>Notification Object with inputted template name</returns>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid or when no template with input name exists</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <example>
+ /// <code>
+ /// Notification notification = new Notification
+ /// {
+ /// Title = "title",
+ /// Content = "content",
+ /// Icon = "absolute icon path",
+ /// Tag = "first notification"
+ /// };
+ ///
+ /// Notification.Accessory accessory = new Notification.Accessory
+ /// {
+ /// LedOption = AccessoryOption.On,
+ /// VibrationOption = AccessoryOption.Custom,
+ /// VibrationPath = "vibration absolute path"
+ /// }
+ /// notification.setAccessory(accessory);
+ ///
+ /// // do something
+ ///
+ /// NotificationManager.Post(notification);
+ ///
+ /// Notification.LockStyle style = new Notification.LockStyle
+ /// {
+ /// IconPath = "icon path",
+ /// ThumbnailPath = "Thumbnail path"
+ /// }
+ /// notification.AddStyle(style);
+ /// NotificationManager.SaveTemplate(notification, "firstTemplate");
+ /// Notification notificationTemplate = NotificationManager.LoadTemplate("firstTemplate");
+ /// </code>
+ /// </example>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static Notification LoadTemplate(string name)
+ {
+ IntPtr handle = IntPtr.Zero;
+
+ if (string.IsNullOrEmpty(name))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to load template");
+ }
+
+ handle = Interop.Notification.LoadTemplate(name);
+ if (handle == IntPtr.Zero)
+ {
+ NotificationError ret = (NotificationError)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
+ if (ret == NotificationError.DbError)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "the name does not exist");
+ }
+ else
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to create Notification from template");
+ }
+ }
+
+ Notification notification = new Notification
+ {
+ Handle = new NotificationSafeHandle(handle, true)
+ }.Build();
+
+ return notification;
+ }
+
+ /// <summary>
+ /// Gets notification block state.
+ /// </summary>
+ /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
+ /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+ /// <remarks>
+ /// The user can set the notification block state in settings.
+ /// The block state indicates whether or not notifications can be posted.
+ /// Additionally only notifications to the notification panel are allowed in "Do not disturb mode".
+ /// Sound, Vibrate and Active notifications are blocked.
+ /// </remarks>
+ /// <returns>NotificationBlockState is state if notification is posted</returns>
+ /// <exception cref="InvalidOperationException">Thrown when no template with input name exists</exception>
+ /// <privilege>http://tizen.org/privilege/notification</privilege>
+ public static NotificationBlockState GetBlockState()
+ {
+ NotificationBlockState state;
+ NotificationError ret;
+
+ ret = Interop.Notification.GetBlockState(out state);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "GetBlockState failed");
+ }
+
+ Log.Info(Notification.LogTag, "Current block state is " + state.ToString());
+ return state;
+ }
+
+ /// <summary>
+ /// Method to get style you already added.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when argument is null</exception>
+ /// <param name="notification">Notification to make <see cref="NotificationSafeHandle"/>.</param>
+ /// <returns>
+ /// The Notification object
+ /// </returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static NotificationSafeHandle MakeNotificationSafeHandle(Notification notification)
+ {
+ if (notification == null)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid notification object");
+ }
+
+ notification.Make();
+
+ return notification.Handle;
+ }
+
+ /// <summary>
+ /// Method to get style you already added.
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when argument is null</exception>
+ /// <param name="handle">SafeHandle to make <see cref="Notification"/> Object</param>
+ /// <returns>
+ /// The Notification object
+ /// </returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static Notification MakeNotification(NotificationSafeHandle handle)
+ {
+ if (handle == null || handle.IsInvalid == true)
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "handle is invalid or null");
+ }
+
+ Notification notification = new Notification { Handle = handle }.Build();
+
+ return notification;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for displaying progress notification
+ /// You must initialize progress category, current, max value when you create object.
+ /// </summary>
+ public sealed class ProgressType : MakerBase
+ {
+ private double progressCurrent;
+ private double progressMax;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ProgressType"/> class.
+ /// You must initialize category, current, max value of progress.
+ /// </summary>
+ /// <param name="category">The category of progress that appeared on Notification</param>
+ /// <param name="current">The current value of the progress</param>
+ /// <param name="max">The max value of the progress</param>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public ProgressType(ProgressCategory category, double current, double max)
+ {
+ if (IsNegativeNumber(current))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The current must be a positive integer.");
+ }
+
+ if (IsNegativeNumber(max))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The max must be a positive integer.");
+ }
+
+ Category = category;
+ ProgressCurrent = current;
+ ProgressMax = max;
+ }
+
+ /// <summary>
+ /// Gets or sets category of ProgressType.
+ /// </summary>
+ /// <seealso cref="Tizen.Applications.Notifications.ProgressCategory"></seealso>
+ public ProgressCategory Category { get; set; }
+
+ /// <summary>
+ /// Gets or sets current value of ProgressType
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public double ProgressCurrent
+ {
+ get
+ {
+ return progressCurrent;
+ }
+
+ set
+ {
+ if (IsNegativeNumber(value))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
+ }
+
+ progressCurrent = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets max value of ProgressType
+ /// </summary>
+ /// <exception cref="ArgumentException">Thrown when argument is invalid</exception>
+ public double ProgressMax
+ {
+ get
+ {
+ return progressMax;
+ }
+
+ set
+ {
+ if (IsNegativeNumber(value))
+ {
+ throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "The value must be a positive integer.");
+ }
+
+ progressMax = value;
+ }
+ }
+
+ internal override void Make(Notification notification)
+ {
+ ProgressBinder.BindObject(notification);
+ }
+
+ private bool IsNegativeNumber(double number)
+ {
+ return number < 0;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ internal static class ProgressBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ double current, max;
+
+ Notification.ProgressType progress = notification.Progress;
+ Interop.Notification.SetProgressType(notification.Handle, progress.Category);
+
+ if (progress.Category == ProgressCategory.PendingBar)
+ {
+ current = 0;
+ max = 0;
+ }
+ else if (progress.Category == ProgressCategory.Percent)
+ {
+ current = progress.ProgressCurrent / 100;
+ max = progress.ProgressMax;
+ }
+ else
+ {
+ current = progress.ProgressCurrent;
+ max = progress.ProgressMax;
+ }
+
+ Interop.Notification.SetProgress(notification.Handle, current);
+ Interop.Notification.SetProgressSize(notification.Handle, max);
+ Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Progress);
+ Interop.Notification.SetOngoingFlag(notification.Handle, true);
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ NotificationLayout layout;
+ Interop.Notification.GetLayout(notification.Handle, out layout);
+
+ if (layout == NotificationLayout.Progress)
+ {
+ ProgressCategory category;
+ double current, max;
+
+ Interop.Notification.GetProgressType(notification.Handle, out category);
+ Interop.Notification.GetProgress(notification.Handle, out current);
+ Interop.Notification.GetProgressSize(notification.Handle, out max);
+
+ if (category == ProgressCategory.Percent)
+ {
+ current *= 100;
+ }
+
+ notification.Progress = new Notification.ProgressType(category, current, max);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// Class for displaying direct-reply at notification.
+ /// You must set a ReplyMax and Button. Otherwise user can't send written text to application which is set by AppControl.
+ /// </summary>
+ public sealed class ReplyAction : MakerBase
+ {
+ /// <summary>
+ /// Gets or sets the Index of Button which is appeared at Notification.
+ /// If you set ParentIndex, ReplyAction is displayed when button matched with ParentIndex click by the user.
+ /// If you don't set ParentIndex, appeared to notification directly.
+ /// </summary>
+ public ButtonIndex ParentIndex { get; set; } = ButtonIndex.None;
+
+ /// <summary>
+ /// Gets or sets the PlaceHolderText of ReplyAction which is appeared at Notification.
+ /// If you set PlaceHolderText, it is displayed to placeholder in notification.
+ /// </summary>
+ public string PlaceHolderText { get; set; }
+
+ /// <summary>
+ /// Gets or sets the ReplyMax of ReplyAction which is appeared at Notification.
+ /// You must set a ReplyMax. Otherwise user don't write text to placeholder in notification.
+ /// </summary>
+ /// <value>
+ /// Default value is 160.
+ /// </value>
+ public int ReplyMax { get; set; } = 160;
+
+ /// <summary>
+ /// Gets or sets the Button which is appeared to ReplyAction in Notification.
+ /// You must set a Button. Otherwise user can't send written text to application which is set by AppControl.
+ /// </summary>
+ /// <remarks>
+ /// If you set it to null, the already set ButtonAction will be removed.
+ /// </remarks>
+ /// <example>
+ /// <code>
+ /// ReplyAction button = new ReplyAction
+ /// {
+ /// ParentIndex = ButtonIndex.Second;
+ /// PlaceHolderText = "Please write your reply."
+ /// ReplyMax = 160,
+ /// Button = new ButtonAction
+ /// {
+ /// text = "Yes",
+ /// ImagePath = "image path",
+ /// Action = new AppControl{ ApplicationId = "org.tizen.app" };
+ /// };
+ /// };
+ /// </code>
+ /// </example>
+ public ButtonAction Button { get; set; }
+
+ internal override void Make(Notification notification)
+ {
+ string replyKey = "__PARENT_INDEX__";
+
+ if (Button != null)
+ {
+ Interop.Notification.SetText(notification.Handle, NotificationText.InputButton, Button.Text, null, -1);
+ Interop.Notification.SetImage(notification.Handle, NotificationImage.TextInputButton, Button.ImagePath);
+
+ if (this.Button.Action != null && this.Button.Action.SafeAppControlHandle.IsInvalid == false)
+ {
+ Interop.Notification.SetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, this.Button.Action.SafeAppControlHandle);
+
+ if (this.ParentIndex != ButtonIndex.None)
+ {
+ Interop.Notification.SetEventHandler(notification.Handle, (int)this.ParentIndex, this.Button.Action.SafeAppControlHandle);
+ }
+ }
+ }
+
+ Bundle bundle = new Bundle();
+ bundle.AddItem(replyKey, ((int)this.ParentIndex).ToString());
+ Interop.Notification.SetExtentionData(notification.Handle, replyKey, bundle.SafeBundleHandle);
+
+ Interop.Notification.SetPlaceHolderLength(notification.Handle, this.ReplyMax);
+ Interop.Notification.SetText(notification.Handle, NotificationText.PlaceHolder, PlaceHolderText, null, -1);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+ using System.ComponentModel;
+ using System.Runtime.InteropServices;
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class NotificationSafeHandle : SafeHandle
+ {
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public NotificationSafeHandle()
+ : base(IntPtr.Zero, true)
+ {
+ }
+
+ internal NotificationSafeHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
+ {
+ SetHandle(existingHandle);
+ }
+
+ /// <summary>
+ /// Gets a value that indicates whether the handle is invalid.
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool IsInvalid
+ {
+ get { return this.DangerousGetHandle() == IntPtr.Zero; }
+ }
+
+ protected override bool ReleaseHandle()
+ {
+ Interop.Notification.Destroy(this.handle);
+ this.SetHandle(IntPtr.Zero);
+ return true;
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.Notifications
+{
+ /// <summary>
+ /// Class containing common properties and methods of Notifications
+ /// </summary>
+ /// <remarks>
+ /// A notification is a message that is displayed on the notification area.
+ /// It is created to notify information to the user through the application.
+ /// This class helps you to provide method and property for creating notification object.
+ /// </remarks>
+ public sealed partial class Notification
+ {
+ /// <summary>
+ /// An object that can apply a rich notification style to a Notification object.
+ /// If the platform does not provide rich notification styles in this class have no effect.
+ /// </summary>
+ public abstract class StyleBase : MakerBase
+ {
+ internal abstract string Key { get; }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.Notifications
+{
+ using System;
+
+ internal static class IndicatorBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ int flag;
+ NotificationError ret = NotificationError.None;
+ Notification.IndicatorStyle style = (Notification.IndicatorStyle)notification.GetStyle("Indicator");
+
+ ret = Interop.Notification.SetText(notification.Handle, NotificationText.FirstMainText, style.SubText, null, -1);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set indicator text");
+ }
+
+ ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForIndicator, style.IconPath);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set indicator image");
+ }
+
+ Interop.Notification.GetApplist(notification.Handle, out flag);
+ Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Indicator | (int)NotificationDisplayApplist.Ticker);
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ int appList;
+ Interop.Notification.GetApplist(notification.Handle, out appList);
+ if ((appList & ((int)NotificationDisplayApplist.Ticker | (int)NotificationDisplayApplist.Indicator)) != 0)
+ {
+ string path, text;
+ Notification.IndicatorStyle indicator = new Notification.IndicatorStyle();
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForIndicator, out path);
+ indicator.IconPath = path;
+ Interop.Notification.GetText(notification.Handle, NotificationText.FirstMainText, out text);
+ indicator.SubText = text;
+
+ notification.AddStyle(indicator);
+ }
+ }
+ }
+
+ internal static class ActiveBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ int flag;
+ NotificationError ret = NotificationError.None;
+ Notification.ActiveStyle style = (Notification.ActiveStyle)notification.GetStyle("Active");
+
+ Interop.Notification.SetAutoRemove(notification.Handle, style.IsAutoRemove);
+ if (style.IsAutoRemove == true)
+ {
+ int hidetime;
+ int deletetime;
+ style.GetRemoveTime(out hidetime, out deletetime);
+
+ Interop.Notification.SetHideTime(notification.Handle, hidetime);
+ Interop.Notification.SetDeleteTime(notification.Handle, deletetime);
+ }
+
+ ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.Background, style?.BackgroundImage);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set background Image");
+ }
+
+ Interop.Notification.GetApplist(notification.Handle, out flag);
+ Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Active);
+
+ foreach (Notification.ButtonAction button in style.GetButtonAction())
+ {
+ button.Make(notification);
+ }
+
+ if (style.ReplyAction != null)
+ {
+ style.ReplyAction.Make(notification);
+ }
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ int appList;
+ Interop.Notification.GetApplist(notification.Handle, out appList);
+
+ if ((appList & (int)NotificationDisplayApplist.Active) != 0)
+ {
+ Notification.ActiveStyle active = new Notification.ActiveStyle();
+ bool isExisted = false;
+ bool autoRemove;
+ string path, text;
+ SafeAppControlHandle appcontrol = null;
+ string replyKey = "__PARENT_INDEX__";
+
+ for (int i = (int)ButtonIndex.First; i <= (int)ButtonIndex.Third; i++)
+ {
+ appcontrol = null;
+
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.FirstButton + i, out path);
+ Interop.Notification.GetText(notification.Handle, NotificationText.FirstButton + i, out text);
+ Interop.Notification.GetEventHandler(notification.Handle, i, out appcontrol);
+
+ if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
+ || (appcontrol != null && appcontrol.IsInvalid == false))
+ {
+ Notification.ButtonAction button = new Notification.ButtonAction();
+ if (appcontrol != null && appcontrol.IsInvalid == false)
+ {
+ button.Action = new AppControl(appcontrol);
+ }
+
+ button.ImagePath = path;
+ button.Text = text;
+ button.Index = (ButtonIndex)i;
+ active.AddButtonAction(button);
+ isExisted = true;
+ }
+ }
+
+ Interop.Notification.GetAutoRemove(notification.Handle, out autoRemove);
+ active.IsAutoRemove = autoRemove;
+ if (autoRemove)
+ {
+ int hidetime, deletetime;
+ Interop.Notification.GetHideTime(notification.Handle, out hidetime);
+ Interop.Notification.GetDeleteTime(notification.Handle, out deletetime);
+ active.SetRemoveTime(hidetime, deletetime);
+ }
+
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.Background, out path);
+ if (string.IsNullOrEmpty(path) == false)
+ {
+ isExisted = true;
+ active.BackgroundImage = path;
+ }
+
+ appcontrol = null;
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.TextInputButton, out path);
+ Interop.Notification.GetText(notification.Handle, NotificationText.InputButton, out text);
+ Interop.Notification.GetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, out appcontrol);
+
+ if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
+ || (appcontrol != null && appcontrol.IsInvalid == false))
+ {
+ Notification.ReplyAction reply = new Notification.ReplyAction();
+ Notification.ButtonAction button = new Notification.ButtonAction();
+ if (appcontrol != null && appcontrol.IsInvalid == false)
+ {
+ button.Action = new AppControl(appcontrol);
+ }
+
+ button.ImagePath = path;
+ button.Text = text;
+ reply.Button = button;
+
+ Interop.Notification.GetText(notification.Handle, NotificationText.PlaceHolder, out text);
+ reply.PlaceHolderText = text;
+
+ int holderLength;
+ Interop.Notification.GetPlaceHolderLength(notification.Handle, out holderLength);
+ reply.ReplyMax = holderLength;
+
+ isExisted = true;
+
+ try
+ {
+ SafeBundleHandle bundleHandle;
+ Interop.Notification.GetExtentionData(notification.Handle, replyKey, out bundleHandle);
+ Bundle bundle = new Bundle(bundleHandle);
+ reply.ParentIndex = (ButtonIndex)int.Parse(bundle.GetItem(replyKey).ToString());
+ }
+ catch (Exception ex)
+ {
+ Log.Error(Notification.LogTag, ex.ToString());
+ }
+
+ active.ReplyAction = reply;
+ }
+
+ if (isExisted)
+ {
+ notification.AddStyle(active);
+ }
+ }
+ }
+ }
+
+ internal static class LockBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ int flag;
+ NotificationError ret = NotificationError.None;
+ Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock");
+
+ ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set lock icon");
+ }
+
+ ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath);
+ if (ret != NotificationError.None)
+ {
+ throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail");
+ }
+
+ Interop.Notification.GetApplist(notification.Handle, out flag);
+ Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock);
+ }
+
+ internal static void BindSafehandle(Notification notification)
+ {
+ int applist;
+ Interop.Notification.GetApplist(notification.Handle, out applist);
+
+ if ((applist & (int)NotificationDisplayApplist.Lock) != 0)
+ {
+ string path;
+ Notification.LockStyle lockStyle = new Notification.LockStyle();
+
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForLock, out path);
+ lockStyle.IconPath = path;
+
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.ThumbnailForLock, out path);
+ lockStyle.ThumbnailPath = path;
+
+ notification.AddStyle(lockStyle);
+ }
+ }
+ }
+
+ internal static class BigPictureBinder
+ {
+ internal static void BindObject(Notification notification)
+ {
+ Notification.BigPictureStyle style = (Notification.BigPictureStyle)notification.GetStyle("BigPicture");
+
+ Interop.Notification.SetImage(notification.Handle, NotificationImage.BigPicture, style.ImagePath);
+ Interop.Notification.SetBigPictureSize(notification.Handle, style.ImageSize);
+ Interop.Notification.SetText(notification.Handle, NotificationText.BigPicture, style.Content, null, -1);
+ Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Extension);
+ }
+
+ internal static void BindSafeHandle(Notification notification)
+ {
+ NotificationLayout layout;
+
+ Interop.Notification.GetLayout(notification.Handle, out layout);
+ if (layout == NotificationLayout.Extension)
+ {
+ Notification.BigPictureStyle style = new Notification.BigPictureStyle();
+
+ string text;
+ Interop.Notification.GetImage(notification.Handle, NotificationImage.BigPicture, out text);
+ style.ImagePath = text;
+
+ int size;
+ Interop.Notification.GetBigPictureSize(notification.Handle, out size);
+ style.ImageSize = size;
+
+ Interop.Notification.GetText(notification.Handle, NotificationText.BigPicture, out text);
+ style.Content = text;
+
+ notification.AddStyle(style);
+ }
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2016 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;
-
-namespace Tizen.Applications.Notifications
-{
- /// <summary>
- /// Class for creating a simple event notification
- /// </summary>
- /// <example>
- /// <code>
- /// public class EventNotificationExample
- /// {
- /// /// ...
- /// EventNotification noti = new EventNotification();
- /// noti.EventCount = 2;
- /// noti.Title = "Unread Messages";
- /// NotificationManager.Post(noti);
- /// }
- /// </code>
- /// </example>
- public class EventNotification : Notification
- {
- /// <summary>
- /// Intializes instance of EventNotification class
- /// </summary>
- public EventNotification()
- {
- int ret;
-
- _handle = Interop.Notification.Create(NotificationType.Event);
- if (_handle.IsInvalid)
- {
- ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to create Event Notification");
- }
-
- ret = Interop.Notification.SetLayout(_handle, NotiLayout.SingleEvent);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set event layout");
- }
-
- NotificationType = NotificationType.Event;
- }
-
- internal EventNotification(Interop.Notification.SafeNotificationHandle handle)
- {
- _handle = handle;
-
- NotificationType = NotificationType.Event;
- }
-
- /// <summary>
- /// Sets and gets the event count to be displayed on a Notification.
- /// </summary>
- /// <value>
- /// EventCount is a numeric value which is displayed on a notification.
- /// For example, to show unread message count on a messenger notification event count can be set.
- /// </value>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.EventCount = 2;
- /// Log.Debug(LogTag, "Event Count: " + noti.EventCount);
- /// </code>
- /// </example>
- public int EventCount
- {
- get
- {
- IntPtr countPtr;
- string count;
- int cnt;
- int ret = Interop.Notification.GetText(_handle, NotiText.EventCount, out countPtr);
- if(ret != (int)NotificationError.None)
- {
- Log.Warn(_logTag, "unable to get event count");
- return 0;
- }
-
- if(countPtr == IntPtr.Zero)
- return 0;
-
- count = Marshal.PtrToStringAnsi(countPtr);
- if(Int32.TryParse(count, out cnt))
- {
- return cnt;
- }
- else
- {
- Log.Warn(_logTag, "unable to parse string");
- return 0;
- }
- }
- set
- {
- int ret;
- if(value <= 0)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid value for event count");
- }
-
- ret = Interop.Notification.SetText(_handle, NotiText.EventCount, value.ToString(), null, -1);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set event count");
- }
- }
- }
-
- /// <summary>
- /// Gets and sets TimeStamp. Defaults to 0 ms UTC i.e 1 Jan 1970.
- /// </summary>
- /// <value>
- /// Timestamp can be used to display a timestamp on a notification.
- /// For example, in a message received notification, Timestamp can be used to display the time of message reception.
- /// </value>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.Timestamp = DateTime.Now;
- /// Log.Debug(LogTag, "Timestamp: " + noti.Timestamp);
- /// </code>
- /// </example>
- public DateTime Timestamp
- {
- get
- {
- int time;
- int ret = Interop.Notification.GetTime(_handle, out time);
- if(ret != (int)NotificationError.None)
- {
- Log.Warn(_logTag, "unable to get timestamp");
- return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(0).ToLocalTime();
- }
-
- return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime();
- }
- set
- {
- int time = (int)value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
- int ret = Interop.Notification.SetTime(_handle, time);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set timestamp");
- }
- }
- }
-
- /// <summary>
- /// Method to add a button to an event notification
- /// </summary>
- /// <param name="index">Index of the Button to be added to notification</param>
- /// <param name="imagePath">Path of Button image</param>
- /// <param name="text">Text of button</param>
- /// <param name="appControl">App control to be invoke on button click</param>
- /// <remarks>
- /// AddButton method can be used to add 2 different types of buttons, one for positive response and one for negative.
- /// A button comprises of Image path for the button, Text for the button and an App control which is to be invoked on button click.
- /// </remarks>
- /// <example>
- /// <code>
- /// Application app = Application.Current;
- /// DirectoryInfo dir = app.DirectoryInfo;
- /// string imagePath = dir.Resource+"notification.png";
- /// string text = "Click";
- /// AppControl clickApp = new AppControl();
- /// clickApp.ApplicationId = "org.tizen.setting"; /// EventNotification noti = new EventNotification();
- /// noti.AddButton(ButtonIndex.Positive, imagePath, text, clickApp);
- /// </code>
- /// </example>
- public void AddButton(ButtonIndex index, string imagePath = "", string text = "", AppControl appControl = null)
- {
- int ret = Interop.Notification.SetImage(_handle, (NotiImage)((int)index + (int)NotiImage.PositiveButton), imagePath);
- if (ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "set button image path failed");
- }
-
- ret = Interop.Notification.SetText(_handle, (NotiText)((int)NotiText.PositiveButton + (int)index), text, null, -1);
- if (ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button text");
- }
-
- if(appControl != null)
- {
- ret = Interop.Notification.SetEventHandler(_handle, (int)index, appControl.SafeAppControlHandle);
- if (ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button event handler");
- }
- }
-
- ret = Interop.Notification.AddButton(_handle, (int)index + 1);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to add button");
- }
- }
-
- /// <summary>
- /// Method to remove a button from an event notification
- /// </summary>
- /// <param name="index">Index of button to be removed</param>
- /// <remarks>
- /// RemoveButton method can be used to remove a button which has been added to the notification.
- /// RemoveButton should only be called after a button has been added.
- /// </remarks>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.AddButton(ButtonIndex.Positive);
- /// /// ...
- /// noti.RemoveButton(ButtonIndex.Negative);
- /// </code>
- /// </example>
- public void RemoveButton(ButtonIndex index)
- {
- int ret = Interop.Notification.RemoveButton(_handle, (int)index + 1);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to remove button");
- }
-
- ret = Interop.Notification.SetImage(_handle, (NotiImage)((int)index + (int)NotiImage.PositiveButton), string.Empty);
- if (ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "set button image path failed");
- }
-
- ret = Interop.Notification.SetText(_handle, (NotiText)((int)NotiText.PositiveButton + (int)index), string.Empty, null, -1);
- if (ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set button text");
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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;
-
-namespace Tizen.Applications.Notifications
-{
- /// <summary>
- /// NotificationManager class to post, update, delete and get Notifications.
- /// </summary>
- public static class NotificationManager
- {
- /// <summary>
- /// Posts a new Notification.
- /// </summary>
- /// <param name="notification">Notification to post</param>
- /// <exception cref="ArgumentNullException">Thrown when argument is null</exception>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.Title = "Title";
- /// NotificationManager.Post(noti);
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- public static void Post(Notification notification)
- {
- if(notification == null)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
- }
-
- int ret = Interop.Notification.Post(notification._handle);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "post notification failed");
- }
- }
-
- /// <summary>
- /// Updates a posted Notification.
- /// </summary>
- /// <param name="notification">Notification to update</param>
- /// <exception cref="ArgumentNullException">Thrown when argument is null</exception>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.Title = "Title";
- /// NotificationManager.Post(noti);
- /// ...
- /// noti.Title = "New Title";
- /// NotificationManager.Update(noti);
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- /// <pre>
- /// Post method should be called on the Notification object.
- /// </pre>
- public static void Update(Notification notification)
- {
- if(notification == null)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
- }
-
- int ret = Interop.Notification.Update(notification._handle);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "update notification failed");
- }
- }
-
- /// <summary>
- /// Deletes a posted Notification.
- /// </summary>
- /// <param name="notification">Notification to remove</param>
- /// <exception cref="ArgumentNullException">Thrown when argument is null</exception>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// NotificationManager.Post(noti);
- /// ...
- /// NotificationManager.Delete(noti);
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- /// <pre>
- /// Post method should be called on the Notification object.
- /// </pre>
- public static void Delete(Notification notification)
- {
- if(notification == null)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "invalid argument to post method");
- }
-
- int ret = Interop.Notification.Delete(notification._handle);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "delete notification failed");
- }
- }
-
- /// <summary>
- /// Removes all posted Notification of NotificationType type of calling application.
- /// </summary>
- /// <param name="type">Type of Notifications to remove</param>
- /// <example>
- /// <code>
- /// EventNotification notiE = new EventNotification();
- /// NotificationManager.Post(notiE);
- /// NotificationManager.DeleteAll(NotificationType.Event);
- /// /// ...
- /// ProgressNotification notiP = new ProgressNotification();
- /// NotificationManager.Post(notiP);
- /// NotificationManager.DeleteAll(NotificationType.Progress);
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- public static void DeleteAll(NotificationType type)
- {
- int ret = Interop.Notification.DeleteAll((int)type);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "delete all notifications failed of type " + type);
- }
- }
-
- /// <summary>
- /// Removes all posted Notification of calling application.
- /// </summary>
- /// <example>
- /// <code>
- /// EventNotification notiE = new EventNotification();
- /// NotificationManager.Post(notiE);
- /// ProgressNotification notiP = new ProgressNotification();
- /// NotificationManager.Post(notiP);
- /// NotificationManager.DeleteAll();
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- public static void DeleteAll()
- {
- DeleteAll(NotificationType.Progress);
-
- DeleteAll(NotificationType.Event);
- }
-
- /// <summary>
- /// Searches for a posted notification which has the inputted tag
- /// </summary>
- /// <remarks>
- /// Load method should be called only for notifcations which have been posted using NotificationManager.Post method.
- /// If two or more notifications share the same tag, the notification posted most recently is returned.
- /// </remarks>
- /// <typeparam name="T">Type of notification to be queried</typeparam>
- /// <param name="tag">Tag used to query</param>
- /// <returns>Notification Object with inputted tag</returns>
- /// <exception cref="InvalidOperationException">Thrown when no notification with inputed tag exists</exception>
- /// <example>
- /// <code>
- /// EventNotification noti = new EventNotification();
- /// noti.Title = "Title";
- /// noti.Tag = "Hello";
- /// NotificationManager.Post(noti);
- /// /// ...
- /// EventNotification notiCopy = NotificationManager/<EventNotification/>("Hello");
- /// </code>
- /// </example>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- public static T Load<T>(string tag) where T : Notification
- {
- Notification result = null;
- Interop.Notification.SafeNotificationHandle handle = Interop.Notification.Load(tag);
- if(handle.IsInvalid)
- {
- int ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
-
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to load Notification");
- }
-
- result = CreateNotificationFromTag(handle);
-
- return (T)result;
- }
-
- internal static Notification CreateNotificationFromTag(Interop.Notification.SafeNotificationHandle handle)
- {
- Notification result = null;
- NotificationType type;
-
- int ret = Interop.Notification.GetType(handle, out type);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to get type");
- }
-
- if(type == NotificationType.Event)
- {
- result = (Notification)new EventNotification(handle);
- }
- else
- {
- result = (Notification)new ProgressNotification(handle);
- }
-
- return result;
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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;
-
-namespace Tizen.Applications.Notifications
-{
- /// <summary>
- /// Class for creating progress notifications
- /// </summary>
- public class ProgressNotification : Notification
- {
- /// <summary>
- /// Intializes instance of ProgressNotification class
- /// </summary>
- public ProgressNotification()
- {
- int ret;
-
- _handle = Interop.Notification.Create(NotificationType.Progress);
- if (_handle.IsInvalid)
- {
- ret = Tizen.Internals.Errors.ErrorFacts.GetLastResult();
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to create Progress Notification");
- }
-
- ret = Interop.Notification.SetLayout(_handle, NotiLayout.Progress);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set progress layout");
- }
-
- ret = Interop.Notification.SetProgressSize(_handle, 100.0);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "unable to set default progress size");
- }
-
- NotificationType = NotificationType.Progress;
- }
-
- internal ProgressNotification(Interop.Notification.SafeNotificationHandle handle)
- {
- _handle = handle;
-
- NotificationType = NotificationType.Progress;
- }
-
- /// <summary>
- /// Gets and sets maximum value for progress ticker. Defaults to 100.
- /// </summary>
- /// <value>
- /// Maximum should not be less than 0.
- /// </value>
- /// <example>
- /// <code>
- /// ProgressNotification noti = new ProgressNotification();
- /// noti.Maximum = 200;
- /// Log.Debug(LogTag, "Maximum: " + noti.Maximum);
- /// </code>
- /// </example>
- /// <exception cref="ArgumentException">Thrown when value of Maximum being set is less than 0</exception>
- public double Maximum
- {
- get
- {
- double size;
- int ret = Interop.Notification.GetProgressSize(_handle, out size);
- if(ret != (int)NotificationError.None)
- {
- Log.Warn(_logTag, "get progress size failed");
- return 100.0;
- }
-
- return size;
- }
- set
- {
- if(value < 0)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "wrong value for progress size");
- }
-
- int ret = Interop.Notification.SetProgressSize(_handle, value);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "set progress size failed");
- }
- }
- }
-
- /// <summary>
- /// gets and sets current progress value for ticker. Defaults to 0.
- /// </summary>
- /// <value>
- /// ProgressValue should not be less than 0 or greater than Maximum.
- /// </value>
- /// <example>
- /// <code>
- /// ProgressNotification noti = new ProgressNotification();
- /// noti.Maximum = 200;
- /// noti.ProgressValue = 100;
- /// Log.Debug(LogTag, "Progress Value: " + noti.ProgressValue);
- /// </code>
- /// </example>
- /// <exception cref="ArgumentException">Thrown when value of ProgressValue being set is less than 0 or greater than value of Maximum</exception>
- public double ProgressValue
- {
- get
- {
- double size;
- int ret = Interop.Notification.GetProgress(_handle, out size);
- if(ret != (int)NotificationError.None)
- {
- Log.Warn(_logTag, "get progress failed");
- return 0;
- }
-
- return size;
- }
- set
- {
- if(value < 0 || value > Maximum)
- {
- throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "wrong value for progress value");
- }
-
- int ret = Interop.Notification.SetProgress(_handle, value);
- if(ret != (int)NotificationError.None)
- {
- throw NotificationErrorFactory.GetException((NotificationError)ret, "set progress failed");
- }
- }
- }
- }
-}