Skip to content

Commit

Permalink
date & time dialogs done on android
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed May 6, 2016
1 parent 1d58cba commit a7c5fe1
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Acr.UserDialogs.Android/Acr.UserDialogs.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<FileAlignment>512</FileAlignment>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v6.0.99</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
110 changes: 110 additions & 0 deletions src/Acr.UserDialogs.Android/Acr.UserDialogs.Android.csproj.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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>
<ProjectGuid>{4A67E27E-0E7F-4EF2-B3E6-2C24E18EF442}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Acr.UserDialogs</RootNamespace>
<AssemblyName>Acr.UserDialogs</AssemblyName>
<FileAlignment>512</FileAlignment>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;__ANDROID__;__PLATFORM__</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;__ANDROID__;__PLATFORM__</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="Acr.Support.Android, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Acr.Support.2.0.2\lib\MonoAndroid10\Acr.Support.Android.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AndHUD, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AndHUD.1.2.0\lib\MonoAndroid\AndHUD.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="Splat, Version=1.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.1.6.2\lib\monoandroid\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="Xamarin.Android.Support.Design, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.Design.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.Design.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v4.23.1.1.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Android.Support.v7.AppCompat, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v7.AppCompat.23.0.1.3\lib\MonoAndroid403\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ActionSheetListAdapter.cs" />
<Compile Include="Builders\AlertBuilder.cs" />
<Compile Include="Builders\ConfirmBuilder.cs" />
<Compile Include="Builders\ActionSheetBuilder.cs" />
<Compile Include="Builders\TimePromptBuilder.cs" />
<Compile Include="Builders\DatePromptBuilder.cs" />
<Compile Include="Builders\LoginBuilder.cs" />
<Compile Include="Builders\PromptBuilder.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Fragments\AbstractDialogFragment.cs" />
<Compile Include="Fragments\ActionSheetDialogFragment.cs" />
<Compile Include="Fragments\AlertDialogFragment.cs" />
<Compile Include="Fragments\ConfirmDialogFragment.cs" />
<Compile Include="Fragments\TimeDialogFragment.cs" />
<Compile Include="Fragments\DateDialogFragment.cs" />
<Compile Include="Fragments\InMemoryConfigStore.cs" />
<Compile Include="Fragments\LoginDialogFragment.cs" />
<Compile Include="Fragments\PromptDialogFragment.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProgressDialog.cs" />
<Compile Include="UserDialogsImpl.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\Acr.UserDialogs.Interface\Acr.UserDialogs.Interface.csproj">
<Project>{6A0AE941-711D-4C36-A311-960B65534B22}</Project>
<Name>Acr.UserDialogs.Interface</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="..\Acr.UserDialogs.Shared\Acr.UserDialogs.Shared.projitems" Label="Shared" Condition="Exists('..\Acr.UserDialogs.Shared\Acr.UserDialogs.Shared.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- 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>
23 changes: 12 additions & 11 deletions src/Acr.UserDialogs.Android/Builders/DatePromptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public static DatePickerDialog Build(Activity activity, DatePromptConfig config)
var dateTime = config.SelectedDate ?? DateTime.Now;
var dialog = new DatePickerDialog(
activity,
(sender, args) => dateTime = args.Date,
(sender, args) => { },
dateTime.Year,
dateTime.Month + 1,
dateTime.Day
);
dialog.SetCancelable(false);

if (!String.IsNullOrWhiteSpace(config.Title))
dialog.SetTitle(config.Title);

Expand All @@ -27,33 +29,32 @@ public static DatePickerDialog Build(Activity activity, DatePromptConfig config)
if (config.MaximumDate != null)
dialog.DatePicker.MaxDate = config.MaximumDate.Value.ToUnixTimestamp();

dialog.SetCancelable(config.IsCancellable);
if (config.IsCancellable)
{
dialog.SetButton(
(int) DialogButtonType.Negative,
new SpannableString(config.CancelText),
(sender, args) => config.OnResult?.Invoke(new DatePromptResult(false, dateTime))
(sender, args) =>
{
config.OnResult?.Invoke(new DatePromptResult(false, dialog.DatePicker.DateTime.Date));
}
);
}
dialog.SetButton(
(int)DialogButtonType.Positive,
new SpannableString(config.OkText),
(sender, args) => config.OnResult?.Invoke(new DatePromptResult(true, dateTime))
(sender, args) =>
{
config.OnResult?.Invoke(new DatePromptResult(true, dialog.DatePicker.DateTime.Date));
}
);
// hook these, not called by fragments though
dialog.DismissEvent += (sender, args) => config.OnResult?.Invoke(new DatePromptResult(true, dateTime));
dialog.CancelEvent += (sender, args) => config.OnResult?.Invoke(new DatePromptResult(false, dateTime));

