2 * Copyright (c) 2018 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 using System.Collections.Generic;
20 namespace Tizen.Applications.WatchfaceComplication
23 /// Represents the Complication data class.
25 /// <since_tizen> 6 </since_tizen>
26 public abstract class ComplicationData
28 private long _timestamp;
29 private string _imagePath;
30 private double _currentValue;
31 private double _minValue;
32 private double _maxValue;
33 private string _iconPath;
34 private string _longText;
35 private string _shortText;
36 private string _extraData;
37 private string _screenReaderText;
38 private string _title;
39 private ComplicationTypes _type;
40 private const string LogTag = "WatchfaceComplication";
42 internal string ShortText
54 internal string LongText
66 internal string IconPath
78 internal string ImagePath
102 internal string ExtraData
114 internal string ScreenReaderText
118 return _screenReaderText;
122 _screenReaderText = value;
126 internal long Timestamp
138 internal double RangeCurrent
142 return _currentValue;
146 _currentValue = value;
150 internal double RangeMin
162 internal double RangeMax
174 internal ComplicationTypes Type
186 private bool IsDataValid(IntPtr sharedData)
188 bool isValid = false;
189 ComplicationError err = Interop.WatchfaceComplication.ProviderSharedDataIsValid(sharedData, out isValid);
190 if (err != ComplicationError.None)
191 ErrorFactory.ThrowException(err, "fail to check shared data validation");
195 internal ComplicationError UpdateSharedData(IntPtr sharedData)
197 ComplicationError err = ComplicationError.None;
200 case ComplicationTypes.ShortText:
201 err = Interop.WatchfaceComplication.ProviderSetShortText(sharedData, _shortText);
202 Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath);
203 Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title);
204 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
206 case ComplicationTypes.LongText:
207 err = Interop.WatchfaceComplication.ProviderSetLongText(sharedData, _longText);
208 Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath);
209 Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title);
210 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
212 case ComplicationTypes.RangedValue:
213 Interop.WatchfaceComplication.ProviderSetLongText(sharedData, _shortText);
214 Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath);
215 Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title);
216 err = Interop.WatchfaceComplication.ProviderSetRangedValue(sharedData, _currentValue, _minValue, _maxValue);
217 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
219 case ComplicationTypes.Time:
220 err = Interop.WatchfaceComplication.ProviderSetTimestamp(sharedData, _timestamp);
221 Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath);
222 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
224 case ComplicationTypes.Icon:
225 err = Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath);
226 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
228 case ComplicationTypes.Image:
229 err = Interop.WatchfaceComplication.ProviderSetImagePath(sharedData, _imagePath);
230 Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData);
233 Interop.WatchfaceComplication.ProviderSetScreenReaderText(sharedData, _screenReaderText);
236 if (!IsDataValid(sharedData))
237 return ComplicationError.IO;
241 Log.Error(LogTag, "valid check fail : " + ex);
242 return ComplicationError.IO;