Example #1
0
        private void PickImage(NativeAction actionPick)
        {
#if UNITY_ANDROID
            NativeGallery.RequestPermission((result, action) =>
            {
                if (result == (int)NativeGallery.Permission.Granted)
                {
                    NativeGallery.GetImageFromGalleryForAndroid((path) =>
                    {
                        if (path.IsNotNullAndEmpty())
                        {
                            mPhotoPath = path;
                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + path, ImgPhoto);
                            BtnDel.gameObject.SetActive(true);
                        }
                        Debug.Log("Image path: " + path);
                    }, "选择图片", "image/*", false, action);
                }
            }, (int)actionPick);
#elif UNITY_IOS
            // NativeGallery.Permission rest;
            if (actionPick == NativeAction.Album)
            {
                NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(1);
                if (rest == NativeGallery.Permission.Granted)
                {
                    NativeGallery.GetImageFromGallery((backPath) =>
                    {
                        if (backPath.IsNotNullAndEmpty())
                        {
                            mPhotoPath = backPath;
                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false);
                            BtnDel.gameObject.SetActive(true);
                        }
                    }, "选择图片", "image/*");
                }
            }
            else if (actionPick == NativeAction.Camera)
            {
                NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(4);
                if (rest == NativeGallery.Permission.Granted)
                {
                    NativeGallery.GetIPhoneCameraImageFromGallery((backPath) =>
                    {
                        if (backPath.IsNotNullAndEmpty())
                        {
                            mPhotoPath = backPath;
                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false);
                            BtnDel.gameObject.SetActive(true);
                        }
                    }, "选择图片", "image/*");
                }
            }
#else
#endif
        }
