Skip to content

Commit

Permalink
WindowsPhone: Added app icon, splash, icons for sync list, etc. Also …
Browse files Browse the repository at this point in the history
…SyncDiscoveryService is now functional in async, but the number of concurrent connections should be limited.

Related to issue #424.
  • Loading branch information
ycastonguay committed Sep 30, 2013
1 parent 8c814eb commit 475596b
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 73 deletions.
77 changes: 62 additions & 15 deletions MPfm/MPfm.Library/Services/WinRT/SyncDiscoveryService.cs
Expand Up @@ -101,23 +101,26 @@ private async Task<List<SyncDevice>> SearchForDevicesAsync(List<string> ips)
IsRunning = true;

List<SyncDevice> devices = new List<SyncDevice>();
List<Task<SyncDevice>> tasks = new List<Task<SyncDevice>>();
for (int a = 0; a < ips.Count; a++)
{
try
{
Tracing.Log("SyncDiscoveryService - Pinging {0}...", ips[a]);
//Tracing.Log("SyncDiscoveryService - Pinging {0}...", ips[a]);
string url = string.Format("http://{0}:{1}/sessionsapp.version", ips[a], Port);
string content = await _httpClient.GetStringAsync(url);

Tracing.Log("SyncDiscoveryService - Got version from {0}: {1}", ips[a], content);
var device = XmlSerialization.Deserialize<SyncDevice>(content);
if (device.SyncVersionId.ToUpper() == SyncListenerService.SyncVersionId.ToUpper())
{
device.Url = url;
devices.Add(device);
if (OnDeviceFound != null) OnDeviceFound(device);
Tracing.Log("SyncDiscoveryService - The following host is available: {0}", ips[a]);
}
tasks.Add(ProcessDevice(url, ips[a]));

//string content = await _httpClient.GetStringAsync(url);

//Tracing.Log("SyncDiscoveryService - Got version from {0}: {1}", ips[a], content);
//var device = XmlSerialization.Deserialize<SyncDevice>(content);
//if (device.SyncVersionId.ToUpper() == SyncListenerService.SyncVersionId.ToUpper())
//{
// device.Url = url;
// devices.Add(device);
// if (OnDeviceFound != null) OnDeviceFound(device);
// Tracing.Log("SyncDiscoveryService - The following host is available: {0}", ips[a]);
//}
}
catch (Exception ex)
{
Expand All @@ -126,16 +129,60 @@ private async Task<List<SyncDevice>> SearchForDevicesAsync(List<string> ips)
}
finally
{
float percentageDone = ((float)a / (float)ips.Count) * 100;
if (OnDiscoveryProgress != null)
OnDiscoveryProgress(percentageDone, String.Format("Finding devices on local network ({0:0}%)", percentageDone));
//float percentageDone = ((float)a / (float)ips.Count) * 100;
//if (OnDiscoveryProgress != null)
// OnDiscoveryProgress(percentageDone, String.Format("Finding devices on local network ({0:0}%)", percentageDone));
}
}

int b = 0;
while (true)
{
if (b > tasks.Count - 1)
break;

float percentageDone = ((float)b / (float)tasks.Count) * 100;
if (OnDiscoveryProgress != null)
OnDiscoveryProgress(percentageDone, String.Format("Finding devices on local network ({0:0}%)", percentageDone));

Tracing.Log("SyncDiscoveryService - SearchForDevicesAsync - while loop index {0} - done {1}", b, percentageDone);

var device = await tasks[b];
if(device != null)
devices.Add(device);
b++;
}

IsRunning = false;

return devices;
}

private async Task<SyncDevice> ProcessDevice(string url, string ip)
{
try
{
Tracing.Log("SyncDiscoveryService - ProcessDevice - Getting content... url: {0} ip:{1}", url, ip);
string content = await _httpClient.GetStringAsync(url);
Tracing.Log("SyncDiscoveryService - ProcessDevice - Getting content... done! url: {0} ip:{1}", url, ip);
Tracing.Log("SyncDiscoveryService - Got version from {0}: {1}", ip, content);
var device = XmlSerialization.Deserialize<SyncDevice>(content);
if (device.SyncVersionId.ToUpper() == SyncListenerService.SyncVersionId.ToUpper())
{
device.Url = url;
if (OnDeviceFound != null) OnDeviceFound(device);
Tracing.Log("SyncDiscoveryService - The following host is available: {0}", ip);
}
return device;
}
catch (Exception ex)
{
Tracing.Log("SyncDiscoveryService - ProcessDevice - Exception: {0}", ex);
}

return null;
}

