diff --git a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs index 2436d9f4d71..34b09c61f7a 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs @@ -23,11 +23,13 @@ internal class Platform : BindableObject, IPlatformLayout, INavigation, IDisposa bool _navAnimationInProgress; NavigationModel _navModel = new NavigationModel(); Page _pendingRootChange = null; + internal static string PackageName { get; private set; } + internal static string GetPackageName() => PackageName ?? Android.Platform.PackageName; public Platform(Context context) { _context = context; - + PackageName = context?.PackageName; _renderer = new PlatformRenderer(context, this); FormsAppCompatActivity.BackPressed += HandleBackPressed; diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs index ad10a23a3d5..2923a56e8ad 100644 --- a/Xamarin.Forms.Platform.Android/Platform.cs +++ b/Xamarin.Forms.Platform.Android/Platform.cs @@ -28,6 +28,8 @@ public class Platform : BindableObject, INavigation, IDisposable, IPlatformLayou { internal static string PackageName { get; private set; } + internal static string GetPackageName() => PackageName ?? AppCompat.Platform.PackageName; + internal const string CloseContextActionsSignalName = "Xamarin.CloseContextActions"; internal static readonly BindableProperty RendererProperty = BindableProperty.CreateAttached("Renderer", typeof(IVisualElementRenderer), typeof(Platform), default(IVisualElementRenderer), diff --git a/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs index 1c8025e7b27..38b795d074b 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs @@ -24,7 +24,7 @@ internal static bool DecodeSynchronously { if (File.Exists (file)) bitmap = !DecodeSynchronously ? (await BitmapFactory.DecodeFileAsync (file).ConfigureAwait (false)) : BitmapFactory.DecodeFile (file); else - bitmap = !DecodeSynchronously ? (await context.Resources.GetBitmapAsync (file).ConfigureAwait (false)) : context.Resources.GetBitmap (file); + bitmap = !DecodeSynchronously ? (await context.Resources.GetBitmapAsync (file, context).ConfigureAwait (false)) : context.Resources.GetBitmap (file, context); if (bitmap == null) { diff --git a/Xamarin.Forms.Platform.Android/ResourceManager.cs b/Xamarin.Forms.Platform.Android/ResourceManager.cs index a4de2a0dfae..bb12381d262 100644 --- a/Xamarin.Forms.Platform.Android/ResourceManager.cs +++ b/Xamarin.Forms.Platform.Android/ResourceManager.cs @@ -254,11 +254,21 @@ public static Bitmap GetBitmap(this Resources resource, string name) return BitmapFactory.DecodeResource(resource, IdFromTitle(name, DrawableClass, _drawableDefType, resource)); } + public static Bitmap GetBitmap(this Resources resource, string name, Context context) + { + return BitmapFactory.DecodeResource(resource, IdFromTitle(name, DrawableClass, _drawableDefType, resource, context.PackageName)); + } + public static Task GetBitmapAsync(this Resources resource, string name) { return BitmapFactory.DecodeResourceAsync(resource, IdFromTitle(name, DrawableClass, _drawableDefType, resource)); } + public static Task GetBitmapAsync(this Resources resource, string name, Context context) + { + return BitmapFactory.DecodeResourceAsync(resource, IdFromTitle(name, DrawableClass, _drawableDefType, resource, context.PackageName)); + } + [Obsolete("GetDrawable(this Resources, string) is obsolete as of version 2.5. " + "Please use GetDrawable(this Context, string) instead.")] [EditorBrowsable(EditorBrowsableState.Never)] @@ -310,11 +320,21 @@ public static int GetLayoutByName(string name) return IdFromTitle(name, LayoutClass); } + public static int GetLayout(this Context context, string name) + { + return IdFromTitle(name, LayoutClass, "layout", context); + } + public static int GetStyleByName(string name) { return IdFromTitle(name, StyleClass); } + public static int GetStyle(this Context context, string name) + { + return IdFromTitle(name, StyleClass, "style", context); + } + public static void Init(Assembly masterAssembly) { DrawableClass = masterAssembly.GetTypes().FirstOrDefault(x => x.Name == "Drawable" || x.Name == "Resource_Drawable"); @@ -335,7 +355,7 @@ static int IdFromTitle(string title, Type type) static int IdFromTitle(string title, Type resourceType, string defType, Resources resource) { - return IdFromTitle(title, resourceType, defType, resource, Platform.PackageName); + return IdFromTitle(title, resourceType, defType, resource, AppCompat.Platform.GetPackageName()); } static int IdFromTitle(string title, Type resourceType, string defType, Context context) @@ -359,7 +379,7 @@ static int IdFromTitle(string title, Type resourceType, string defType, Resource if (packageName != null) { id = resource.GetIdentifier(name, defType, packageName); - + if (id > 0) return id; }