Bug Fixes & Layout
This commit is contained in:
parent
84a4b04122
commit
6a211566d3
11 changed files with 181 additions and 92 deletions
|
|
@ -297,6 +297,7 @@ namespace XLabs.Forms
|
|||
|
||||
base.OnStop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -334,8 +335,10 @@ namespace XLabs.Forms
|
|||
this.AppContext.Stop += (o, e) => this.OnClosing();
|
||||
this.AppContext.Pause += (o, e) => this.OnSuspended();
|
||||
this.AppContext.Resume += (o, e) => this.OnResumed();
|
||||
|
||||
this.AppDataDirectory = Environment.ExternalStorageDirectory.AbsolutePath;
|
||||
|
||||
this.Orientation = AppContext.RequestedOrientation == Android.Content.PM.ScreenOrientation.Portrait ?
|
||||
Enums.Orientation.Portrait : Enums.Orientation.None;
|
||||
if (initServices)
|
||||
{
|
||||
DependencyService.Register<TextToSpeechService>();
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ namespace BookAStar.Droid
|
|||
ToolbarResource = Resource.Layout.Toolbar;
|
||||
|
||||
base.OnCreate(bundle);
|
||||
|
||||
global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
|
||||
SetPersistent(true);
|
||||
// global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never);
|
||||
|
||||
//var tb = FindViewById<Android.Support.V7.Widget.Toolbar>(ToolbarResource);
|
||||
// FIXME tb is null
|
||||
|
|
@ -73,7 +73,8 @@ namespace BookAStar.Droid
|
|||
IXFormsApp<XFormsCompatApplicationDroid> app =null;
|
||||
if (!Resolver.IsSet)
|
||||
{
|
||||
this.SetIoc();
|
||||
var xfapp = new XFormsCompatAppDroid();
|
||||
this.SetIoc(xfapp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -93,8 +94,8 @@ namespace BookAStar.Droid
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
LoadApplication(new BookAStar.App(this));
|
||||
var fapp = new BookAStar.App(this);
|
||||
LoadApplication(fapp);
|
||||
// TabLayoutResource = Resource.Layout.Tabbar;
|
||||
// ToolbarResource = Resource.Layout.Toolbar;
|
||||
/*
|
||||
|
|
@ -108,11 +109,10 @@ namespace BookAStar.Droid
|
|||
|
||||
}
|
||||
|
||||
private void SetIoc()
|
||||
private SimpleContainer SetIoc(XFormsCompatAppDroid app)
|
||||
{
|
||||
var resolverContainer = new SimpleContainer();
|
||||
|
||||
var app = new XFormsCompatAppDroid();
|
||||
|
||||
app.Init(this);
|
||||
|
||||
|
|
@ -133,6 +133,7 @@ namespace BookAStar.Droid
|
|||
t => new SQLiteSimpleCache(new SQLitePlatformAndroid(),
|
||||
new SQLiteConnectionString(pathToDatabase, true), t.Resolve<IJsonSerializer>()));
|
||||
Resolver.SetResolver(resolverContainer.GetResolver());
|
||||
return resolverContainer;
|
||||
}
|
||||
|
||||
public bool EnablePushNotifications(bool enable)
|
||||
|
|
@ -425,18 +426,25 @@ namespace BookAStar.Droid
|
|||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
return (T) Resolver.Resolve(typeof(T));
|
||||
}
|
||||
|
||||
public object Resolve(Type t)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Resolver.Resolve(t);
|
||||
}
|
||||
|
||||
public void Init(App context, bool initServices = true)
|
||||
protected override void OnSaveInstanceState(Bundle outState)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
base.OnSaveInstanceState(outState);
|
||||
}
|
||||
public override void OnStateNotSaved()
|
||||
{
|
||||
base.OnStateNotSaved();
|
||||
}
|
||||
public override void OnRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState)
|
||||
{
|
||||
base.OnRestoreInstanceState(savedInstanceState, persistentState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using BookAStar.Droid;
|
|||
using System;
|
||||
using Java.Interop;
|
||||
using System.ComponentModel;
|
||||
using Android.Views;
|
||||
|
||||
[assembly: Xamarin.Forms.ExportRenderer(typeof(MarkdownView), typeof(MarkdownViewRenderer))]
|
||||
namespace BookAStar.Droid
|
||||
|
|
@ -27,9 +28,13 @@ namespace BookAStar.Droid
|
|||
|
||||
if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer))
|
||||
{
|
||||
hybridRenderer.Element.Markdown=data;
|
||||
hybridRenderer.Element.Markdown = data;
|
||||
MarkdownViewRenderer.OnPageFinished(hybridRenderer.Element,
|
||||
hybridRenderer.EditorView);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class MarkdownViewRenderer : ViewRenderer<MarkdownView, WebView>
|
||||
|
|
@ -39,12 +44,30 @@ namespace BookAStar.Droid
|
|||
private MarkdownDeep.Markdown markdown = new MarkdownDeep.Markdown();
|
||||
const string JavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}";
|
||||
|
||||
public WebView EditorView
|
||||
{
|
||||
get
|
||||
{
|
||||
return editorView;
|
||||
}
|
||||
}
|
||||
|
||||
public static async void OnPageFinished(MarkdownView xview, WebView view)
|
||||
{
|
||||
int i = 10;
|
||||
while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered
|
||||
await System.Threading.Tasks.Task.Delay(100);
|
||||
xview.BatchBegin();
|
||||
xview.HeightRequest = view.ContentHeight;
|
||||
xview.BatchCommit();
|
||||
}
|
||||
private void SetMDEditorText(string text)
|
||||
{
|
||||
editorTemplate.Model = (text == null) ? null : markdown.Transform(text);
|
||||
var html = editorTemplate.GenerateString();
|
||||
editorView.LoadDataWithBaseURL("file:///android_asset/",
|
||||
EditorView.LoadDataWithBaseURL("file:///android_asset/",
|
||||
html, "text/html", "utf-8", null);
|
||||
OnPageFinished(Element, editorView);
|
||||
}
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<MarkdownView> e)
|
||||
|
|
@ -63,7 +86,7 @@ namespace BookAStar.Droid
|
|||
// Subscribe
|
||||
var viewclient = new MarkdownWebViewClient(
|
||||
md => { e.NewElement.Markdown = md; });
|
||||
editorView.SetWebViewClient(viewclient);
|
||||
EditorView.SetWebViewClient(viewclient);
|
||||
Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");
|
||||
SetMDEditorText(e.NewElement.Markdown);
|
||||
InjectJS(JavaScriptFunction);
|
||||
|
|
@ -81,33 +104,40 @@ namespace BookAStar.Droid
|
|||
private WebView CreateNativeControl()
|
||||
{
|
||||
editorView = new WebView(Context);
|
||||
editorView.Settings.BuiltInZoomControls = true;
|
||||
editorView.Settings.JavaScriptEnabled = true;
|
||||
editorView.Settings.LoadsImagesAutomatically = true;
|
||||
editorView.Settings.SetAppCacheEnabled(true);
|
||||
editorView.Settings.AllowContentAccess = true;
|
||||
editorView.Settings.AllowFileAccess = true;
|
||||
editorView.Settings.AllowFileAccessFromFileURLs = true;
|
||||
editorView.Settings.AllowUniversalAccessFromFileURLs = true;
|
||||
editorView.Settings.BlockNetworkImage = false;
|
||||
editorView.Settings.BlockNetworkLoads = false;
|
||||
editorView.Settings.DomStorageEnabled = true;
|
||||
EditorView.Settings.BuiltInZoomControls = false;
|
||||
EditorView.Settings.JavaScriptEnabled = true;
|
||||
EditorView.Settings.LoadsImagesAutomatically = true;
|
||||
EditorView.Settings.SetAppCacheEnabled(true);
|
||||
EditorView.Settings.AllowContentAccess = true;
|
||||
EditorView.Settings.AllowFileAccess = true;
|
||||
EditorView.Settings.AllowFileAccessFromFileURLs = true;
|
||||
EditorView.Settings.AllowUniversalAccessFromFileURLs = true;
|
||||
EditorView.Settings.BlockNetworkImage = false;
|
||||
EditorView.Settings.BlockNetworkLoads = false;
|
||||
EditorView.Settings.DomStorageEnabled = true;
|
||||
|
||||
// editorView.SetMinimumHeight(300);
|
||||
return editorView;
|
||||
return EditorView;
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Markdown")
|
||||
{
|
||||
SetMDEditorText(((MarkdownView)Element).Markdown);
|
||||
}
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
}
|
||||
|
||||
// FIXME no impact...
|
||||
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
base.OnMeasure(widthMeasureSpec, editorView.ContentHeight);
|
||||
MeasureSpecMode widthMode = MeasureSpec.GetMode(widthMeasureSpec);
|
||||
MeasureSpecMode heightMode = MeasureSpec.GetMode(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.GetSize(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.GetSize(heightMeasureSpec);
|
||||
int pxHeight = (int)ContextExtensions.ToPixels(Context, Element.HeightRequest);
|
||||
int pxWidth = (int)ContextExtensions.ToPixels(Context, Element.WidthRequest);
|
||||
var measuredWidth = widthMode != MeasureSpecMode.Exactly ? (widthMode != MeasureSpecMode.AtMost ? pxHeight : Math.Min(pxHeight, widthSize)) : widthSize;
|
||||
var measuredHeight = heightMode != MeasureSpecMode.Exactly ? (heightMode != MeasureSpecMode.AtMost ? pxWidth : Math.Min(pxWidth, heightSize)) : heightSize;
|
||||
SetMeasuredDimension(measuredWidth, measuredHeight< Element.HeightRequest ? (int) Element.HeightRequest : measuredHeight);
|
||||
}
|
||||
/*
|
||||
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
|
||||
{
|
||||
Element.Layout(new Xamarin.Forms.Rectangle(0, 0, ContextExtensions.FromPixels(Context, right - left), ContextExtensions.FromPixels(Context, bottom - top)));
|
||||
base.OnLayout(changed, left, top, right, bottom);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
@ -4952,8 +4952,8 @@ namespace BookAStar.Droid
|
|||
// aapt resource value: 0x7f0c00b3
|
||||
public const int subtitles = 2131493043;
|
||||
|
||||
// aapt resource value: 0x7f0c00b6
|
||||
public const int surface_view = 2131493046;
|
||||
// aapt resource value: 0x7f0c00b5
|
||||
public const int surface_view = 2131493045;
|
||||
|
||||
// aapt resource value: 0x7f0c0019
|
||||
public const int tabMode = 2131492889;
|
||||
|
|
@ -4985,9 +4985,6 @@ namespace BookAStar.Droid
|
|||
// aapt resource value: 0x7f0c0053
|
||||
public const int title_template = 2131492947;
|
||||
|
||||
// aapt resource value: 0x7f0c00b5
|
||||
public const int toolbar = 2131493045;
|
||||
|
||||
// aapt resource value: 0x7f0c003d
|
||||
public const int top = 2131492925;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/toolbar"
|
||||
<android.support.v7.widget.Toolbar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
|
||||
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
tools:context=".MainActivity"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
/>
|
||||
Loading…
Add table
Add a link
Reference in a new issue