示例#1
0
 /// <summary>
 /// This method launches another tone setting app and set proper type based on selection.
 /// </summary>
 /// <param name="alarmRecord">AlarmRecord object</param>
 public void LaunchAlarmToneAppControl(AlarmRecord alarmRecord)
 {
     try
     {
         /// Sets app id
         Native.AppControl appControl = new Native.AppControl()
         {
             ApplicationId = "org.tizen.setting-ringtone"
         };
         /// Sets operation for app control
         appControl.Operation = "http://tizen.org/appcontrol/operation/pick";
         /// Adds selection mode
         appControl.ExtraData.Add("http://tizen.org/appcontrol/data/selection_mode", "single");
         /// Prepares tone resources
         List <string> toneResources = new List <string>()
         {
             Native.Application.Current.DirectoryInfo.SharedResource + "ringtones/alarm.mp3",
             Native.Application.Current.DirectoryInfo.SharedResource + "ringtones",
         };
         /// Sets launch mode
         appControl.LaunchMode = Native.AppControlLaunchMode.Group;
         /// Sets tone resource collections
         appControl.ExtraData.Add("http://tizen.org/appcontrol/data/path", toneResources);
         /// Sets alarm record to update based on app control result
         _bindableRecord = alarmRecord;
         /// Requests launch
         Native.AppControl.SendLaunchRequest(appControl, ReplyAfterLaunching);
     }
     catch (Exception e)
     {
         Debug.WriteLine("[LaunchAlarmToneAppControl] Exception - Message:{0}", e.Message);
     }
 }
示例#2
0
 /// <summary>
 /// Activate to ring
 /// </summary>
 /// <param name="delay">The duration of the alarm delay period before an alarm will activate</param>
 /// <seealso cref="int">
 /// <param name="type">RingType for ringing</param>
 /// <seealso cref="RingType">
 public void ActivateAlarm(int delay, RingType type)
 {
     Native.AppControl appControl = new Native.AppControl();
     appControl.ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId;
     appControl.ExtraData.Add("RingType", type.ToString());
     Native.AlarmManager.CreateAlarm(delay, appControl);
 }