/// <summary>
/// Cancels the discovery process.
/// </summary>
Expand Down
32 changes: 31 additions & 1 deletion MPfm/MPfm.WindowsPhone/App.xaml.cs
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Diagnostics;
using System.Linq;
using System.Resources;
using System.Windows;
using System.Windows.Markup;
Expand Down Expand Up @@ -160,6 +161,7 @@ private void InitializePhoneApplication()
(Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(255, 231, 76, 60);
(Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.White;
(Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Color.FromArgb(255, 32, 40, 46);
SetApplicationTile();
}

// Do not add any additional code to this method
Expand Down Expand Up @@ -282,8 +284,36 @@ private void BootstrapApp()
//container.Register<IAudioPreferencesView, AudioPreferencesFragment>().AsMultiInstance();
//container.Register<IGeneralPreferencesView, GeneralPreferencesFragment>().AsMultiInstance();
//container.Register<ILibraryPreferencesView, LibraryPreferencesFragment>().AsMultiInstance();
//container.Register<IAboutView, AboutActivity>().AsMultiInstance();
//container.Register<IAboutView, AboutActivity>().AsMultiInstance();
}

private void SetApplicationTile()
{
//// Application Tile is always the first Tile, even if it is not pinned to Start.
//ShellTile TileToFind = ShellTile.ActiveTiles.First();

//// Application should always be found
//if (TileToFind != null)
//{
// IconicTileData TileData = new IconicTileData()
// {
// Title = "My App title",
// WideContent1 = "New Wide Content 1",
// WideContent2 = "New Wide Content 2",
// WideContent3 = "New Wide Content 3",
// //Count = 2,
// //BackgroundColor = Colors.Blue,
// //BackgroundColor = new Color { A = 255, R = 200, G = 148, B = 255 },
// //BackgroundColor = Color.FromArgb(255, 200, 148, 55),
// //BackgroundColor = (Color)Application.Current.Resources["PhoneAccentColor"],
// BackgroundColor = Color.FromArgb(255, 200, 148, 55), //Colors.Blue, // HexToColor("#FF7A3B3F"),
// IconImage = new Uri("Assets/Tiles/IconicTileMediumLarge.png", UriKind.Relative),
// SmallIconImage = new Uri("Assets/Tiles/IconicTileSmall.png", UriKind.Relative),
// };

// // Update the Application Tile
// TileToFind.Update(TileData);
//}
}
}
}
Binary file modified MPfm/MPfm.WindowsPhone/Assets/ApplicationIcon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -18,16 +18,15 @@
<VisualState x:Name="Normal"/>
<VisualState x:Name="Selected">
<Storyboard>
<!--<DoubleAnimation Duration="0" To="48" Storyboard.TargetProperty="(Control.FontSize)" Storyboard.TargetName="textBlock" />-->
<ColorAnimation Duration="0" To="DarkGray" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="textBlock" />
<ColorAnimation Duration="0" To="#36454F" Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" Storyboard.TargetName="LayoutRoot" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StackPanel Margin="0,0,0,17">
<TextBlock x:Name="textBlock" Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" Margin="54,0,12,0"/>
<TextBlock x:Name="textBlock2" Text="{Binding Url}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}" Margin="54,0,12,0"/>
<StackPanel Margin="8,6,0,0">
<TextBlock x:Name="textBlock" Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" Margin="54,0,12,0" FontSize="24"/>
<TextBlock x:Name="textBlock2" Text="{Binding Url}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSmallStyle}" Margin="54,0,12,0" FontSize="16"/>
</StackPanel>
<Image HorizontalAlignment="Left" Height="52" VerticalAlignment="Top" Width="52" Source="/Assets/Tiles/FlipCycleTileMedium.png"/>
<Image HorizontalAlignment="Left" Height="52" VerticalAlignment="Top" Width="52" Source="/Assets/Icons/icon_apple.png" Margin="0,8,0,8"/>
</Grid>
</UserControl>
47 changes: 47 additions & 0 deletions MPfm/MPfm.WindowsPhone/Classes/Helpers/ResolutionHelper.cs
@@ -0,0 +1,47 @@
using System;

namespace MPfm.WindowsPhone.Classes.Helpers
{
/// <summary>
/// http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206974(v=vs.105).aspx
/// </summary>
public static class ResolutionHelper
{
public enum Resolutions { WVGA, WXGA, HD720p };

private static bool IsWvga
{
get
{
return App.Current.Host.Content.ScaleFactor == 100;
}
}

private static bool IsWxga
{
get
{
return App.Current.Host.Content.ScaleFactor == 160;
}
}

private static bool Is720p
{
get
{
return App.Current.Host.Content.ScaleFactor == 150;
}
}

public static Resolutions CurrentResolution
{
get
{
if (IsWvga) return Resolutions.WVGA;
else if (IsWxga) return Resolutions.WXGA;
else if (Is720p) return Resolutions.HD720p;
else throw new InvalidOperationException("Unknown resolution");
}
}
}
}
File renamed without changes.
65 changes: 43 additions & 22 deletions MPfm/MPfm.WindowsPhone/Classes/Pages/MainPage.xaml.cs
Expand Up @@ -25,6 +25,7 @@
using System.Windows.Controls;
using System.Windows.Media;
using Windows.Storage;
using Microsoft.Phone.Shell;
using MPfm.Library.Services;
using MPfm.MVP.Bootstrap;
using MPfm.MVP.Navigation;
Expand Down Expand Up @@ -94,31 +95,51 @@ private void CreateDummyData()

