private void EditableUpdatedCallback(IntPtr handle, int selectedIdx, int state, IntPtr userData) { int editableId; ComplicationError err = Interop.WatchfaceComplication.GetEditableId(handle, out editableId); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to get current index"); } int currentIdx; err = Interop.WatchfaceComplication.GetCurrentIdx(handle, out currentIdx); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to get current index"); } DesignElement de = GetDesignElement(editableId); if (de != null) { de.SetCurrentDataIndex(currentIdx); de.NotifyUpdate(currentIdx, (State)state); } }
internal ComplicationError UpdateSharedData(IntPtr sharedData) { ComplicationError err = ComplicationError.None; switch (_type) { case ComplicationTypes.ShortText: err = Interop.WatchfaceComplication.ProviderSetShortText(sharedData, _shortText); Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath); Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; case ComplicationTypes.LongText: err = Interop.WatchfaceComplication.ProviderSetLongText(sharedData, _longText); Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath); Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; case ComplicationTypes.RangedValue: Interop.WatchfaceComplication.ProviderSetLongText(sharedData, _shortText); Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath); Interop.WatchfaceComplication.ProviderSetTitle(sharedData, _title); err = Interop.WatchfaceComplication.ProviderSetRangedValue(sharedData, _currentValue, _minValue, _maxValue); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; case ComplicationTypes.Time: err = Interop.WatchfaceComplication.ProviderSetTimestamp(sharedData, _timestamp); Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; case ComplicationTypes.Icon: err = Interop.WatchfaceComplication.ProviderSetIconPath(sharedData, _iconPath); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; case ComplicationTypes.Image: err = Interop.WatchfaceComplication.ProviderSetImagePath(sharedData, _imagePath); Interop.WatchfaceComplication.ProviderSetExtraData(sharedData, _extraData); break; } Interop.WatchfaceComplication.ProviderSetScreenReaderText(sharedData, _screenReaderText); try { if (!IsDataValid(sharedData)) { return(ComplicationError.IO); } } catch (Exception ex) { Log.Error(LogTag, "valid check fail : " + ex); return(ComplicationError.IO); } return(err); }
/// <summary> /// Emits the update event for complications. /// </summary> /// <privilege>http://tizen.org/privilege/datasharing</privilege> /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <since_tizen> 6 </since_tizen> public void NotifyUpdate() { ComplicationError err = Interop.WatchfaceComplication.NotifyUpdate(_providerId); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to notify"); } }
/// <summary> /// Replies the setup context to the editor /// </summary> /// <param name="recvAppCtrl">The received appcontrol.</param> /// <param name="context">The context created by complication setup app.</param> /// <privilege>http://tizen.org/privilege/datasharing</privilege> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl)) /// { /// Bundle context = ComplicationProviderSetup.GetContext(e.ReceivedAppControl); /// context.AddItem("TEST_KEY", "NEW CONTEXT"); /// ComplicationProviderSetup.ReplyToEditor(e.ReceivedAppControl, context); /// } /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>Event target complication type</returns> /// <since_tizen> 6 </since_tizen> public static void ReplyToEditor(ReceivedAppControl recvAppCtrl, Bundle context) { ComplicationError err = Interop.WatchfaceComplication.SetupReplyToEditor(recvAppCtrl.SafeAppControlHandle, context.SafeBundleHandle); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to check editing"); } }
/// <summary> /// Initializes the ComplicationProvider class. /// </summary> /// <param name="providerId">The id of the complication provider.</param> /// <privilege>http://tizen.org/privilege/datasharing</privilege> /// <exception cref="ArgumentException">Thrown when providerId is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception> /// <example> /// <code> /// public class MyComplicationProvider : ComplicationProvider /// { /// public MyComplicationProvider(string providerId) /// : base(providerId) /// { /// } /// protected override void OnDataUpdateRequested(string reqestAppId, ComplicationTypes type, Bundle contextData) /// { /// } /// } /// </code> /// </example> /// <since_tizen> 6 </since_tizen> protected ComplicationProvider(string providerId) { ComplicationError err = Interop.WatchfaceComplication.AddUpdateRequestedCallback(providerId, DataUpdateRequested, IntPtr.Zero); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to create provider"); } _providerId = providerId; }
/// <summary> /// Initializes the EditablesContainer class. /// </summary> /// <exception cref="ArgumentException">Thrown when some parameter are invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <since_tizen> 6 </since_tizen> protected EditablesContainer() { ComplicationError err = Interop.WatchfaceComplication.AddEditReadyCallback(EditReady, IntPtr.Zero); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "Fail to add edit ready callback"); } Log.Debug(_logTag, "Edit container ready"); }
/// <summary> /// Gets the received event target complication type. /// </summary> /// <param name="recvAppCtrl">The appcontrol received event args.</param> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// ComplicationTypes type = ComplicationProvider.GetEventComplicationType(e.ReceivedAppControl); /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>The target complication type of received event</returns> /// <since_tizen> 6 </since_tizen> public static ComplicationTypes GetEventComplicationType(ReceivedAppControl recvAppCtrl) { ComplicationTypes type; ComplicationError err = Interop.WatchfaceComplication.GetEventComplicationType(recvAppCtrl.SafeAppControlHandle, out type); if (err != ComplicationError.None && err != ComplicationError.NoData) { ErrorFactory.ThrowException(err, "fail to get complication type"); } return(type); }
/// <summary> /// Gets the received event target provider ID. /// </summary> /// <param name="recvAppCtrl">The appcontrol received event args.</param> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// string providerId = ComplicationProvider.GetEventProviderId(e.ReceivedAppControl); /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>The target provider ID of received event</returns> /// <since_tizen> 6 </since_tizen> public static string GetEventProviderId(ReceivedAppControl recvAppCtrl) { string providerId = string.Empty; ComplicationError err = Interop.WatchfaceComplication.GetEventProviderId(recvAppCtrl.SafeAppControlHandle, out providerId); if (err != ComplicationError.None && err != ComplicationError.NoData) { ErrorFactory.ThrowException(err, "fail to get event"); } return(providerId); }
private bool IsDataValid(IntPtr sharedData) { bool isValid = false; ComplicationError err = Interop.WatchfaceComplication.ProviderSharedDataIsValid(sharedData, out isValid); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to check shared data validation"); } return(isValid); }
/// <summary> /// Gets the received appcontrol containing information about edit. /// </summary> /// <param name="recvAppCtrl">The received appcontrol.</param> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl)) /// { /// // do something /// } /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>The boolean value.</returns> /// <since_tizen> 6 </since_tizen> public static bool IsEditing(ReceivedAppControl recvAppCtrl) { bool isEditing = false; ComplicationError err = Interop.WatchfaceComplication.IsSetupEditing(recvAppCtrl.SafeAppControlHandle, out isEditing); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to check editing"); } return(isEditing); }
/// <summary> /// Loads the editable's current data. /// </summary> /// <returns>The editable's latest data that selected by editor.</returns> /// <exception cref="ArgumentException">Thrown when some parameter are invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <remarks> /// This method loads the last editable data which is updated by editor application. /// </remarks> /// <param name="editableId">The id of the editable.</param> /// <example> /// <code> /// internal void InitEditables() /// { /// _container = new MyContainer(); /// Bundle curData = EditablesContainer.LoadCurrentData(_colorEditId); /// List<Bundle> candidatesList = new List<Bundle>(); /// int curIdx = 0; /// int i = 0; /// foreach (string str in _colorArr) /// { /// Bundle data = new Bundle(); /// data.AddItem(_colorKey, str); /// candidatesList.Add(data); /// if (curData != null && curData.GetItem(_colorKey) != null /// && curData.GetItem(_colorKey).Equals(str)) /// { /// curIdx = i; /// } /// i++; /// } /// ColorDesign colorEdit = new ColorDesign(candidatesList, curIdx, "COLOR", _complicationBtn); /// colorEdit.Highlight = new Highlight(ShapeType.Circle, 0, 40, 10, 10); /// _container.Add(colorEdit, _colorEditId); /// } /// </code> /// </example> /// <since_tizen> 6 </since_tizen> public static Bundle LoadCurrentData(int editableId) { SafeBundleHandle handle; ComplicationError err = Interop.WatchfaceComplication.LoadCurrentData(editableId, out handle); if (err == ComplicationError.None) { return(new Bundle(handle)); } return(null); }
/// <summary> /// Gets the received event target complication context. /// </summary> /// <param name="recvAppCtrl">The appcontrol received event args.</param> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// Bundle context = ComplicationProvider.GetEventContext(e.ReceivedAppControl); /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>The context of received event</returns> /// <since_tizen> 6 </since_tizen> public static Bundle GetEventContext(ReceivedAppControl recvAppCtrl) { SafeBundleHandle bHandle; ComplicationError err = Interop.WatchfaceComplication.GetEventContext(recvAppCtrl.SafeAppControlHandle, out bHandle); if (err != ComplicationError.None) { if (err == ComplicationError.NoData) { return(null); } ErrorFactory.ThrowException(err, "fail to get complication context"); } return(new Bundle(bHandle)); }
/// <summary> /// Gets complication's setup context. /// </summary> /// <param name="recvAppCtrl">The received appcontrol.</param> /// <exception cref="ArgumentException">Thrown when e is invalid.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception> /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception> /// <example> /// <code> /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e) /// { /// if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl)) /// { /// Bundle context = ComplicationProviderSetup.GetContext(e.ReceivedAppControl); /// context.AddItem("TEST_KEY", "NEW CONTEXT"); /// ComplicationProviderSetup.ReplyToEditor(e.ReceivedAppControl, context); /// } /// base.OnAppControlReceived(e); /// } /// </code> /// </example> /// <returns>The setup context.</returns> /// <since_tizen> 6 </since_tizen> public static Bundle GetContext(ReceivedAppControl recvAppCtrl) { SafeBundleHandle context; ComplicationError err = Interop.WatchfaceComplication.GetSetupContext(recvAppCtrl.SafeAppControlHandle, out context); if (err != ComplicationError.None) { ErrorFactory.ThrowException(err, "fail to check editing"); } if (context == null) { return(null); } return(new Bundle(context)); }
private void DataUpdateRequested(string providerId, string reqAppId, ComplicationTypes type, IntPtr context, IntPtr sharedData, IntPtr userData) { Bundle bContext = new Bundle(new SafeBundleHandle(context, false)); ComplicationData data = OnDataUpdateRequested(reqAppId, type, bContext); if (data == null) { Log.Error(LogTag, "null complication data"); return; } ComplicationError err = data.UpdateSharedData(sharedData); if (err != ComplicationError.None) { Log.Error(LogTag, "Set complication data error : " + err); } }
internal static void ThrowException(ComplicationError errorCode, string errorMessage = null, [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0) { Log.Error(LogTag, $"{memberName}({lineNumber.ToString()}) : {filePath}"); switch (errorCode) { case ComplicationError.None: return; case ComplicationError.OutOfMemory: case ComplicationError.IO: case ComplicationError.NoData: case ComplicationError.DB: case ComplicationError.DBus: case ComplicationError.EditNotReady: case ComplicationError.ExistID: case ComplicationError.NotExist: throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "error code : " + errorCode.ToString() : $"{errorMessage} - {errorCode}"); case ComplicationError.InvalidParam: Log.Error(LogTag, "Invalid parameter : " + errorMessage); throw new ArgumentException(string.IsNullOrEmpty(errorMessage) ? "Invalid parameter" : "Invalid parameter : " + errorMessage); case ComplicationError.PermissionDeny: Log.Error(LogTag, "Permission denied : " + errorMessage); throw new UnauthorizedAccessException(string.IsNullOrEmpty(errorMessage) ? "Permission denied" : "Permission denied : " + errorMessage); case ComplicationError.NotSupported: Log.Error(LogTag, "Not supported : " + errorMessage); throw new NotSupportedException(string.IsNullOrEmpty(errorMessage) ? "Not supported" : "Not supported : " + errorMessage); default: Log.Error(LogTag, $"Unknown error : {errorMessage} - {errorCode}"); throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "Unknown error : " + errorCode.ToString() : $"Unknown error : {errorMessage} - {errorCode}"); } }