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);
122 internal static void BindSafeHandle(Notification notification)
125 Interop.Notification.GetApplist(notification.Handle, out appList);
127 if ((appList & (int)NotificationDisplayApplist.Active) != 0)
129 Notification.ActiveStyle active = new Notification.ActiveStyle();
130 bool isExisted = false;
133 SafeAppControlHandle appcontrol = null;
134 string replyKey = "__PARENT_INDEX__";
136 for (int i = (int)ButtonIndex.First; i <= (int)ButtonIndex.Third; i++)
140 Interop.Notification.GetImage(notification.Handle, NotificationImage.FirstButton + i, out path);
141 Interop.Notification.GetText(notification.Handle, NotificationText.FirstButton + i, out text);
142 Interop.Notification.GetEventHandler(notification.Handle, i, out appcontrol);
144 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
145 || (appcontrol != null && appcontrol.IsInvalid == false))
147 Notification.ButtonAction button = new Notification.ButtonAction();
148 if (appcontrol != null && appcontrol.IsInvalid == false)
150 button.Action = new AppControl(appcontrol);
153 button.ImagePath = path;
155 button.Index = (ButtonIndex)i;
156 active.AddButtonAction(button);
161 Interop.Notification.GetAutoRemove(notification.Handle, out autoRemove);
162 active.IsAutoRemove = autoRemove;
165 int hidetime, deletetime;
166 Interop.Notification.GetHideTime(notification.Handle, out hidetime);
169 Interop.Notification.GetDeleteTime(notification.Handle, out deletetime);
171 catch (TypeLoadException)
173 // To support in API version 3.0
177 active.SetRemoveTime(hidetime, deletetime);
180 Interop.Notification.GetImage(notification.Handle, NotificationImage.Background, out path);
181 if (string.IsNullOrEmpty(path) == false)
184 active.BackgroundImage = path;
188 Interop.Notification.GetDefaultButton(notification.Handle, out defaultIndex);
189 active.DefaultButton = (ButtonIndex)(defaultIndex - 1);
192 Interop.Notification.GetImage(notification.Handle, NotificationImage.TextInputButton, out path);
193 Interop.Notification.GetText(notification.Handle, NotificationText.InputButton, out text);
194 Interop.Notification.GetEventHandler(notification.Handle, (int)NotificationEventType.ClickOnTextInputButton, out appcontrol);
196 if (string.IsNullOrEmpty(path) == false || string.IsNullOrEmpty(text) == false
197 || (appcontrol != null && appcontrol.IsInvalid == false))
199 Notification.ReplyAction reply = new Notification.ReplyAction();
200 Notification.ButtonAction button = new Notification.ButtonAction();
201 if (appcontrol != null && appcontrol.IsInvalid == false)
203 button.Action = new AppControl(appcontrol);
206 button.ImagePath = path;
208 reply.Button = button;
210 Interop.Notification.GetText(notification.Handle, NotificationText.PlaceHolder, out text);
211 reply.PlaceHolderText = text;
214 Interop.Notification.GetPlaceHolderLength(notification.Handle, out holderLength);
215 reply.ReplyMax = holderLength;
221 SafeBundleHandle bundleHandle;
222 Interop.Notification.GetExtentionData(notification.Handle, replyKey, out bundleHandle);
223 Bundle bundle = new Bundle(bundleHandle);
224 reply.ParentIndex = (ButtonIndex)int.Parse(bundle.GetItem(replyKey).ToString());
228 Log.Error(Notification.LogTag, ex.ToString());
231 active.ReplyAction = reply;
236 notification.AddStyle(active);
242 internal static class LockBinder
244 internal static void BindObject(Notification notification)
247 NotificationError ret = NotificationError.None;
248 Notification.LockStyle style = (Notification.LockStyle)notification.GetStyle("Lock");
250 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.IconForLock, style.IconPath);
251 if (ret != NotificationError.None)
253 throw NotificationErrorFactory.GetException(ret, "unable to set lock icon");
256 ret = Interop.Notification.SetImage(notification.Handle, NotificationImage.ThumbnailForLock, style.ThumbnailPath);
257 if (ret != NotificationError.None)
259 throw NotificationErrorFactory.GetException(ret, "unable to set lock thumbnail");
262 Interop.Notification.GetApplist(notification.Handle, out flag);
263 Interop.Notification.SetApplist(notification.Handle, flag | (int)NotificationDisplayApplist.Lock);
266 internal static void BindSafehandle(Notification notification)
269 Interop.Notification.GetApplist(notification.Handle, out applist);
271 if ((applist & (int)NotificationDisplayApplist.Lock) != 0)
274 Notification.LockStyle lockStyle = new Notification.LockStyle();
276 Interop.Notification.GetImage(notification.Handle, NotificationImage.IconForLock, out path);
277 lockStyle.IconPath = path;
279 Interop.Notification.GetImage(notification.Handle, NotificationImage.ThumbnailForLock, out path);
280 lockStyle.ThumbnailPath = path;
282 notification.AddStyle(lockStyle);