1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Premier test pdf ok

This commit is contained in:
Yan Maniez 2019-04-22 19:50:24 +02:00
parent 6ed9f0ebb7
commit 96d7c1c597
16 changed files with 2914 additions and 2502 deletions

View file

@ -89,12 +89,18 @@
<PackageReference Include="System.Memory">
<Version>4.5.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="XamiTextSharpLGPLv2">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />

View file

@ -19,6 +19,10 @@ namespace AideDeJeu.Droid
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
Xamarin.Essentials.ExperimentalFeatures.Enable(Xamarin.Essentials.ExperimentalFeatures.ShareFileRequest);
//StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
//StrictMode.SetVmPolicy(builder.Build());
Rg.Plugins.Popup.Popup.Init(this, bundle);
@ -43,6 +47,13 @@ namespace AideDeJeu.Droid
// Do something if there are not any pages in the `PopupStack`
}
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

View file

@ -1,4 +1,5 @@
using AideDeJeu.Tools;
using Android.Content;
using Android.Content.PM;
using System.IO;
using System.Threading.Tasks;
@ -92,5 +93,107 @@ namespace AideDeJeu.Droid
}
return newVersion > oldVersion;
}
public async Task SaveStreamAsync(string filename, Stream stream)
{
using (var outStream = CreateStream(filename))
{
await stream.CopyToAsync(outStream);
}
}
public Stream CreateStream(string filename)
{
var documentsDirectoryPath = Android.App.Application.Context.CacheDir.AbsolutePath;
var filepath = Path.Combine(documentsDirectoryPath, filename);
return new FileStream(filepath, FileMode.Create);
}
//public void OpenFileByName(string fileName)
//{
// //try
// //{
// var documentsPath = Android.App.Application.Context.CacheDir.AbsolutePath; ;// System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
// var filePath = Path.Combine(documentsPath, fileName);
// var bytes = File.ReadAllBytes(filePath);
// //Copy the private file's data to the EXTERNAL PUBLIC location
// string externalStorageState = global::Android.OS.Environment.ExternalStorageState;
// var externalPath = global::Android.OS.Environment.ExternalStorageDirectory.Path + "/" + global::Android.OS.Environment.DirectoryDownloads + "/" + fileName;
// File.WriteAllBytes(externalPath, bytes);
// Java.IO.File file = new Java.IO.File(externalPath);
// file.SetReadable(true);
// string application = "";
// string extension = Path.GetExtension(filePath);
// // get mimeTye
// switch (extension.ToLower())
// {
// case ".txt":
// application = "text/plain";
// break;
// case ".doc":
// case ".docx":
// application = "application/msword";
// break;
// case ".pdf":
// application = "application/pdf";
// break;
// case ".xls":
// case ".xlsx":
// application = "application/vnd.ms-excel";
// break;
// case ".jpg":
// case ".jpeg":
// case ".png":
// application = "image/jpeg";
// break;
// default:
// application = "*/*";
// break;
// }
// //Android.Net.Uri uri = Android.Net.Uri.Parse("file://" + filePath);
// Android.Net.Uri uri = Android.Net.Uri.FromFile(file);
// Intent intent = new Intent(Intent.ActionView);
// intent.SetDataAndType(uri, application);
// intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
// Xamarin.Forms.Forms.Context.StartActivity(intent);
// //}
// //catch (Exception ex)
// //{
// // Console.WriteLine(ex.Message);
// //}
//}
//static Task PlatformRequestAsync(Xamarin.Essentials.ShareFileRequest request)
//{
// var contentUri = Platform.GetShareableFileUri(request.File.FullPath);
// var intent = new Intent(Intent.ActionSend);
// intent.SetType(request.File.ContentType);
// intent.SetFlags(ActivityFlags.GrantReadUriPermission);
// intent.PutExtra(Intent.ExtraStream, contentUri);
// if (!string.IsNullOrEmpty(request.Title))
// {
// intent.PutExtra(Intent.ExtraTitle, request.Title);
// }
// var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty);
// chooserIntent.SetFlags(ActivityFlags.ClearTop);
// chooserIntent.SetFlags(ActivityFlags.NewTask);
// Platform.AppContext.StartActivity(chooserIntent);
// return Task.CompletedTask;
//}
}
}

File diff suppressed because it is too large Load diff

View file

@ -205,6 +205,9 @@
<Reference Include="webkit-sharp, Version=1.1.15.0, Culture=neutral, PublicKeyToken=eaa1d335d2e19745, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.Forms.Platform.GTK.4.0.0.346134-pre9\lib\net45\webkit-sharp.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.Essentials.1.1.0\lib\netstandard2.0\Xamarin.Essentials.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.Forms.4.0.0.346134-pre9\lib\netstandard2.0\Xamarin.Forms.Core.dll</HintPath>
</Reference>
@ -217,6 +220,9 @@
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xamarin.Forms.4.0.0.346134-pre9\lib\netstandard2.0\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
<Reference Include="XamiTextSharpLGPLv2, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\XamiTextSharpLGPLv2.1.0.0\lib\netstandard2.0\XamiTextSharpLGPLv2.dll</HintPath>
</Reference>
<Reference Include="YamlDotNet, Version=6.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\..\packages\YamlDotNet.6.0.0\lib\net45\YamlDotNet.dll</HintPath>
</Reference>

View file

