// // playerSetView.m // 双子星云手机 // // Created by xd h on 2024/6/24. // #import "playerSetView.h" #import "SYJUISwitch.h" #import "customSwitchButton.h" @interface playerSetView () @property(nonatomic, strong)UIView* blackBgView; @property(nonatomic, strong) UILabel *delayedLabel;//延时 @property(nonatomic, strong) UILabel *PacketLossLabel;//丢包 @property(nonatomic, strong) UILabel *speedLabel;//速度(带宽) @property(nonatomic, strong) UILabel *fpsLabel; //@property(nonatomic, strong)UIView *bg0View;//1.4.4 新加分辨率 //@property(nonatomic, strong) UIButton *resolution720Button; //@property(nonatomic, strong) UIButton *resolution1080Button; //@property(nonatomic,strong) CAGradientLayer *glayer; //1.4.6 UI @property(nonatomic, strong)UIView *bg1ViewL;//第一行 左边 @property(nonatomic, strong) customSwitchButton * resolutionSwitch;//分辨率切换开关 @property(nonatomic, strong)UIView *bg1ViewR;//第一行 右边 @property(nonatomic, strong) customSwitchButton * bottomNavSwitch;//底部导航栏开关 @property(nonatomic, strong)UIView *bg2ViewL;//第二行 左边 @property(nonatomic, strong) customSwitchButton * fullScreenSwitch;//全面屏开关 @property(nonatomic, strong) UIView *bg1View; //@property(nonatomic, strong) customSwitchButton * bottomNavSwitch;//底部导航栏开关 //@property(nonatomic, strong) SYJUISwitch * fullScreenSwitch;//全面屏开关 @property(nonatomic, strong) UIButton *TVButton; @property(nonatomic, strong) UILabel *TVShowLabel; @property(nonatomic, strong) UIButton *exitPhoneButton; @end @implementation playerSetView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCouldPhoneTvStatusFun:) name:getCouldPhoneTvStatusNotification object:nil]; [self drawAnyView]; return self; } - (void)drawAnyView{ //扩大金融云机范围按钮 UIButton *bigButton = [[UIButton alloc] init]; bigButton.tag = 1; [bigButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:bigButton]; //bigButton.backgroundColor = [UIColor greenColor]; [bigButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.right.mas_equalTo(0); make.left.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; _blackBgView = [UIView new]; _blackBgView.layer.cornerRadius = 20; _blackBgView.backgroundColor = [UIColor hwColor:@"#202630"]; [self addSubview:_blackBgView]; [_blackBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(340);//(256); make.width.mas_equalTo(320);//(245); make.centerX.mas_equalTo(0.f); make.centerY.mas_equalTo(0.f); }]; /***************************顶部按钮显示*******************************************************/ CGFloat laberTop = 24.0; CGFloat laberW = 30.0; CGFloat laberH = 16.0; CGFloat fontSize = 12.0; ///获取设备当前地区的代码和APP语言环境 NSString *languageCode = [NSLocale preferredLanguages][0]; BOOL isForeignType = NO; //目前支持 中文(简体 繁体) 英文 日语 if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound) { } else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound) { } else{ isForeignType = YES; fontSize = 10.5; } _delayedLabel = [[UILabel alloc] init]; _delayedLabel.font = [UIFont systemFontOfSize:fontSize]; //_delayedLabel.textColor = [UIColor whiteColor]; //_delayedLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil); [_blackBgView addSubview:_delayedLabel]; //_delayedLabel.backgroundColor = [UIColor redColor]; [_delayedLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); //make.width.mas_equalTo(laberW+5); make.height.mas_equalTo(laberH); make.top.mas_equalTo(laberTop); }]; _PacketLossLabel = [[UILabel alloc] init]; _PacketLossLabel.font = [UIFont systemFontOfSize:fontSize]; _PacketLossLabel.textAlignment = NSTextAlignmentCenter; _PacketLossLabel.textColor = [UIColor whiteColor];//[UIColor hwColor:@"#FF2855"]; //_PacketLossLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil); [_blackBgView addSubview:_PacketLossLabel]; //_PacketLossLabel.backgroundColor = [UIColor redColor]; [_PacketLossLabel mas_makeConstraints:^(MASConstraintMaker *make) { //make.left.mas_equalTo(PacketLossTipLabel.mas_right).offset(0); make.centerX.mas_equalTo(self.mas_centerX); //make.width.mas_equalTo(laberW*3.0); make.height.mas_equalTo(laberH); make.top.mas_equalTo(laberTop); }]; _speedLabel = [[UILabel alloc] init]; _speedLabel.font = [UIFont systemFontOfSize:fontSize]; _speedLabel.textColor = [UIColor whiteColor]; _speedLabel.textAlignment = NSTextAlignmentRight; //_speedLabel.text = NSLocalizedString(@"webrtc_msg_delayed",nil); [_blackBgView addSubview:_speedLabel]; //_speedLabel.backgroundColor = [UIColor redColor]; [_speedLabel mas_makeConstraints:^(MASConstraintMaker *make) { //make.centerX.mas_equalTo(1.5*laberW); //make.centerX.mas_equalTo(self.mas_centerX); make.right.mas_equalTo(-15); //make.width.mas_equalTo(laberW*3.0); make.height.mas_equalTo(laberH); make.top.mas_equalTo(laberTop); }]; [self setWebRctMsgBydelayed:0 withPacketLoss:0.0 withSpeed:@"-" withFPS:@"-"]; /***************************分辨率*******************************************************/ // _bg0View = [UIView new]; // _bg0View.layer.cornerRadius = 8; // _bg0View.backgroundColor = [UIColor hwColor:@"#29313D"]; // [_blackBgView addSubview:_bg0View]; // // [_bg0View mas_makeConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(36); // make.left.mas_equalTo(12); // make.right.mas_equalTo(-12); // //make.top.mas_equalTo(16.f); // make.top.mas_equalTo(62.f); // }]; // // //分辨率 // UILabel *resolutionTipLabel = [[UILabel alloc] init]; // resolutionTipLabel.text = NSLocalizedString(@"cloudPhone_player_set_resolution",nil); // resolutionTipLabel.textColor = [UIColor whiteColor]; // resolutionTipLabel.font = [UIFont systemFontOfSize:12.0]; // [_bg0View addSubview:resolutionTipLabel]; // // [resolutionTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(15); // make.top.equalTo(_bg0View.mas_top).offset(0); // make.bottom.equalTo(_bg0View.mas_bottom).offset(0); // }]; // // _resolution720Button = [[UIButton alloc] init]; // _resolution720Button.layer.cornerRadius = 5; // _resolution720Button.backgroundColor = [UIColor hwColor:@"#D8D8D8" alpha:0.09]; // [_resolution720Button setTitle:@"720*1280" forState:UIControlStateNormal]; // [_resolution720Button setTitleColor:[UIColor hwColor:@"#FFFFFF"] forState:UIControlStateNormal]; // _resolution720Button.titleLabel.font = [UIFont systemFontOfSize:12.0]; // _resolution720Button.layer.masksToBounds = YES; // [_resolution720Button addTarget:self action:@selector(didClickResolution720ButFun) forControlEvents:UIControlEventTouchUpInside]; // [_bg0View addSubview:_resolution720Button]; // // [_resolution720Button mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(80); // make.width.mas_equalTo(93); // make.height.mas_equalTo(26); // make.centerY.mas_equalTo(0); // }]; // // _resolution1080Button = [[UIButton alloc] init]; // _resolution1080Button.layer.cornerRadius = 5; // _resolution1080Button.backgroundColor = [UIColor hwColor:@"#D8D8D8" alpha:0.09]; // [_resolution1080Button setTitle:@"1080*1920" forState:UIControlStateNormal]; // [_resolution1080Button setTitleColor:[UIColor hwColor:@"#FFFFFF"] forState:UIControlStateNormal]; // _resolution1080Button.titleLabel.font = [UIFont systemFontOfSize:12.0]; // _resolution1080Button.layer.masksToBounds = YES; // [_resolution1080Button addTarget:self action:@selector(didClickResolution1080ButFun) forControlEvents:UIControlEventTouchUpInside]; // [_bg0View addSubview:_resolution1080Button]; // // [_resolution1080Button mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.mas_equalTo(-12); // make.width.mas_equalTo(93); // make.height.mas_equalTo(26); // make.centerY.mas_equalTo(0); // }]; // // // gradient // _glayer = [CAGradientLayer layer]; // _glayer.frame = CGRectMake(0, 0, 93, 26); // _glayer.startPoint = CGPointMake(0, 0.5); // _glayer.endPoint = CGPointMake(0.97, 0.5); // _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor]; // _glayer.locations = @[@(0), @(1.0f)]; // // [self firstSetResolutionFun]; // /***************************1.4.6新UI*******************************************************/ /***************************分辨率*******************************************************/ _bg1ViewL = [UIView new]; _bg1ViewL.layer.cornerRadius = 8; _bg1ViewL.backgroundColor = [UIColor hwColor:@"#29313D"]; [_blackBgView addSubview:_bg1ViewL]; [_bg1ViewL mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(42); make.left.mas_equalTo(15); make.right.equalTo(self.mas_centerX).offset(-6); make.top.mas_equalTo(56.f); }]; UILabel *bg1ViewLeftTipLab = [[UILabel alloc] init]; bg1ViewLeftTipLab.text = NSLocalizedString(@"cloudPhone_player_set_resolution",nil); //bg1ViewLeftTipLab.textAlignment = NSTextAlignmentCenter; bg1ViewLeftTipLab.textColor = [UIColor whiteColor]; bg1ViewLeftTipLab.font = [UIFont systemFontOfSize:12.0]; [_bg1ViewL addSubview:bg1ViewLeftTipLab]; [bg1ViewLeftTipLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(8); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0);; }]; //开启和关闭多国语言 NSString *onStr = NSLocalizedString(@"UISwitch_open_title",nil); NSString *offStr = NSLocalizedString(@"UISwitch_close_title",nil); _resolutionSwitch = [[customSwitchButton alloc] initWithFrame:CGRectMake(0, 0,80, 26) onText:@"720" offText:@"1080"]; [_bg1ViewL addSubview:_resolutionSwitch]; [_resolutionSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-8.f); make.centerY.mas_equalTo(0.f); make.width.mas_equalTo(80.f); make.height.mas_equalTo(26.f); }]; KWeakSelf _resolutionSwitch.didClickSwitchButtonFun = ^(BOOL isOn) { [weakSelf maskSwitchPressed:weakSelf.resolutionSwitch]; }; /***************************导航栏*******************************************************/ _bg1ViewR = [UIView new]; _bg1ViewR.layer.cornerRadius = 8; _bg1ViewR.backgroundColor = [UIColor hwColor:@"#29313D"]; [_blackBgView addSubview:_bg1ViewR]; [_bg1ViewR mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(42); make.right.mas_equalTo(-15); make.left.equalTo(self.mas_centerX).offset(6); make.top.mas_equalTo(56.f); }]; UILabel *bg1ViewRightTipLab = [[UILabel alloc] init]; bg1ViewRightTipLab.text = NSLocalizedString(@"cloudPhone_nav_show_tip",nil); //bg1ViewRightTipLab.textAlignment = NSTextAlignmentCenter; bg1ViewRightTipLab.textColor = [UIColor whiteColor]; bg1ViewRightTipLab.font = [UIFont systemFontOfSize:12.0]; [_bg1ViewR addSubview:bg1ViewRightTipLab]; [bg1ViewRightTipLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(8); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0);; }]; //开启和关闭多国语言 //NSString *onStr = NSLocalizedString(@"UISwitch_open_title",nil); //NSString *offStr = NSLocalizedString(@"UISwitch_close_title",nil); _bottomNavSwitch = [[customSwitchButton alloc] initWithFrame:CGRectMake(0, 0,80, 26) onText:onStr offText:offStr]; [_bg1ViewR addSubview:_bottomNavSwitch]; [_bottomNavSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-8.f); make.centerY.mas_equalTo(0.f); make.width.mas_equalTo(80.f); make.height.mas_equalTo(26.f); }]; _bottomNavSwitch.didClickSwitchButtonFun = ^(BOOL isOn) { [weakSelf maskSwitchPressed:weakSelf.bottomNavSwitch]; }; /***************************全面屏相关*******************************************************/ //全面屏开关 _bg2ViewL = [UIView new]; _bg2ViewL.layer.cornerRadius = 8; _bg2ViewL.backgroundColor = [UIColor hwColor:@"#29313D"]; [_blackBgView addSubview:_bg2ViewL]; [_bg2ViewL mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(42); make.left.mas_equalTo(15); make.right.equalTo(self.mas_centerX).offset(-6); make.top.equalTo(_bg1ViewL.mas_bottom).offset(14); }]; UILabel *fullScreenTipLabel = [[UILabel alloc] init]; fullScreenTipLabel.text = NSLocalizedString(@"cloudPhone_fullScreen_show_tip",nil); //fullScreenTipLabel.textAlignment = NSTextAlignmentCenter; fullScreenTipLabel.textColor = [UIColor whiteColor]; fullScreenTipLabel.font = [UIFont systemFontOfSize:12.0]; [_bg2ViewL addSubview:fullScreenTipLabel]; [fullScreenTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(8); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0);; }]; //开启和关闭多国语言 //NSString *onStr = NSLocalizedString(@"UISwitch_open_title",nil); //NSString *offStr = NSLocalizedString(@"UISwitch_close_title",nil); _fullScreenSwitch = [[customSwitchButton alloc] initWithFrame:CGRectMake(0, 0,80, 26) onText:onStr offText:offStr]; [_bg2ViewL addSubview:_fullScreenSwitch]; [_fullScreenSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-8.f); make.centerY.mas_equalTo(0.f); make.width.mas_equalTo(80.f); make.height.mas_equalTo(26.f); }]; _fullScreenSwitch.didClickSwitchButtonFun = ^(BOOL isOn) { [weakSelf maskSwitchPressed:weakSelf.fullScreenSwitch]; }; //KWeakSelf dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf setAllSwitchFun]; }); /**********************************************************************************/ // UIView *bg2View = [UIView new]; // bg2View.layer.cornerRadius = 12; // bg2View.backgroundColor = [UIColor hwColor:@"#29313D"]; // [_blackBgView addSubview:bg2View]; // // [bg2View mas_makeConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(72); // make.left.mas_equalTo(15); // make.right.mas_equalTo(-15); // make.top.equalTo(_bg1View.mas_bottom).offset(12); // //make.top.mas_equalTo(52); // }]; NSArray *titleArr = @[NSLocalizedString(@"cloudPhone_set_app_upload_tip",nil), NSLocalizedString(@"my_set_no_TV_p2p",nil), NSLocalizedString(@"cloudPhone_set_copy_tip",nil), NSLocalizedString(@"cloudPhone_set_screenshot_tip",nil), NSLocalizedString(@"my_set_no_restart_phone",nil), ]; NSArray *imageArr = @[@"cloudPhone_set_app_upload", @"cloudPhone_set_TV", @"cloudPhone_set_copy", @"cloudPhone_set_screenshot", @"cloudPhone_set_restart", ]; //CGFloat butTopY = 15.0; CGFloat imageWH = 24.0; // CGFloat butHeight = imageWH +20 +5; // CGFloat butWidth = (320 -15*2)/3.0; //70.0; // //CGFloat butWidth = (245 -12*2)/2.0; //70.0; // CGFloat butSpace = 0.0; //(245 - butWidth*3)/3.0; for (int i=0; i= 100) { _delayedLabel.textColor = [UIColor hwColor:@"#FF2855"]; } else if (delayedMS >= 50){ _delayedLabel.textColor = [UIColor yellowColor]; } else{ _delayedLabel.textColor = [UIColor hwColor:@"22A082"]; } if(delayedMS >= 1000){ _delayedLabel.text = [[NSString alloc] initWithFormat:@"%lds",delayedMS/1000]; } else{ _delayedLabel.text = [[NSString alloc] initWithFormat:@"%ldms",delayedMS]; } NSString * delayedStr = @""; if(delayedMS >= 1000){ delayedStr = [[NSString alloc] initWithFormat:@"%lds",delayedMS/1000]; } else{ delayedStr = [[NSString alloc] initWithFormat:@"%ldms",delayedMS]; } NSString*leftStr = NSLocalizedString(@"webrtc_msg_delayed",nil); NSString *fullTitle = [[NSString alloc] initWithFormat:@"%@%@",leftStr,delayedStr]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:fullTitle]; NSRange leftRange = NSMakeRange([fullTitle rangeOfString:leftStr].location, [fullTitle rangeOfString:leftStr].length); [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:leftRange]; _delayedLabel.attributedText = attrStr; NSString*LossleftStr = NSLocalizedString(@"webrtc_msg_PacketLoss",nil); NSString*LossRightStr = [[NSString alloc] initWithFormat:@"%.02f%%",PacketLoss]; NSString *LossfullTitle = [[NSString alloc] initWithFormat:@"%@%@",LossleftStr,LossRightStr]; NSMutableAttributedString *attrStr2 = [[NSMutableAttributedString alloc] initWithString:LossfullTitle]; NSRange rightRange = NSMakeRange([LossfullTitle rangeOfString:LossRightStr].location, LossRightStr.length); UIColor *rightColor = [UIColor hwColor:@"22A082"]; if(PacketLoss >= 5 && PacketLoss < 10){ rightColor = [UIColor yellowColor]; } else if(PacketLoss >= 10){ rightColor = [UIColor hwColor:@"#FF2855"]; } [attrStr2 addAttribute:NSForegroundColorAttributeName value:rightColor range:rightRange]; _PacketLossLabel.attributedText = attrStr2; _speedLabel.text = [[NSString alloc] initWithFormat:@"%@%@",NSLocalizedString(@"webrtc_msg_speed",nil),speedStr]; //_fpsLabel.text = [[NSString alloc] initWithFormat:@"FPS:%@",fpsStr]; } #pragma mark 设置分辨率 - (void)firstSetResolutionFun { NSInteger curResolution = [HWDataManager getIntegerWithKey:Const_cloudPhone_cur_resolution]; // if(curResolution == 0 || curResolution == 1){ // _resolution720Button.selected = YES; // [_resolution720Button.layer insertSublayer:_glayer atIndex:0]; // } // else{ // _resolution1080Button.selected = YES; // [_resolution1080Button.layer insertSublayer:_glayer atIndex:0]; // } } #pragma mark 是否要显示设置分辨率(全面屏要隐藏) - (void)handleResolutionUIFun { BOOL isHide = [HWDataManager getBoolWithKey:Consn_player_full_screen_show]; if (isHide) { // [_blackBgView mas_updateConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(260);//(256); // }]; // // _bg0View.hidden = YES; // // [_bg1View mas_updateConstraints:^(MASConstraintMaker *make) { // make.top.mas_equalTo(62); // }]; _bg1ViewL.alpha = 0.5; _resolutionSwitch.enabled = NO; } else{ _bg1ViewL.alpha = 1.0; _resolutionSwitch.enabled = YES; // [_blackBgView mas_updateConstraints:^(MASConstraintMaker *make) { // make.height.mas_equalTo(260 + 50);//(256); // }]; // // _bg0View.hidden = NO; // // [_bg1View mas_updateConstraints:^(MASConstraintMaker *make) { // make.top.mas_equalTo(112); // }]; } } #pragma mark 点击了分辨率720 - (void)didClickResolution720ButFun { // if(_resolution720Button.selected){ // return; // } // // _resolution1080Button.selected = NO; // _resolution720Button.selected = YES; // [_resolution720Button.layer insertSublayer:_glayer atIndex:0]; if(_didClickButtonFun){ _didClickButtonFun(1); } [HWDataManager setIntegerWithKey:Const_cloudPhone_cur_resolution value:1]; } #pragma mark 点击了分辨率1080 - (void)didClickResolution1080ButFun { // if(_resolution1080Button.selected){ // return; // } // _resolution720Button.selected = NO; // _resolution1080Button.selected = YES; // [_resolution1080Button.layer insertSublayer:_glayer atIndex:0]; if(_didClickButtonFun){ _didClickButtonFun(2); } [HWDataManager setIntegerWithKey:Const_cloudPhone_cur_resolution value:2]; } @end