private async void Button_Click(object sender, RoutedEventArgs e)
{
List<string> list = new List<string>();
list.Add("test");
list.Add("test2");
listAlbums.ItemsSource = list;
return;

var folder = ApplicationData.Current.LocalFolder;
var audioFolder = await folder.GetFolderAsync("Audio");
var files = await audioFolder.GetFilesAsync();
foreach (var file in files)
{
if (file.Path.Contains(".mp3"))
{
Debug.WriteLine("Definitely a mp3: " + file.Path);
AudioFile audioFile = new AudioFile(file.Path);
txtStuff.Text = audioFile.Title;
}
else
{
Debug.WriteLine("Not mp3: " + file.Path);
}
}
//var folder = ApplicationData.Current.LocalFolder;
//var audioFolder = await folder.GetFolderAsync("Audio");
//var files = await audioFolder.GetFilesAsync();
//foreach (var file in files)
//{
// if (file.Path.Contains(".mp3"))
// {
// Debug.WriteLine("Definitely a mp3: " + file.Path);
// AudioFile audioFile = new AudioFile(file.Path);
// txtStuff.Text = audioFile.Title;
// }
// else
// {
// Debug.WriteLine("Not mp3: " + file.Path);
// }
//}

//CreateDummyFile();
//AudioFile audioFile = new AudioFile();

IconicTileData oIcontile = new IconicTileData();
oIcontile.Title = "Hello Iconic Tile!!";
oIcontile.Count = 7;

oIcontile.IconImage = new Uri("Assets/Tiles/LargeIconicTile.png", UriKind.Relative);
oIcontile.SmallIconImage = new Uri("Assets/Tiles/SmallIconicTile.png", UriKind.Relative);

oIcontile.WideContent1 = "windows phone 8 Live tile";
oIcontile.WideContent2 = "Icon tile";
oIcontile.WideContent3 = "All about Live tiles By WmDev";

oIcontile.BackgroundColor = Color.FromArgb(255, 54, 69, 79);

// find the tile object for the application tile that using "Iconic" contains string in it.
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Iconic".ToString()));

if (TileToFind != null && TileToFind.NavigationUri.ToString().Contains("Iconic"))
{
TileToFind.Delete();
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
else
{
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
}

private async Task WriteToFile()
Expand Down
29 changes: 15 additions & 14 deletions MPfm/MPfm.WindowsPhone/MPfm.WindowsPhone.csproj
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Classes\Controls\ListArtistControl.xaml.cs">
<DependentUpon>ListArtistControl.xaml</DependentUpon>
</Compile>
<Compile Include="Classes\Helpers\ResolutionHelper.cs" />
<Compile Include="Classes\Helpers\XamlHelper.cs" />
<Compile Include="Classes\Navigation\WindowsPhoneNavigationManager.cs" />
<Compile Include="Classes\Pages\Base\BasePage.cs" />
Expand All @@ -151,7 +152,7 @@
<Compile Include="Classes\Controls\ListSimpleControl.xaml.cs">
<DependentUpon>ListSimpleControl.xaml</DependentUpon>
</Compile>
<Compile Include="LocalizedStrings.cs" />
<Compile Include="Classes\LocalizedStrings.cs" />
<Compile Include="Classes\Pages\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -223,22 +224,21 @@
<Content Include="Assets\ApplicationIcon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Tiles\FlipCycleTileLarge.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Tiles\FlipCycleTileMedium.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Content Include="Assets\Icons\icon_android.png" />
<Content Include="Assets\Icons\icon_apple.png" />
<Content Include="Assets\Icons\icon_linux.png" />
<Content Include="Assets\Icons\icon_phone.png" />
<Content Include="Assets\Icons\icon_tablet.png" />
<Content Include="Assets\Icons\icon_windows.png" />
<Content Include="Assets\Tiles\LargeIconicTile.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Tiles\FlipCycleTileSmall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Content Include="Assets\Tiles\SmallIconicTile.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Tiles\IconicTileMediumLarge.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Tiles\IconicTileSmall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Content Include="SplashScreenImage.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="README_FIRST.txt" />
<Content Include="Toolkit.Content\ApplicationBar.Add.png" />
<Content Include="Toolkit.Content\ApplicationBar.Cancel.png" />
<Content Include="Toolkit.Content\ApplicationBar.Check.png" />
Expand Down Expand Up @@ -287,6 +287,7 @@
<HintPath>..\MPfm.Core\Lib\PCL\TinyIoC.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 475596b

Please sign in to comment.