return dialog;
}


public static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
public static long ToUnixTimestamp(this DateTime dateTime)
{
var utc = TimeZoneInfo.ConvertTimeToUtc(dateTime);
return Convert.ToInt64((utc - Epoch).TotalSeconds);
return new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();
}
}
}
53 changes: 28 additions & 25 deletions src/Acr.UserDialogs.Android/Builders/TimePromptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,49 @@
using Android.App;
using Android.Content;
using Android.Text;
using Android.Widget;


namespace Acr.UserDialogs.Builders
{
public static class TimePromptBuilder
{
public static TimePickerDialog Build(Activity activity, TimePromptConfig config)
public static Dialog Build(Activity activity, TimePromptConfig config)
{
var time = config.SelectedTime ?? DateTime.Now.TimeOfDay;
var dateTime = DateTime.Now;
var picker = new TimePicker(activity);
var builder = new AlertDialog
.Builder(activity)
.SetCancelable(false)
.SetTitle(config.Title)
.SetView(picker);

var dialog = new TimePickerDialog(
activity,
(sender, args) => dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, args.HourOfDay, args.Minute, 0),
time.Hours,
time.Minutes,
false
);
if (!String.IsNullOrWhiteSpace(config.Title))
dialog.SetTitle(config.Title);
if (config.SelectedTime != null)
{
picker.Hour = config.SelectedTime.Value.Hours;
picker.Minute = config.SelectedTime.Value.Minutes;
}

dialog.SetCancelable(config.IsCancellable);
if (config.IsCancellable)
{
dialog.SetButton(
(int) DialogButtonType.Negative,
new SpannableString(config.CancelText),
(sender, args) => config.OnResult?.Invoke(new TimePromptResult(false, dateTime.TimeOfDay))
builder.SetNegativeButton(
config.CancelText,
(sender, args) =>
{
var ts = new TimeSpan(0, picker.Hour, picker.Minute, 0);
config.OnResult?.Invoke(new TimePromptResult(false, ts));
}
);
}
dialog.SetButton(
(int)DialogButtonType.Positive,
new SpannableString(config.OkText),
(sender, args) => config.OnResult?.Invoke(new TimePromptResult(true, dateTime.TimeOfDay))
builder.SetPositiveButton(
config.OkText,
(sender, args) =>
{
var ts = new TimeSpan(0, picker.Hour, picker.Minute, 0);
config.OnResult?.Invoke(new TimePromptResult(true, ts));
}
);
// hook these, not called by fragments though
dialog.DismissEvent += (sender, args) => config.OnResult?.Invoke(new TimePromptResult(true, dateTime.TimeOfDay));
dialog.CancelEvent += (sender, args) => config.OnResult?.Invoke(new TimePromptResult(false, dateTime.TimeOfDay));

return dialog;
return builder.Show();
}
}
}
24 changes: 21 additions & 3 deletions src/Samples/Samples.Droid/Samples.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis>armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
<BundleAssemblies>False</BundleAssemblies>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<Debugger>Xamarin</Debugger>
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -42,7 +49,18 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidSupportedAbis>armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
<BundleAssemblies>False</BundleAssemblies>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<Debugger>Xamarin</Debugger>
<AotAssemblies>False</AotAssemblies>
<EnableLLVM>False</EnableLLVM>
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
<EnableProguard>False</EnableProguard>
<DebugSymbols>False</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="AndHUD, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/Samples.Uwp/project.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12224,7 +12224,7 @@
]
},
"Microsoft.NETCore.Runtime.CoreCLR-arm/1.0.0": {
"sha512": "vUQyaKbHCa7BJAAzdfCP2FfBYOSt0YnDw7VMJLmD1/k68HIJgw1QO7GAfHhqoa39zkkvimC47QBH27wG4C5OGQ==",
"sha512": "hoJfIl981eXwn9Tz8onO/J1xaYApIfp/YrhjSh9rRhml1U5Wj80LBgyp/6n+KI3VlvcAraThhnHnCTp+M3Uh+w==",
"type": "package",
"files": [
"Microsoft.NETCore.Runtime.CoreCLR-arm.1.0.0.nupkg.sha512",
Expand Down
3 changes: 1 addition & 2 deletions src/Samples/Samples/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:samples="clr-namespace:Samples;assembly=Samples"
x:Class="Samples.MainPage"
Title="ACR UserDialogs"
Padding="0, 30, 0, 0">
Title="ACR UserDialogs">
<TabbedPage.Children>
<NavigationPage Title="Standard">
<x:Arguments>
Expand Down

0 comments on commit a7c5fe1

Please sign in to comment.