and android
This commit is contained in:
		| @@ -37,7 +37,8 @@ | |||||||
|     <EnableLLVM>false</EnableLLVM> |     <EnableLLVM>false</EnableLLVM> | ||||||
|     <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot> |     <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot> | ||||||
|     <BundleAssemblies>false</BundleAssemblies> |     <BundleAssemblies>false</BundleAssemblies> | ||||||
|     <AndroidSupportedAbis>x86_64</AndroidSupportedAbis> |     <AndroidSupportedAbis>x86_64;x86</AndroidSupportedAbis> | ||||||
|  | <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||||||
|     <DebugSymbols>true</DebugSymbols> |     <DebugSymbols>true</DebugSymbols> | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| namespace Billing.UI; | namespace Billing.UI | ||||||
|  |  | ||||||
| public static partial class Definition |  | ||||||
| { | { | ||||||
|     public static partial string GetCascadiaRegularFontFamily() => "CascadiaCode-Regular.ttf#CascadiaCode-Regular"; |     public static partial class Definition | ||||||
|     public static partial string GetCascadiaBoldFontFamily() => "CascadiaCode-Bold.ttf#CascadiaCode-Bold"; |     { | ||||||
|     public static partial string GetRobotoCondensedRegularFontFamily() => "RobotoCondensed-Regular.ttf#RobotoCondensed-Regular"; |         public static partial string GetCascadiaRegularFontFamily() => "CascadiaCode-Regular.ttf#CascadiaCode-Regular"; | ||||||
|     public static partial string GetRobotoCondensedBoldFontFamily() => "RobotoCondensed-Bold.ttf#RobotoCondensed-Bold"; |         public static partial string GetCascadiaBoldFontFamily() => "CascadiaCode-Bold.ttf#CascadiaCode-Bold"; | ||||||
| } |         public static partial string GetRobotoCondensedRegularFontFamily() => "RobotoCondensed-Regular.ttf#RobotoCondensed-Regular"; | ||||||
|  |         public static partial string GetRobotoCondensedBoldFontFamily() => "RobotoCondensed-Bold.ttf#RobotoCondensed-Bold"; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -8,26 +8,27 @@ using Xamarin.Forms.Platform.Android; | |||||||
|  |  | ||||||
| [assembly: ResolutionGroupName("Org.Tsanie")] | [assembly: ResolutionGroupName("Org.Tsanie")] | ||||||
| [assembly: ExportEffect(typeof(ShadowEffectPlatform), nameof(ShadowEffect))] | [assembly: ExportEffect(typeof(ShadowEffectPlatform), nameof(ShadowEffect))] | ||||||
| namespace Billing.Droid.Effects; | namespace Billing.Droid.Effects | ||||||
|  |  | ||||||
| public class ShadowEffectPlatform : PlatformEffect |  | ||||||
| { | { | ||||||
|     protected override void OnAttached() |     public class ShadowEffectPlatform : PlatformEffect | ||||||
|     { |     { | ||||||
|         try |         protected override void OnAttached() | ||||||
|         { |         { | ||||||
|             var effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect); |             try | ||||||
|             var paint = new Paint(PaintFlags.AntiAlias); |             { | ||||||
|             paint.SetShadowLayer(effect.Radius, (float)effect.Offect.Width, (float)effect.Offect.Height, effect.Color.ToAndroid()); |                 var effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect); | ||||||
|             Control.SetLayerPaint(paint); |                 var paint = new Paint(PaintFlags.AntiAlias); | ||||||
|  |                 paint.SetShadowLayer(effect.Radius, (float)effect.Offect.Width, (float)effect.Offect.Height, effect.Color.ToAndroid()); | ||||||
|  |                 Control.SetLayerPaint(paint); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 Helper.Error("shadow.effect.attached", $"Cannot set property on attached control, error: {ex.Message}"); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         catch (Exception ex) |  | ||||||
|         { |  | ||||||
|             Helper.Error("shadow.effect.attached", $"Cannot set property on attached control, error: {ex.Message}"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     protected override void OnDetached() |         protected override void OnDetached() | ||||||
|     { |         { | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -3,29 +3,30 @@ using Android.Content.PM; | |||||||
| using Android.Runtime; | using Android.Runtime; | ||||||
| using Android.OS; | using Android.OS; | ||||||
|  |  | ||||||
| namespace Billing.Droid; | namespace Billing.Droid | ||||||
|  |  | ||||||
| [Activity( |  | ||||||
|     Label = "Billing", |  | ||||||
|     Icon = "@mipmap/icon", |  | ||||||
|     RoundIcon = "@mipmap/icon_round", |  | ||||||
|     Theme = "@style/MainTheme", |  | ||||||
|     MainLauncher = true, |  | ||||||
|     ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )] |  | ||||||
| public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity |  | ||||||
| { | { | ||||||
|     protected override void OnCreate(Bundle savedInstanceState) |     [Activity( | ||||||
|  |         Label = "Billing", | ||||||
|  |         Icon = "@mipmap/icon", | ||||||
|  |         RoundIcon = "@mipmap/icon_round", | ||||||
|  |         Theme = "@style/MainTheme", | ||||||
|  |         MainLauncher = true, | ||||||
|  |         ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)] | ||||||
|  |     public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity | ||||||
|     { |     { | ||||||
|         base.OnCreate(savedInstanceState); |         protected override void OnCreate(Bundle savedInstanceState) | ||||||
|  |         { | ||||||
|  |             base.OnCreate(savedInstanceState); | ||||||
|  |  | ||||||
|         Xamarin.Essentials.Platform.Init(this, savedInstanceState); |             Xamarin.Essentials.Platform.Init(this, savedInstanceState); | ||||||
|         Xamarin.Forms.Forms.Init(this, savedInstanceState); |             Xamarin.Forms.Forms.Init(this, savedInstanceState); | ||||||
|         LoadApplication(new App()); |             LoadApplication(new App()); | ||||||
|     } |         } | ||||||
|     public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults) |         public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults) | ||||||
|     { |         { | ||||||
|         Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); |             Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||||||
|  |  | ||||||
|         base.OnRequestPermissionsResult(requestCode, permissions, grantResults); |             base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -2,65 +2,66 @@ | |||||||
| using System.Globalization; | using System.Globalization; | ||||||
| using System.Threading; | using System.Threading; | ||||||
|  |  | ||||||
| namespace Billing.Languages; | namespace Billing.Languages | ||||||
|  |  | ||||||
| public partial class PlatformCulture |  | ||||||
| { | { | ||||||
|     public partial string GetNamespace() |     public partial class PlatformCulture | ||||||
|     { |     { | ||||||
|         return typeof(MainActivity).Namespace; |         public partial string GetNamespace() | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public partial void Init() |  | ||||||
|     { |  | ||||||
|         var locale = Java.Util.Locale.Default; |  | ||||||
|         string lang = AndroidToDotnetLanguage($"{locale.Language}-{locale.Country}"); |  | ||||||
|  |  | ||||||
|         CultureInfo ci; |  | ||||||
|         Init(lang); |  | ||||||
|         try |  | ||||||
|         { |         { | ||||||
|             ci = new CultureInfo(Language); |             return typeof(MainActivity).Namespace; | ||||||
|         } |         } | ||||||
|         catch (CultureNotFoundException e) |  | ||||||
|  |         public partial void Init() | ||||||
|         { |         { | ||||||
|  |             var locale = Java.Util.Locale.Default; | ||||||
|  |             string lang = AndroidToDotnetLanguage($"{locale.Language}-{locale.Country}"); | ||||||
|  |  | ||||||
|  |             CultureInfo ci; | ||||||
|  |             Init(lang); | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 var fallback = ToDotnetFallbackLanguage(); |                 ci = new CultureInfo(Language); | ||||||
|                 Helper.Debug($"{lang} failed, trying {fallback} ({e.Message})"); |  | ||||||
|                 ci = new CultureInfo(fallback); |  | ||||||
|             } |             } | ||||||
|             catch (CultureNotFoundException e1) |             catch (CultureNotFoundException e) | ||||||
|             { |             { | ||||||
|                 Helper.Error("culture.get", $"{lang} couldn't be set, using 'zh-CN' ({e1.Message})"); |                 try | ||||||
|                 ci = new CultureInfo("zh-CN"); |                 { | ||||||
|  |                     var fallback = ToDotnetFallbackLanguage(); | ||||||
|  |                     Helper.Debug($"{lang} failed, trying {fallback} ({e.Message})"); | ||||||
|  |                     ci = new CultureInfo(fallback); | ||||||
|  |                 } | ||||||
|  |                 catch (CultureNotFoundException e1) | ||||||
|  |                 { | ||||||
|  |                     Helper.Error("culture.get", $"{lang} couldn't be set, using 'zh-CN' ({e1.Message})"); | ||||||
|  |                     ci = new CultureInfo("zh-CN"); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             Thread.CurrentThread.CurrentCulture = ci; | ||||||
|  |             Thread.CurrentThread.CurrentUICulture = ci; | ||||||
|  |  | ||||||
|  |             Helper.Debug($"CurrentCulture set: {ci.Name}"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Thread.CurrentThread.CurrentCulture = ci; |         private static string AndroidToDotnetLanguage(string androidLanguage) | ||||||
|         Thread.CurrentThread.CurrentUICulture = ci; |  | ||||||
|  |  | ||||||
|         Helper.Debug($"CurrentCulture set: {ci.Name}"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private static string AndroidToDotnetLanguage(string androidLanguage) |  | ||||||
|     { |  | ||||||
|         //certain languages need to be converted to CultureInfo equivalent |  | ||||||
|         string netLanguage = androidLanguage switch |  | ||||||
|         { |         { | ||||||
|             // Not supported .NET culture |             //certain languages need to be converted to CultureInfo equivalent | ||||||
|             "ms-BN" or "ms-MY" or "ms-SG" => "ms", // closest supported |             string netLanguage = androidLanguage switch | ||||||
|             // "Indonesian (Indonesia)" has different code in .NET |             { | ||||||
|             "in-ID" => "id-ID",  // correct code for .NET |                 // Not supported .NET culture | ||||||
|             // "Schwiizertüütsch (Swiss German)" not supported .NET culture |                 "ms-BN" or "ms-MY" or "ms-SG" => "ms", // closest supported | ||||||
|             "gsw-CH" => "de-CH", // closest supported |                                                        // "Indonesian (Indonesia)" has different code in .NET | ||||||
|  |                 "in-ID" => "id-ID",  // correct code for .NET | ||||||
|  |                                      // "Schwiizertüütsch (Swiss German)" not supported .NET culture | ||||||
|  |                 "gsw-CH" => "de-CH", // closest supported | ||||||
|  |  | ||||||
|             // add more application-specific cases here (if required) |                 // add more application-specific cases here (if required) | ||||||
|             // ONLY use cultures that have been tested and known to work |                 // ONLY use cultures that have been tested and known to work | ||||||
|  |  | ||||||
|             _ => androidLanguage, |                 _ => androidLanguage, | ||||||
|         }; |             }; | ||||||
|         Helper.Debug($"Android Language: {androidLanguage}, .NET Language/Locale: {netLanguage}"); |             Helper.Debug($"Android Language: {androidLanguage}, .NET Language/Locale: {netLanguage}"); | ||||||
|         return netLanguage; |             return netLanguage; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -5,29 +5,30 @@ using Xamarin.Forms; | |||||||
| using Xamarin.Forms.Platform.Android; | using Xamarin.Forms.Platform.Android; | ||||||
|  |  | ||||||
| [assembly: ExportRenderer(typeof(LongPressButton), typeof(LongPressButtonRenderer))] | [assembly: ExportRenderer(typeof(LongPressButton), typeof(LongPressButtonRenderer))] | ||||||
| namespace Billing.Droid.Renderers; | namespace Billing.Droid.Renderers | ||||||
|  |  | ||||||
| public class LongPressButtonRenderer : ButtonRenderer |  | ||||||
| { | { | ||||||
|     public LongPressButtonRenderer(Context context) : base(context) |     public class LongPressButtonRenderer : ButtonRenderer | ||||||
|     { |     { | ||||||
|     } |         public LongPressButtonRenderer(Context context) : base(context) | ||||||
|  |  | ||||||
|     protected override void OnElementChanged(ElementChangedEventArgs<Button> e) |  | ||||||
|     { |  | ||||||
|         base.OnElementChanged(e); |  | ||||||
|  |  | ||||||
|         if (Element is LongPressButton && Control != null) |  | ||||||
|         { |         { | ||||||
|             Control.LongClick += Control_LongClick; |         } | ||||||
|  |  | ||||||
|  |         protected override void OnElementChanged(ElementChangedEventArgs<Button> e) | ||||||
|  |         { | ||||||
|  |             base.OnElementChanged(e); | ||||||
|  |  | ||||||
|  |             if (Element is LongPressButton && Control != null) | ||||||
|  |             { | ||||||
|  |                 Control.LongClick += Control_LongClick; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         private void Control_LongClick(object sender, LongClickEventArgs e) | ||||||
|  |         { | ||||||
|  |             if (Element is LongPressButton button) | ||||||
|  |             { | ||||||
|  |                 button.TriggerLongPress(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|     private void Control_LongClick(object sender, LongClickEventArgs e) |  | ||||||
|     { |  | ||||||
|         if (Element is LongPressButton button) |  | ||||||
|         { |  | ||||||
|             button.TriggerLongPress(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -6,22 +6,23 @@ using Xamarin.Forms; | |||||||
| using Xamarin.Forms.Platform.Android; | using Xamarin.Forms.Platform.Android; | ||||||
|  |  | ||||||
| [assembly: ExportRenderer(typeof(OptionEntry), typeof(OptionEntryRenderer))] | [assembly: ExportRenderer(typeof(OptionEntry), typeof(OptionEntryRenderer))] | ||||||
| namespace Billing.Droid.Renderers; | namespace Billing.Droid.Renderers | ||||||
|  |  | ||||||
| public class OptionEntryRenderer : EntryRenderer |  | ||||||
| { | { | ||||||
|     public OptionEntryRenderer(Context context) : base(context) |     public class OptionEntryRenderer : EntryRenderer | ||||||
|     { |     { | ||||||
|     } |         public OptionEntryRenderer(Context context) : base(context) | ||||||
|  |  | ||||||
|     protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) |  | ||||||
|     { |  | ||||||
|         base.OnElementChanged(e); |  | ||||||
|  |  | ||||||
|         if (e.NewElement != null) |  | ||||||
|         { |         { | ||||||
|             var drawable = new ColorDrawable(e.NewElement.BackgroundColor.ToAndroid()); |         } | ||||||
|             Control.SetBackground(drawable); |  | ||||||
|  |         protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) | ||||||
|  |         { | ||||||
|  |             base.OnElementChanged(e); | ||||||
|  |  | ||||||
|  |             if (e.NewElement != null) | ||||||
|  |             { | ||||||
|  |                 var drawable = new ColorDrawable(e.NewElement.BackgroundColor.ToAndroid()); | ||||||
|  |                 Control.SetBackground(drawable); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -6,31 +6,32 @@ using Xamarin.Forms; | |||||||
| using Xamarin.Forms.Platform.Android; | using Xamarin.Forms.Platform.Android; | ||||||
|  |  | ||||||
| [assembly: ExportRenderer(typeof(TintImage), typeof(TintImageRenderer))] | [assembly: ExportRenderer(typeof(TintImage), typeof(TintImageRenderer))] | ||||||
| namespace Billing.Droid.Renderers; | namespace Billing.Droid.Renderers | ||||||
|  |  | ||||||
| public class TintImageRenderer : ImageRenderer |  | ||||||
| { | { | ||||||
|     public TintImageRenderer(Context context) : base(context) |     public class TintImageRenderer : ImageRenderer | ||||||
|     { |     { | ||||||
|     } |         public TintImageRenderer(Context context) : base(context) | ||||||
|  |  | ||||||
|     protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) |  | ||||||
|     { |  | ||||||
|         base.OnElementPropertyChanged(sender, e); |  | ||||||
|  |  | ||||||
|         if (e.PropertyName == nameof(TintImage.PrimaryColor) && Control?.Drawable != null && Element is TintImage image) |  | ||||||
|         { |         { | ||||||
|             Control.Drawable.SetTint(image.PrimaryColor?.ToAndroid() ?? 0); |         } | ||||||
|  |  | ||||||
|  |         protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) | ||||||
|  |         { | ||||||
|  |             base.OnElementPropertyChanged(sender, e); | ||||||
|  |  | ||||||
|  |             if (e.PropertyName == nameof(TintImage.PrimaryColor) && Control?.Drawable != null && Element is TintImage image) | ||||||
|  |             { | ||||||
|  |                 Control.Drawable.SetTint(image.PrimaryColor?.ToAndroid() ?? 0); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         protected override void OnElementChanged(ElementChangedEventArgs<Image> e) | ||||||
|  |         { | ||||||
|  |             base.OnElementChanged(e); | ||||||
|  |  | ||||||
|  |             if (Control?.Drawable != null && Element is TintImage image) | ||||||
|  |             { | ||||||
|  |                 Control.Drawable.SetTint(image.PrimaryColor?.ToAndroid() ?? 0); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|     protected override void OnElementChanged(ElementChangedEventArgs<Image> e) |  | ||||||
|     { |  | ||||||
|         base.OnElementChanged(e); |  | ||||||
|  |  | ||||||
|         if (Control?.Drawable != null && Element is TintImage image) |  | ||||||
|         { |  | ||||||
|             Control.Drawable.SetTint(image.PrimaryColor?.ToAndroid() ?? 0); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -14,7 +14,7 @@ namespace Billing.Droid | |||||||
| { | { | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "12.2.0.155")] | 	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] | ||||||
| 	public partial class Resource | 	public partial class Resource | ||||||
| 	{ | 	{ | ||||||
| 		 | 		 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user