// // cloudPhoneViewController.m // 双子星云手机 // // Created by xd h on 2024/6/20. // #import "cloudPhoneViewController.h" #import "cloudPhoneSetView.h" #import "PlayerViewController.h" #import "audioPlayingView.h" #import "DFPlayer.h" #import "audioPlayerViewController.h" @interface cloudPhoneViewController () @property (nonatomic,strong) cloudPhoneSetView *cloudPhoneSetV; @end @implementation cloudPhoneViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view setBackgroundColor:HWF5F7FAColor]; [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:YES]; [self drawAnyView]; } - (void)drawAnyView{ //顶底底部图片 UIImageView *topImageV = [UIImageView new]; topImageV.userInteractionEnabled = YES; topImageV.image = [UIImage imageNamed:@"cloudPhone_bg"]; [self.view addSubview:topImageV]; [topImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; CGFloat imageTopY = 54.0; //设置按钮 UIButton *setButton = [[UIButton alloc] init]; //[setButton setBackgroundImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal]; [setButton setImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal]; setButton.tag = 1; [setButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:setButton]; //setButton.backgroundColor = [UIColor greenColor]; [setButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(imageTopY); make.right.mas_equalTo(-16); make.width.mas_equalTo(50); make.height.mas_equalTo(50); // make.top.mas_equalTo(imageTopY); // make.right.mas_equalTo(-16); // make.width.mas_equalTo(24); // make.height.mas_equalTo(24); }]; //中间图片 UIImageView *midImageV = [UIImageView new]; midImageV.userInteractionEnabled = YES; midImageV.image = [UIImage imageNamed:@"cloudPhone_mid_img"]; [self.view addSubview:midImageV]; [midImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(326*WAUTOSCALE); make.height.mas_equalTo(608*WAUTOSCALE); make.centerX.mas_equalTo(0); make.centerY.mas_equalTo(-10); }]; NSString *midTopTipImageStr = @"cloudPhone_topTip_img_cs"; //欢迎 //en-US 英文 ja-JP 日文 NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; NSLog(@"arLanguages:%@",arLanguages); ///获取设备当前地区的代码和APP语言环境 NSString *languageCode = [NSLocale preferredLanguages][0]; //目前支持 中文(简体 繁体) 英文 日语 if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound) { midTopTipImageStr = @"cloudPhone_topTip_img_cs"; } else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound) { midTopTipImageStr = @"cloudPhone_topTip_img_ct"; } else{ midTopTipImageStr = @"cloudPhone_topTip_img_en"; } //提示文字图片 UIImageView *midTopTipImageV = [UIImageView new]; midTopTipImageV.image = [UIImage imageNamed:midTopTipImageStr]; [midImageV addSubview:midTopTipImageV]; [midTopTipImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(282*WAUTOSCALE); make.height.mas_equalTo(84*WAUTOSCALE); make.centerX.mas_equalTo(0); make.top.equalTo(midImageV.mas_top).offset(64); }]; //进入云机 UIButton*enterCloudPhoneButton = [[UIButton alloc] init]; CGFloat w_btn = SCREEN_W - 15*2 - 50*2; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,w_btn,44.f); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(0.97, 0.5); gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor]; gl.locations = @[@(0), @(1.0f)]; [enterCloudPhoneButton.layer addSublayer:gl]; [enterCloudPhoneButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; //[enterCloudPhoneButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)]; [enterCloudPhoneButton setTitle:NSLocalizedString(@"cloudPhone_enter_tip",nil) forState:(UIControlStateNormal)]; [enterCloudPhoneButton.titleLabel setFont:[UIFont systemFontOfSize:16.f]]; [enterCloudPhoneButton.layer setCornerRadius:21.f]; enterCloudPhoneButton.layer.borderWidth = 1.5; enterCloudPhoneButton.layer.borderColor = [UIColor whiteColor].CGColor; enterCloudPhoneButton.clipsToBounds = YES; //enterCloudPhoneButton.tag = 2; [midImageV addSubview:enterCloudPhoneButton]; [enterCloudPhoneButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(w_btn); make.height.mas_equalTo(42); make.centerX.mas_equalTo(0); make.bottom.equalTo(midImageV.mas_bottom).offset(-60); }]; //扩大金融云机范围按钮 UIButton *bigButton = [[UIButton alloc] init]; bigButton.tag = 2; [bigButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:bigButton]; //bigButton.backgroundColor = [UIColor greenColor]; [bigButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(midImageV.mas_top).offset(0); make.right.equalTo(midImageV.mas_right).offset(0); make.left.equalTo(midImageV.mas_left).offset(0); make.bottom.equalTo(midImageV.mas_bottom).offset(0); }]; } #pragma mark 点击按钮 - (void)didClickButtonFun:(UIButton*)but { if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable) { [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show]; return; } NSInteger tag = but.tag; HLog(@"%ld",tag); switch (tag) { case 1: { //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_settings"]; _cloudPhoneSetV = [cloudPhoneSetView new]; [ksharedAppDelegate.window addSubview:_cloudPhoneSetV]; [_cloudPhoneSetV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; KWeakSelf _cloudPhoneSetV.didClickButtonFun = ^(NSInteger tag) { if (tag == 10) {//重启 [weakSelf didClickRestartFun]; } else if (tag == 11){//恢复出厂 [weakSelf RestoreFactoryAleartFun]; } }; } break; case 2: { BOOL isTVShowType = ksharedAppDelegate.TvStatusMod.isTVShowType; if(isTVShowType){//关闭全屏屏 [HWDataManager setBoolWithKey:Consn_player_full_screen_show value:NO]; } BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show]; //重新设置分辨率 if(fullscreenType){ NSString *commandStr = [RCCommandHelp commondToSetFullScreenPhoneSize]; [[webSocketManager shareInstance] send_data:commandStr]; } else{ if ((ksharedAppDelegate.couldPhone_W_PHONE == 720 && ksharedAppDelegate.couldPhone_H_PHONE == 1280) || (ksharedAppDelegate.couldPhone_W_PHONE == 1080 && ksharedAppDelegate.couldPhone_H_PHONE == 1920)) {//云机可能存在的分辨率 } else{ NSString *commondStr = @"{\"data\":{\"height\":1920,\"width\":1080},\"type\":\"setPhoneSize\"}"; [[webSocketManager shareInstance] send_data:commondStr]; } } PlayerViewController *vc = [PlayerViewController new]; [self pushViewController:vc animated:YES]; if(ksharedAppDelegate.TvStatusMod.isTVShowType){ [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show]; } //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_enter"]; } break; default: break; } } #pragma mark 点击了重启空间 - (void)didClickRestartFun { KWeakSelf /*弹窗提示重启*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil) msg:@"" imageStr:@"" cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO didClickOk:^{ [weakSelf sureToRestartCloudPhoneFun]; } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 确认重启云机 - (void)sureToRestartCloudPhoneFun{ // /*重启云手机*/ // 通过指令通道发送 {"type":"reboot"} [[webSocketManager shareInstance] needToRebootFun]; //提示语 [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show]; } #pragma mark 点击恢复出厂 - (void)RestoreFactoryAleartFun { KWeakSelf /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_tips",nil) msg:NSLocalizedString(@"my_set_no_Restore_Factory_msg",nil) imageStr:@"icon_Restore_Factory_big" cancelTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) okTitle:NSLocalizedString(@"other_cancel",nil) isOkBtnHighlight:YES didClickOk:^{ } didClickCancel:^{ //点击确定 [weakSelf gotoResetFun]; }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 点击了恢复出厂 - (void)gotoResetFun { [[webSocketManager shareInstance] needToResetFun]; [self RestoreFactoryingFun]; } #pragma mark 恢复出厂中 - (void)RestoreFactoryingFun { KWeakSelf /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil) msg:NSLocalizedString(@"my_set_no_Restore_Factorying_msg",nil) imageStr:@"" cancelTitle:NSLocalizedString(@"my_set_no_Restore_Factorying",nil) okTitle:@"" isOkBtnHighlight:NO didClickOk:^{ [weakSelf RestoreFactoryCompleteFun]; } didClickCancel:^{ }]; [nextVC setButtonCountdownFun:180];//90 nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 恢复出厂倒计时结束 - (void)RestoreFactoryCompleteFun { //KWeakSelf //瑞云发起重连 //[[connectDeviceManager shareInstance] onConnectFun]; /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_ok_tips",nil) msg:@"" imageStr:@"" cancelTitle:NSLocalizedString(@"my_set_no_Restore_FactoryOK",nil) okTitle:@"" isOkBtnHighlight:NO didClickOk:^{ } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self handelAudioPlayingViewFun]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated { [self.navigationController pushViewController:vc animated:animated]; } #pragma mark 处理音频播放中的视图状态 - (void)handelAudioPlayingViewFun { audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying ||[DFPlayer sharedPlayer].state == DFPlayerStatePause){//播放中 [self showAudioPlayingViewFun]; } else{ [self hideAudioPlayingViewFun]; } KWeakSelf audioPlayingV.didClickButtonFun = ^(NSInteger tag) { if(tag == 1){ [weakSelf hideAudioPlayingViewFun]; } else if(tag == 5){ [weakSelf AudioPlayingGotoAudioPlayerVCFun]; } }; } - (void)AudioPlayingGotoAudioPlayerVCFun{ audioPlayerViewController *vc = [audioPlayerViewController new]; vc.isfirstEnterType = NO; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark 显示音频播放中的视图 - (void)showAudioPlayingViewFun { audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; [self.view addSubview:audioPlayingV]; [audioPlayingV mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(49); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-TABBARHEIGHT); }]; } #pragma mark 隐藏音频播放中的视图 - (void)hideAudioPlayingViewFun { // audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; // [audioPlayingV removeFromSuperview]; } @end