mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-22 15:06:26 +01:00
123 lines
4.2 KiB
C#
123 lines
4.2 KiB
C#
using System.Collections.Generic;
|
||
using Android.App;
|
||
using Android.Content;
|
||
using Android.Content.PM;
|
||
using Android.Content.Res;
|
||
using Android.OS;
|
||
using Android.Util;
|
||
using Firebase;
|
||
using Java.Interop;
|
||
using Java.Security.Acl;
|
||
using Plugin.Permissions;
|
||
using Xamarin.Forms.Platform.Android.AppLinks;
|
||
using static Xamarin.Essentials.Permissions;
|
||
using Xamarin.Essentials;
|
||
using Android.Runtime;
|
||
using Xamarin.Forms;
|
||
|
||
namespace ShareeBike.Droid
|
||
{
|
||
[Activity(
|
||
Label = "LastenradBayern",
|
||
Icon = "@drawable/app_logo",
|
||
Theme = "@style/MainTheme",
|
||
MainLauncher = true,
|
||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
|
||
|
||
[IntentFilter(new[] { Intent.ActionView },
|
||
Categories = new[] { Intent.ActionView, Intent.CategoryBrowsable, Intent.CategoryDefault },
|
||
DataScheme = "https",
|
||
DataHost = "app.sharee.bike",
|
||
DataPathPrefix = "/App-LastenradBayern",
|
||
AutoVerify = true)]
|
||
|
||
[IntentFilter(new[] { Intent.ActionView },
|
||
Categories = new[] { Intent.ActionView, Intent.CategoryBrowsable, Intent.CategoryDefault },
|
||
DataScheme = "http",
|
||
DataHost = "app.sharee.bike",
|
||
DataPathPrefix = "/App-LastenradBayern",
|
||
AutoVerify = true)]
|
||
|
||
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
||
{
|
||
private void initFontScale()
|
||
{
|
||
Configuration configuration = Resources.Configuration;
|
||
configuration.FontScale = (float)1;
|
||
//0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big
|
||
DisplayMetrics metrics = new DisplayMetrics();
|
||
WindowManager.DefaultDisplay.GetMetrics(metrics);
|
||
metrics.ScaledDensity = configuration.FontScale * metrics.Density;
|
||
BaseContext.Resources.UpdateConfiguration(configuration, metrics);
|
||
}
|
||
protected override async void OnCreate(Bundle bundle)
|
||
{
|
||
initFontScale();
|
||
|
||
TabLayoutResource = Resource.Layout.Tabbar;
|
||
ToolbarResource = Resource.Layout.Toolbar;
|
||
|
||
base.OnCreate(bundle);
|
||
|
||
global::Xamarin.Forms.Forms.Init(this, bundle);
|
||
|
||
FirebaseApp.InitializeApp(this);
|
||
AndroidAppLinks.Init(this);
|
||
|
||
// Initialize xamarin.essentials, see https://docs.microsoft.com/en-us/xamarin/essentials/get-started?tabs=macos%2Candroid.
|
||
Xamarin.Essentials.Platform.Init(this, bundle);
|
||
|
||
// Required for initialization of Maps, see https://developer.xamarin.com/guides/xamarin-forms/user-interface/map/
|
||
Xamarin.FormsGoogleMaps.Init(this, bundle);
|
||
|
||
// Required for initialization of binding package, see https://github.com/nuitsjp/Xamarin.Forms.GoogleMaps.Bindings.
|
||
Xamarin.FormsGoogleMapsBindings.Init();
|
||
|
||
// Get version name of app.
|
||
Context context = ApplicationContext;
|
||
new Model.Device.AppInfo(context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName);
|
||
|
||
Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) =>
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(e.View.AutomationId))
|
||
{
|
||
e.NativeView.ContentDescription = e.View.AutomationId;
|
||
}
|
||
};
|
||
|
||
await Permissions.RequestAsync<BLEPermissions>();
|
||
await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
|
||
|
||
LoadApplication(new App());
|
||
}
|
||
|
||
//Bluetooth Permission on Android 12 "Detect Devices nearby"
|
||
// https://stackoverflow.com/questions/71028853/xamarin-forms-ble-plugin-scan-issue-android-12
|
||
public class BLEPermissions : BasePlatformPermission
|
||
{
|
||
public override (string androidPermission, bool isRuntime)[] RequiredPermissions => new List<(string androidPermission, bool isRuntime)>
|
||
{
|
||
(Android.Manifest.Permission.BluetoothScan, true),
|
||
(Android.Manifest.Permission.BluetoothConnect, true),
|
||
}.ToArray();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Handles opening the dialog to request for permissions.
|
||
/// </summary>
|
||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
|
||
{
|
||
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
|
||
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
}
|
||
|
||
[Export("TapStation")]
|
||
public void TapStation(string stationNr)
|
||
{
|
||
BackdoorMethodHelpers.DoTapPage(stationNr);
|
||
}
|
||
}
|
||
}
|
||
|