Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Notification / Tizen.Applications.Notifications / NotificationProgressBinder.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 namespace Tizen.Applications.Notifications
18 {
19     internal static class ProgressBinder
20     {
21         internal static void BindObject(Notification notification)
22         {
23             double current, max;
24
25             Notification.ProgressType progress = notification.Progress;
26
27             if (progress.Category == ProgressCategory.PendingBar)
28             {
29                 Interop.Notification.SetProgressType(notification.Handle, ProgressCategory.Percent);
30                 current = 0;
31                 max = 0;
32             }
33             else if (progress.Category == ProgressCategory.Percent)
34             {
35                 Interop.Notification.SetProgressType(notification.Handle, progress.Category);
36                 current = progress.ProgressCurrent / 100;
37                 max = progress.ProgressMax;
38             }
39             else
40             {
41                 Interop.Notification.SetProgressType(notification.Handle, progress.Category);
42                 current = progress.ProgressCurrent;
43                 max = progress.ProgressMax;
44             }
45
46             Interop.Notification.SetProgress(notification.Handle, current);
47             Interop.Notification.SetProgressSize(notification.Handle, max);
48             Interop.Notification.SetLayout(notification.Handle, NotificationLayout.Progress);
49             Interop.Notification.SetOngoingFlag(notification.Handle, true);
50         }
51
52         internal static void BindSafeHandle(Notification notification)
53         {
54             NotificationLayout layout;
55             Interop.Notification.GetLayout(notification.Handle, out layout);
56
57             if (layout == NotificationLayout.Progress)
58             {
59                 ProgressCategory category;
60                 double current, max;
61
62                 Interop.Notification.GetProgressType(notification.Handle, out category);
63                 Interop.Notification.GetProgress(notification.Handle, out current);
64                 Interop.Notification.GetProgressSize(notification.Handle, out max);
65
66                 if (category == ProgressCategory.Percent)
67                 {
68                     current *= 100;
69                 }
70
71                 notification.Progress = new Notification.ProgressType(category, current, max);
72             }
73         }
74     }
75 }