Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tials

# Conflicts:
#	src/FreshEssentials/Controls/BindablePicker.cs
#	src/FreshEssentials/FreshEssentials.csproj
  • Loading branch information
jessejiang0214 committed Aug 17, 2016
2 parents 0339c91 + 813b545 commit 34723a9
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 21 deletions.
10 changes: 5 additions & 5 deletions FreshEssentials.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>FreshEssentials</id>
<version>1.1.0</version>
<version>2.0.1</version>
<title>FreshEssentials</title>
<authors>Michael Ridland @ XAM Consulting</authors>
<owners>rid00z</owners>
Expand Down Expand Up @@ -31,12 +31,12 @@ Attached Properties
<tags>Xamarin, Xamarin.Forms, FreshEssentials</tags>
</metadata>
<files>
<file src="src/FreshEssentials/bin/Release/FreshEssentials*.*" target="lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />
<file src="src\FreshEssentials\bin\Release\FreshEssentials*.*" target="lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10" />

<file src="src/iOS/bin/Release/FreshEssentials*.*" target="lib\Xamarin.iOS10" />
<file src="src\iOS\bin\Release\FreshEssentials*.*" target="lib\Xamarin.iOS10" />

<file src="src/Droid/bin/Release/FreshEssentials*.*" target="lib\MonoAndroid10" />
<file src="src\Droid\bin\Release\FreshEssentials*.*" target="lib\MonoAndroid10" />

