Monodroid Spinner Resource reference error - xamarin.android

I'm following the spinner from monodroid tutorial. But encountered problem on the resource.
It cannot lookup the SimpleSpinnerItem & SimpleSpinnerDropDownItem on VS 2010.
Am I missing something?
Edit: Create a partial class to register android runtime as per jonp
public partial class Resource
{
public partial class Layout
{
[Register("simple_spinner_dropdown_item")]
public const int SimpleSpinnerDropDownItem = 17367049;
[Register("simple_spinner_item")]
public const int SimpleSpinnerItem = 17367048;
}
}
Edit 2: Tried the global resource
Edit 3: Conflict on my project namespace
I already identified why the const cannot be recognize. It's because of my namespace projectname.Android, it's being duplicated. When I changed it to projectname.AndroidMobile the global resource is there.
See the conflict below.
Also, to avoid the conflict just use the global:: as per jonp

You need to qualify the class, as there are two Resource types: one local to your project (Your.Namespace.Resource, located in Resource.designer.cs), and global::Android.Resource. You need to use global::Android.Resource.Layout.SimpleSpinnerItem.

Related

Refer/Import existing AutoScalingGroup Resource from CDK Stack

I'm trying to referring an existing AutoScalingGroup from my CodeDeploy with AutoScalingGroup.from_auto_scaling_group_name static method in order to integrate with CodePipeline for automating EC2/On-premise deployment. I have the following code snippet for your reference.
# Refer existing AutoScaling Group
asg_1 = autoscaling.AutoScalingGroup.from_auto_scaling_group_name(self, "AutoScaleGroup", "WSAutoscaleStack-webServerAsgIdASG12345-XXXXXX")
# EC2 Deployment Groups
deployment_group = codedeploy.ServerDeploymentGroup(self, "CodeDeployDeploymentGroup", deployment_group_name="MyDeploymentGroup", install_agent=True, auto_scaling_groups=[asg_1])
After validating the stack with 'cdk ls', I got an error which says,
jsii.errors.JSIIError: Cannot get policy fragment of AMIPipelineStack/AutoScaleGroup, resource imported without a role
As far as I understand, the referenced resource should be imported as an object, so that I can use it all dependents including iam.role from the resource. Any ideas?
Looks like the fromAutoScalingGroupName method doesn't "Import" the role (see here)
One option you have is to implement that import by yourself. The above linked Import class would then look like (in Typescript):
public static fromAutoScalingGroupNameWithRole(scope: Construct, id: string, autoScalingGroupName: string, roleArn:string): IAutoScalingGroup {
class ImportWithRole extends AutoScalingGroupBase {
public autoScalingGroupName = autoScalingGroupName;
public autoScalingGroupArn = Stack.of(this).formatArn({
service: 'autoscaling',
resource: 'autoScalingGroup:*:autoScalingGroupName',
resourceName: this.autoScalingGroupName,
});
public readonly osType = ec2.OperatingSystemType.UNKNOWN;
public readonly grantPrincipal = iam.Role.fromRoleArn(this, `${id}-role`, roleArn)
}
return new ImportWithRole(scope, id);
}
Another maneuver you could do (if applicable to your use-case) is to really import the auto-scaling group and its role into the Cloudformation stack. The resources will then be managed with the CDK/Cloudformation stack and you could use the standard AutoScalingGroup constructor and provide your Role. The downside here is that it's currently quite a painful process (see link)

Localize blazor with IStringLocalizer using a unique resource file per language

I'm trying to localize my Blazor app (.NET 5.0) using IStringLocalizer and user UI selection based on cookies. Following the documentation, it seems to work if I create a .resx file for each page in my Resources/Pages folder.
I'd like to group all key-value pairs within a single file as follows :
MyApp
|-- Resources
| MyResources.resx <--- set to public modifiers to generate class!!!
| MyResources.es.resx
| MyResources.fr.resx
...
|-- Resources
| Index.razor
So in Startup.cs I register the Resources folder:
services.AddControllers();
services.AddLocalization(options => options.ResourcesPath = "Resources");
I also added MapControllers in the configure method, as well as registering supported cultures. I also added the controller:
[Route("[controller]/[action]")]
public class CultureController : Controller {
public IActionResult SetCulture(string culture, string redirectUri) {
if (culture != null) {
HttpContext.Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
}
return LocalRedirect(redirectUri);
}
}
Now, on my main "index.razor" page I inject the IStringLocalizer<MyResources> as follows:
#page "/index"
#inject IStringLocalizer<Language> _localizer
<h2>#_localizer["hello_world"]</h2>
<h2>#DateTime.Now.ToShortDateString()</h2>
<h2>#DateTime.Now.ToLongDateString()</h2>
I make sure that all resx files actually contain the "hello_world" key with some values and added a language selector.
When I run the app, changing the language does change the displayed dates, however, the hello_world key is not found so the app displays the key instead. When exploring the _localizer variable, I see that the container is empty - none of the key-value pairs of the .resx are actually loaded.
Is it possible to get this to work? If so, what am I doing wrong here?
The mistake is because of naming here:
#inject IStringLocalizer<Language> _localizer
should be
#inject IStringLocalizer<MyResources> _localizer
And important is to add an empty file MyResources.razor at the root of the project.
Edit:
Another mistake I made is to add the myApp.Resources to _Imports.razor
...
#using myApp.Resources <==== do NOT add this
#neggenbe
Adding an empty razor(AppLang.razor) component at the root of my project with same name with my resource(AppLang.resx) file solved the challenge. I stumbled accross #neggenbe after over 48 hours trying to figure out what was wrong with my code.
If your project is purely blazor, you wont come accross this challenge but if its a mix of MVC and razor(blazor) components, then you'll definately need to do this.

