private void AddBackgroundJob(Action execute, Action callback, AndroidCallback androidCallback)
        {
            AndroidJob job = new AndroidJob(
                action: execute,
                androidCallback: androidCallback,
                callback: callback);

            backgroundJobs.Enqueue(job);
            Dequeue();
        }
        public void SaveToGallery(byte[] image, Action <string> callback)
        {
            AndroidCallback androidCallback = new AndroidCallback();

            AddBackgroundJob(
                execute: () => androidGallery.CallStatic("SaveToGallery", image, context, androidCallback),
                callback: () =>
            {
                Debug.Log($"AndroidGallery finished SaveToGallery call with result {androidCallback.Result}");
                callback(androidCallback.Result);
            },
                androidCallback: androidCallback);
        }
        // TODO: AT - this is actually save photo in app the returns the image
        // need to refactor name and hard coded path
        // we can load the photo using the Database
        public void LoadPhoto(string uri, Action <Texture2D> callback)
        {
            AndroidCallback androidCallback = new AndroidCallback();

            AddBackgroundJob(
                execute: () => androidGallery.CallStatic("CallLoadPhoto", uri, context, androidCallback),
                callback: () =>
            {
                Debug.Log($"AndroidGallery finished LoadPhoto call with result {androidCallback.Result}");
                androidCallbackHelper.StartCoroutine(GetTexture(androidCallback.Result, callback));
            },
                androidCallback: androidCallback);
        }
        public void SelectPhotoPath(Action <string> callback)
        {
            AndroidCallback androidCallback = new AndroidCallback();

            AddForegroundJob(
                execute: () => androidGallery.CallStatic("CallPickPhoto", context, androidCallback),
                callback: () =>
            {
                Debug.Log($"AndroidGallery finished SelectPhotoPath call with result {androidCallback.Result}");
                callback(androidCallback.Result);
            },
                androidCallback: androidCallback);
        }
        private void AddForegroundJob(Action execute, Action callback, AndroidCallback androidCallback)
        {
            if (CurrentBackgroundJob != null && !CurrentForegroundJob.CallbackCalled)
            {
                Debug.LogError("AndroidPhotoGallery: There can only be one foreground task at a time");
                return;
            }
            ;
            AndroidJob job = new AndroidJob(
                action: execute,
                androidCallback: androidCallback,
                callback: callback);

            CurrentForegroundJob = job;
            job.Execute();
        }
Exemple #6
0
 public AndroidJob(Action action, AndroidCallback androidCallback, Action callback)
 {
     this.androidCallback = androidCallback;
     this.action          = action;
     this.callback        = callback;
 }