Example #2
0
 protected override void OnInit(QFramework.IUIData uiData)
 {
     mData = uiData as AttendanceMainPanelData ?? new AttendanceMainPanelData();
     BtnBack.onClick.AddListener(() =>
     {
         AudioManager.PlaySound("Button_Audio");
         Back();
     });
     BtnPicture.onClick.AddListener(() =>
     {
         AudioManager.PlaySound("Button_Audio");
         UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData()
         {
             action = ChoosePhotoAction.AttendancePic,
         });
     });
     BtnAudio.onClick.AddListener(() =>
     {
         AudioManager.PlaySound("Button_Audio");
         if (Application.platform == RuntimePlatform.Android)
         {
             NativeGallery.RequestPermission((result, action) =>
             {
                 if (result == (int)NativeGallery.Permission.Granted)
                 {
                     UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE);
                 }
             }, (int)NativeAction.Audio);
         }
         else
         {
             UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE);
         }
     })
     ;
     BtnVideo.onClick.AddListener(() =>
     {
         AudioManager.PlaySound("Button_Audio");
         // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData()
         // {
         //     action = ChoosePhotoAction.AttendanceVideo,
         //     showTip = true
         // });
         if (Application.platform == RuntimePlatform.IPhonePlayer)
         {
             IPhonePlayerMakeVideoOpenCamera();
         }
         else if (Application.platform == RuntimePlatform.Android)
         {
             NativeGallery.RequestPermission((result, action) =>
             {
                 if (result == (int)NativeGallery.Permission.Granted)
                 {
                     NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                     {
                         if (json.IsNotNullAndEmpty())
                         {
                             NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                             if (model.IsNotNull())
                             {
                                 if (model.status == 1)
                                 {
                                     UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData()
                                     {
                                         BoxId         = mData.BoxId,
                                         BoxDay        = mData.BoxDay,
                                         Path          = model.videoPath,
                                         ThumbnailPath = model.imagePath,
                                         Action        = AttendanceAdd.Video,
                                     }, UITransitionType.CIRCLE);
                                     Close();
                                 }
                             }
                         }
                     }, "选择视频", "video/*", action);
                 }
             }, (int)NativeAction.Camera);
         }
     });
     SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path =>
     {
         UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData()
         {
             BoxId  = mData.BoxId,
             BoxDay = mData.BoxDay,
             Action = AttendanceAdd.Audio,
             Path   = Path.Path
         }, UITransitionType.CIRCLE);
         Close();
     }).AddTo(this);
     SimpleEventSystem.GetEvent <ChoosePhotoClick>()
     .Subscribe(_ =>
     {
         if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic)
         {
             if (Application.platform == RuntimePlatform.IPhonePlayer)
             {
                 if (_.GetAction == NativeAction.Camera)
                 {
                     IPhonePlayerSelectPictureOpenCamera();
                 }
                 else if (_.GetAction == NativeAction.Album)
                 {
                     IPhonePlayerSelectPictureOpenAlbum();
                 }
                 else
                 {
                 }
             }
             else if (Application.platform == RuntimePlatform.Android)
             {
                 NativeGallery.RequestPermission((result, action) =>
                 {
                     if (result == (int)NativeGallery.Permission.Granted)
                     {
                         NativeGallery.GetImageFromGalleryForAndroid((path) =>
                         {
                             if (path.IsNotNullAndEmpty())
                             {
                                 UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData()
                                 {
                                     BoxId         = mData.BoxId,
                                     BoxDay        = mData.BoxDay,
                                     Path          = path,
                                     ThumbnailPath = path,
                                     Action        = AttendanceAdd.Pic
                                 }, UITransitionType.CIRCLE);
                                 Close();
                             }
                             Debug.Log("Image path: " + path);
                         }, "选择图片", "image/*", true, action);
                     }
                 }, (int)_.GetAction);
             }
         }
         // 视频不需要了
         else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo)
         {
             if (Application.platform == RuntimePlatform.IPhonePlayer)
             {
                 if (_.GetAction == NativeAction.Album)
                 {
                     IPhonePlayerSelectVideoOpenAlbum();
                 }
                 else if (_.GetAction == NativeAction.Camera)
                 {
                     IPhonePlayerMakeVideoOpenCamera();
                 }
             }
             else if (Application.platform == RuntimePlatform.Android)
             {
                 NativeGallery.RequestPermission((result, action) =>
                 {
                     if (result == (int)NativeGallery.Permission.Granted)
                     {
                         NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                         {
                             if (json.IsNotNullAndEmpty())
                             {
                                 NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                                 if (model.IsNotNull())
                                 {
                                     if (model.status == 1)
                                     {
                                         UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData()
                                         {
                                             BoxId         = mData.BoxId,
                                             BoxDay        = mData.BoxDay,
                                             Path          = model.videoPath,
                                             ThumbnailPath = model.imagePath,
                                             Action        = AttendanceAdd.Video,
                                         }, UITransitionType.CIRCLE);
                                         Close();
                                     }
                                 }
                             }
                         }, "选择视频", "video/*", action);
                     }
                 }, (int)_.GetAction);
             }
         }
     }).AddTo(this);
 }
        protected override void OnInit(QFramework.IUIData uiData)
        {
            mData             = uiData as AttendanceAddPanelData ?? new AttendanceAddPanelData();
            mPath             = mData.Path;
            mThumbnailPath    = mData.ThumbnailPath;
            texture2DAddPhoto = mResLoader.LoadSync <Texture2D>("attendance_main_add");
            BtnBack.onClick.AddListener(() => {
                AudioManager.PlaySound("Button_Audio");
                Back();
            });
            BtnCancel.onClick.AddListener(() => {
                AudioManager.PlaySound("Button_Audio");
                Back();
            });
            BtnPush.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                // if (InputContent.text.IsNullOrEmpty())
                // {
                //     CommonUtil.toast("请输入内容");
                //     Log.I("请输入内容");
                //     return;
                // }
                if (mPath.IsNullOrEmpty())
                {
                    if (mData.Action == AttendanceAdd.Pic)
                    {
                        CommonUtil.toast("请添加图片");
                        Log.I("请添加图片");
                    }
                    else if (mData.Action == AttendanceAdd.Audio)
                    {
                        CommonUtil.toast("请添加音频");
                        Log.I("请添加音频");
                    }
                    else if (mData.Action == AttendanceAdd.Video)
                    {
                        CommonUtil.toast("请添加视频");
                        Log.I("请添加视频");
                    }
                    return;
                }
                LoadingManager.GetInstance().CreatLoading();
                BtnPush.enabled = false;
                if (mData.Action == AttendanceAdd.Pic)
                {
                    string fileType = mPath.Substring(mPath.LastIndexOf("."));
                    Log.I("mPath: " + mPath + " fileType: " + fileType);
                    StartRequestForUpload("attendance" + fileType, mPath);
                }
                else if (mData.Action == AttendanceAdd.Audio)
                {
                    MicrophoneManager.GetInstance().StopPlay();
                    string fileType = mPath.Substring(mPath.LastIndexOf("."));
                    Log.I("mPath: " + mPath + " fileType: " + fileType);
                    StartRequestForUpload("attendance" + fileType, mPath);
                }
                else if (mData.Action == AttendanceAdd.Video)
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        // CommonUtil.toast("视频压缩上传中,请稍等");
                        AndroidForUnity.CallAndroidForVideoCompress(mPath);
                    }
                    else
                    {
                        StartCoroutine(IPhonePlayerCompressFinished());
                    }
                }
            });
            BtnAdd.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                if (mData.Action == AttendanceAdd.Audio)
                {
                    UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE);
                }
                else
                { //unityForPlayVideo
                    if (mPath.IsNullOrEmpty())
                    {
                        if (mData.Action == AttendanceAdd.Pic)
                        {
                            UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData()
                            {
                                action = ChoosePhotoAction.AttendancePic,
                            });
                        }
                        else if (mData.Action == AttendanceAdd.Video)
                        {
                            // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData()
                            // {
                            //     action = ChoosePhotoAction.AttendanceVideo,
                            //     showTip = true
                            //
                            // });
                            if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                IPhonePlayerMakeVideoOpenCamera();
                            }
                            else if (Application.platform == RuntimePlatform.Android)
                            {
                                NativeGallery.RequestPermission((result, action) =>
                                {
                                    if (result == (int)NativeGallery.Permission.Granted)
                                    {
                                        NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                                        {
                                            if (json.IsNotNullAndEmpty())
                                            {
                                                NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                                                if (model.IsNotNull())
                                                {
                                                    if (model.status == 1)
                                                    {
                                                        mPath          = model.videoPath;
                                                        mThumbnailPath = model.imagePath;
                                                        AudioContent.gameObject.SetActive(false);
                                                        if (model.imagePath.IsNotNullAndEmpty())
                                                        {
                                                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic);
                                                            BtnVideo.gameObject.SetActive(true);
                                                            BtnDel.gameObject.SetActive(true);
                                                        }
                                                    }
                                                    else if (model.status == 0)
                                                    {
                                                        mPath           = null;
                                                        mThumbnailPath  = null;
                                                        ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                                                        BtnVideo.gameObject.SetActive(false);
                                                        BtnDel.gameObject.SetActive(false);
                                                    }
                                                }
                                            }
                                        }, "选择视频", "video/*", action);
                                    }
                                }, (int)NativeAction.Camera);
                            }
                        }
                    }
                    else
                    {
                        if (mData.Action == AttendanceAdd.Pic)
                        {
                            if (Application.platform == RuntimePlatform.Android)
                            {
                                AndroidForUnity.CallAndroidForShowPic(mPath);
                            }
                            else if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                UIMgr.OpenPanel <PhotoBrowserPanel>(new PhotoBrowserPanelData()
                                {
                                    ImageUrl = mPath,
                                }, UITransitionType.NULL);
                            }
                        }
                        else if (mData.Action == AttendanceAdd.Video)
                        {
                            if (Application.platform == RuntimePlatform.Android)
                            {
                                AndroidForUnity.CallAndroidForPlayVideo(mPath);
                            }
                            else if (Application.platform == RuntimePlatform.IPhonePlayer)
                            {
                                Dictionary <string, object> paramDic = new Dictionary <string, object>();
                                Dictionary <string, object> subParam = new Dictionary <string, object>();
                                subParam.Add("url", mPath);
                                paramDic.Add("target", AppConst.VIDEO_IOS);
                                paramDic.Add("method", IOSClientUtil.VideoMediaPlay);
                                paramDic.Add("params", subParam);
                                IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson());
                            }
                        }
                    }
                }
            });
            BtnVideo.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                if (mData.Action == AttendanceAdd.Video)
                {
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        AndroidForUnity.CallAndroidForPlayVideo(mPath);
                    }
                    else if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        Dictionary <string, object> paramDic = new Dictionary <string, object>();
                        Dictionary <string, object> subParam = new Dictionary <string, object>();
                        subParam.Add("url", mPath);
                        paramDic.Add("target", AppConst.VIDEO_IOS);
                        paramDic.Add("method", IOSClientUtil.VideoMediaPlay);
                        paramDic.Add("params", subParam);
                        IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson());
                    }
                }
            });
            if (mData.Action == AttendanceAdd.Audio)
            {
                UpdateTvTime("0");
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
                TextAdd.text = "添加语音";
            }
            else
            {
                if (mData.Action == AttendanceAdd.Pic)
                {
                    TextAdd.text = "添加图片";
                    AudioContent.gameObject.SetActive(false);
                    if (mPath.IsNotNullAndEmpty())
                    {
                        ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                        BtnVideo.gameObject.SetActive(false);
                        BtnDel.gameObject.SetActive(true);
                    }
                }
                else
                {
                    TextAdd.text = "添加视频";
                    AudioContent.gameObject.SetActive(false);
                    if (mPath.IsNotNullAndEmpty())
                    {
                        ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                        BtnVideo.gameObject.SetActive(true);
                        BtnDel.gameObject.SetActive(true);
                    }
                }
            }
            BtnPlayAndPause.onClick.AddListener(() =>
            {
                if (mPath.IsNotNullAndEmpty())
                {
                    if (mPlayStatus == PlayStatus.NoPlaying || mPlayStatus == PlayStatus.Stop)
                    {
                        MicrophoneManager.GetInstance().PlayRecord();
                    }
                    else if (mPlayStatus == PlayStatus.Playing)
                    {
                        MicrophoneManager.GetInstance().PausePlay();
                    }
                    else if (mPlayStatus == PlayStatus.Pause)
                    {
                        MicrophoneManager.GetInstance().PlayRecord(MicrophoneManager.GetInstance().mPlayingTime.Value);
                    }
                }
            });
            BtnClose.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                mPath = null;
                MicrophoneManager.GetInstance().StopPlay();
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
            });
            BtnDel.onClick.AddListener(() =>
            {
                AudioManager.PlaySound("Button_Audio");
                // 弹窗
                UIMgr.OpenPanel <TipPanel>(new TipPanelData()
                {
                    action  = TipAction.DelAttendance,
                    message = "确定要删除当前内容吗?",
                });
            });
            InputContent.onValueChange.AddListener(EditChange);

            if (mData.Action == AttendanceAdd.Audio)
            {
                MicrophoneManager.GetInstance().mPlayStatus.Subscribe(status =>
                {
                    mPlayStatus = status;
                    if (mPlayStatus == PlayStatus.Playing)
                    {
                        // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audio_playing");
                        // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f);
                        ImgPlayAndPause.gameObject.SetActive(false);
                        ImgPlaying.gameObject.SetActive(true);
                    }
                    else
                    {
                        // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audiio_pause");
                        // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f);
                        ImgPlayAndPause.gameObject.SetActive(true);
                        ImgPlaying.gameObject.SetActive(false);
                    }

                    if (mPlayStatus == PlayStatus.Stop)
                    {
                        UpdateTvTime("0");
                    }
                }).AddTo(this);
            }
            SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path =>
            {
                mPath = Path.Path;
                UpdateTvTime("0");
                AddContent.gameObject.SetActive(mPath.IsNullOrEmpty());
                AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty());
            }).AddTo(this);
            SimpleEventSystem.GetEvent <ChoosePhotoClick>()
            .Subscribe(_ =>
            {
                if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic)
                {
                    if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        if (_.GetAction == NativeAction.Camera)
                        {
                            IPhonePlayerSelectPictureOpenCamera();
                        }
                        else if (_.GetAction == NativeAction.Album)
                        {
                            IPhonePlayerSelectPictureOpenAlbum();
                        }
                    }
                    else if (Application.platform == RuntimePlatform.Android)
                    {
                        NativeGallery.RequestPermission((result, action) =>
                        {
                            if (result == (int)NativeGallery.Permission.Granted)
                            {
                                NativeGallery.GetImageFromGalleryForAndroid((path) =>
                                {
                                    if (path.IsNotNullAndEmpty())
                                    {
                                        mPath          = path;
                                        mThumbnailPath = path;
                                        AudioContent.gameObject.SetActive(false);
                                        if (mPath.IsNotNullAndEmpty())
                                        {
                                            ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic);
                                            BtnVideo.gameObject.SetActive(false);
                                            BtnDel.gameObject.SetActive(true);
                                        }
                                    }
                                    Debug.Log("Image path: " + path);
                                }, "选择图片", "image/*", true, action);
                            }
                        }, (int)_.GetAction);
                    }
                }
                // 视频不需要了
                else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo)
                {
                    NativeGallery.RequestPermission((result, action) =>
                    {
                        if (result == (int)NativeGallery.Permission.Granted)
                        {
                            NativeGallery.GetVideoFromGalleryForAndroid((json) =>
                            {
                                if (json.IsNotNullAndEmpty())
                                {
                                    NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json);
                                    if (model.IsNotNull())
                                    {
                                        if (model.status == 1)
                                        {
                                            mPath          = model.videoPath;
                                            mThumbnailPath = model.imagePath;
                                            AudioContent.gameObject.SetActive(false);
                                            if (model.imagePath.IsNotNullAndEmpty())
                                            {
                                                ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic);
                                                BtnVideo.gameObject.SetActive(true);
                                                BtnDel.gameObject.SetActive(true);
                                            }
                                        }
                                        else if (model.status == 0)
                                        {
                                            mPath           = null;
                                            mThumbnailPath  = null;
                                            ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                                            BtnVideo.gameObject.SetActive(false);
                                            BtnDel.gameObject.SetActive(false);
                                        }
                                    }
                                }
                            }, "选择视频", "video/*", action);
                        }
                    }, (int)_.GetAction);
                }
            }).AddTo(this);
            SimpleEventSystem.GetEvent <TipConfirmClick>()
            .Subscribe(_ =>
            {
                if (_.GetAction == TipAction.DelAttendance)
                {
                    mPath           = null;
                    mThumbnailPath  = null;
                    ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f);
                    BtnVideo.gameObject.SetActive(false);
                    BtnDel.gameObject.SetActive(false);
                }
            }).AddTo(this);
            SimpleEventSystem.GetEvent <VideoCompressResult>().Subscribe(res =>
            {
                VideoCompressModel model = res.Model;

                if (Application.platform == RuntimePlatform.Android)
                {
                    if (model.status == 1)
                    {
                        string fileType = model.path.Substring(model.path.LastIndexOf("."));
                        Log.I("mPath: " + model.path + " fileType: " + fileType);
                        StartRequestForUpload("attendance" + fileType, model.path);
                    }
                    else
                    {
                        CommonUtil.toast("视频压缩失败");
                    }
                }
                else if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                }
            }).AddTo(this);
        }