コード例 #1
0
        /// <summary>
        /// Convert HuaweiTask to System.Threading.Task with Generic return type
        /// </summary>
        /// <typeparam name="TResult">Return type,a Java object</typeparam>
        /// <param name="HuaweiTask">Huawei.Hmf.Tasks.Task class</param>
        /// <returns>System.Threading.Task with wrapped a generic type</returns>
        public static Task <TResult> CastTask <TResult>(this HuaweiTask HuaweiTask) where TResult : Java.Lang.Object
        {
            var tcs = new TaskCompletionSource <TResult>();

            HuaweiTask.AddOnCompleteListener(new HuaweiTaskCompleteListener(
                                                 t =>
            {
                if (t.Exception == null)
                {
                    tcs.TrySetResult(t.Result.JavaCast <TResult>());
                }
                else
                {
                    tcs.TrySetException(t.Exception);
                }
            }));

            return(tcs.Task);
        }
コード例 #2
0
        /// <summary>
        /// Convert HuaweiTask to System.Threading.Task without return type
        /// </summary>
        /// <param name="HuaweiTask">Huawei.Hmf.Tasks.Task</param>
        /// <returns>System.Threading.Task</returns>
        public static System.Threading.Tasks.Task CastTask(this HuaweiTask HuaweiTask)
        {
            var tcs = new TaskCompletionSource <bool>();

            HuaweiTask.AddOnCompleteListener(new HuaweiTaskCompleteListener(
                                                 t =>
            {
                if (t.Exception == null)
                {
                    tcs.TrySetResult(false);
                }
                else
                {
                    tcs.TrySetException(t.Exception);
                }
            }
                                                 ));

            return(tcs.Task);
        }
コード例 #3
0
        private void GetLastLocation()
        {
            Task lastLocation = fusedLocationProviderClient.LastLocation;

            lastLocation.AddOnSuccessListener(new LastLocationSuccess(this)).AddOnFailureListener(new LastLocationFailure(this));
        }
コード例 #4
0
 public Java.Lang.Object Then(Huawei.Hmf.Tasks.Task task)
 {
     this.successAction(task);
     return(null);
 }
コード例 #5
0
 private void GetAAID()
 {
     Huawei.Hmf.Tasks.Task getAAID = instance.AAID;
     getAAID.AddOnSuccessListener(new GetAAIDSuccessListener()).AddOnFailureListener(new GetAAIDFailureListener());
 }
コード例 #6
0
 public void OnComplete(HuaweiTask task)
 => OnCompleteHandler?.Invoke(task);