/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Tizen.Applications.WatchfaceComplication
{
///
/// Represents the complication setup for a setup application.
///
/// 6
public static class ComplicationProviderSetup
{
///
/// Gets the received appcontrol containing information about edit.
///
/// The received appcontrol.
/// Thrown when e is invalid.
/// Thrown when the method failed due to invalid operation.
/// Thrown when the watchface complication is not supported.
///
///
/// protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
/// {
/// if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl))
/// {
/// // do something
/// }
/// base.OnAppControlReceived(e);
/// }
///
///
/// The boolean value.
/// 6
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;
}
///
/// Replies the setup context to the editor
///
/// The received appcontrol.
/// The context created by complication setup app.
/// http://tizen.org/privilege/datasharing
/// Thrown when e is invalid.
/// Thrown when the method failed due to invalid operation.
/// Thrown when the watchface complication is not supported.
/// Thrown when the application does not have privilege to access this method.
///
///
/// 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);
/// }
///
///
/// Event target complication type
/// 6
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");
}
///
/// Gets complication's setup context.
///
/// The received appcontrol.
/// Thrown when e is invalid.
/// Thrown when the method failed due to invalid operation.
/// Thrown when the watchface complication is not supported.
///
///
/// 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);
/// }
///
///
/// The setup context.
/// 6
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);
}
}
}