230 lines
9.6 KiB
C#
230 lines
9.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using SafeMobileLib;
|
|||
|
using Telerik.WinControls.Layouts;
|
|||
|
using Telerik.WinControls.UI;
|
|||
|
|
|||
|
namespace Safedispatch_4_0.Radio
|
|||
|
{
|
|||
|
public class RecordingVisualListItem : SimpleListViewVisualItem
|
|||
|
{
|
|||
|
private DockLayoutPanel dockLayout;
|
|||
|
private LightVisualElement callTypeIcon;
|
|||
|
private StackLayoutElement callInformationStack;
|
|||
|
private LightVisualElement username;
|
|||
|
private LightVisualElement duration;
|
|||
|
private LightVisualElement dateUnix;
|
|||
|
private LightVisualElement buttonPlay;
|
|||
|
|
|||
|
protected override void CreateChildElements()
|
|||
|
{
|
|||
|
base.CreateChildElements();
|
|||
|
|
|||
|
this.dockLayout = new DockLayoutPanel();
|
|||
|
this.dockLayout.StretchHorizontally = true;
|
|||
|
this.dockLayout.ShouldHandleMouseInput = false;
|
|||
|
this.dockLayout.Padding = new Padding(2, 2, 10, 2);
|
|||
|
this.dockLayout.Margin = new Padding(2, 2, 10, 2);
|
|||
|
|
|||
|
this.callTypeIcon = new LightVisualElement();
|
|||
|
this.callTypeIcon.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
|
|||
|
this.callTypeIcon.AutoSize = true;
|
|||
|
this.callTypeIcon.Alignment = ContentAlignment.MiddleCenter;
|
|||
|
//this.callTypeIcon.ImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
|||
|
this.callTypeIcon.ShouldHandleMouseInput = false;
|
|||
|
this.dockLayout.Children.Add(this.callTypeIcon);
|
|||
|
DockLayoutPanel.SetDock(callTypeIcon, Telerik.WinControls.Layouts.Dock.Left);
|
|||
|
|
|||
|
|
|||
|
this.buttonPlay = new LightVisualElement();
|
|||
|
this.buttonPlay.Tag = "stopped";
|
|||
|
//this.buttonPlay.Margin = new Padding(0,12,3,12);
|
|||
|
this.buttonPlay.Image = ScaleImage(Dispatcher.Properties.Resources.r_play, 32, 32);
|
|||
|
/*
|
|||
|
this.buttonPlay.MouseEnter += delegate(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.buttonPlay.Image = ScaleImage(Dispatcher.Properties.Resources.r_play,32,32);
|
|||
|
};
|
|||
|
this.buttonPlay.MouseLeave += delegate(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.buttonPlay.Image = ScaleImage(Dispatcher.Properties.Resources.r_play_blue, 32, 32);
|
|||
|
};*/
|
|||
|
this.buttonPlay.Click += delegate(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (MainForm2.PlayingFile)
|
|||
|
return;
|
|||
|
|
|||
|
if (this.buttonPlay.Tag.Equals("stopped"))
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
// get data
|
|||
|
if (this.Data != null)
|
|||
|
{
|
|||
|
Recording item = this.Data.DataBoundItem as Recording;
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
this.buttonPlay.Image = Utils.ScaleImage(Dispatcher.Properties.Resources.r_play_blue, 32, 32);
|
|||
|
this.buttonPlay.Tag = "playing";
|
|||
|
|
|||
|
// trigger event for when click is done
|
|||
|
if (_onPlay_Click != null)
|
|||
|
_onPlay_Click(buttonPlay, new ToggleClickEventArgs()
|
|||
|
{
|
|||
|
recording = item,
|
|||
|
isActive = !buttonPlay.Tag.Equals("playing")
|
|||
|
});
|
|||
|
|
|||
|
Thread t = new Thread(new ThreadStart(delegate
|
|||
|
{
|
|||
|
Thread.Sleep(item.duration * 1000);
|
|||
|
|
|||
|
this.buttonPlay.Image = Utils.ScaleImage(Dispatcher.Properties.Resources.r_play, 32, 32);
|
|||
|
this.buttonPlay.Tag = "stopped";
|
|||
|
}));
|
|||
|
t.Start();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
else
|
|||
|
{
|
|||
|
this.buttonPlay.Image = Utils.ScaleImage(Dispatcher.Properties.Resources.r_play, 32, 32);
|
|||
|
this.buttonPlay.Tag = "stopped";
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
};
|
|||
|
this.buttonPlay.ShouldHandleMouseInput = true;
|
|||
|
this.buttonPlay.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
|
|||
|
//this.buttonPlay.Image = ScaleImage(Dispatcher.Properties.Resources.r_play_blue, 32, 32);
|
|||
|
//this.buttonPlay.ImageAlignment = ContentAlignment.MiddleCenter;
|
|||
|
this.dockLayout.Children.Add(this.buttonPlay);
|
|||
|
DockLayoutPanel.SetDock(buttonPlay, Telerik.WinControls.Layouts.Dock.Right);
|
|||
|
|
|||
|
this.callInformationStack = new StackLayoutElement();
|
|||
|
this.callInformationStack.Padding = new Padding(0);
|
|||
|
this.callInformationStack.Margin = new Padding(0);
|
|||
|
this.callInformationStack.ShouldHandleMouseInput = false;
|
|||
|
this.callInformationStack.Orientation = Orientation.Vertical;
|
|||
|
this.dockLayout.Children.Add(this.callInformationStack);
|
|||
|
DockLayoutPanel.SetDock(this.callInformationStack, Telerik.WinControls.Layouts.Dock.Top);
|
|||
|
|
|||
|
|
|||
|
this.username = new LightVisualElement();
|
|||
|
this.username.ShouldHandleMouseInput = false;
|
|||
|
this.username.StretchHorizontally = false;
|
|||
|
this.username.StretchVertically = true;
|
|||
|
this.username.MaxSize = new Size(150, 35);
|
|||
|
this.username.MinSize = new Size(150, 35);
|
|||
|
this.username.Padding = new Padding(0, 0, 0, 0);
|
|||
|
this.username.Margin = new Padding(0, 0, 0, 0);
|
|||
|
this.username.Font = new System.Drawing.Font("Segoe UI", 9, FontStyle.Bold, GraphicsUnit.Point);
|
|||
|
this.username.TextAlignment = ContentAlignment.MiddleLeft;
|
|||
|
this.username.TextWrap = true;
|
|||
|
this.callInformationStack.Children.Add(this.username);
|
|||
|
|
|||
|
this.duration = new LightVisualElement();
|
|||
|
this.duration.ShouldHandleMouseInput = false;
|
|||
|
this.duration.StretchHorizontally = false;
|
|||
|
this.duration.Padding = new Padding(0, 14, 0, 0);
|
|||
|
this.duration.Margin = new Padding(0, 0, 0, 0);
|
|||
|
this.duration.TextAlignment = ContentAlignment.TopLeft;
|
|||
|
this.duration.ForeColor = Color.FromArgb(0x66,0x66,0x66);
|
|||
|
this.callInformationStack.Children.Add(this.duration);
|
|||
|
|
|||
|
this.dateUnix = new LightVisualElement();
|
|||
|
this.dateUnix.ShouldHandleMouseInput = false;
|
|||
|
this.dateUnix.StretchHorizontally = false;
|
|||
|
this.callInformationStack.Children.Add(this.dateUnix);
|
|||
|
|
|||
|
this.Children.Add(this.dockLayout);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected override void SynchronizeProperties()
|
|||
|
{
|
|||
|
base.SynchronizeProperties();
|
|||
|
Recording rec = (Recording)this.Data.Value;
|
|||
|
this.Text = "";
|
|||
|
this.callTypeIcon.Image = ScaleImage(rec.callTypeImage, 48,48);
|
|||
|
this.username.Text = Convert.ToString(this.Data["username"]);// rec.username;
|
|||
|
|
|||
|
DateTime dt = new DateTime(1970, 1, 1).AddSeconds(rec.dateUnix);
|
|||
|
this.duration.Text = String.Format("{0:HH:mm:ss}", dt) + " [" + Convert.ToString(this.Data["duration"]) + " sec]";
|
|||
|
|
|||
|
if (this.Data.Selected)
|
|||
|
this.buttonPlay.Visibility = Telerik.WinControls.ElementVisibility.Visible;
|
|||
|
else
|
|||
|
this.buttonPlay.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
|
|||
|
//this.dateUnix.Text = String.Format("{0:HH:mm:ss dd/MM}", new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(rec.dateUnix)); // Convert.ToDateTime(this.Data[3]);
|
|||
|
}
|
|||
|
|
|||
|
protected override Type ThemeEffectiveType
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return typeof(SimpleListViewVisualItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Resize an image keeping the aspect ratio of the image
|
|||
|
/// </summary>
|
|||
|
/// <param name="image">Image which needs to be resized</param>
|
|||
|
/// <param name="maxWidth">Maximum allowed width for this image</param>
|
|||
|
/// <param name="maxHeight">Maximum allowed height for this image</param>
|
|||
|
/// <returns>The resized image</returns>
|
|||
|
public static Image ScaleImage(Image image, int maxWidth, int maxHeight)
|
|||
|
{
|
|||
|
var ratioX = (double)maxWidth / image.Width;
|
|||
|
var ratioY = (double)maxHeight / image.Height;
|
|||
|
var ratio = Math.Min(ratioX, ratioY);
|
|||
|
|
|||
|
var newWidth = (int)(image.Width * ratio);
|
|||
|
var newHeight = (int)(image.Height * ratio);
|
|||
|
|
|||
|
var newImage = new Bitmap(newWidth, newHeight);
|
|||
|
Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
|
|||
|
return newImage;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#region CELL CLICK EVENTS
|
|||
|
public class ToggleClickEventArgs : EventArgs
|
|||
|
{
|
|||
|
public Recording recording { get; set; }
|
|||
|
public Boolean isActive { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
private object _lockPlayClick = new object();
|
|||
|
private event EventHandler<ToggleClickEventArgs> _onPlay_Click;
|
|||
|
public event EventHandler<ToggleClickEventArgs> OnPlay_Click
|
|||
|
{
|
|||
|
add { lock (_lockPlayClick) { _onPlay_Click += value; } }
|
|||
|
remove { lock (_lockPlayClick) { _onPlay_Click -= value; } }
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
|
|||
|
private object _lockRemoteClick = new object();
|
|||
|
private event EventHandler<ToggleClickEventArgs> _onRemote_Click;
|
|||
|
public event EventHandler<ToggleClickEventArgs> OnRemote_Click
|
|||
|
{
|
|||
|
add { lock (_lockRemoteClick) { _onRemote_Click += value; } }
|
|||
|
remove { lock (_lockRemoteClick) { _onRemote_Click -= value; } }
|
|||
|
}*/
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|