sweet home

This commit is contained in:
Paul Schneider 2017-02-25 17:45:44 +01:00
commit 438e2f8631
28 changed files with 569 additions and 168 deletions

View file

@ -67,7 +67,7 @@ namespace ZicMoove.Rendering
_density = Resources.DisplayMetrics.Density;
var targetButton = Control;
if (targetButton != null) targetButton.SetOnTouchListener(TouchListener.Instance.Value);
if (targetButton != null) targetButton.SetOnTouchListener(ImageButtonTouchListener.Instance.Value);
if (Element != null && Element.Font != Font.Default && targetButton != null) targetButton.Typeface = Element.Font.ToExtendedTypeface(Context);
@ -274,14 +274,14 @@ namespace ZicMoove.Rendering
}
//Hot fix for the layout positioning issue on Android as described in http://forums.xamarin.com/discussion/20608/fix-for-button-layout-bug-on-android
class TouchListener : Java.Lang.Object, View.IOnTouchListener
class ImageButtonTouchListener : Java.Lang.Object, View.IOnTouchListener
{
public static readonly Lazy<TouchListener> Instance = new Lazy<TouchListener>(() => new TouchListener());
public static readonly Lazy<ImageButtonTouchListener> Instance = new Lazy<ImageButtonTouchListener>(() => new ImageButtonTouchListener());
/// <summary>
/// Make TouchListener a singleton.
/// </summary>
private TouchListener()
private ImageButtonTouchListener()
{ }
public bool OnTouch(View v, MotionEvent e)

View file

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Xamarin.Forms;
using ZicMoove.Views;
using XamSvg;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(SvgImage), typeof(ZicMoove.Droid.Rendering.SvgRenderer))]
namespace ZicMoove.Droid.Rendering
{
class SvgRenderer : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<SvgImage, ImageView>
{
private ImageView view;
private ImageView CreateNativeControl()
{
view = new ImageView(Context);
view.LayoutParameters = new Gallery.LayoutParams(LayoutParams.WrapContent, LayoutParams.FillParent);
return view;
}
protected override void OnElementChanged(ElementChangedEventArgs<SvgImage> e)
{
base.OnElementChanged(e);
if (Control == null)
{
// Init
SetNativeControl(CreateNativeControl());
}
if (e.OldElement != null)
{
// Unsubscribe
}
if (e.NewElement != null) if (e.NewElement.Svg != null)
{
// Subscribe
if (!e.NewElement.Svg.EndsWith(".svg"))
throw new NotSupportedException("Source must end width '.svg'");
var fi = new System.IO.FileInfo(e.NewElement.Svg);
if (fi.Exists)
{
using (var stream = fi.OpenRead())
{
var svg = SvgFactory.GetSvg(System.Threading.CancellationToken.None,
stream);
var drawable = XamSvg.SvgFactory.GetDrawable(svg, XamSvg.Shared.Cross.SvgFillMode.Fill);
view.SetImageDrawable(drawable);
}
}
}
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
namespace ZicMoove.Droid.Rendering
{
public class YaSvgImageView : ImageView
{
Bitmap currentBitmap;
public YaSvgImageView(Context context, IAttributeSet attrs) :
base(context, attrs)
{
Initialize();
}
public YaSvgImageView(Context context) : base(context)
{
Initialize();
}
public YaSvgImageView(Context context, IAttributeSet attrs, int defStyle) :
base(context, attrs, defStyle)
{
Initialize();
}
private void Initialize()
{
}
XamSvg.Svg svg;
XamSvg.SvgPictureDrawable drawable;
public void SetSvg(XamSvg.Svg svg)
{
this.svg = svg;
this.drawable = XamSvg.SvgFactory.GetDrawable(svg, XamSvg.Shared.Cross.SvgFillMode.Fill);
this.SetImageDrawable(drawable);
}
}
}