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.HiddenByUserAction.SafeAppControlHandle);
131 if (style.HiddenByExternalAction != null)
133 Interop.Notification.SetExtensionAction(notification.Handle, NotificationEventType.HiddenByExternal, style.HiddenByUserAction.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();
145 bool isExisted = false;
148 SafeAppControlHandle appcontrol = null;
149 string replyKey = "__PARENT_INDEX__";
151 for (int i = (int)ButtonIndex.First; i <= (int)ButtonIndex.Third; i++)
155 Interop.Notification.GetImage(notification.Handle, NotificationImage.FirstButton + i, out path);
156 Interop.Notification.GetText(notification.Handle, NotificationText.FirstButton + i, out text);
157 Interop.Notification.GetEventHandler(notification.Handle, i, out appcontrol);
159 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
160 || (appcontrol != null && appcontrol.IsInvalid == false))
162 Notification.ButtonAction button = new Notification.ButtonAction();
163 if (appcontrol != null && appcontrol.IsInvalid == false)
165 button.Action = new AppControl(appcontrol);
168 button.ImagePath = path;
170 button.Index = (ButtonIndex)i;
171 active.AddButtonAction(button);
177 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByUser, out appcontrol);
178 if (appcontrol != null)
180 active.HiddenByUserAction = new AppControl(appcontrol);
184 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByTimeout, out appcontrol);
185 if (appcontrol != null)
187 active.HiddenByTimeoutAction = new AppControl(appcontrol);
191 Interop.Notification.GetExtensionAction(notification.Handle, NotificationEventType.HiddenByExternal, out appcontrol);
192 if (appcontrol != null)
194 active.HiddenByExternalAction = new AppControl(appcontrol);
197 Interop.Notification.GetAutoRemove(notification.Handle, out autoRemove);
198 active.IsAutoRemove = autoRemove;
201 int hidetime, deletetime;
202 Interop.Notification.GetHideTime(notification.Handle, out hidetime);
205 Interop.Notification.GetDeleteTime(notification.Handle, out deletetime);
207 catch (TypeLoadException)
209 // To support in API version 3.0
213 active.SetRemoveTime(hidetime, deletetime);
216 Interop.Notification.GetImage(notification.Handle, NotificationImage.Background, out path);
217 if (string.IsNullOrEmpty(path) == false)
220 active.BackgroundImage = path;
224 Interop.Notification.GetDefaultButton(notification.Handle, out defaultIndex);
225 active.DefaultButton = (ButtonIndex)(defaultIndex - 1);
228 Interop.Notification.GetImage(notification.Handle, NotificationImage.TextInputButton, out path);
229 Interop.Notification.GetText(notification.Handle, NotificationText.InputButton, out text);
230 Interop.Notification.GetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, out appcontrol);
232 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
233 || (appcontrol != null && appcontrol.IsInvalid == false))
235 Notification.ReplyAction reply = new Notification.ReplyAction();
236 Notification.ButtonAction button = new Notification.ButtonAction();
237 if (appcontrol != null && appcontrol.IsInvalid == false)
239 button.Action = new AppControl(appcontrol);
242 button.ImagePath = path;
244 reply.Button = button;
246 Interop.Notification.GetText(notification.Handle, NotificationText.PlaceHolder, out text);
247 reply.PlaceHolderText = text;
250 Interop.Notification.GetPlaceHolderLength(notification.Handle, out holderLength);
251 reply.ReplyMax = holderLength;
257 SafeBundleHandle bundleHandle;
258 Interop.Notification.GetExtentionData(notification.Handle, replyKey, out bundleHandle);
259 Bundle bundle = new Bundle(bundleHandle);
260 reply.ParentIndex = (ButtonIndex)int.Parse(bundle.GetItem(replyKey).ToString());
264 Log.Error(Notification.LogTag, ex.ToString());
267 active.ReplyAction = reply;
272 notification.AddStyle(active);
278 internal static class LockBinder
280 internal static void BindObject(Notification notification)
283 NotificationError ret = NotificationError.None;
284 Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock");
286 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath);
287 if (ret != NotificationError.None)
289 throw NotificationErrorFactory.GetException(ret, "unable to set lock icon");
292 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath);
293 if (ret != NotificationError.None)
295 throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail");
298 Interop.Notification.GetApplist(notification.Handle, out flag);
299 Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock);
302 internal static void BindSafehandle(Notification notification)
305 Interop.Notification.GetApplist(notification.Handle, out applist);
307 if ((applist & (int)NotificationDisplayApplist.Lock) != 0)
310 Notification.LockStyle lockStyle = new Notification.LockStyle();
312 Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForLock, out path);
313 lockStyle.IconPath = path;
315 Interop.Notification.GetImage(notification.Handle, NotificationImage.ThumbnailForLock, out path);
316 lockStyle.ThumbnailPath = path;
318 notification.AddStyle(lockStyle);