Error when using MvxAppCompatActivity

I am writing an application with Xamarin.Android with MvvmCross. I want my Activity to inherit from MvxAppCompatActivity so that I can use fragments. Here is my base class:
public class BaseActivity<TViewModel> : MvxAppCompatActivity<TViewModel> where TViewModel : MvxViewModel
{
public new TViewModel ViewModel
{
get { return base.ViewModel; }
set { base.ViewModel = value; }
}
}
I get this error on the OnCreate of my Activity:
Failed resolution of: Landroid/support/v7/appcompat/R$drawable; Didn't
find class "android.support.v7.appcompat.R$drawable" on path:
DexPathList...
But if I change MvxAppCompatActivity to MvxActivity it works fine...why?
I downloaded your solution and tried to build the Android project. It fails with 18 occurrences of the same error:
error: No resource identifier found for attribute 'loginButtonBackgroundColor' in package ...
So after a little inspection of your solution, I did the following steps to solve your issue:
1) In login_screen.axml I saw you had this line:
xmlns:[YOURNAMESPACE]="http://schemas.android.com/apk/res/[YOUR PACKAGE]"
Which is unnecessary. After removing it, and changing the lines [YOURNAMESPACE]:loginButtonBackgroundColor=... to local:loginButtonBackgroundColor=... the build succeeds.
2) I saw some layout files are located inside the /drawable folder (button_round_corner.xml, input_box.xml and login_button.xml). I moved them to the /layout folder and fixed the issues the change produced (only two).
3) Made Setup class inherit from MvxAppCompatSetup.
4) Added a RegisterAttribute over the LoginButton control. So the class definition looks like this:
using Android.Runtime;
...
namespace Xxx.Droid.Components
{
[Register(nameof(LoginButton))]
public class LoginButton : FrameLayout, IMvxNotifyPropertyChanged
{
...
}
}
And that's it! Probably (2) was not necessary, but leaving it here just in case.
It could be several things but it is probably the lack of some android support packages. Mainly the lack of Xamarin.Android.Support.Design gives that error. So check if you have that added and if not add it and it should solve your problem.
If it doesn't it's highly likely you lack some other android support packages

How to get my own ICultureSelector implementation injected in the framework

I have implemented my version of ICultureSelector, in a custom module.
Here it is a part of its definition (my question is not about the logic to select the culture; I tried with my own namespace and also with a namespace same as the namespace used in the module Orchard.Localization):
namespace Orchard.Localization.Selectors
{
[OrchardFeature("Orchard.Localization.CultureSelector")]
public class ShortRouteCultureSelector : ICultureSelector
{
public CultureSelectorResult GetCulture(HttpContextBase context)
{
...
I put a breakpoint in the method GetCurrentCulture of the class CurrentCultureWorkContext in the Orchard.Framework project, and I see that the variable IEnumerable _cultureSelectors contains all the implementation of ICultureSelector of the module Orchard.Localization but not my implementation, that is never used.
What am I missing?
Remove the OrchardFeature attribute or define your own feature name as Orchard.Localization.CultureSelector is defined in Orchard.Localization module already.

Orchard - Can't find the Resource defined in ResourceManifest.cs

I have a custom there, where I try to require some of my css and js files via the ResourceManifest.cs file - I keep into running a quite weird issue tough.
I get the following error:
a 'script' named 'FoundationScript' could not be found
This is my ResourceManifest.cs:
using Orchard.UI.Resources;
namespace Themes.TestTheme
{
public class ResourceManifest : IResourceManifestProvider
{
public void BuildManifest(ResourceManifestBuilder builder)
{
var manifest = builder.Add();
manifest.DefineStyle("Foundation").SetUrl("foundation.min.css");
manifest.DefineScript("FoundationScript").SetUrl("foundation.min.js");
}
}
}
In the Layout.cshtml, I have following:
#{
Script.Require("ShapesBase");
Script.Require("FoundationScript");
Style.Include("site.css");
Style.Require("Foundation");
}
What am I missing here?
The issue here is, that the project Themes has a problem with the dynamic compile mechanism of Orchard (i don't know what is wrong exactly) because it resides in folder Themes. Even if you define a class inside the Themes assembly, it will result in an error telling you there is no such class in that assembly.
solution :
Try re-generating your theme with /CreateProject:true and /IncludeInSolution:true parameters as follows:
codegen theme TestTheme /CreateProject:true /IncludeInSolution:true /BasedOn :TheThemeMachine
It will create your theme in a separate project and orchard will pick your registered ResourceManifest.
Hope this helps.

Resources