@ -44,8 +44,10 @@
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net471" />
<package id="System.Text.Encoding.CodePages" version="4.5.0" targetFramework="net471" />
<package id="System.Threading.Tasks.Extensions" version="4.6.0-preview.18571.3" targetFramework="net471" />
<package id="Xamarin.Essentials" version="1.1.0" targetFramework="net471" />
<package id="Xamarin.Forms" version="4.0.0.346134-pre9" targetFramework="net471" />
<package id="Xamarin.Forms.Platform.GTK" version="4.0.0.346134-pre9" targetFramework="net471" />
<package id="Xamarin.Forms.Visual.Material" version="4.0.0.346134-pre9" targetFramework="net471" />
<package id="XamiTextSharpLGPLv2" version="1.0.0" targetFramework="net471" />
<package id="YamlDotNet" version="6.0.0" targetFramework="net471" />
</packages>

View file

@ -221,12 +221,18 @@
<PackageReference Include="sqlite-net-pcl">
<Version>1.6.258-beta</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="XamiTextSharpLGPLv2">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AideDeJeu\AideDeJeu.csproj">
@ -234,7 +240,6 @@
<Name>AideDeJeu</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>

View file

@ -57,6 +57,8 @@ namespace AideDeJeu.UWP
//Xamarin.Forms.Forms.Init(e);
//Xamarin.Forms.SetFlags("CollectionView_Experimental");
//Xamarin.Forms.SetFlags("Shell_Experimental");
Xamarin.Essentials.ExperimentalFeatures.Enable(Xamarin.Essentials.ExperimentalFeatures.ShareFileRequest);
Xamarin.Forms.Forms.Init(e, Rg.Plugins.Popup.Popup.GetExtraAssemblies());
SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());

View file

@ -89,5 +89,24 @@ namespace AideDeJeu.UWP
return newVersion > oldVersion;
}
public async Task SaveStreamAsync(string filename, Stream stream)
{
using (var outStream = CreateStream(filename))
{
await stream.CopyToAsync(outStream);
}
}
public Stream CreateStream(string filename)
{
var documentsDirectoryPath = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
var filepath = Path.Combine(documentsDirectoryPath, filename);
return new FileStream(filepath, FileMode.Create);
}
//public void OpenFileExternal(string filename)
//{
//}
}
}

View file

@ -142,12 +142,18 @@
<PackageReference Include="sqlite-net-pcl">
<Version>1.6.258-beta</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.Visual.Material">
<Version>4.0.0.346134-pre9</Version>
</PackageReference>
<PackageReference Include="XamiTextSharpLGPLv2">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\tab_about.png" />

View file

@ -36,8 +36,10 @@
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.68.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.258-beta" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="4.0.0.346134-pre9" />
<PackageReference Include="XamiTextSharpLGPLv2" Version="1.0.0" />
<PackageReference Include="YamlDotNet" Version="6.0.0" />
</ItemGroup>

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
@ -10,5 +11,8 @@ namespace AideDeJeu.Tools
string GetVersion();
int GetBuild();
Task<string> GetDatabasePathAsync(string databaseName);
Task SaveStreamAsync(string filename, Stream stream);
Stream CreateStream(string filename);
//void OpenFileByName(string fileName);
}
}

View file

@ -1,10 +1,13 @@
using AideDeJeu.Tools;
using AideDeJeuLib;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@ -861,11 +864,50 @@ namespace AideDeJeu.ViewModels.PlayerCharacter
{
get
{
return new Command(ExecuteRollDicesCommand);
return new Command(async() => await ExecuteRollDicesCommandAsync());
}
}
private void ExecuteRollDicesCommand()
private async Task ExecuteRollDicesCommandAsync()
{
//PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
//PdfDocument srcDoc;
//PdfFormXObject page;
//PdfCanvas canvas = new PdfCanvas(pdfDoc..FirstPage.newContentStreamBefore(),
// pdfDoc.getFirstPage().getResources(), pdfDoc);
//for (String path : EXTRA)
//{
// srcDoc = new PdfDocument(new PdfReader(path));
// page = srcDoc.getFirstPage().copyAsFormXObject(pdfDoc);
// canvas.addXObject(page, 0, 0);
// srcDoc.close();
//}
//pdfDoc.close();
Document document = new Document();
var stream = DependencyService.Get<INativeAPI>().CreateStream("test.pdf");
PdfWriter.GetInstance(document, stream);
document.Open();
document.Add(new iTextSharp.text.Jpeg(new Uri("https://www.w3.org/MarkUp/Test/xhtml-print/20050519/tests/jpeg444.jpg")));
document.Add(new Paragraph("Hello World!"));
document.Close();
//DependencyService.Get<INativeAPI>().OpenFileByName("test.pdf");
//var file = Path.Combine(FileSystem.CacheDirectory, fn);
//File.WriteAllText(file, "Hello World");
var testfile = Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, "test.pdf");
var shareFile = new Xamarin.Essentials.ShareFile(testfile);
//var truc = Platform.GetShareableFileUri(request.File.FullPath);
//await Xamarin.Essentials.Browser.OpenAsync(testfile);
await Xamarin.Essentials.Share.RequestAsync(new Xamarin.Essentials.ShareFileRequest()
{
Title = "ou yeah",
File = shareFile
});
var random = new Random(DateTime.Now.Millisecond);
var values = RollMRick(random);
values.Sort();

View file

@ -14,7 +14,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.0.0-preview3.19153.1" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.258-beta" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="XamiTextSharpLGPLv2" Version="1.0.0" />
</ItemGroup>
<ItemGroup>

View file

@ -13,7 +13,9 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0-beta2" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0-beta2" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.258-beta" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="XamiTextSharpLGPLv2" Version="1.0.0" />
</ItemGroup>
<ItemGroup>

View file

@ -13,7 +13,9 @@
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.0.0-preview3.19153.1" />
<PackageReference Include="sqlite-net-pcl" Version="1.6.258-beta" />
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
<PackageReference Include="Xamarin.Forms" Version="4.0.0.346134-pre9" />
<PackageReference Include="XamiTextSharpLGPLv2" Version="1.0.0" />
</ItemGroup>
<ItemGroup>