Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Functions/SantaTalk.Functions/SantaTalk.Functions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SantaTalk.Functions", "SantaTalk.Functions.csproj", "{F98A568D-8F95-48FE-B1DC-7F8EF9F3431F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F98A568D-8F95-48FE-B1DC-7F8EF9F3431F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F98A568D-8F95-48FE-B1DC-7F8EF9F3431F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F98A568D-8F95-48FE-B1DC-7F8EF9F3431F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F98A568D-8F95-48FE-B1DC-7F8EF9F3431F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions src/SantaTalk.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.CurrentActivity;

namespace SantaTalk.Droid
{
Expand All @@ -19,6 +20,8 @@ protected override void OnCreate(Bundle savedInstanceState)

base.OnCreate(savedInstanceState);

CrossCurrentActivity.Current.Init(this, savedInstanceState);

Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
Expand All @@ -27,8 +30,10 @@ protected override void OnCreate(Bundle savedInstanceState)
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

}
}
23 changes: 23 additions & 0 deletions src/SantaTalk.Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Android.App;
using Android.Runtime;
using Plugin.CurrentActivity;

#if DEBUG
[Application(Debuggable = true)]
#else
[Application(Debuggable = false)]
#endif
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer)
{
}

public override void OnCreate()
{
base.OnCreate();
CrossCurrentActivity.Current.Init(this);
}
}
8 changes: 7 additions & 1 deletion src/SantaTalk.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.codemilltech.santatalk">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="SantaTalk.Android" android:networkSecurityConfig="@xml/network_security_config"></application>
<application android:label="SantaTalk.Android" android:networkSecurityConfig="@xml/network_security_config">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
3 changes: 3 additions & 0 deletions src/SantaTalk.Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]

[assembly: UsesFeature("android.hardware.camera", Required = true)]
[assembly: UsesFeature("android.hardware.camera.autofocus", Required = true)]
7 changes: 5 additions & 2 deletions src/SantaTalk.Android/Resources/Resource.designer.cs

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

5 changes: 5 additions & 0 deletions src/SantaTalk.Android/Resources/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>
11 changes: 11 additions & 0 deletions src/SantaTalk.Android/SantaTalk.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="Xam.Plugin.Media">
<Version>4.0.1.5</Version>
</PackageReference>
<PackageReference Include="Plugin.CurrentActivity">
<Version>2.1.0.4</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MainApplication.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down Expand Up @@ -125,6 +132,10 @@
<SubType></SubType>
<Generator></Generator>
</AndroidResource>
<AndroidResource Include="Resources\xml\file_paths.xml">
<SubType></SubType>
<Generator></Generator>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable\" />
Expand Down
8 changes: 8 additions & 0 deletions src/SantaTalk.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<key>NSAllowLocalNetworking</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to microphone.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery.</string>
<key>UIAppFonts</key>
<array>
<string>futura_book.ttf</string>
Expand Down
3 changes: 3 additions & 0 deletions src/SantaTalk.iOS/SantaTalk.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="Xam.Plugin.Media">
<Version>4.0.1.5</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
64 changes: 37 additions & 27 deletions src/SantaTalk/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:controls="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
xmlns:viewmodels="clr-namespace:SantaTalk"
mc:Ignorable="d"
NavigationPage.HasNavigationBar="False"
NavigationPage.BackButtonTitle=""
ios:Page.UseSafeArea="True"
BackgroundColor="{StaticResource dark_gradient}"
x:Class="SantaTalk.MainPage">
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="SantaTalk.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodels="clr-namespace:SantaTalk"
ios:Page.UseSafeArea="True"
BackgroundColor="{StaticResource dark_gradient}"
NavigationPage.BackButtonTitle=""
NavigationPage.HasNavigationBar="False"
mc:Ignorable="d">

<ContentPage.BindingContext>
<viewmodels:MainPageViewModel />
</ContentPage.BindingContext>

<controls:PancakeView BackgroundGradientStartColor="{StaticResource dark_gradient}"
BackgroundGradientEndColor="{StaticResource light_gradient}">
<controls:PancakeView BackgroundGradientEndColor="{StaticResource light_gradient}" BackgroundGradientStartColor="{StaticResource dark_gradient}">

