mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +00:00
PdfView :)
This commit is contained in:
parent
56b902a25d
commit
85be3862f6
5 changed files with 134 additions and 34 deletions
|
|
@ -107,6 +107,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="MainActivity.cs" />
|
<Compile Include="MainActivity.cs" />
|
||||||
|
<Compile Include="PdfViewRenderer.cs" />
|
||||||
<Compile Include="Resources\Resource.Designer.cs" />
|
<Compile Include="Resources\Resource.Designer.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="NativeAPI.cs" />
|
<Compile Include="NativeAPI.cs" />
|
||||||
|
|
|
||||||
62
AideDeJeu/AideDeJeu.Android/PdfViewRenderer.cs
Normal file
62
AideDeJeu/AideDeJeu.Android/PdfViewRenderer.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using AideDeJeu.Droid;
|
||||||
|
using AideDeJeu.Views;
|
||||||
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
|
using Android.OS;
|
||||||
|
using Android.Runtime;
|
||||||
|
using Android.Views;
|
||||||
|
using Android.Widget;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Platform.Android;
|
||||||
|
|
||||||
|
[assembly: ExportRenderer(typeof(PdfView), typeof(PdfViewRenderer))]
|
||||||
|
namespace AideDeJeu.Droid
|
||||||
|
{
|
||||||
|
public class PdfViewRenderer : WebViewRenderer
|
||||||
|
{
|
||||||
|
public PdfViewRenderer(Context context) : base(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnElementPropertyChanged(sender, e);
|
||||||
|
if (e.PropertyName == "Uri")
|
||||||
|
{
|
||||||
|
var pdfView = Element as PdfView;
|
||||||
|
if (pdfView.Uri != null)
|
||||||
|
{
|
||||||
|
Control.Settings.AllowFileAccess = true;
|
||||||
|
Control.Settings.AllowFileAccessFromFileURLs = true;
|
||||||
|
Control.Settings.AllowUniversalAccessFromFileURLs = true;
|
||||||
|
//Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/Content/{0}", WebUtility.UrlEncode(customWebView.Uri))));
|
||||||
|
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file://{0}", WebUtility.UrlEncode(pdfView.Uri))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
|
||||||
|
{
|
||||||
|
base.OnElementChanged(e);
|
||||||
|
|
||||||
|
if (e.NewElement != null)
|
||||||
|
{
|
||||||
|
var pdfView = Element as PdfView;
|
||||||
|
if (pdfView.Uri != null)
|
||||||
|
{
|
||||||
|
Control.Settings.AllowFileAccess = true;
|
||||||
|
Control.Settings.AllowFileAccessFromFileURLs = true;
|
||||||
|
Control.Settings.AllowUniversalAccessFromFileURLs = true;
|
||||||
|
//Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/Content/{0}", WebUtility.UrlEncode(customWebView.Uri))));
|
||||||
|
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file://{0}", WebUtility.UrlEncode(pdfView.Uri))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
AideDeJeu/AideDeJeu/Views/PdfView.cs
Normal file
34
AideDeJeu/AideDeJeu/Views/PdfView.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace AideDeJeu.Views
|
||||||
|
{
|
||||||
|
public class PdfView : WebView
|
||||||
|
{
|
||||||
|
//public static readonly BindableProperty UriProperty =
|
||||||
|
// BindableProperty.Create<PdfView, string>(p => p.Uri, default(string));
|
||||||
|
public string Uri
|
||||||
|
{
|
||||||
|
get { return (string)GetValue(UriProperty); }
|
||||||
|
set { SetValue(UriProperty, value); }
|
||||||
|
}
|
||||||
|
public static readonly BindableProperty UriProperty = BindableProperty.Create(
|
||||||
|
nameof(Uri),
|
||||||
|
typeof(string),
|
||||||
|
typeof(PdfView),
|
||||||
|
defaultValue: default(string),
|
||||||
|
propertyChanged: OnUriChanged);
|
||||||
|
|
||||||
|
static void OnUriChanged(BindableObject bindable, object oldValue, object newValue)
|
||||||
|
{
|
||||||
|
var view = bindable as PdfView;
|
||||||
|
}
|
||||||
|
//public string Uri
|
||||||
|
//{
|
||||||
|
// get { return (string)GetValue(UriProperty); }
|
||||||
|
// set { SetValue(UriProperty, value); }
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
xmlns:views="clr-namespace:AideDeJeu.Views"
|
||||||
x:Class="AideDeJeu.Views.PlayerCharacter.PdfViewPage">
|
x:Class="AideDeJeu.Views.PlayerCharacter.PdfViewPage">
|
||||||
<ContentPage.Content>
|
<ContentPage.Content>
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Label Text="{Binding PdfFile.Result}"
|
<Label Text="{Binding PdfFile.Result}"
|
||||||
VerticalOptions="CenterAndExpand"
|
VerticalOptions="CenterAndExpand"
|
||||||
HorizontalOptions="CenterAndExpand" />
|
HorizontalOptions="CenterAndExpand" />
|
||||||
|
|
||||||
|
<views:PdfView Uri="{Binding PdfFile.Result}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage.Content>
|
</ContentPage.Content>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
using AideDeJeu.ViewModels;
|
//using AideDeJeu.ViewModels;
|
||||||
using AideDeJeuLib;
|
//using AideDeJeuLib;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
//using Microsoft.VisualStudio.T.TestTools.UnitTesting;
|
||||||
using System.Collections.Generic;
|
//using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
//using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
//using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AideDeJeuUnitTest
|
//namespace AideDeJeuUnitTest
|
||||||
{
|
|
||||||
[TestClass]
|
|
||||||
public class UnitTest1
|
|
||||||
{
|
|
||||||
[TestMethod]
|
|
||||||
public async Task TestMethod1()
|
|
||||||
{
|
|
||||||
var diceRoller = new DiceRollerViewModel();
|
|
||||||
var diceRolls = diceRoller.DicesValues(6, 3);
|
|
||||||
foreach(var diceRoll in diceRolls)
|
|
||||||
{
|
|
||||||
Debug.WriteLine($"{diceRoll.Key} => {diceRoll.Value / 3}");
|
|
||||||
}
|
|
||||||
Assert.IsNotNull(diceRolls);
|
|
||||||
//var allItems = new Dictionary<string, Item>();
|
|
||||||
//var store = new StoreViewModel();
|
|
||||||
//var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md"), allItems);
|
|
||||||
//var md = item.Markdown;
|
|
||||||
//var children = await item.GetChildrenAsync();
|
|
||||||
//foreach(var iitem in children)
|
|
||||||
//{
|
//{
|
||||||
// md += iitem.Markdown;
|
// [TestClass]
|
||||||
|
// public class UnitTest1
|
||||||
|
// {
|
||||||
|
// [TestMethod]
|
||||||
|
// public async Task TestMethod1()
|
||||||
|
// {
|
||||||
|
// var diceRoller = new DiceRollerViewModel();
|
||||||
|
// var diceRolls = diceRoller.DicesValues(6, 3);
|
||||||
|
// foreach(var diceRoll in diceRolls)
|
||||||
|
// {
|
||||||
|
// Debug.WriteLine($"{diceRoll.Key} => {diceRoll.Value / 3}");
|
||||||
|
// }
|
||||||
|
// Assert.IsNotNull(diceRolls);
|
||||||
|
// //var allItems = new Dictionary<string, Item>();
|
||||||
|
// //var store = new StoreViewModel();
|
||||||
|
// //var item = store.ToItem(null, AideDeJeu.Tools.Helpers.GetResourceString($"AideDeJeu.Data.sandbox.md"), allItems);
|
||||||
|
// //var md = item.Markdown;
|
||||||
|
// //var children = await item.GetChildrenAsync();
|
||||||
|
// //foreach(var iitem in children)
|
||||||
|
// //{
|
||||||
|
// // md += iitem.Markdown;
|
||||||
|
// //}
|
||||||
|
// //Assert.IsNotNull(md);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
//Assert.IsNotNull(md);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue