2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 namespace Tizen.Applications.Notifications
21 internal static class AccessorySetBinder
23 internal static void BindObject(Notification notification)
25 BindLedToHandle(notification);
26 BindSoundToHandle(notification);
27 BindVibrationToHandle(notification);
30 internal static void BindSafeHandle(Notification notification)
32 Notification.AccessorySet accessory = new Notification.AccessorySet();
33 BindHandleToLed(notification, accessory);
34 BindHandleToSound(notification, accessory);
35 BindHandleToVibration(notification, accessory);
36 notification.Accessory = accessory;
39 private static void BindLedToHandle(Notification notification)
41 NotificationError ret = NotificationError.None;
42 Notification.AccessorySet accessory = notification.Accessory;
44 ret = Interop.Notification.SetLed(notification.Handle, accessory.LedOption, 0);
45 if (ret != NotificationError.None)
47 throw NotificationErrorFactory.GetException(ret, "unable to set led");
50 ret = Interop.Notification.SetLedTimePeriod(notification.Handle, accessory.LedOnMillisecond, accessory.LedOffMillisecond);
51 if (ret != NotificationError.None)
53 throw NotificationErrorFactory.GetException(ret, "unable to set led period");
56 if (notification.Accessory.LedOption == AccessoryOption.Custom)
58 Color color = accessory.LedColor;
59 ret = Interop.Notification.SetLed(notification.Handle, AccessoryOption.Custom, color.GetArgb());
60 if (ret != NotificationError.None)
62 throw NotificationErrorFactory.GetException(ret, "unable to set led color");
67 private static void BindVibrationToHandle(Notification notification)
69 Notification.AccessorySet accessory = notification.Accessory;
70 if (accessory.CanVibrate == false)
72 Interop.Notification.SetVibration(notification.Handle, AccessoryOption.Off, null);
76 Interop.Notification.SetVibration(notification.Handle, AccessoryOption.On, null);
80 private static void BindSoundToHandle(Notification notification)
82 Notification.AccessorySet accessory = notification.Accessory;
84 if (accessory.SoundOption == AccessoryOption.Custom && string.IsNullOrEmpty(accessory.SoundPath))
86 throw NotificationErrorFactory.GetException(NotificationError.InvalidParameter, "If the option is set to Custom, the path must also be set.");
89 NotificationError ret = Interop.Notification.SetSound(notification.Handle, accessory.SoundOption, accessory.SoundPath);
90 if (ret != NotificationError.None)
92 throw NotificationErrorFactory.GetException(ret, "unable to set sound");
96 private static void BindHandleToLed(Notification notification, Notification.AccessorySet accessory)
100 Interop.Notification.GetLed(notification.Handle, out type, out argb);
102 accessory.LedOption = type;
103 if (type == AccessoryOption.Custom)
105 accessory.LedColor = new Color(argb >> 16 & 255, argb >> 8 & 255, argb >> 0 & 255, argb >> 24 & 255);
108 int onMillisecond, offMillisecond;
109 Interop.Notification.GetLedTimePeriod(notification.Handle, out onMillisecond, out offMillisecond);
110 accessory.LedOnMillisecond = onMillisecond;
111 accessory.LedOffMillisecond = offMillisecond;
114 private static void BindHandleToSound(Notification notification, Notification.AccessorySet accessory)
116 AccessoryOption type;
119 Interop.Notification.GetSound(notification.Handle, out type, out path);
121 accessory.SoundOption = type;
122 if (type == AccessoryOption.Custom)
124 accessory.SoundPath = path;
128 private static void BindHandleToVibration(Notification notification, Notification.AccessorySet accessory)
130 AccessoryOption type;
133 Interop.Notification.GetVibration(notification.Handle, out type, out path);
134 if (type == AccessoryOption.Off)
136 accessory.CanVibrate = false;
140 accessory.CanVibrate = true;