Saratsin.MvxOverlay.Android 1.0.0

dotnet add package Saratsin.MvxOverlay.Android --version 1.0.0                
NuGet\Install-Package Saratsin.MvxOverlay.Android -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Saratsin.MvxOverlay.Android" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Saratsin.MvxOverlay.Android --version 1.0.0                
#r "nuget: Saratsin.MvxOverlay.Android, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Saratsin.MvxOverlay.Android as a Cake Addin
#addin nuget:?package=Saratsin.MvxOverlay.Android&version=1.0.0

// Install Saratsin.MvxOverlay.Android as a Cake Tool
#tool nuget:?package=Saratsin.MvxOverlay.Android&version=1.0.0                

MvxOverlay.Android

MvvmCross plugin for creating overlay views and show/close it with NavigationService

Getting Started

First of all, make sure you really need such kind of stuff, system overlays are very uncommon thing for apps and it's always better to use Activities or Fragments. Also if you're sure, then welcome

Prerequisites

Things you need:

  • Xamarin.Android project
  • MvvmCross (6.0 or higher)

Installing

First of all, add an overlay permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Before showing app overlay, you can check if your app has the overlay permissions (by default it disabled).

using System;
using MvvmCross.Plugin.Overlay.Platforms.Android.Services;

...

var overlayPermissionIsEnabled = OverlayPermissionService.Instance.CanDrawOverlays;

var overlayPermissionIsOrBecomeEnabled = await OverlayPermissionService.Instance.TryEnablePermissionIfDisabled(timeout: TimeSpan.FromMinutes(1), toastHintText: "Looks like we have no permissions :(");

If you won't do it, plugin will ask it by itself anyway.

Overlay Example

Android view implementation

public class ExampleOverlay : MvxOverlay<ExampleViewModel>
{
    public ExampleOverlay(Context context) : base(context)
    { 
    }

    public override View CreateAndSetViewBindings()
    {
        var button = new Button(Context)
        {
            LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
        };

        var set = this.CreateBindingSet<ExampleOverlay, ExampleViewModel>();

        set.Bind(button).For(v => v.Text).To(vm => vm.ButtonText);
        set.Bind(button).For(nameof(View.Click)).To(vm => vm.ButtonClickedCommand);
        set.Bind(button).For(nameof(View.LongClick)).To(vm => vm.ConnectButtonLongClickedCommand);

        set.Apply();

        return button;
    }

    public override OverlayLocationParams CreateLocationParams()
    {
        return new OverlayLocationParams(
            gravity: GravityFlags.CenterHorizontal | GravityFlags.Top, 
            y: 50
        );
    }
}

ViewModel showing (inside the core project)

await Mvx.Resolve<IMvxNavigationService>().Navigate<ExampleViewModel>().ConfigureAwait(false);

Authors

  • Taras Shevchuk - Initial work - Saratsin

License

This project is licensed under the MIT License

Product Compatible and additional computed target framework versions.
MonoAndroid monoandroid81 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,136 6/7/2018