Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
2015-12-01 14:10:52 +01:00
10 changed files with 88 additions and 33 deletions
+3 -5
View File
@@ -44,7 +44,7 @@ namespace HueUWP
{
if(l.IsOn)
{
var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness},\"hue\": {l.Hue},\"sat\": {l.Saturation}}}");
var json = await nwh.SetLightInfo(l.ID, $"{{\"bri\": {l.Brightness-1},\"hue\": {(l.Hue/360)*65535},\"sat\": {l.Saturation*254}}}");
Debug.WriteLine(json);
}
@@ -55,16 +55,14 @@ namespace HueUWP
List<Light> lightlist = new List<Light>();
try {
var json = await nwh.AllLights();
Debug.WriteLine(json);
JObject o = JObject.Parse(json);
Debug.WriteLine(o.ToString());
for (int i = 1; i <= o.Count; i++)
{
var light = o["" + i];
var state = light["state"];
alllights.Add(new Light() { api = this,ID = i, Brightness = (int)state["bri"], IsOn = (string)state["on"] == "true" ? true : false, Hue = (int)state["hue"], Saturation = (int)state["sat"], Name = (string)light["name"], Type = (string)light["type"] });
Debug.WriteLine("Added light number " + i);
alllights.Add(new Light() { api = this,ID = i, Brightness = (int)state["bri"], IsOn = ((string)state["on"]).ToLower() == "true" ? true : false, Hue = (int)state["hue"], Saturation = (int)state["sat"], Name = (string)light["name"], Type = (string)light["type"] });
Debug.WriteLine("Added light number " + i + " " + state["on"]);
} }
catch(Exception e)
{
+23 -1
View File
@@ -7,6 +7,7 @@ using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
@@ -22,6 +23,8 @@ namespace HueUWP
/// </summary>
sealed partial class App : Application
{
Frame rootFrame;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -47,7 +50,7 @@ namespace HueUWP
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
@@ -57,6 +60,8 @@ namespace HueUWP
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.Navigated += RootFrame_Navigated;
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
@@ -78,6 +83,23 @@ namespace HueUWP
Window.Current.Activate();
}
private void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
rootFrame.CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
if (rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
@@ -7,25 +7,25 @@ using Windows.UI.Xaml.Data;
namespace HueUWP.Converters
{
public class BooleanToStringConverter : IValueConverter
public class NullableBooleanConverter : IValueConverter
{
//From bool to nullable
public object Convert(object value, Type targetType, object parameter, string language)
{
bool b = (bool)value;
return b.ToString();
bool? be = b as bool?;
return be;
}
//From nullable to bool
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
string s = (string)value;
bool b = false;
bool? b = (bool?)value;
bool be = false;
if (b.HasValue)
be = (bool)b;
if (s == "true")
b = true;
return b;
return be;
}
}
}
+9
View File
@@ -8,6 +8,15 @@
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RelativePanel Grid.Row="0">
<TextBlock RelativePanel.AlignLeftWithPanel="True" FontSize="24" Margin="20,10,0,0" Text="{Binding Name}"/>
</RelativePanel>
</Grid>
</Grid>
</Page>
+8
View File
@@ -22,9 +22,17 @@ namespace HueUWP
/// </summary>
public sealed partial class DetailView : Page
{
Light l;
public DetailView()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
l = e.Parameter as Light;
this.DataContext = l;
}
}
}
+1 -1
View File
@@ -98,7 +98,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="ColorUtil.cs" />
<Compile Include="Converters\BooleanToStringConverter.cs" />
<Compile Include="Converters\NullableBooleanConverter.cs" />
<Compile Include="DetailView.xaml.cs">
<DependentUpon>DetailView.xaml</DependentUpon>
</Compile>
+9 -1
View File
@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml.Media;
namespace HueUWP
{
@@ -22,7 +23,12 @@ namespace HueUWP
public double Saturation { get; set; }
public APIHandler api { get; set; }
public SolidColorBrush Color
{
get { return new SolidColorBrush(HueUWP.ColorUtil.HsvToRgb(Hue, Saturation, Brightness)); }
}
public Light()
{
}
@@ -43,6 +49,8 @@ namespace HueUWP
this.Hue = h; this.Saturation = s; this.Brightness = v;
api.SetLightValues(this);
Debug.WriteLine(r + "-" + g + "-" + b);
Debug.WriteLine(h + "-" + s + "-" + v);
NotifyPropertyChanged(nameof(UpdateColor));
}
+4 -4
View File
@@ -11,7 +11,7 @@
mc:Ignorable="d">
<Page.Resources>
<convert:BooleanToStringConverter x:Key="BooltostringC"/>
<convert:NullableBooleanConverter x:Key="BoolConverter"/>
</Page.Resources>
<Grid>
@@ -29,18 +29,18 @@
</RelativePanel>
<StackPanel Grid.Row="1" Margin="20,40,20,40">
<ListView x:Name="myListView" ItemsSource="{Binding}" >
<ListView x:Name="myListView" ItemsSource="{Binding}" IsItemClickEnabled="True" ItemClick="myListView_ItemClick">
<ListView.ItemTemplate>
<DataTemplate x:Name="dataTemplate">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20" Fill="Red" Margin="20, 0,0,0" />
<Rectangle Width="20" Height="20" Fill="{Binding Color}" Margin="20, 0,0,0" />
<StackPanel Orientation="Vertical" Width="200" Margin="20,0,0,0">
<TextBlock Text="{Binding Name}" FontSize="24" />
<TextBlock Text="{Binding Type}" FontSize="14" />
</StackPanel>
<ToggleSwitch Margin="40,0,0,0" Toggled="ToggleSwitch_Toggled" IsOn="{Binding IsOn, Converter={StaticResource BooltostringC}}">
<ToggleSwitch Margin="40,0,0,0" Toggled="ToggleSwitch_Toggled" IsOn="{Binding IsOn, Converter={StaticResource BoolConverter}}">
<ToggleSwitch.OffContent>Off</ToggleSwitch.OffContent>
<ToggleSwitch.OnContent>On</ToggleSwitch.OnContent>
</ToggleSwitch>
+16 -13
View File
@@ -32,6 +32,8 @@ namespace HueUWP
private ObservableCollection<Light> _lightsViewModel = LightDataSource.GetLights();
private APIHandler api;
public ObservableCollection<Light> LightsViewModel
{
get { return this._lightsViewModel; }
@@ -43,12 +45,9 @@ namespace HueUWP
LOCAL_SETTINGS.Values["ip"] = "localhost";
LOCAL_SETTINGS.Values["port"] = 8000;
NetworkHandler nwh = new NetworkHandler();
APIHandler api = new APIHandler(nwh);
//api.Register();
api = new APIHandler(nwh);
_lightsViewModel.Clear();
api.GetAllLights(_lightsViewModel);
Debug.WriteLine(LOCAL_SETTINGS.Values["id"]);
}
private void ColorChanged(object sender, RoutedEventArgs e)
@@ -73,23 +72,27 @@ namespace HueUWP
ToggleSwitch button = ((ToggleSwitch)sender);
Light light = (Light)button.DataContext;
light.UpdateState(button.IsOn);
}
private void slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider slider = ((Slider)sender);
Light l = (Light)slider.DataContext;
l.UpdateColor((int)slider.Value, 255, 255);
light.UpdateColor(0, 38, 255);
}
private void RegisterButton_Click(object sender, RoutedEventArgs e)
{
api.Register();
Debug.WriteLine(LOCAL_SETTINGS.Values["id"]);
}
private void RefreshButton_Click(object sender, RoutedEventArgs e)
{
_lightsViewModel.Clear();
api.GetAllLights(_lightsViewModel);
}
private void myListView_ItemClick(object sender, ItemClickEventArgs e)
{
Light l = e.ClickedItem as Light;
Frame rootframe = Window.Current.Content as Frame;
if (l != null)
rootframe.Navigate(typeof(DetailView), l);
}
}
}
+7
View File
@@ -8,6 +8,13 @@
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RelativePanel Grid.Row="0">
<TextBlock RelativePanel.AlignLeftWithPanel="True" FontSize="24" Margin="20,10,0,0">Settings</TextBlock>
</RelativePanel>
</Grid>
</Page>