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 IndicatorBinder
23 internal static void BindObject(Notification notification)
26 NotificationError ret = NotificationError.None;
27 Notification.IndicatorStyle style = (Notification.IndicatorStyle)notification.GetStyle("Indicator");
28 Interop.Notification.GetApplist(notification.Handle, out flag);
30 if (string.IsNullOrEmpty(style.SubText) == false)
32 ret = Interop.Notification.SetText(notification.Handle, NotificationText.FirstMainText, style.SubText, null, -1);
33 if (ret != NotificationError.None)
35 throw NotificationErrorFactory.GetException(ret, "unable to set indicator text");
37 flag |= (int)NotificationDisplayApplist.Ticker;
40 if (string.IsNullOrEmpty(style.IconPath) == false)
42 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForIndicator, style.IconPath);
43 if (ret != NotificationError.None)
45 throw NotificationErrorFactory.GetException(ret, "unable to set indicator image");
47 flag |= (int)NotificationDisplayApplist.Indicator;
49 Interop.Notification.SetApplist(notification.Handle, flag);
52 internal static void BindSafeHandle(Notification notification)
55 Interop.Notification.GetApplist(notification.Handle, out appList);
56 if ((appList & (int)NotificationDisplayApplist.Ticker) != 0 || (appList & (int)NotificationDisplayApplist.Indicator) != 0)
59 Notification.IndicatorStyle indicator = new Notification.IndicatorStyle();
60 Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForIndicator, out path);
61 indicator.IconPath = path;
62 Interop.Notification.GetText(notification.Handle, NotificationText.FirstMainText, out text);
63 indicator.SubText = text;
65 notification.AddStyle(indicator);
70 internal static class ActiveBinder
72 internal static void BindObject(Notification notification)
75 NotificationError ret = NotificationError.None;
76 Notification.ActiveStyle style = (Notification.ActiveStyle)notification.GetStyle("Active");
78 Interop.Notification.SetAutoRemove(notification.Handle, style.IsAutoRemove);
79 if (style.IsAutoRemove == true)
83 style.GetRemoveTime(out hidetime, out deletetime);
85 Interop.Notification.SetHideTime(notification.Handle, hidetime);
88 Interop.Notification.SetDeleteTime(notification.Handle, deletetime);
90 catch (TypeLoadException)
92 // To support in API version 3.0
93 style.SetRemoveTime(hidetime, 60);
97 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.Background, style?.BackgroundImage);
98 if (ret != NotificationError.None)
100 throw NotificationErrorFactory.GetException(ret, "unable to set background Image");
103 if (style.DefaultButton != ButtonIndex.None)
105 Interop.Notification.SetDefaultButton(notification.Handle, (int)style.DefaultButton + 1);
108 Interop.Notification.GetApplist(notification.Handle, out flag);
109 Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Active);
111 foreach (Notification.ButtonAction button in style.GetButtonAction())
113 button.Make(notification);
116 if (style.ReplyAction != null)
118 style.ReplyAction.Make(notification);
121 if (style.HiddenByUserAction != null)
123 Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByUser, style.HiddenByUserAction.SafeAppControlHandle);
126 if (style.HiddenByTimeoutAction != null)
128 Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByTimeout, style.HiddenByTimeoutAction.SafeAppControlHandle);
131 if (style.HiddenByExternalAction != null)
133 Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByExternal, style.HiddenByExternalAction.SafeAppControlHandle);
137 internal static void BindSafeHandle(Notification notification)
140 Interop.Notification.GetApplist(notification.Handle, out appList);
142 if ((appList & (int)NotificationDisplayApplist.Active) != 0)
144 Notification.ActiveStyle active = new Notification.ActiveStyle();
147 SafeAppControlHandle appcontrol = null;
148 string replyKey = "__PARENT_INDEX__";
150 for (int i = (int)ButtonIndex.First; i <= (int)ButtonIndex.Third; i++)
154 Interop.Notification.GetImage(notification.Handle, NotificationImage.FirstButton + i, out path);
155 Interop.Notification.GetText(notification.Handle, NotificationText.FirstButton + i, out text);
156 Interop.Notification.GetEventHandler(notification.Handle, i, out appcontrol);
158 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
159 || (appcontrol != null && appcontrol.IsInvalid == false))
161 Notification.ButtonAction button = new Notification.ButtonAction();
162 if (appcontrol != null && appcontrol.IsInvalid == false)
164 button.Action = new AppControl(appcontrol);
167 button.ImagePath = path;
169 button.Index = (ButtonIndex)i;
170 active.AddButtonAction(button);
175 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByUser, out appcontrol);
176 if (appcontrol != null && appcontrol.IsInvalid == false)
178 active.HiddenByUserAction = new AppControl(appcontrol);
182 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByTimeout, out appcontrol);
183 if (appcontrol != null && appcontrol.IsInvalid == false)
185 active.HiddenByTimeoutAction = new AppControl(appcontrol);
189 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByExternal, out appcontrol);
190 if (appcontrol != null && appcontrol.IsInvalid == false)
192 active.HiddenByExternalAction = new AppControl(appcontrol);
195 Interop.Notification.GetAutoRemove(notification.Handle, out autoRemove);
196 active.IsAutoRemove = autoRemove;
199 int hidetime, deletetime;
200 Interop.Notification.GetHideTime(notification.Handle, out hidetime);
203 Interop.Notification.GetDeleteTime(notification.Handle, out deletetime);
205 catch (TypeLoadException)
207 // To support in API version 3.0
211 active.SetRemoveTime(hidetime, deletetime);
214 Interop.Notification.GetImage(notification.Handle, NotificationImage.Background, out path);
215 if (string.IsNullOrEmpty(path) == false)
217 active.BackgroundImage = path;
221 Interop.Notification.GetDefaultButton(notification.Handle, out defaultIndex);
222 active.DefaultButton = (ButtonIndex)(defaultIndex - 1);
225 Interop.Notification.GetImage(notification.Handle, NotificationImage.TextInputButton, out path);
226 Interop.Notification.GetText(notification.Handle, NotificationText.InputButton, out text);
227 Interop.Notification.GetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, out appcontrol);
229 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
230 || (appcontrol != null && appcontrol.IsInvalid == false))
232 Notification.ReplyAction reply = new Notification.ReplyAction();
233 Notification.ButtonAction button = new Notification.ButtonAction();
234 if (appcontrol != null && appcontrol.IsInvalid == false)
236 button.Action = new AppControl(appcontrol);
239 button.ImagePath = path;
241 reply.Button = button;
243 Interop.Notification.GetText(notification.Handle, NotificationText.PlaceHolder, out text);
244 reply.PlaceHolderText = text;
247 Interop.Notification.GetPlaceHolderLength(notification.Handle, out holderLength);
248 reply.ReplyMax = holderLength;
252 SafeBundleHandle bundleHandle;
253 Interop.Notification.GetExtensionData(notification.Handle, replyKey, out bundleHandle);
254 Bundle bundle = new Bundle(bundleHandle);
255 reply.ParentIndex = (ButtonIndex)int.Parse(bundle.GetItem(replyKey).ToString());
259 Log.Error(Notification.LogTag, ex.ToString());
262 active.ReplyAction = reply;
265 notification.AddStyle(active);
270 internal static class LockBinder
272 internal static void BindObject(Notification notification)
275 NotificationError ret = NotificationError.None;
276 Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock");
278 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath);
279 if (ret != NotificationError.None)
281 throw NotificationErrorFactory.GetException(ret, "unable to set lock icon");
284 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath);
285 if (ret != NotificationError.None)
287 throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail");
290 Interop.Notification.GetApplist(notification.Handle, out flag);
291 Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock);
294 internal static void BindSafehandle(Notification notification)
297 Interop.Notification.GetApplist(notification.Handle, out applist);
299 if ((applist & (int)NotificationDisplayApplist.Lock) != 0)
302 Notification.LockStyle lockStyle = new Notification.LockStyle();
304 Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForLock, out path);
305 lockStyle.IconPath = path;
307 Interop.Notification.GetImage(notification.Handle, NotificationImage.ThumbnailForLock, out path);
308 lockStyle.ThumbnailPath = path;
310 notification.AddStyle(lockStyle);