using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using Shared.SimpleControl.R;
using Shared.SimpleControl.Phone.Music;
using Shared.SimpleControl.Phone;
using Shared.SimpleControl;
namespace SmartHome.UI.SimpleControl.Phone.Music
{
///
/// 收音机播放界面
///
class RadioPage : FrameLayout
{
///
/// 停止/播放
///
Button btnPlay;
///
/// 静音图标
///
Button btnMute;
Button btnMusicvol;
HorizontalSeekBar horizontalSeekBarVol;
///
/// 频道
///
Button channel;
///
/// 频率
///
Button Range;
///
/// 当前界面对象
///
static RadioPage currentPage;
FrameLayout middleFrameLayout = new FrameLayout () {
Height = Application.GetRealHeight (1000 + 100),
BackgroundImagePath = "MusicIcon/PlayBackgroun.png",
};
MusicModel currentMusiceModel;
public void Show(MusicModel musiceModel)
{
if (currentPage != null)
{
currentPage.RemoveFromParent();
}
currentPage = this;
currentMusiceModel = musiceModel;
//读取当前的音乐状态
readStatus();
AddChidren(new Button()
{
Height = Application.GetRealHeight(36),
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
});
var topFrameLayout = new FrameLayout()
{
Height = Application.GetRealHeight(100),
Y = Application.GetRealHeight(36),
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
};
AddChidren(topFrameLayout);
var back = new Button
{
Width = Application.GetMinRealAverage(72),
Height = Application.GetMinRealAverage(89),
X = Application.GetRealWidth(10),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayBack.png",
};
topFrameLayout.AddChidren(back);
back.MouseDownEventHandler += (sender, o) =>
{
currentPage = null;
//退出界面的时候,从父控件里移除掉
RemoveFromParent();
};
topFrameLayout.AddChidren(new Button
{
Width = Application.GetMinRealAverage(300),
Height = Application.GetMinRealAverage(60),
Text = currentMusiceModel.Name,
Gravity = Gravity.Center,
TextColor = SkinStyle.Current.MusicTextColor,
});
var set = new Button
{
Width = Application.GetRealWidth(76),
Height = Application.GetRealHeight(66),
X = Application.GetRealWidth(550),
UnSelectedImagePath = "MusicIcon/PlayMusicset.png",
Gravity = Gravity.CenterVertical,
Tag = currentMusiceModel,
};
topFrameLayout.AddChidren(set);
set.MouseDownEventHandler += (sender, e) =>
{
SourcePage sourcePage = new SourcePage { };
MainPage.MainFrameLayout.AddChidren(sourcePage);
sourcePage.Show((MusicModel)set.Tag);
};
middleFrameLayout.Y = topFrameLayout.Bottom;
AddChidren(middleFrameLayout);
topFrameLayout.BringToFront();//隐藏底层
var sdname = new Button
{
Width = Application.GetRealWidth(200),
Height = Application.GetRealHeight(60),
TextID = MyInternationalizationString.MusicFM,
X = Application.GetRealWidth(230),
Y = Application.GetRealHeight(175 - 130)
};
middleFrameLayout.AddChidren(sdname);
var audio = new Button
{
Height = Application.GetRealHeight(248),
Y = Application.GetRealHeight(380 - 130),
UnSelectedImagePath = "MusicIcon/Radioaudio.png",
};
middleFrameLayout.AddChidren(audio);
var Radiogarden = new Button
{
Width = Application.GetRealWidth(319),
Height = Application.GetRealHeight(315),
X = Application.GetRealWidth(170),
Y = Application.GetRealHeight(360 - 130),
UnSelectedImagePath = "MusicIcon/Radiogarden.png",
};
middleFrameLayout.AddChidren(Radiogarden);
//频率
Range = new Button
{
Width = Application.GetMinRealAverage(350),
Height = Application.GetMinRealAverage(80),
//Text = "UnKown",
TextSize =25,
X = Application.GetRealWidth(145),
Y = Application.GetRealHeight(430 - 130),
};
middleFrameLayout.AddChidren(Range);
var Range1 = new Button
{
Width = Application.GetMinRealAverage(350),
Height = Application.GetMinRealAverage(60),
Text ="MHz",
TextSize = 20,
X = Application.GetRealWidth(150),
Y = Application.GetRealHeight(510 - 130),
};
middleFrameLayout.AddChidren(Range1);
var down = new Button
{
Width = Application.GetRealWidth(103),
Height = Application.GetRealHeight(103),
X = Application.GetRealWidth(18),
Y = Application.GetRealHeight(839 - 130),
UnSelectedImagePath = "MusicIcon/Radiodown.png",
SelectedImagePath = "MusicIcon/RadiodownSelected.png",
};
middleFrameLayout.AddChidren(down);
down.MouseDownEventHandler += Down_MouseDownEventHandler;
down.MouseUpEventHandler += Down_MouseUpEventHandler;
//频道
channel = new Button
{
Width = Application.GetMinRealAverage(350),
Height = Application.GetMinRealAverage(60),
//Text = "UnKown",
TextSize = 15,
X = Application.GetRealWidth(150),
Y = Application.GetRealHeight(847 - 130),
};
middleFrameLayout.AddChidren(channel);
Button upward = new Button
{
Width = Application.GetRealWidth(103),
Height = Application.GetRealHeight(103),
X = Application.GetRealWidth(540),
Y = Application.GetRealHeight(827 - 130),
UnSelectedImagePath = "MusicIcon/Radioupward.png",
SelectedImagePath="MusicIcon/RadioupwardSelected.png",
Tag = currentMusiceModel.Name,
};
middleFrameLayout.AddChidren(upward);
upward.MouseDownEventHandler += Upward_MouseDownEventHandler;
upward.MouseUpEventHandler += Upward_MouseUpEventHandler;
#region 上,下,暂停/播放
var tempFrameLayout = new FrameLayout
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(130),
Y = Application.GetRealHeight(960 - 130)
};
middleFrameLayout.AddChidren(tempFrameLayout);
var prve = new Button
{
Width = Application.GetRealWidth(126),
Height = Application.GetRealHeight(126),
X = Application.GetRealWidth(127),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayPrve.png",
SelectedImagePath = "MusicIcon/PlayPrveSelected.png",
};
prve.MouseDownEventHandler += Prve_MouseDownEventHandler;
prve.MouseUpEventHandler += Prve_MouseUpEventHandler;
tempFrameLayout.AddChidren(prve);
btnPlay = new Button
{
Width = Application.GetRealWidth(159),
Height = Application.GetRealHeight(127),
X = Application.GetRealWidth(260),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/Playplay.png",
SelectedImagePath = "MusicIcon/playmusicplaySelected.png",
};
tempFrameLayout.AddChidren(btnPlay);
btnPlay.MouseDownEventHandler += Play_MouseDownEventHandler;
var next = new Button
{
Width = Application.GetRealWidth(126),
Height = Application.GetRealHeight(126),
X = Application.GetRealWidth(430),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayNext.png",
SelectedImagePath = "MusicIcon/PlayNextSelected.png",
};
next.MouseDownEventHandler += Next_MouseDownEventHandler;
next.MouseUpEventHandler += Next_MouseUpEventHandler;
tempFrameLayout.AddChidren(next);
#endregion
#region 音量+,-,静音
btnMute = new Button
{
Width = Application.GetRealWidth(107),
Height = Application.GetRealHeight(127),
X = Application.GetRealWidth(15),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayMute.png",
SelectedImagePath = "MusicIcon/PlayMuteSelected.png",
};
tempFrameLayout.AddChidren(btnMute);
btnMute.MouseDownEventHandler += BtnMute_MouseDownEventHandler;
btnMusicvol = new Button
{
Width = Application.GetRealWidth(107),
Height = Application.GetRealHeight(127),
X = Application.GetRealWidth(540),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
SelectedImagePath = "MusicIcon/PlayVoiceSelected.png",
};
tempFrameLayout.AddChidren(btnMusicvol);
btnMusicvol.MouseDownEventHandler += BtnMusicvol_MouseDownEventHandler;
var ProgFrameLayout = new FrameLayout
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(100),
Y = Application.GetRealHeight(1120 - 130),
};
middleFrameLayout.AddChidren(ProgFrameLayout);
var btnMusicvo2 = new Button
{
Width = Application.GetRealWidth(107),
Height = Application.GetRealHeight(127),
X = Application.GetRealWidth(15),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
};
ProgFrameLayout.AddChidren(btnMusicvo2);
var frameLayout = new FrameLayout
{
Width = Application.GetRealWidth(490),
Height = Application.GetRealHeight(50),
Gravity = Gravity.CenterVertical,
X =Application.GetRealWidth(100),
};
ProgFrameLayout.AddChidren(frameLayout);
//当前播放的音量
horizontalSeekBarVol = new HorizontalSeekBar
{
Width = Application.GetRealWidth(490 - 26),
Height = Application.GetRealHeight(50),
Radius = (uint)Application.GetRealHeight(25),
X = Application.GetRealWidth(13),
Gravity = Gravity.CenterVertical,
Max = 79,
BackgroundColor=0xff525252,
ProgressColor = 0xffFE5E00,
};
frameLayout.AddChidren(horizontalSeekBarVol);
horizontalSeekBarVol.ProgressChanged += HorizontalSeekBarVol_ProgressChanged;
#endregion
}
private void Upward_MouseUpEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = false;
}
private void Upward_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = true;
send("*S5PREVCHANNELSCAN");
}
private void Down_MouseUpEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = false;
}
private void Down_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = true;
send("*S5NEXTCHANNELSCAN");
}
private void Next_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = true;
send("*S5NEXTCHANNEL");
}
private void Prve_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = true;
send("*S5PREVCHANNEL");
}
private void Prve_MouseUpEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = false;
}
private void Next_MouseUpEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
button.IsSelected = false;
}
//点击静音之前的音量
string beforeVol = "30";
private void BtnMute_MouseDownEventHandler(object sender, MouseEventArgs e)
{
if (btnMute.IsSelected)
{
btnMute.IsSelected = false;
send("*Z1VOL" + beforeVol);
}
else
{
//静音之前先保存之前的音量,为还原音量
beforeVol = currentMusiceModel.CurVol;
btnMute.IsSelected = true;
send("*Z1VOL79");
}
}
private void BtnMusicvol_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = sender as Button;
if (button.IsSelected)
{
button.IsSelected = false;
middleFrameLayout.Y += Application.GetRealHeight(100);
}
else
{
button.IsSelected = true;
middleFrameLayout.Y -= Application.GetRealHeight(100);
}
}
private void HorizontalSeekBarVol_ProgressChanged(object sender, int e)
{
int volValue = 79 - e;
send("*Z1VOL" + volValue);
}
private void Play_MouseDownEventHandler(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
if (button.IsSelected)
{
button.IsSelected = false;
}
else
{
button.IsSelected = true;
}
send("*S5PLAYSTOP");
}
void send(string command)
{
MyMusic.dateTime = System.DateTime.Now;
if (currentMusiceModel.SourceID != "5")
{
Control.ControlBytesSend(Command.ControlMusicModel, currentMusiceModel.SubnetID, currentMusiceModel.DeviceID, MusicModel.MusiceBytes("*Z1SRC5"));
}
Control.ControlBytesSend(Command.ControlMusicModel, currentMusiceModel.SubnetID, currentMusiceModel.DeviceID, MusicModel.MusiceBytes(command));
}
///
/// 读取音乐状态
///
void readStatus()
{
System.Threading.Tasks.Task.Run(() =>
{
System.DateTime dateTime = System.DateTime.Now.AddSeconds(-10);
while (Parent != null)
{
//等待1秒
System.Threading.Thread.Sleep(1000 * 1);
Application.RunOnMainThread(() =>
{
try
{
Range.Text = currentMusiceModel.curMusicListName.Replace("MHz","");
channel.Text = currentMusiceModel.curPlayMusicName.Replace(".mp3", "");
horizontalSeekBarVol.Progress = 79 - int.Parse(currentMusiceModel.CurVol);
btnMute.IsSelected = currentMusiceModel.CurVol == "79" ? true : false;
if (currentMusiceModel.PlayStatus == MusicModel.Status.Play)
{
btnPlay.IsSelected = true;
}
else
{
btnPlay.IsSelected = false;
}
}
catch { }
});
}
});
}
}
}