Skip to content

Instantly share code, notes, and snippets.

View bbenetskyy's full-sized avatar
👾
Making Apps with MAUI 😛

Bohdan Benetskyi bbenetskyy

👾
Making Apps with MAUI 😛
View GitHub Profile
public class MainActivity : MvxFormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
//other on initialization code here skipped
using var builder = new Constraints.Builder();
builder.SetRequiredNetworkType(NetworkType.Connected);
var workConstraints = builder.Build();
var interval = TimeSpan.FromMinutes(16);
/// <summary>
/// Android Background Worker
/// </summary>
public class BackgroundWork : Worker
{
#region Fields
private ILogger _logger;
private IBackgroundWorkManager _backgroundWorkManager;
/// <summary>
/// Android Native Background Service
/// </summary>
[Service]
public class BackgroundService : Service
{
#region Fields
/// <summary>
/// The Id of the Service
/// <summary>
/// Native Background Worker Interface
/// </summary>
public interface IBackgroundWorker
{
/// <summary>
/// Worker Stopped Event
/// </summary>
public event EventHandler WorkerStopped;
/// <summary>
/// Simple Background Work Manager to set and get work delegate
/// </summary>
/// <remarks>it's too simple to show how it's implemented, LOL</remarks>
public interface IBackgroundWorkManager
{
/// <summary>
/// Get Background Work
/// </summary>
Func<Task> GetBackgroundWork();
protected override double Convert(double value, Type targetType, object parameter, CultureInfo culture)
{
if (value > 0)
{
var result = value * (double)parameter;
return result;
}
return value;
}
ChatWebView.Source = new HtmlWebViewSource
{
Html = "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>" +
"<script type=\"text/javascript\">" +
" function Run(text) { try { InvokeDisplayJSText(link); } catch(err) { alert(err); }} " +
" function DisplayXFText(text) { alert('DisplayXFText ' + text); } " +
"</script >" +
"<p><a href=\"#\" onclick=\"Run('Hello');\">Send 'Hello' to Xamarin.Forms</a></p>" +
"<p><a href=\"#\" onclick=\"Run2('From JS');\">Send 'From JS' to Xamarin.Forms</a></p>" +
"</body ></html >"
public class CustomWebView : WebView
{
public void Cleanup()
{
_displayJSTextAction = null;
}
#region DisplayJSTextAction
private Action<string> _displayJSTextAction;
public class DraggableView : ContentView, IDisposable
{
public static readonly BindableProperty NewXProperty = BindableProperty.Create(
propertyName: nameof(NewX),
returnType: typeof(double),
declaringType: typeof(DraggableView));
public double NewX
{
get => (double)GetValue(NewXProperty);
#region Protected Methods
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Xamarin.Forms.VisualElement.XProperty.PropertyName || e.PropertyName == Xamarin.Forms.VisualElement.YProperty.PropertyName)
{
CancellationToken(() =>
{
var draggableView = Element as DraggableView;