<file src="src/UWP/bin/Release/FreshEssentials*.*" target="lib\uap10.0" />
<file src="src\UWP\bin\Release\FreshEssentials*.*" target="lib\uap10.0" />
</files>
</package>
20 changes: 20 additions & 0 deletions licenses/xamarin.forms-toolkit-LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 James Montemagno / Refractored LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions src/FreshEssentials.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreshEssentials.Droid", "Dr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreshEssentials.UWP", "UWP\FreshEssentials.UWP.csproj", "{33C343D6-8FA2-46E1-B753-422CA1554E40}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Licenses", "Licenses", "{7463B33D-C1CF-4780-A10C-D34BA5F6E00B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,6 +90,8 @@ Global
{BE93CF9E-D82C-40D8-A2E3-76C669BD13E8}.Release|x86.ActiveCfg = Release|Any CPU
{BE93CF9E-D82C-40D8-A2E3-76C669BD13E8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 1.1.0
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion src/FreshEssentials/Controls/AdvancedFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum RoundedCorners

public class AdvancedFrame: Frame
{
public static readonly BindableProperty InnerBackgroundProperty = BindableProperty.Create<AdvancedFrame, Color>(p => p.InnerBackground, default(Color));
public static readonly BindableProperty InnerBackgroundProperty = BindableProperty.Create("InnerBackground", typeof(Color), typeof(AdvancedFrame), default(Color));

public Color InnerBackground
{
Expand Down
22 changes: 15 additions & 7 deletions src/FreshEssentials/Controls/BindablePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace FreshEssentials
{
public class BindablePicker: Picker
public class BindablePicker : Picker
{
public BindablePicker()
{
Expand All @@ -17,6 +17,7 @@ public BindablePicker()
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(BindablePicker), null, BindingMode.TwoWay, null, new BindableProperty.BindingPropertyChangedDelegate(BindablePicker.OnSelectedItemChanged), null, null, null);
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(BindablePicker), null, BindingMode.OneWay, null, new BindableProperty.BindingPropertyChangedDelegate(BindablePicker.OnItemsSourceChanged), null, null, null);
public static readonly BindableProperty DisplayPropertyProperty = BindableProperty.Create("DisplayProperty", typeof(string), typeof(BindablePicker), null, BindingMode.OneWay, null, new BindableProperty.BindingPropertyChangedDelegate(BindablePicker.OnDisplayPropertyChanged), null, null, null);
private bool disableEvents;

public IList ItemsSource
{
Expand All @@ -30,13 +31,16 @@ public object SelectedItem
set
{
base.SetValue(BindablePicker.SelectedItemProperty, value);
if (ItemsSource.Contains(SelectedItem))
if (ItemsSource != null && SelectedItem != null)
{
SelectedIndex = ItemsSource.IndexOf(SelectedItem);
}
else
{
SelectedIndex = -1;
if (ItemsSource.Contains(SelectedItem))
{
SelectedIndex = ItemsSource.IndexOf(SelectedItem);
}
else
{
SelectedIndex = -1;
}
}
}
}
Expand All @@ -49,6 +53,8 @@ public string DisplayProperty

private void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (disableEvents) return;

if (SelectedIndex == -1)
{
this.SelectedItem = null;
Expand Down Expand Up @@ -100,6 +106,7 @@ static void loadItemsAndSetSelected(BindableObject bindable)
BindablePicker picker = (BindablePicker)bindable;
if (picker.ItemsSource as IEnumerable != null)
{
picker.disableEvents = true;
picker.SelectedIndex = -1;
picker.Items.Clear();
int count = 0;
Expand Down Expand Up @@ -132,6 +139,7 @@ static void loadItemsAndSetSelected(BindableObject bindable)
}
count++;
}
picker.disableEvents = false;
}
}
}
Expand Down
41 changes: 36 additions & 5 deletions src/FreshEssentials/Controls/SegmentedButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,60 @@ public class SegmentedButton

public class SegmentedButtonGroup : Grid
{
public static readonly BindableProperty OnColorProperty = BindableProperty.Create<SegmentedButtonGroup, Color>(p => p.OnColor, Color.Blue);
public static readonly BindableProperty OnColorProperty = BindableProperty.Create("OnColor", typeof(Color), typeof(SegmentedButtonGroup), Color.Blue);

public Color OnColor
{
get { return (Color)GetValue(OnColorProperty); }
set { SetValue(OnColorProperty, value); }
}

public static readonly BindableProperty OffColorProperty = BindableProperty.Create<SegmentedButtonGroup, Color>(p => p.OffColor, Color.White);
public static readonly BindableProperty OffColorProperty = BindableProperty.Create("OffColor", typeof(Color), typeof(SegmentedButtonGroup), Color.White);

public Color OffColor
{
get { return (Color)GetValue(OffColorProperty); }
set { SetValue(OffColorProperty, value); }
}

public static readonly BindableProperty CommandProperty = BindableProperty.Create<SegmentedButtonGroup, Command>(p => p.Command, default(Command));
public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(Command), typeof(SegmentedButtonGroup), default(Command));

public Command Command
{
get { return (Command)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}

public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create("CornerRadius", typeof(int), typeof(SegmentedButtonGroup), 0);

public int CornerRadius
{
get { return (int)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}

public IList<SegmentedButton> SegmentedButtons
{
get;
internal set;
}

public static readonly BindableProperty SelectedIndexProperty = BindableProperty.Create<SegmentedButtonGroup, int>(p => p.SelectedIndex, default(int));
public static readonly BindableProperty SelectedIndexProperty = BindableProperty.Create("SelectedIndex", typeof(int), typeof(SegmentedButtonGroup), default(int));

public int SelectedIndex
{
get { return (int)GetValue(SelectedIndexProperty); }
set { SetValue(SelectedIndexProperty, value); }
}

public static readonly BindableProperty FontSizeProperty = BindableProperty.Create("FontSize", typeof(string), typeof(SegmentedButtonGroup), "Small");

public string FontSize
{
get { return (string)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}

public SegmentedButtonGroup()
{
var segmentedButtons = new ObservableCollection<SegmentedButton>();
Expand Down Expand Up @@ -90,10 +106,23 @@ void RebuildButtons()
{
var buttonSeg = SegmentedButtons[i];

double fontSize; // local variable to save the interpreted font size
try
{
// convert the normal names first
fontSize = Device.GetNamedSize((NamedSize)Enum.Parse(typeof(NamedSize), FontSize, true), typeof(Label));
}
catch (Exception)
{
// convert as a double and default if there is a problem
if(double.TryParse(FontSize, out fontSize) == false)
fontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label));
}

var label = new Label
{
Text = buttonSeg.Title,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
FontSize = fontSize,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center
};
Expand All @@ -106,6 +135,8 @@ void RebuildButtons()
frame.Corners = RoundedCorners.right;
else
frame.Corners = RoundedCorners.none;

frame.CornerRadius = CornerRadius;
frame.OutlineColor = OnColor;
frame.Content = label;
frame.HorizontalOptions = LayoutOptions.FillAndExpand;
Expand Down
64 changes: 64 additions & 0 deletions src/FreshEssentials/Converters/HasDataConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using Xamarin.Forms;
using System.Globalization;
using System.Collections;

namespace FreshEssentials
{
public class HasDataConverter : IValueConverter
{
/// <summary>
/// Init this instance.
/// </summary>
public static void Init()
{
var time = DateTime.UtcNow;
}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//if null then not visible
if (value == null)
return false;

//if empty string then not visible
if (value is string)
return !string.IsNullOrWhiteSpace((string)value);

//if blank list not visible
if (value is IList)
return ((IList)value).Count > 0;

return true;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

/*
The MIT License (MIT)
Copyright (c) 2014 James Montemagno / Refractored LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
1 change: 1 addition & 0 deletions src/FreshEssentials/FreshEssentials.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Include="Controls\AdvancedFrame.cs" />
<Compile Include="Controls\BindablePicker.cs" />
<Compile Include="Controls\AutoGrid.cs" />
<Compile Include="Converters\HasDataConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.2.2.0.31\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.2.0.31\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
Expand Down
12 changes: 9 additions & 3 deletions src/UWP/Renderers/AdvancedFrameRendererUWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.F
if (e.NewElement != null)
{
myFrame = (e.NewElement as AdvancedFrame);

int topLeft = myFrame.Corners == RoundedCorners.left || myFrame.Corners == RoundedCorners.all ? myFrame.CornerRadius : 0;
int topRight = myFrame.Corners == RoundedCorners.right || myFrame.Corners == RoundedCorners.all ? myFrame.CornerRadius : 0;
int bottomRight = myFrame.Corners == RoundedCorners.right || myFrame.Corners == RoundedCorners.all ? myFrame.CornerRadius : 0;
Expand All @@ -50,9 +50,15 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

if (e.PropertyName == "InnerBackground" || e.PropertyName == "OutlineColor")
{
this.UpdateNativeControl();
this.Control.Background = new SolidColorBrush(
Windows.UI.Color.FromArgb(
(byte)Math.Round(myFrame.InnerBackground.A * 255),
(byte)Math.Round(myFrame.InnerBackground.R * 255),
(byte)Math.Round(myFrame.InnerBackground.G * 255),
(byte)Math.Round(myFrame.InnerBackground.B * 255)
));
}
}

}
}

0 comments on commit 34723a9

Please sign in to comment.