Using UserDialogs in Android - android

I'm stucked with usage of plugin Acr.UserDialogs in android app, based on MVVMCross.
In PCL project i used IUserDialog in viewmodel constructor injection.
I have installed Acr.UserDialogs package both in PCL and in Droid project, but when i run app, it throws:
In android, you must call UserDialogs.Init(Activity) from your first
activity OR UserDialogs.Init(App) from your custom application OR
provide a factory function to get the current top activity via
UserDialogs.Init(() => supply top activity)
I tryed to call in my viewModel:
UserDialogs.Init(this);
But Init is not recognized
And calling of UserDialogs.Instance.Loading ().Hide(); in app throws the same issue.
How it should be initialized in android project?
Upd: Final solution to workaround this looks like:
In PCL project App.cs add: Mvx.RegisterSingleton(() =>
UserDialogs.Instance);
In Your first loaded activity in OnCreate
add: UserDialogs.Init(() => this);

This error is very clearly. You can't initialize it in viewModel, You can only do that in your main activity.
FAQ
I'm getting a nullreferenceexception when using loading.
This happens when you run loading (or almost any dialog) from the
constructor of your page or viewmodel. The view hasn't been rendered
yet, therefore there is nothing to render to.
Android Initialization In your MainActivity
UserDialogs.Init(this);
OR UserDialogs.Init(() => provide your own top level activity provider)
OR MvvmCross - UserDialogs.Init(() => Mvx.Resolve<IMvxTopActivity>().Activity)
OR Xamarin.Forms - UserDialogs.Init(() => (Activity)Forms.Context)
GitHub docs.

Related

Android status bar show in Unty

I'm triyng to show the status bar in an Android phone using Unity. I have try this code:
void Start() {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
But an error appear;
Assets/Scenes/Control/control.cs(15,34): error CS0103: The name 'WindowManager' does not exist in the current context
Does I need to call or import another package? Some could help me with this detail. Thanks in advance.
You cannot use Android Java functions directly in Unity. You can only use whats available in Unity C Sharp. Unity doesn’t understand the method. Suggested workaround, use a ‘Slider’ UI element and manipulate it in a custom c sharp script. Complicated workaround create a custom Unity Plugin which calls the native Android method (possible but complex).

Xamarin Forms and Prism to native view - Navigating from a view in prism project to a view in shared project

My Project:
MyAppB (External Shared Project)
includes multiple views (xaml files) which extends from ContentPage
uses e.g. await Navigation.PushAsync(new Chat());
MyApplicationA (Code Sharing - .NET Standard 2.0)
is build with prism framework (Model-View-ViewModel)
uses e.g. await NavigationService.NavigateAsync("name", parameters);
MyApplicationA.Android
references both (MyApplicationA and MyAppB) -> Is this correct?
MyApplicationA.iOS
references both (MyApplicationA and MyAppB) -> Is this correct?
My Goal:
I want to navigate from a view or viewmodel in MyApplicationA to a view in MyAppB.
Fortunatly navigating to a view in MyAppB from a viewmodel in MyApplicationA is working.
I'm using a interface definition in MyApplicationA and calls it in the viewmodel.
The interface is implemented in the MyApplicationA.Android and MyApplicationA.iOS.
WORKS: To navigate i use: App.Current.MainPage = new NavigationPage(new MainPage(screenCaptureIntent)); // (the intent is the reason why i have to navigate from MyApplicationA to MyApplicationA.Android and then to MyAppB)
DONT WORK: Using await App.Current.MainPage.Navigation.PushAsync(new MainPage(screenCaptureIntent)); is not working and gives the following error:
PushAsync is not supported globally on Android, please use a NavigationPage.
But i have problems to go back from the view in MyAppB to the application in MyApplicationA e.g. a view which loads data, in best case it would be the last page in the navigation stack...
Does someone have a hint for me how to solve this? Am I doing it the right way? Or can i reference MyAppB in MyApplicationA - but what happens to the device specific code e.g. #if __IOS__
Thx
Daniel

MVVMCROSS Xamarin.Android 6.1.2 Library Navigation

could you help me to understand is it possible make navigation in platform library layer in last MvvmCross version.
My solution has the next structure:
Core Layer
Library Layer (Android Library)
WL (White Lable) Layer (a bunch of android apps)
All my necessary code for android apps placed in Library Layer, in WL layer I just change some resources and images.
Earlier I used MvvmCross 5.1.1 and custom presenter works fine for Me, but in new one MvvmCross 6.1.2 with default presenter doesn't, couldn't find View for ViewModel.
If i Move Activity from Library Layer in to any app in WL Layer it works fine.
[MvxActivityPresentation] doesn't work in Libraries project ???
In your Setup.cs you need to override your GetViewAssemblies and add the assembly where your Activity is:
public override IEnumerable<Assembly> GetViewAssemblies()
{
var viewsAssemblies = new List<Assembly>(base.GetViewAssemblies());
viewsAssemblies.Add(typeof(MyActivity).Assembly);
return viewsAssemblies;
}
Doing this you ensure that that assembly will be taken into account to find the View corresponding to your ViewModel
More info in Providing additional View and ViewModel Assemblies
HIH

React Native modules into an existing app

I've been working on adding react native to an existing app. I followed the guide on the official docs and after fixing some errors that popped up all was well.
Now I want to use react native components to talk to native code. There are a few use-cases that I need but the current one is that I have an AndroidToolbar and when clicking the navIcon I want to end the current Activity (I want to use native navigation). My thought was to create a native module and just simply call it from my react native code (natively calling onBackPressed). The problem is that when following the docs they suggest to add the package to getPackages function within your ReactApplication. Something like:
public class MainApplication extends Application implements ReactApplication {
...
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AnExampleReactPackage());
}
...
}
The problem is that if you follow the "Integration with existing apps" docs then you never create a ReactApplication. Instead you just create an Activity somewhere in your app and just start that activity somewhere in your app. If anyone can point me in the right direction for how to call native code when you have integrated into an existing app, that would be greatly appreciated.

Add window to Activity created by Titanium Module

I made a Activity using Titanium Mobile Module, and it has simple white background.
Can I pass a window (Titanium object) from this Activity to another js files to add (draw) new objects (like buttons) ?
Yes, you can.
If you are using Alloy for it, just do anything similar as
//index.js
function doClick(e) {
require('utils').createButton($.index);
}
And
//utils.js inside /lib
exports.createButton = function createButton(window){
var button = Ti.UI.createButton({
height:'20dp',
width:'20dp',
title:'Test'
});
window.add(button);
}
However, keep in mind, to your memory consumption, because you are sending a big object $.index as a local variable.

Categories

Resources