<Grid x:Name="MainGrid">
<ScrollView VerticalOptions="FillAndExpand">
<StackLayout VerticalOptions="FillAndExpand" Padding="24" Spacing="0">
<StackLayout Padding="24"
Spacing="0"
VerticalOptions="FillAndExpand">
<StackLayout VerticalOptions="CenterAndExpand">
<Label Text="WELCOME TO" FontSize="16" TextColor="{StaticResource highlight_text}"/>
<Label Text="Santa Talk" FontSize="48"/>
<Label Margin="0,24,0,16" FontSize="15" Text="Write Santa a letter, and he'll instantly let you know if you've been naughty or nice!" />
<Label FontSize="16"
Text="WELCOME TO"
TextColor="{StaticResource highlight_text}" />
<Label FontSize="48" Text="Santa Talk" />
<Label Margin="0,24,0,16"
FontSize="15"
Text="Write Santa a letter, and he'll instantly let you know if you've been naughty or nice!" />
</StackLayout>
<StackLayout Spacing="16" VerticalOptions="CenterAndExpand">
<StackLayout Spacing="8">
<Label Text="WHAT'S YOUR NAME?" FontSize="12"/>
<Label FontSize="12" Text="WHAT'S YOUR NAME?" />
<Entry Text="{Binding KidsName}" />
</StackLayout>
<StackLayout Spacing="8">
<Label Text="WRITE YOUR LETTER TO SANTA" FontSize="12"/>
<Editor Text="{Binding LetterText}" TextColor="White"/>
<Label FontSize="12" Text="WRITE YOUR LETTER TO SANTA" />
<Editor Text="{Binding LetterText}" TextColor="White" />
</StackLayout>
<Image Source="{Binding Photo}" />
<Button Margin="16"
Command="{Binding TakePictureCommand}"
Text="TAKE PHOTO TO SANTA"
VerticalOptions="EndAndExpand" />
</StackLayout>
<Button VerticalOptions="EndAndExpand" Text="SEND TO SANTA" Margin="16" Command="{Binding SendLetterCommand}" />
<Button Margin="16"
Command="{Binding SendLetterCommand}"
Text="SEND TO SANTA"
VerticalOptions="EndAndExpand" />
</StackLayout>
</ScrollView>
</Grid>

</controls:PancakeView>

</ContentPage>
28 changes: 28 additions & 0 deletions src/SantaTalk/Models/Face.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace SantaTalk.Models
{
public class Face
{
[JsonProperty("smile")]
public double Smile { get; set; }

[JsonProperty("gender")]
public string Gender { get; set; }

[JsonProperty("age")]
public double Age { get; set; }

[JsonProperty("emotion")]
public Dictionary<string, double> Emotions;

public string CurrentEmotion()
{
var emotions = Emotions.OrderByDescending(x => x.Value);
return emotions.FirstOrDefault().Key;
}
}
}
4 changes: 4 additions & 0 deletions src/SantaTalk/ResultsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@

<controls:PancakeView Margin="0,24,0,0" BackgroundColor="{StaticResource white}" CornerRadius="8">
<StackLayout Padding="24" Spacing="8">
<StackLayout IsVisible="{Binding TheresFoto}">
<Label Text="Here is Santa! And I really like your photo .. and it shows me that you are: " Style="{StaticResource SantaText}"/>
<Label Text="{Binding EmotionPhoto}" FontSize="Large" FontAttributes="Bold" Style="{StaticResource SantaText}"/>
</StackLayout>
<Label Text="I think it's very nice that you took the time to write me." Style="{StaticResource SantaText}" />
<Label Style="{StaticResource SantaText}">
<Label.FormattedText>
Expand Down
3 changes: 2 additions & 1 deletion src/SantaTalk/ResultsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class ResultsPage : ContentPage
private List<VisualElement> _stars = new List<VisualElement>();
private ResultsPageViewModel vm = new ResultsPageViewModel();

public ResultsPage(string kidsName, string letterText)
public ResultsPage(string kidsName, string letterText, string filePath)
{
InitializeComponent();

Expand All @@ -28,6 +28,7 @@ public ResultsPage(string kidsName, string letterText)
vm.KidsName = kidsName;
vm.LetterText = letterText;
vm.CurrentState = State.Loading;
vm.FilePath = filePath;

_formsWidth = Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density);
_formsHeight = Convert.ToInt32(DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density);
Expand Down
2 changes: 2 additions & 0 deletions src/SantaTalk/SantaTalk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
<PackageReference Include="Xamarin.Forms.PancakeView" Version="1.3.6" />
<PackageReference Include="Xamarin.Forms.StateSquid" Version="1.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Xam.Plugin.Media" Version="4.0.1.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Functions\SantaTalk.Models\SantaTalk.Models.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
<Folder Include="ViewModels\" />
<Folder Include="Models\" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions src/SantaTalk/Services/FaceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SantaTalk.Models;

namespace SantaTalk.Services
{
public class FaceResponse
{
public Face FaceAttributes { get; set; }
}
}
56 changes: 56 additions & 0 deletions src/SantaTalk/Services/PhotoDeliveryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace SantaTalk.Services
{
public class PhotoDeliveryService
{
const string subscriptionKey = "4c8b5bdac07d45e58a64734a1a10eff6";
const string uriBase = "https://brazilsouth.api.cognitive.microsoft.com/face/v1.0/detect";

public async Task<List<FaceResponse>> MakeAnalysisRequest(string imageFilePath)
{
var httpClient = new HttpClient();

httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

string requestParameters = "returnFaceId=true&returnFaceLandmarks=false" +
"&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses," +
"emotion,hair,makeup,occlusion,accessories,blur,exposure,noise";

string uri = uriBase + "?" + requestParameters;

byte[] byteData = GetImageAsByteArray(imageFilePath);

List<FaceResponse> result;

using (ByteArrayContent content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

var response = await httpClient.PostAsync(uri, content);

string contentString = await response.Content.ReadAsStringAsync();

result = JsonConvert.DeserializeObject<List<FaceResponse>>(contentString);
}

return result;
}

private byte[] GetImageAsByteArray(string imageFilePath)
{
using (FileStream fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
{
BinaryReader binaryReader = new BinaryReader(fileStream);
return binaryReader.ReadBytes((int)fileStream.Length);
}
}
}
}

Loading