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

PdfView :)

This commit is contained in:
Yan Maniez 2019-05-11 14:53:34 +02:00
parent 56b902a25d
commit 85be3862f6
5 changed files with 134 additions and 34 deletions

View file

@ -107,6 +107,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="PdfViewRenderer.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NativeAPI.cs" />

View 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))));
}
}
}
}
}

View 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); }
//}
}
}

View file

@ -1,12 +1,15 @@
<?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:views="clr-namespace:AideDeJeu.Views"
x:Class="AideDeJeu.Views.PlayerCharacter.PdfViewPage">
<ContentPage.Content>
<StackLayout>
<Label Text="{Binding PdfFile.Result}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<views:PdfView Uri="{Binding PdfFile.Result}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>

View file

@ -1,35 +1,35 @@
using AideDeJeu.ViewModels;
using AideDeJeuLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
//using AideDeJeu.ViewModels;
//using AideDeJeuLib;
//using Microsoft.VisualStudio.T.TestTools.UnitTesting;
//using System.Collections.Generic;
//using System.Diagnostics;
//using System.Threading.Tasks;
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)
//namespace AideDeJeuUnitTest
//{
// 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);
}
}
}