示例#3
0
        private void Call()
        {
            var request = new Tizen.Applications.AppControl()
            {
                Operation = Tizen.Applications.AppControlOperations.Call,
                Uri       = "tel:" + _number
            };

            Tizen.Log.Info(Tag, "Calling " + request.Uri);
            Tizen.Applications.AppControl.SendLaunchRequest(request, OnLaunchResult);
        }
 internal static int?SaveAlarm(AlarmRecord alarmRecord)
 {
     Native.AppControl appControl = new Native.AppControl()
     {
         ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId
     };
     appControl.ExtraData.Add("AlarmRecord.DateCreated", alarmRecord.DateCreated.ToString());
     Native.AlarmWeekFlag nativeFlag  = Convert(alarmRecord.WeekFlag);
     Native.Alarm         nativeAlarm = Native.AlarmManager.CreateAlarm(alarmRecord.ScheduledDateTime, nativeFlag, appControl);
     return(nativeAlarm.AlarmId);
 }
        async protected override void OnAppControlReceived(Native.AppControlReceivedEventArgs e)
        {
            base.OnAppControlReceived(e);
            Native.AppControl appControl = e.ReceivedAppControl;
            try
            {
                if (appControl.ExtraData.Count() != 0)
                {
                    IEnumerable <string> stack1 = appControl.ExtraData.GetKeys();
                    string type = appControl.ExtraData.Get <string>("RingType");
                    if (type == RingType.RING_TYPE_ALARM.ToString())
                    {
                        var    navi             = app_.MainPage as NavigationPage;
                        var    currentPage      = navi.CurrentPage;
                        string AlarmCreatedDate = appControl.ExtraData.Get <string>("AlarmRecord.UniqueIdentifier");
                        if (AlarmModel.AlarmRecordDictionary == null)
                        {
                            // IAlarmPersistentHandler serizliazer = DependencyService.Get<IAlarmPersistentHandler>();
                            // Need to retrieve at the page creation time
                            AlarmModel.AlarmRecordDictionary = DependencyService.Get <IAlarmPersistentHandler>().DeserializeAlarmRecord();
                        }

                        AlarmRecord retrievedRecord;
                        if (AlarmModel.AlarmRecordDictionary != null)
                        {
                            if (AlarmModel.AlarmRecordDictionary.TryGetValue(AlarmCreatedDate, out retrievedRecord))
                            {
                                if (retrievedRecord == null)
                                {
                                    DependencyService.Get <ILog>().Error("[OnAppControlReceived]", "retrievedRecord is null!!");
                                }

                                if (retrievedRecord != null && retrievedRecord.AlarmState < AlarmStates.Inactive)
                                {
                                    retrievedRecord.PrintProperty();
                                    await currentPage.Navigation.PushAsync(new RingPage(RingType.RING_TYPE_ALARM, retrievedRecord));
                                }
                            }
                        }
                    }
                    else if (type == RingType.RING_TYPE_TIMER.ToString())
                    {
                        var navi        = app_.MainPage as NavigationPage;
                        var currentPage = navi.CurrentPage as MainTabbedPage;
                        await currentPage.Navigation.PushAsync(new RingPage(RingType.RING_TYPE_TIMER));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[OnAppControlReceived] Exception - Message: " + ex.Message + ", source: " + ex.Source + ", " + ex.StackTrace);
            }
        }
 /// <summary>
 /// Creates a system alarm of AlarmRecord
 /// </summary>
 /// <param name="binableAlarmRecord">AlarmRecord object to create a system alarm based on</param>
 /// <seealso cref="AlarmRecord">
 /// <returns> Returns native alarm object </returns>
 public static int CreateAlarm(AlarmRecord record)
 {
     Native.AppControl appControl = new Native.AppControl()
     {
         ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId
     };
     appControl.ExtraData.Add("AlarmRecord.UniqueIdentifier", record.GetUniqueIdentifier());
     //temporary set AllDays , After implement select day of week. additional implementation should be add.
     Native.Alarm nativeAlarm = Native.AlarmManager.CreateAlarm(record.ScheduledDateTime, Native.AlarmWeekFlag.AllDays, appControl);
     Console.WriteLine("@@ [Alarm.CreateAlarm] UID : " + record.GetUniqueIdentifier()
                       + ", ScheduledDateTime : " + record.ScheduledDateTime + " NativeAlarmID : " + nativeAlarm.AlarmId);
     return(nativeAlarm.AlarmId);
 }
示例#7
0
        /// <summary>
        /// Creates a system alarm of AlarmRecord
        /// </summary>
        /// <param name="binableAlarmRecord">AlarmRecord object to create a system alarm based on</param>
        /// <seealso cref="AlarmRecord">
        /// <returns> Returns native alarm object </returns>
        public int CreateAlarm(AlarmRecord record)
        {
            Native.AppControl appControl = new Native.AppControl()
            {
                ApplicationId = Native.Application.Current.ApplicationInfo.ApplicationId
            };
            appControl.ExtraData.Add("AlarmRecord.UniqueIdentifier", record.GetUniqueIdentifier());
            appControl.ExtraData.Add("RingType", RingType.RING_TYPE_ALARM.ToString());
            Native.AlarmWeekFlag nativeFlag  = Convert(record.WeekFlag);
            Native.Alarm         nativeAlarm = Native.AlarmManager.CreateAlarm(record.ScheduledDateTime, nativeFlag, appControl);
#if ALARM_DEBUG
            System.Diagnostics.Debug.WriteLine("@@ [Alarm.CreateAlarm] UID : " + record.GetUniqueIdentifier()
                                               + ", ScheduledDateTime : " + record.ScheduledDateTime + " nativeFlag : " + nativeFlag);
            System.Diagnostics.Debug.WriteLine(" --> Done       Native UID : " + nativeAlarm.AlarmId
                                               + ", ScheduledDate : " + nativeAlarm.ScheduledDate + " nativeFlag : " + nativeAlarm.WeekFlag);
#endif
            return(nativeAlarm.AlarmId);
        }
示例#8
0
        private void ReplyAfterLaunching(Native.AppControl launchRequest, Native.AppControl replyRequest, Native.AppControlReplyResult result)
        {
            //_bindableRecord.AlarmToneType = AlarmToneTypes.RingtoneSdk;
            if (result == Native.AppControlReplyResult.Succeeded)
            {
                List <string> data = (List <string>)replyRequest.ExtraData.Get("http://tizen.org/appcontrol/data/selected");
                if (data.Count == 1)
                {
                    Debug.WriteLine("[LaunchAlarmToneAppControl] Type {0}", data[0]);
                    switch (data[0])
                    {
                    case "/opt/usr/data/settings/Ringtones/rintone_sdk.mp3":
                        _bindableRecord.AlarmToneType = AlarmToneTypes.RingtoneSdk;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// Cancel to ring
        /// </summary>
        public void DeactivateAlarm()
        {
            IEnumerable <Native.Alarm> alarmList = Native.AlarmManager.GetAllScheduledAlarms();

            // Find an alarm for Timer page in native all registered alarms
            foreach (Native.Alarm alarm in alarmList)
            {
                Native.AppControl appControl = alarm.AlarmAppControl;
                try
                {
                    string type = (string)appControl.ExtraData.Get("RingType");
                    if (type == RingType.RING_TYPE_TIMER.ToString())
                    {
                        alarm.Cancel();
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("[DeactivateAlarm] Exception - Message:{0}", e.Message);
                }
            }
        }
示例#10
0
        /// <summary>
        /// Request to launch an application
        /// </summary>
        /// <param name="appId">application's ID to launch</param>
        /// <seealso cref="string">
        /// <param name="op">AppControl operation type</param>
        /// <seealso cref="AppControlOperation">
        /// <param name="type">The launching mode to launch an application</param>
        /// <seealso cref="AppControlLaunchType">
        public void ApplicationLaunchRequest(string appId, AppControlOperation op, AppControlLaunchType type)
        {
            Native.AppControl appControl = new Native.AppControl()
            {
                ApplicationId = appId,
                Operation     = Native.AppControlOperations.Default,
            };

            if (op == AppControlOperation.PICK)
            {
                appControl.Operation = Native.AppControlOperations.Pick;
            }

            if (type == AppControlLaunchType.SINGLE)
            {
                appControl.LaunchMode = Native.AppControlLaunchMode.Single;
            }
            else
            {
                appControl.LaunchMode = Native.AppControlLaunchMode.Group;
            }

            Native.AppControl.SendLaunchRequest(appControl, ReplyAfterLaunching);
        }
示例#11
0
        /// <summary>
        /// Sends the launch request asynchronously.
        /// </summary>
        /// <remarks>
        /// The operation is mandatory information for the launch request.
        /// If the operation is not specified, AppControlOperations.Default is used by default.
        /// If the operation is AppControlOperations.Default, the application ID is mandatory to explicitly launch the application.<br/>
        /// Since Tizen 2.4, the launch request of the service application over out of packages is restricted by the platform.
        /// Also, implicit launch requests are NOT delivered to service applications since 2.4.
        /// To launch a service application, an explicit launch request with the application ID given by property ApplicationId MUST be sent.
        /// </remarks>
        /// <param name="launchRequest">The AppControl.</param>
        /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered.</param>
        /// <returns>A task with the result of the launch request.</returns>
        /// <exception cref="ArgumentException">Thrown when failed because of the argument is invalid.</exception>
        /// <exception cref="Exceptions.AppNotFoundException">Thrown when the application to run is not found.</exception>
        /// <exception cref="Exceptions.LaunchRejectedException">Thrown when the launch request is rejected.</exception>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <since_tizen> 6 </since_tizen>
        public static Task <AppControlResult> SendLaunchRequestAsync(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching)
        {
            if (launchRequest == null)
            {
                throw new ArgumentNullException(nameof(launchRequest));
            }

            var task = new TaskCompletionSource <AppControlResult>();

            Interop.AppControl.ErrorCode err;
            int requestId = 0;

            lock (s_resultNativeCallbackMaps)
            {
                requestId = s_reaustId++;
                s_resultNativeCallbackMaps[requestId] = (handle, result, userData) =>
                {
                    task.SetResult((AppControlResult)result);
                    lock (s_resultNativeCallbackMaps)
                    {
                        s_resultNativeCallbackMaps.Remove((int)userData);
                    }
                };
            }

            if (replyAfterLaunching != null)
            {
                lock (s_replyCallbackMaps)
                {
                    s_replyCallbackMaps[requestId] = replyAfterLaunching;
                }
                err = Interop.AppControl.SendLaunchRequestAsync(launchRequest.SafeAppControlHandle, s_resultNativeCallbackMaps[requestId], s_replyNativeCallback, (IntPtr)requestId);
            }
            else
            {
                err = Interop.AppControl.SendLaunchRequestAsync(launchRequest.SafeAppControlHandle, s_resultNativeCallbackMaps[requestId], null, (IntPtr)requestId);
            }

            if (err != Interop.AppControl.ErrorCode.None)
            {
                switch (err)
                {
                case Interop.AppControl.ErrorCode.InvalidParameter:
                    throw new ArgumentException("Invalid Arguments");

                case Interop.AppControl.ErrorCode.AppNotFound:
                    throw new Exceptions.AppNotFoundException("App not found");

                case Interop.AppControl.ErrorCode.LaunchRejected:
                    throw new Exceptions.LaunchRejectedException("Launch rejected");

                case Interop.AppControl.ErrorCode.PermissionDenied:
                    throw new Exceptions.PermissionDeniedException("Permission denied");

                default:
                    throw new Exceptions.LaunchRejectedException("Launch rejected");
                }
            }

            return(task.Task);
        }
示例#12
0
 /// <summary>
 /// Sends the launch request.
 /// </summary>
 /// <remarks>
 /// The operation is mandatory information for the launch request.
 /// If the operation is not specified, AppControlOperations.Default is used by default.
 /// If the operation is AppControlOperations.Default, the application ID is mandatory to explicitly launch the application.<br/>
 /// Since Tizen 2.4, the launch request of the service application over out of packages is restricted by the platform.
 /// Also, implicit launch requests are NOT delivered to service applications since 2.4.
 /// To launch a service application, an explicit launch request with the application ID given by property ApplicationId MUST be sent.
 /// </remarks>
 /// <param name="launchRequest">The AppControl.</param>
 /// <exception cref="ArgumentNullException">Thrown when failed because of a null argument.</exception>
 /// <exception cref="InvalidOperationException">Thrown when failed because of an invalid operation.</exception>
 /// <exception cref="TimeoutException">Thrown when failed because of timeout.</exception>
 /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
 /// <example>
 /// <code>
 /// AppControl appControl = new AppControl();
 /// appControl.ApplicationId = "org.tizen.calculator";
 /// AppControl.SendLaunchRequest(appControl);
 /// </code>
 /// </example>
 /// <since_tizen> 3 </since_tizen>
 public static void SendLaunchRequest(AppControl launchRequest)
 {
     SendLaunchRequest(launchRequest, null);
 }
示例#13
0
        /// <summary>
        /// Sends the launch request.
        /// </summary>
        /// <remarks>
        /// The operation is mandatory information for the launch request.
        /// If the operation is not specified, AppControlOperations.Default is used by default.
        /// If the operation is AppControlOperations.Default, the application ID is mandatory to explicitly launch the application.<br/>
        /// Since Tizen 2.4, the launch request of the service application over out of packages is restricted by the platform.
        /// Also, implicit launch requests are NOT delivered to service applications since 2.4.
        /// To launch a service application, an explicit launch request with the application ID given by property ApplicationId MUST be sent.
        /// </remarks>
        /// <param name="launchRequest">The AppControl.</param>
        /// <param name="replyAfterLaunching">The callback function to be called when the reply is delivered.</param>
        /// <exception cref="ArgumentException">Thrown when failed because of the argument is invalid.</exception>
        /// <exception cref="Exceptions.AppNotFoundException">Thrown when the application to run is not found.</exception>
        /// <exception cref="Exceptions.LaunchFailedException">Thrown when the request failed to launch the application.</exception>
        /// <exception cref="Exceptions.LaunchRejectedException">Thrown when the launch request is rejected.</exception>
        /// <exception cref="Exceptions.OutOfMemoryException">Thrown when the memory is insufficient.</exception>
        /// <exception cref="Exceptions.PermissionDeniedException">Thrown when the permission is denied.</exception>
        /// <exception cref="TimeoutException">Thrown when failed because of timeout.</exception>
        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
        /// <example>
        /// <code>
        /// AppControl appControl = new AppControl();
        /// appControl.ApplicationId = "org.tizen.calculator";
        /// AppControl.SendLaunchRequest(appControl, (launchRequest, replyRequest, result) => {
        ///     // ...
        /// });
        /// </code>
        /// </example>
        /// <since_tizen> 3 </since_tizen>
        public static void SendLaunchRequest(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching)
        {
            if (launchRequest == null)
            {
                throw new ArgumentNullException("launchRequest");
            }

            Interop.AppControl.ErrorCode err;

            if (replyAfterLaunching != null)
            {
                int id = 0;
                lock (s_replyNativeCallbackMaps)
                {
                    id = s_replyNativeCallbackId++;
                    s_replyNativeCallbackMaps[id] = (launchRequestHandle, replyRequestHandle, result, userData) =>
                    {
                        if (replyAfterLaunching != null)
                        {
                            Log.Debug(LogTag, "Reply Callback is launched");
                            replyAfterLaunching(new AppControl(launchRequestHandle), new AppControl(replyRequestHandle), (AppControlReplyResult)result);
                            if (result != Interop.AppControl.AppStartedStatus)
                            {
                                lock (s_replyNativeCallbackMaps)
                                {
                                    s_replyNativeCallbackMaps.Remove(id);
                                }
                            }
                        }
                    };
                }
                err = Interop.AppControl.SendLaunchRequest(launchRequest._handle, s_replyNativeCallbackMaps[id], IntPtr.Zero);
            }
            else
            {
                err = Interop.AppControl.SendLaunchRequest(launchRequest._handle, null, IntPtr.Zero);
            }

            if (err != Interop.AppControl.ErrorCode.None)
            {
                switch (err)
                {
                case Interop.AppControl.ErrorCode.InvalidParameter:
                    throw new ArgumentException("Invalid Arguments");

                case Interop.AppControl.ErrorCode.TimedOut:
                    throw new TimeoutException("Timed out");

                case Interop.AppControl.ErrorCode.OutOfMemory:
                    throw new Exceptions.OutOfMemoryException("Out-of-memory");

                case Interop.AppControl.ErrorCode.AppNotFound:
                    throw new Exceptions.AppNotFoundException("App not found");

                case Interop.AppControl.ErrorCode.LaunchRejected:
                    throw new Exceptions.LaunchRejectedException("Launch rejected");

                case Interop.AppControl.ErrorCode.LaunchFailed:
                    throw new Exceptions.LaunchFailedException("Launch failed");

                case Interop.AppControl.ErrorCode.PermissionDenied:
                    throw new Exceptions.PermissionDeniedException("Permission denied");

                default:
                    throw new Exceptions.LaunchRejectedException("Launch rejected");
                }
            }
        }
示例#14
0
        /// <summary>
        /// Called when the replay is delivered
        /// </summary>
        /// <param name="launchRequest">
        /// AppControl for launch
        /// </param>
        /// <param name="replyRequest">
        /// AppControl for replay
        /// </param>
        /// <param name="result">
        /// The result of requesting an app launch
        /// </param>
        void ReplyAfterLaunching(Native.AppControl launchRequest, Native.AppControl replyRequest, Native.AppControlReplyResult result)
        {
            if (result != Native.AppControlReplyResult.Succeeded)
            {
                return;
            }

            try
            {
                if (replyRequest.ExtraData.Count() != 0)
                {
                    bool normal = false;

                    IEnumerable <string> stack1 = replyRequest.ExtraData.GetKeys();
                    foreach (var item in stack1)
                    {
                        if (item == "city_name")
                        {
                            normal = true;
                        }
                    }

                    if (!normal)
                    {
                        return;
                    }

                    string city         = replyRequest.ExtraData.Get <string>("city_name");
                    string country_name = replyRequest.ExtraData.Get <string>("country_name");
                    string timezone     = replyRequest.ExtraData.Get <string>("timezone");
                    string tzpath       = replyRequest.ExtraData.Get <string>("tzpath");

                    string[] times    = timezone.Split(':');
                    bool     positive = true;

                    for (int i = 0; i < times.Length; i++)
                    {
                        if (i == 0 && times[i][0] == '-')
                        {
                            positive = false;
                        }
                    }

                    int h = 0, m = 0;
                    h = Int32.Parse(times[0]);
                    if (times.Length > 1)
                    {
                        m = Int32.Parse(times[1]);
                    }

                    int gmt_offset = 0;
                    if (positive)
                    {
                        gmt_offset = h * 60 + m;
                    }
                    else
                    {
                        gmt_offset = h * 60 - m;
                    }

                    Location l = new Location(city, country_name, gmt_offset, 0, 0);
                    App.ClockInfo.OnItemAdded(l);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(" [ReplyAfterLaunching] Exception - " + ex.Message);
            }
        }