Skip to content

Commit

Permalink
brianchance#8 Added Windows Phone and Windows Store support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianRuiz committed Apr 28, 2014
1 parent 39ec10b commit d90bc29
Show file tree
Hide file tree
Showing 18 changed files with 769 additions and 17 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3856B230-5B7B-4285-B591-A36C7BBE08CB}</ProjectGuid>
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone</RootNamespace>
<AssemblyName>Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone</AssemblyName>
<TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
<SilverlightVersion>
</SilverlightVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Bin\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>Bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<DebugType>full</DebugType>
<PlatformTarget>
</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>Bin\x86\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<Optimize>true</Optimize>
<NoStdLib>true</NoStdLib>
<DebugType>pdbonly</DebugType>
<PlatformTarget>
</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>Bin\ARM\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<NoStdLib>true</NoStdLib>
<DebugType>full</DebugType>
<PlatformTarget>
</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>Bin\ARM\Release</OutputPath>
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
<Optimize>true</Optimize>
<NoStdLib>true</NoStdLib>
<DebugType>pdbonly</DebugType>
<PlatformTarget>
</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cirrious.CrossCore">
<HintPath>..\lib\WindowsPhone\Cirrious.CrossCore.dll</HintPath>
</Reference>
<Reference Include="Cirrious.CrossCore.WindowsPhone">
<HintPath>..\lib\WindowsPhone\Cirrious.CrossCore.WindowsPhone.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Phone.Controls.Toolkit">
<HintPath>..\packages\WPtoolkit.4.2013.08.16\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserInteraction.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Chance.MvvmCross.Plugins.UserInteraction\Chance.MvvmCross.Plugins.UserInteraction.csproj">
<Project>{C912911A-2216-447C-ADF4-8DC190804D75}</Project>
<Name>Chance.MvvmCross.Plugins.UserInteraction</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<ProjectExtensions />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
15 changes: 15 additions & 0 deletions Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using Cirrious.CrossCore.Plugins;
using Cirrious.CrossCore;

namespace Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone
{
public class Plugin : IMvxPlugin
{
public void Load()
{
Mvx.RegisterType<IUserInteraction, UserInteraction>();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3856b230-5b7b-4285-b591-a36c7bbe08cb")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone
{
public class UserInteraction : IUserInteraction
{
public void Confirm(string message, Action okClicked, string title = null, string okButton = "OK", string cancelButton = "Cancel")
{
Task<bool> result = ConfirmAsync(message, title, okButton, cancelButton);


result.ContinueWith((button) =>
{
if (button.Result)
{
//ok clicked
okClicked();
}
});
}

public void Confirm(string message, Action<bool> answer, string title = null, string okButton = "OK", string cancelButton = "Cancel")
{
Task<bool> result = ConfirmAsync(message, title, okButton, cancelButton);

result.ContinueWith((button) => answer(button.Result));
}

public Task<bool> ConfirmAsync(string message, string title = "", string okButton = "OK", string cancelButton = "Cancel")
{
var box = new Microsoft.Phone.Controls.CustomMessageBox()
{
Caption = title,
Message = message,
LeftButtonContent = okButton,
RightButtonContent = cancelButton
};
var complete = new TaskCompletionSource<bool>();
box.Dismissed += (sender, args) => complete.TrySetResult(args.Result == CustomMessageBoxResult.LeftButton);
box.Show();
return complete.Task;
}






public void Alert(string message, Action done = null, string title = "", string okButton = "OK")
{

AlertAsync(message, title, okButton).ContinueWith((button) => { if (done != null) done(); });
}

public Task AlertAsync(string message, string title = "", string okButton = "OK")
{
var box = new Microsoft.Phone.Controls.CustomMessageBox()
{
Caption = title,
Message = message,
LeftButtonContent = okButton,
IsRightButtonEnabled = false
};
var complete = new TaskCompletionSource<bool>();
box.Dismissed += (sender, args) => complete.TrySetResult(true);
box.Show();
return complete.Task;
}


public void Input(string message, Action<string> okClicked, string placeholder = null, string title = null, string okButton = "OK",
string cancelButton = "Cancel", string initialText = null)
{
var result = InputAsync(message, placeholder, title, okButton, cancelButton);
result.ContinueWith((value) =>
{
if (value.Result.Ok)
{
okClicked(value.Result.Text);
}
});
}

public void Input(string message, Action<bool, string> answer, string placeholder = null, string title = null, string okButton = "OK",
string cancelButton = "Cancel", string initialText = null)
{
var result = InputAsync(message, placeholder, title, okButton, cancelButton);
result.ContinueWith(value => answer(value.Result.Ok, value.Result.Text));
}

public Task<InputResponse> InputAsync(string message, string placeholder = null, string title = null, string okButton = "OK",
string cancelButton = "Cancel", string initialText = null)
{
var textBox = new PhoneTextBox { Hint = placeholder };

var box = new Microsoft.Phone.Controls.CustomMessageBox()
{
Caption = title,
Message = message,
LeftButtonContent = okButton,
RightButtonContent = cancelButton,
Content = textBox
};

var response = new TaskCompletionSource<InputResponse>();
box.Dismissed += (sender, args) => response.TrySetResult(new InputResponse()
{
Ok = args.Result == CustomMessageBoxResult.LeftButton,
Text = textBox.Text
});
box.Show();
return response.Task;
}


public void ConfirmThreeButtons(string message, Action<ConfirmThreeButtonsResponse> answer, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe")
{

var result = ConfirmThreeButtonsAsync(message, title, positive, negative, neutral);
result.ContinueWith((value) => answer(value.Result));
}

public Task<ConfirmThreeButtonsResponse> ConfirmThreeButtonsAsync(string message, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe")
{
StackPanel contents = new StackPanel();
contents.Orientation = Orientation.Vertical;
var positiveButton = new Button() { Content = positive };
var neutralButton = new Button() { Content = neutral };
var negativeButton = new Button() { Content = negative };
contents.Children.Add(positiveButton);
contents.Children.Add(neutralButton);
contents.Children.Add(negativeButton);

var box = new Microsoft.Phone.Controls.CustomMessageBox()
{
Caption = title,
Message = message,
IsLeftButtonEnabled = false,
IsRightButtonEnabled = false,
Content = contents
};

var response = new TaskCompletionSource<ConfirmThreeButtonsResponse>();
positiveButton.Click += (sender, args) =>
{
response.TrySetResult(ConfirmThreeButtonsResponse.Positive);
box.Dismiss();
};
neutralButton.Click += (sender, args) =>
{
response.TrySetResult(ConfirmThreeButtonsResponse.Neutral);
box.Dismiss();
};
negativeButton.Click += (sender, args) =>
{
response.TrySetResult(ConfirmThreeButtonsResponse.Negative);
box.Dismiss();
};
box.Show();
return response.Task;


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Cirrious.CrossCore.Plugins;

namespace <YourNamespace>.Bootstrap
{
public class UserInteractionPluginBootstrap
: MvxLoaderPluginBootstrapAction<Chance.MvvmCross.Plugins.UserInteraction.PluginLoader, Chance.MvvmCross.Plugins.UserInteraction.WindowsPhone.Plugin>

{
}
}

Loading

0 comments on commit d90bc29

Please sign in to comment.